|
|
bda387 |
From 471d43cbfe99db1c8246fb863e3ce49b3403fc61 Mon Sep 17 00:00:00 2001
|
|
|
bda387 |
From: Vojtech Trefny <vtrefny@redhat.com>
|
|
|
bda387 |
Date: Wed, 11 Sep 2019 10:48:19 +0200
|
|
|
bda387 |
Subject: [PATCH] Fix util.detect_virt function
|
|
|
bda387 |
|
|
|
bda387 |
Fixed the systemd Manager object path, also get_property_sync
|
|
|
bda387 |
returns a tuple so we need to check its first element.
|
|
|
bda387 |
|
|
|
bda387 |
Resolves: rhbz#1676935
|
|
|
bda387 |
---
|
|
|
bda387 |
blivet/util.py | 8 ++++----
|
|
|
bda387 |
tests/formats_test/disklabel_test.py | 26 ++++++++++++++------------
|
|
|
bda387 |
tests/util_test.py | 4 ++++
|
|
|
bda387 |
3 files changed, 22 insertions(+), 16 deletions(-)
|
|
|
bda387 |
|
|
|
bda387 |
diff --git a/blivet/util.py b/blivet/util.py
|
|
|
bda387 |
index 2932e8b5..27468992 100644
|
|
|
bda387 |
--- a/blivet/util.py
|
|
|
bda387 |
+++ b/blivet/util.py
|
|
|
bda387 |
@@ -40,7 +40,7 @@ program_log_lock = Lock()
|
|
|
bda387 |
|
|
|
bda387 |
|
|
|
bda387 |
SYSTEMD_SERVICE = "org.freedesktop.systemd1"
|
|
|
bda387 |
-SYSTEMD_MANAGER_PATH = "/org/freedesktop/systemd1/Manager"
|
|
|
bda387 |
+SYSTEMD_MANAGER_PATH = "/org/freedesktop/systemd1"
|
|
|
bda387 |
SYSTEMD_MANAGER_IFACE = "org.freedesktop.systemd1.Manager"
|
|
|
bda387 |
VIRT_PROP_NAME = "Virtualization"
|
|
|
bda387 |
|
|
|
bda387 |
@@ -1115,6 +1115,6 @@ def detect_virt():
|
|
|
bda387 |
vm = safe_dbus.get_property_sync(SYSTEMD_SERVICE, SYSTEMD_MANAGER_PATH,
|
|
|
bda387 |
SYSTEMD_MANAGER_IFACE, VIRT_PROP_NAME)
|
|
|
bda387 |
except (safe_dbus.DBusCallError, safe_dbus.DBusPropertyError):
|
|
|
bda387 |
- vm = None
|
|
|
bda387 |
-
|
|
|
bda387 |
- return vm in ('qemu', 'kvm')
|
|
|
bda387 |
+ return False
|
|
|
bda387 |
+ else:
|
|
|
bda387 |
+ return vm[0] in ('qemu', 'kvm')
|
|
|
bda387 |
diff --git a/tests/formats_test/disklabel_test.py b/tests/formats_test/disklabel_test.py
|
|
|
bda387 |
index 4b105da6..94f3775f 100644
|
|
|
bda387 |
--- a/tests/formats_test/disklabel_test.py
|
|
|
bda387 |
+++ b/tests/formats_test/disklabel_test.py
|
|
|
bda387 |
@@ -163,16 +163,18 @@ class DiskLabelTestCase(unittest.TestCase):
|
|
|
bda387 |
arch.is_efi.return_value = False
|
|
|
bda387 |
|
|
|
bda387 |
arch.is_s390.return_value = True
|
|
|
bda387 |
- with mock.patch.object(dl, '_label_type_size_check') as size_check:
|
|
|
bda387 |
- size_check.return_value = True
|
|
|
bda387 |
- with mock.patch("blivet.formats.disklabel.blockdev.s390") as _s390:
|
|
|
bda387 |
- _s390.dasd_is_fba.return_value = False
|
|
|
bda387 |
- self.assertEqual(dl._get_best_label_type(), "msdos")
|
|
|
bda387 |
-
|
|
|
bda387 |
- _s390.dasd_is_fba.return_value = True
|
|
|
bda387 |
- self.assertEqual(dl._get_best_label_type(), "msdos")
|
|
|
bda387 |
-
|
|
|
bda387 |
- _s390.dasd_is_fba.return_value = False
|
|
|
bda387 |
- dl._parted_device.type = parted.DEVICE_DASD
|
|
|
bda387 |
- self.assertEqual(dl._get_best_label_type(), "dasd")
|
|
|
bda387 |
+ with mock.patch('blivet.util.detect_virt') as virt:
|
|
|
bda387 |
+ virt.return_value = False
|
|
|
bda387 |
+ with mock.patch.object(dl, '_label_type_size_check') as size_check:
|
|
|
bda387 |
+ size_check.return_value = True
|
|
|
bda387 |
+ with mock.patch("blivet.formats.disklabel.blockdev.s390") as _s390:
|
|
|
bda387 |
+ _s390.dasd_is_fba.return_value = False
|
|
|
bda387 |
+ self.assertEqual(dl._get_best_label_type(), "msdos")
|
|
|
bda387 |
+
|
|
|
bda387 |
+ _s390.dasd_is_fba.return_value = True
|
|
|
bda387 |
+ self.assertEqual(dl._get_best_label_type(), "msdos")
|
|
|
bda387 |
+
|
|
|
bda387 |
+ _s390.dasd_is_fba.return_value = False
|
|
|
bda387 |
+ dl._parted_device.type = parted.DEVICE_DASD
|
|
|
bda387 |
+ self.assertEqual(dl._get_best_label_type(), "dasd")
|
|
|
bda387 |
arch.is_s390.return_value = False
|
|
|
bda387 |
diff --git a/tests/util_test.py b/tests/util_test.py
|
|
|
bda387 |
index 5fa3070e..9a2ff492 100644
|
|
|
bda387 |
--- a/tests/util_test.py
|
|
|
bda387 |
+++ b/tests/util_test.py
|
|
|
bda387 |
@@ -37,6 +37,10 @@ class MiscTest(unittest.TestCase):
|
|
|
bda387 |
# real deduplication
|
|
|
bda387 |
self.assertEqual([1, 2, 3, 4, 5, 6], util.dedup_list([1, 2, 3, 4, 2, 2, 2, 1, 3, 5, 3, 6, 6, 2, 3, 1, 5]))
|
|
|
bda387 |
|
|
|
bda387 |
+ def test_detect_virt(self):
|
|
|
bda387 |
+ in_virt = not util.run_program(["systemd-detect-virt", "--vm"])
|
|
|
bda387 |
+ self.assertEqual(util.detect_virt(), in_virt)
|
|
|
bda387 |
+
|
|
|
bda387 |
|
|
|
bda387 |
class TestDefaultNamedtuple(unittest.TestCase):
|
|
|
bda387 |
def test_default_namedtuple(self):
|
|
|
bda387 |
--
|
|
|
bda387 |
2.20.1
|
|
|
bda387 |
|