示例#1
0
    def test_get_related_disks(self):
        tree = DeviceTree()

        sda = DiskDevice("sda", size=Size('300g'))
        sdb = DiskDevice("sdb", size=Size('300g'))
        sdc = DiskDevice("sdc", size=Size('300G'))

        tree._add_device(sda)
        tree._add_device(sdb)
        tree._add_device(sdc)

        self.assertTrue(sda in tree.devices)
        self.assertTrue(sdb in tree.devices)
        self.assertTrue(sdc in tree.devices)

        sda.format = get_format("lvmpv", device=sda.path)
        sdb.format = get_format("lvmpv", device=sdb.path)
        vg = LVMVolumeGroupDevice("relvg", parents=[sda, sdb])
        tree._add_device(vg)

        self.assertEqual(tree.get_related_disks(sda), set([sda, sdb]))
        self.assertEqual(tree.get_related_disks(sdb), set([sda, sdb]))
        self.assertEqual(tree.get_related_disks(sdc), set())
        tree.hide(sda)
        self.assertEqual(tree.get_related_disks(sda), set([sda, sdb]))
        self.assertEqual(tree.get_related_disks(sdb), set([sda, sdb]))
        tree.hide(sdb)
        self.assertEqual(tree.get_related_disks(sda), set([sda, sdb]))
        self.assertEqual(tree.get_related_disks(sdb), set([sda, sdb]))
        tree.unhide(sda)
        self.assertEqual(tree.get_related_disks(sda), set([sda, sdb]))
        self.assertEqual(tree.get_related_disks(sdb), set([sda, sdb]))
示例#2
0
    def test_get_related_disks(self):
        tree = DeviceTree()

        sda = DiskDevice("sda", size=Size('300g'))
        sdb = DiskDevice("sdb", size=Size('300g'))
        sdc = DiskDevice("sdc", size=Size('300G'))

        tree._add_device(sda)
        tree._add_device(sdb)
        tree._add_device(sdc)

        self.assertTrue(sda in tree.devices)
        self.assertTrue(sdb in tree.devices)
        self.assertTrue(sdc in tree.devices)

        sda.format = get_format("lvmpv", device=sda.path)
        sdb.format = get_format("lvmpv", device=sdb.path)
        vg = LVMVolumeGroupDevice("relvg", parents=[sda, sdb])
        tree._add_device(vg)

        self.assertEqual(tree.get_related_disks(sda), set([sda, sdb]))
        self.assertEqual(tree.get_related_disks(sdb), set([sda, sdb]))
        self.assertEqual(tree.get_related_disks(sdc), set())
        tree.hide(sda)
        self.assertEqual(tree.get_related_disks(sda), set([sda, sdb]))
        self.assertEqual(tree.get_related_disks(sdb), set([sda, sdb]))
        tree.hide(sdb)
        self.assertEqual(tree.get_related_disks(sda), set([sda, sdb]))
        self.assertEqual(tree.get_related_disks(sdb), set([sda, sdb]))
        tree.unhide(sda)
        self.assertEqual(tree.get_related_disks(sda), set([sda, sdb]))
        self.assertEqual(tree.get_related_disks(sdb), set([sda, sdb]))
示例#3
0
    def test_device_name(self):
        # check that devicetree.names property contains all device's names

        # mock lvs_info to avoid blockdev call allowing run as non-root
        with patch.object(LVsInfo, 'cache',
                          new_callable=PropertyMock) as mock_lvs_cache:
            mock_lvs_cache.return_value = {"sdmock": "dummy"}

            tree = DeviceTree()
            dev_names = ["sda", "sdb", "sdc"]

            for dev_name in dev_names:
                dev = DiskDevice(dev_name)
                tree._add_device(dev)
                self.assertTrue(dev in tree.devices)

            # frobnicate a bit with the hidden status of the devices:
            # * hide sda
            # * hide and unhide again sdb
            # * leave sdc unchanged
            tree.hide(tree.get_device_by_name("sda"))
            tree.hide(tree.get_device_by_name("sdb"))
            tree.unhide(tree.get_device_by_name("sdb", hidden=True))

            # some lvs names may be already present in the system (mocked)
            lv_info = list(lvs_info.cache.keys())

            # all devices should still be present in the tree.names
            self.assertEqual(sorted(tree.names), sorted(lv_info + dev_names))
示例#4
0
    def test_device_name(self):
        # check that devicetree.names property contains all device's names

        # mock lvs_info to avoid blockdev call allowing run as non-root
        with patch.object(LVsInfo, 'cache',
                          new_callable=PropertyMock) as mock_lvs_cache:
            mock_lvs_cache.return_value = {
                "sdmock": "dummy",
                "testvg-testlv": "dummy"
            }

            tree = DeviceTree()
            dev_names = ["sda", "sdb", "sdc"]

            for dev_name in dev_names:
                dev = DiskDevice(dev_name, size=Size("1 GiB"))
                tree._add_device(dev)
                self.assertTrue(dev in tree.devices)
                self.assertTrue(dev.name in tree.names)

            dev.format = get_format("lvmpv", device=dev.path)
            vg = LVMVolumeGroupDevice("testvg", parents=[dev])
            tree._add_device(vg)
            dev_names.append(vg.name)

            lv = LVMLogicalVolumeDevice("testlv", parents=[vg])
            tree._add_device(lv)
            dev_names.append(lv.name)

            # frobnicate a bit with the hidden status of the devices:
            # * hide sda
            # * hide and unhide again sdb
            # * leave sdc unchanged
            tree.hide(tree.get_device_by_name("sda"))
            tree.hide(tree.get_device_by_name("sdb"))
            tree.unhide(tree.get_device_by_name("sdb", hidden=True))

            # some lvs names may be already present in the system (mocked)
            lv_info = list(lvs_info.cache.keys())

            # all devices should still be present in the tree.names
            self.assertEqual(set(tree.names), set(lv_info + dev_names))

            # "remove" the LV, it should no longer be in the list
            tree.actions._actions.append(
                Mock(device=lv,
                     type=ACTION_TYPE_DESTROY,
                     obj=ACTION_OBJECT_DEVICE))
            tree._remove_device(lv)
            self.assertFalse(lv.name in tree.names)
示例#5
0
    def test_get_device_by_name(self):
        dt = DeviceTree()

        dev1 = StorageDevice("dev1", exists=False, parents=[])
        dev2 = StorageDevice("dev2", exists=False, parents=[dev1])
        dt._add_device(dev1)
        dt._add_device(dev2)

        self.assertIsNone(dt.get_device_by_name("dev3"))
        self.assertEqual(dt.get_device_by_name("dev2"), dev2)
        self.assertEqual(dt.get_device_by_name("dev1"), dev1)

        dev2.complete = False
        self.assertEqual(dt.get_device_by_name("dev2"), None)
        self.assertEqual(dt.get_device_by_name("dev2", incomplete=True), dev2)

        dev3 = StorageDevice("dev3", exists=True, parents=[])
        dt._add_device(dev3)
        dt.hide(dev3)
        self.assertIsNone(dt.get_device_by_name("dev3"))
        self.assertEqual(dt.get_device_by_name("dev3", hidden=True), dev3)
示例#6
0
    def test_get_device_by_name(self):
        dt = DeviceTree()

        dev1 = StorageDevice("dev1", exists=False, parents=[])
        dev2 = StorageDevice("dev2", exists=False, parents=[dev1])
        dt._add_device(dev1)
        dt._add_device(dev2)

        self.assertIsNone(dt.get_device_by_name("dev3"))
        self.assertEqual(dt.get_device_by_name("dev2"), dev2)
        self.assertEqual(dt.get_device_by_name("dev1"), dev1)

        dev2.complete = False
        self.assertEqual(dt.get_device_by_name("dev2"), None)
        self.assertEqual(dt.get_device_by_name("dev2", incomplete=True), dev2)

        dev3 = StorageDevice("dev3", exists=True, parents=[])
        dt._add_device(dev3)
        dt.hide(dev3)
        self.assertIsNone(dt.get_device_by_name("dev3"))
        self.assertEqual(dt.get_device_by_name("dev3", hidden=True), dev3)