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]))
def test_validate_container_name(self): """Test ValidateContainerName.""" dev1 = DiskDevice( "dev1" ) self._add_device(dev1) report = self.interface.ValidateContainerName("dev1") self._check_report(report, "Name is already in use.") report = self.interface.ValidateContainerName("_my/contain$er") self._check_report(report, "Invalid container name.") report = self.interface.ValidateContainerName("my_container") self._check_report(report, None)
def test_collect_unused_devices(self): """Test CollectUnusedDevices.""" dev1 = DiskDevice("dev1", fmt=get_format("disklabel")) dev2 = StorageDevice("dev2", parents=[dev1], fmt=get_format("ext4")) dev3 = StorageDevice("dev3", parents=[dev1], fmt=get_format("ext4")) dev4 = StorageDevice("dev4", parents=[dev1], fmt=get_format("ext4", mountpoint="/")) self._add_device(dev1) self._add_device(dev2) self._add_device(dev3) self._add_device(dev4) assert self.interface.CollectUnusedDevices() == ["dev2", "dev3"]
def test_resize(self): an_fs = self._fs_class() if not an_fs.formattable: self.skipTest("can not create filesystem %s" % an_fs.name) an_fs.device = self.loop_devices[0] self.assertIsNone(an_fs.create()) an_fs.update_size_info() self._test_sizes(an_fs) # CHECKME: target size is still 0 after updated_size_info is called. self.assertEqual(an_fs.size, Size(0) if an_fs.resizable else an_fs._size) if not self.can_resize(an_fs): self.assertFalse(an_fs.resizable) # Not resizable, so can not do resizing actions. with self.assertRaises(DeviceFormatError): an_fs.target_size = Size("64 MiB") with self.assertRaises(DeviceFormatError): an_fs.do_resize() else: disk = DiskDevice(os.path.basename(self.loop_devices[0])) part = self._create_partition(disk, Size("50 MiB")) an_fs = self._fs_class() an_fs.device = part.path self.assertIsNone(an_fs.create()) an_fs.update_size_info() self.assertTrue(an_fs.resizable) # grow the partition so we can grow the filesystem self._remove_partition(part, disk) part = self._create_partition(disk, size=part.size + Size("40 MiB")) # Try a reasonable target size TARGET_SIZE = Size("64 MiB") an_fs.target_size = TARGET_SIZE self.assertEqual(an_fs.target_size, TARGET_SIZE) self.assertNotEqual(an_fs._size, TARGET_SIZE) self.assertIsNone(an_fs.do_resize()) ACTUAL_SIZE = TARGET_SIZE.round_to_nearest(an_fs._resize.unit, rounding=ROUND_DOWN) self.assertEqual(an_fs.size, ACTUAL_SIZE) self.assertEqual(an_fs._size, ACTUAL_SIZE) self._test_sizes(an_fs) # and no errors should occur when checking self.assertIsNone(an_fs.do_check()) self._remove_partition(part, disk)
def get_device_data_test(self): """Test GetDeviceData.""" self._add_device( DiskDevice("dev1", fmt=get_format("ext4"), size=Size("10 MiB"), serial="SERIAL_ID", vendor="VENDOR_ID", model="MODEL_ID", bus="BUS_ID", wwn="0x0000000000000000", uuid="1234-56-7890")) self.assertEqual( self.interface.GetDeviceData("dev1"), { 'type': get_variant(Str, 'disk'), 'name': get_variant(Str, 'dev1'), 'path': get_variant(Str, '/dev/dev1'), 'size': get_variant(UInt64, Size("10 MiB").get_bytes()), 'is-disk': get_variant(Bool, True), 'protected': get_variant(Bool, False), 'removable': get_variant(Bool, False), 'parents': get_variant(List[Str], []), 'children': get_variant(List[Str], []), 'attrs': get_variant( Dict[Str, Str], { "serial": "SERIAL_ID", "vendor": "VENDOR_ID", "model": "MODEL_ID", "bus": "BUS_ID", "wwn": "0x0000000000000000", "uuid": "1234-56-7890" }), 'description': get_variant(Str, "VENDOR_ID MODEL_ID 0x0000000000000000") })
def add_device_test(self): """Test AddDevice.""" self._add_device( DiskDevice("dev1", exists=True, size=Size("15 GiB"), fmt=get_format("disklabel"))) request = DeviceFactoryRequest() request.device_type = DEVICE_TYPE_LVM request.mount_point = "/home" request.size = Size("5 GiB") request.disks = ["dev1"] self.storage.factory_device = Mock() self.interface.AddDevice(DeviceFactoryRequest.to_structure(request)) self.storage.factory_device.assert_called_once()
def test_get_devices(self): """Test GetDevices.""" self.assertEqual(self.interface.GetDevices(), []) self._add_device(DiskDevice( "dev1", fmt=get_format("ext4"), size=Size("10 GiB") )) self._add_device(StorageDevice( "dev2", fmt=get_format("ext4"), size=Size("10 GiB") )) self.assertEqual(self.interface.GetDevices(), ["dev1", "dev2"])
def generate_device_factory_permissions_test(self): """Test GenerateDeviceFactoryPermissions.""" dev1 = DiskDevice("dev1", fmt=get_format("disklabel"), size=Size("10 GiB"), exists=True) dev2 = PartitionDevice("dev2", size=Size("5 GiB"), parents=[dev1], fmt=get_format("ext4", mountpoint="/", label="root")) self._add_device(dev1) self._add_device(dev2) request = self.interface.GenerateDeviceFactoryRequest("dev1") permissions = self.interface.GenerateDeviceFactoryPermissions(request) self.assertEqual( get_native(permissions), { 'mount-point': False, 'reformat': True, 'format-type': True, 'label': True, 'device-type': False, 'device-name': False, 'device-size': False, 'device-encrypted': True, 'device-raid-level': False, }) request = self.interface.GenerateDeviceFactoryRequest("dev2") permissions = self.interface.GenerateDeviceFactoryPermissions(request) self.assertEqual( get_native(permissions), { 'mount-point': True, 'reformat': False, 'format-type': True, 'label': True, 'device-type': True, 'device-name': False, 'device-size': True, 'device-encrypted': True, 'device-raid-level': True, })
def is_device_editable_test(self): """Test IsDeviceEditable.""" dev1 = StorageDevice( "dev1", fmt=get_format("ext4"), size=Size("10 GiB") ) dev2 = DiskDevice( "dev2", fmt=get_format("disklabel"), size=Size("10 GiB") ) self._add_device(dev1) self._add_device(dev2) self.assertEqual(self.interface.IsDeviceEditable("dev1"), False) self.assertEqual(self.interface.IsDeviceEditable("dev2"), True)
def fix_btrfs_test(self, configure, install, conf): """Test the final configuration of the boot loader.""" storage = create_storage() sysroot = "/tmp/sysroot" version = "4.17.7-200.fc28.x86_64" conf.target.is_directory = True FixBTRFSBootloaderTask(storage, BootloaderMode.ENABLED, [version], sysroot).run() configure.assert_not_called() install.assert_not_called() conf.target.is_directory = False FixBTRFSBootloaderTask(storage, BootloaderMode.DISABLED, [version], sysroot).run() configure.assert_not_called() install.assert_not_called() conf.target.is_directory = False FixBTRFSBootloaderTask(storage, BootloaderMode.ENABLED, [version], sysroot).run() configure.assert_not_called() install.assert_not_called() dev1 = DiskDevice("dev1", fmt=get_format("disklabel"), size=Size("10 GiB")) storage.devicetree._add_device(dev1) dev2 = BTRFSDevice("dev2", fmt=get_format("btrfs", mountpoint="/"), size=Size("5 GiB"), parents=[dev1]) storage.devicetree._add_device(dev2) # Make the btrfs format mountable. dev2.format._mount = Mock(available=True) conf.target.is_directory = False FixBTRFSBootloaderTask(storage, BootloaderMode.ENABLED, [version], sysroot).run() configure.assert_called_once_with(storage, BootloaderMode.ENABLED, [version], sysroot) install.assert_called_once_with(storage, BootloaderMode.ENABLED)
def get_actions_test(self): """Test GetActions.""" self.assertEqual(self.interface.GetActions(), []) self._add_device(DiskDevice( "dev1", fmt=get_format("ext4"), size=Size("10 MiB"), )) device = self.storage.devicetree.get_device_by_name("dev1") self.storage.destroy_device(device) self.assertEqual(self.interface.GetActions(), [{ 'action-type': get_variant(Str, 'destroy'), 'action-object': get_variant(Str, 'device'), 'device-name': get_variant(Str, 'dev1'), 'description': get_variant(Str, 'destroy device'), }])
def gather_unusable_requests_test(self): """Test GatherRequests with unusable devices.""" self.module.on_storage_changed(create_storage()) # Add device with no size. self._add_device(StorageDevice("dev1", size=Size(0))) self.assertEqual(self.interface.GatherRequests(), []) # Add protected device. device = StorageDevice("dev2", size=Size("1 GiB")) device.protected = True self._add_device(device) self.assertEqual(self.interface.GatherRequests(), []) # Add unselected disk. self._add_device(DiskDevice("dev3", size=Size("1 GiB"))) self.module.on_selected_disks_changed(["dev1", "dev2"]) self.assertEqual(self.interface.GatherRequests(), [])
def generate_device_factory_request_test(self, blockdev): device = StorageDevice("dev1") with self.assertRaises(UnsupportedDeviceError): utils.generate_device_factory_request(self.storage, device) disk = DiskDevice("dev2") request = utils.generate_device_factory_request(self.storage, disk) self.assertEqual(DeviceFactoryRequest.to_structure(request), { "device-spec": get_variant(Str, "dev2"), "disks": get_variant(List[Str], ["dev2"]), "mount-point": get_variant(Str, ""), "reformat": get_variant(Bool, False), "format-type": get_variant(Str, ""), "label": get_variant(Str, ""), "luks-version": get_variant(Str, ""), "device-type": get_variant(Int, devicefactory.DEVICE_TYPE_DISK), "device-name": get_variant(Str, "dev2"), "device-size": get_variant(UInt64, 0), "device-encrypted": get_variant(Bool, False), "device-raid-level": get_variant(Str, ""), "container-spec": get_variant(Str, ""), "container-name": get_variant(Str, ""), "container-size-policy": get_variant(Int64, devicefactory.SIZE_POLICY_AUTO), "container-encrypted": get_variant(Bool, False), "container-raid-level": get_variant(Str, ""), }) partition = PartitionDevice( "dev3", size=Size("5 GiB"), parents=[disk], fmt=get_format("ext4", mountpoint="/", label="root") ) request = utils.generate_device_factory_request(self.storage, partition) self.assertEqual(DeviceFactoryRequest.to_structure(request), { "device-spec": get_variant(Str, "dev3"), "disks": get_variant(List[Str], ["dev2"]), "mount-point": get_variant(Str, "/"), "reformat": get_variant(Bool, True), "format-type": get_variant(Str, "ext4"), "label": get_variant(Str, "root"), "luks-version": get_variant(Str, ""), "device-type": get_variant(Int, devicefactory.DEVICE_TYPE_PARTITION), "device-name": get_variant(Str, "dev3"), "device-size": get_variant(UInt64, Size("5 GiB").get_bytes()), "device-encrypted": get_variant(Bool, False), "device-raid-level": get_variant(Str, ""), "container-spec": get_variant(Str, ""), "container-name": get_variant(Str, ""), "container-size-policy": get_variant(Int64, devicefactory.SIZE_POLICY_AUTO), "container-encrypted": get_variant(Bool, False), "container-raid-level": get_variant(Str, ""), }) pv1 = StorageDevice( "pv1", size=Size("1025 MiB"), fmt=get_format("lvmpv") ) pv2 = StorageDevice( "pv2", size=Size("513 MiB"), fmt=get_format("lvmpv") ) vg = LVMVolumeGroupDevice( "testvg", parents=[pv1, pv2] ) lv = LVMLogicalVolumeDevice( "testlv", size=Size("512 MiB"), parents=[vg], fmt=get_format("xfs"), exists=False, seg_type="raid1", pvs=[pv1, pv2] ) request = utils.generate_device_factory_request(self.storage, lv) self.assertEqual(DeviceFactoryRequest.to_structure(request), { "device-spec": get_variant(Str, "testvg-testlv"), "disks": get_variant(List[Str], []), "mount-point": get_variant(Str, ""), "reformat": get_variant(Bool, True), "format-type": get_variant(Str, "xfs"), "label": get_variant(Str, ""), "luks-version": get_variant(Str, ""), "device-type": get_variant(Int, devicefactory.DEVICE_TYPE_LVM), "device-name": get_variant(Str, "testlv"), "device-size": get_variant(UInt64, Size("508 MiB").get_bytes()), "device-encrypted": get_variant(Bool, False), "device-raid-level": get_variant(Str, ""), "container-spec": get_variant(Str, "testvg"), "container-name": get_variant(Str, "testvg"), "container-size-policy": get_variant(Int64, Size("1.5 GiB")), "container-encrypted": get_variant(Bool, False), "container-raid-level": get_variant(Str, ""), })
def generate_device_factory_request_partition_test(self, blockdev): disk = DiskDevice("dev2") request = utils.generate_device_factory_request(self.storage, disk) self.assertEqual( DeviceFactoryRequest.to_structure(request), { "device-spec": get_variant(Str, "dev2"), "disks": get_variant(List[Str], ["dev2"]), "mount-point": get_variant(Str, ""), "reformat": get_variant(Bool, False), "format-type": get_variant(Str, ""), "label": get_variant(Str, ""), "luks-version": get_variant(Str, ""), "device-type": get_variant(Int, devicefactory.DEVICE_TYPE_DISK), "device-name": get_variant(Str, "dev2"), "device-size": get_variant(UInt64, 0), "device-encrypted": get_variant(Bool, False), "device-raid-level": get_variant(Str, ""), "container-spec": get_variant(Str, ""), "container-name": get_variant(Str, ""), "container-size-policy": get_variant(Int64, devicefactory.SIZE_POLICY_AUTO), "container-encrypted": get_variant(Bool, False), "container-raid-level": get_variant(Str, ""), }) partition = PartitionDevice("dev3", size=Size("5 GiB"), parents=[disk], fmt=get_format("ext4", mountpoint="/", label="root")) request = utils.generate_device_factory_request( self.storage, partition) self.assertEqual( DeviceFactoryRequest.to_structure(request), { "device-spec": get_variant(Str, "dev3"), "disks": get_variant(List[Str], ["dev2"]), "mount-point": get_variant(Str, "/"), "reformat": get_variant(Bool, True), "format-type": get_variant(Str, "ext4"), "label": get_variant(Str, "root"), "luks-version": get_variant(Str, ""), "device-type": get_variant(Int, devicefactory.DEVICE_TYPE_PARTITION), "device-name": get_variant(Str, "dev3"), "device-size": get_variant(UInt64, Size("5 GiB").get_bytes()), "device-encrypted": get_variant(Bool, False), "device-raid-level": get_variant(Str, ""), "container-spec": get_variant(Str, ""), "container-name": get_variant(Str, ""), "container-size-policy": get_variant(Int64, devicefactory.SIZE_POLICY_AUTO), "container-encrypted": get_variant(Bool, False), "container-raid-level": get_variant(Str, ""), })
def setUp(self): """Create some device objects to test with. This sets up two disks (sda, sdb). The first partition of each is a biosboot partition. The second partitions comprise a RAID1 array formatted as /boot. sda additionally contains a third partition formatted as ext4. """ super(GRUBRaidSimpleTest, self).setUp() # Make some disks self.sda = DiskDevice(name="sda", size=Size("100 GiB")) self.sda.format = get_format("disklabel") self.sdb = DiskDevice(name="sdb", size=Size("100 GiB")) self.sdb.format = get_format("disklabel") # Set up biosboot partitions, an mdarray for /boot, and a btrfs array on sda + sdb. # Start with the partitions self.sda1 = PartitionDevice(name="sda1", parents=[self.sda], size=Size("1 MiB")) self.sda1.format = get_format("biosboot") self.sda2 = PartitionDevice(name="sda2", parents=[self.sda], size=Size("500 MiB")) self.sda2.format = get_format("mdmember") self.sda4 = PartitionDevice(name="sda4", parents=[self.sda], size=Size("500 MiB")) self.sda4.format = get_format("btrfs") self.sdb1 = PartitionDevice(name="sdb1", parents=[self.sdb], size=Size("1 MiB")) self.sdb1.format = get_format("biosboot") self.sdb2 = PartitionDevice(name="sdb2", parents=[self.sdb], size=Size("500 MiB")) self.sdb2.format = get_format("mdmember") self.sdb4 = PartitionDevice(name="sdb4", parents=[self.sdb], size=Size("4 GiB")) self.sdb4.format = get_format("btrfs") # Add an extra partition for /boot on not-RAID self.sda3 = PartitionDevice(name="sda3", parents=[self.sda], size=Size("500 MiB")) self.sda3.format = get_format("ext4", mountpoint="/boot") # Pretend that the partitions are real with real parent disks for part in (self.sda1, self.sda2, self.sda3, self.sda4, self.sdb1, self.sdb2, self.sdb4): part.parents = part.req_disks self.boot_md = MDRaidArrayDevice(name="md1", size=Size("500 MiB"), parents=[self.sda2, self.sdb2], level=1, member_devices=2, total_devices=2) self.boot_md.format = get_format("ext4", mountpoint="/boot") # Set up the btrfs raid1 volume with a subvolume for /boot self.btrfs_volume = BTRFSVolumeDevice(parents=[self.sda4, self.sdb4], data_level=RAID1) self.btrfs_volume.format = get_format("btrfs") self.boot_btrfs = BTRFSSubVolumeDevice(parents=[self.btrfs_volume]) self.boot_btrfs.format = get_format("btrfs", mountpoint="/boot") self.grub = GRUB2()
def setUp(self): self.md_chunk_size = mdraid.MD_CHUNK_SIZE mdraid.MD_CHUNK_SIZE = Size("1 MiB") self.get_superblock_size = MDRaidArrayDevice.get_superblock_size MDRaidArrayDevice.get_superblock_size = lambda a, s: Size(0) self.addCleanup(self._clean_up) parents = [DiskDevice("name1", fmt=get_format("mdmember"))] self.dev1 = MDContainerDevice("dev1", level="container", parents=parents, total_devices=1, member_devices=1) parents = [ DiskDevice("name1", fmt=get_format("mdmember"), size=Size("1 GiB")), DiskDevice("name2", fmt=get_format("mdmember"), size=Size("1 GiB")) ] self.dev2 = MDRaidArrayDevice("dev2", level="raid0", parents=parents, total_devices=2, member_devices=2) parents = [ DiskDevice("name1", fmt=get_format("mdmember")), DiskDevice("name2", fmt=get_format("mdmember")) ] self.dev3 = MDRaidArrayDevice("dev3", level="raid1", parents=parents) parents = [ DiskDevice("name1", fmt=get_format("mdmember")), DiskDevice("name2", fmt=get_format("mdmember")), DiskDevice("name3", fmt=get_format("mdmember")) ] self.dev4 = MDRaidArrayDevice("dev4", level="raid4", parents=parents) parents = [ DiskDevice("name1", fmt=get_format("mdmember")), DiskDevice("name2", fmt=get_format("mdmember")), DiskDevice("name3", fmt=get_format("mdmember")) ] self.dev5 = MDRaidArrayDevice("dev5", level="raid5", parents=parents) parents = [ DiskDevice("name1", fmt=get_format("mdmember")), DiskDevice("name2", fmt=get_format("mdmember")), DiskDevice("name3", fmt=get_format("mdmember")), DiskDevice("name4", fmt=get_format("mdmember")) ] self.dev6 = MDRaidArrayDevice("dev6", level="raid6", parents=parents) parents = [ DiskDevice("name1", fmt=get_format("mdmember")), DiskDevice("name2", fmt=get_format("mdmember")), DiskDevice("name3", fmt=get_format("mdmember")), DiskDevice("name4", fmt=get_format("mdmember")) ] self.dev7 = MDRaidArrayDevice("dev7", level="raid10", parents=parents) self.dev8 = MDRaidArrayDevice("dev8", level=1, exists=True) parents_1 = [ DiskDevice("name1", fmt=get_format("mdmember")), DiskDevice("name2", fmt=get_format("mdmember")) ] dev_1 = MDContainerDevice("parent", level="container", parents=parents_1, total_devices=2, member_devices=2, exists=True) self.dev9 = MDBiosRaidArrayDevice("dev9", level="raid0", member_devices=1, parents=[dev_1], total_devices=1, exists=True) parents = [ DiskDevice("name1", fmt=get_format("mdmember")), DiskDevice("name2", fmt=get_format("mdmember")) ] self.dev10 = MDRaidArrayDevice("dev10", level="raid0", parents=parents, size=Size("32 MiB")) parents_1 = [ DiskDevice("name1", fmt=get_format("mdmember")), DiskDevice("name2", fmt=get_format("mdmember")) ] dev_1 = MDContainerDevice("parent", level="container", parents=parents, total_devices=2, member_devices=2) self.dev11 = MDBiosRaidArrayDevice("dev11", level=1, exists=True, parents=[dev_1], size=Size("32 MiB")) self.dev13 = MDRaidArrayDevice( "dev13", level=0, member_devices=2, parents=[ Mock(**{ "size": Size("4 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("2 MiB"), "format": get_format("mdmember") }) ], size=Size("32 MiB"), total_devices=2) self.dev14 = MDRaidArrayDevice( "dev14", level=4, member_devices=3, parents=[ Mock(**{ "size": Size("4 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("2 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("2 MiB"), "format": get_format("mdmember") }) ], total_devices=3) self.dev15 = MDRaidArrayDevice( "dev15", level=5, member_devices=3, parents=[ Mock(**{ "size": Size("4 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("2 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("2 MiB"), "format": get_format("mdmember") }) ], total_devices=3) self.dev16 = MDRaidArrayDevice( "dev16", level=6, member_devices=4, parents=[ Mock(**{ "size": Size("4 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("4 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("2 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("2 MiB"), "format": get_format("mdmember") }) ], total_devices=4) self.dev17 = MDRaidArrayDevice( "dev17", level=10, member_devices=4, parents=[ Mock(**{ "size": Size("4 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("4 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("2 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("2 MiB"), "format": get_format("mdmember") }) ], total_devices=4) self.dev18 = MDRaidArrayDevice( "dev18", level=10, member_devices=4, parents=[ Mock(**{ "size": Size("4 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("4 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("2 MiB"), "format": get_format("mdmember") }), Mock(**{ "size": Size("2 MiB"), "format": get_format("mdmember") }) ], total_devices=5) parents = [ DiskDevice("name1", fmt=get_format("mdmember")), DiskDevice("name2", fmt=get_format("mdmember")) ] self.dev19 = MDRaidArrayDevice( "dev19", level="raid1", parents=parents, uuid='3386ff85-f501-2621-4a43-5f061eb47236') parents = [ DiskDevice("name1", fmt=get_format("mdmember")), DiskDevice("name2", fmt=get_format("mdmember")) ] self.dev20 = MDRaidArrayDevice("dev20", level="raid1", parents=parents, uuid='Just-pretending')
def test_expand_taglist(self): tree = DeviceTree() sda = DiskDevice("sda") sdb = DiskDevice("sdb") sdc = DiskDevice("sdc") sdd = DiskDevice("sdd") tree._add_device(sda) tree._add_device(sdb) tree._add_device(sdc) tree._add_device(sdd) sda.tags = {Tags.remote} sdb.tags = {Tags.ssd} sdc.tags = {Tags.local, Tags.ssd} sdd.tags = set() self.assertEqual(tree.expand_taglist(["sda", "sdb"]), {"sda", "sdb"}) self.assertEqual(tree.expand_taglist(["@local"]), {"sdc"}) self.assertEqual(tree.expand_taglist(["@ssd"]), {"sdb", "sdc"}) self.assertEqual(tree.expand_taglist(["@ssd", "sdd", "@local"]), {"sdb", "sdc", "sdd"}) with self.assertRaises(ValueError): tree.expand_taglist(["sdd", "@invalid_tag"])
def test_get_actions(self): """Test GetActions.""" self.assertEqual(self.interface.GetActions(), []) dev1 = DiskDevice( "dev1", fmt=get_format("disklabel"), size=Size("1 GiB"), vendor="VENDOR", model="MODEL" ) self._add_device(dev1) self.storage.initialize_disk(dev1) dev1.format._label_type = "msdos" action_1 = { 'action-type': 'create', 'action-description': 'create format', 'object-type': 'format', 'object-description': 'partition table (MSDOS)', 'device-name': 'dev1', 'device-description': 'VENDOR MODEL (dev1)', 'attrs': {}, } self.assertEqual(get_native(self.interface.GetActions()), [ action_1 ]) dev2 = StorageDevice( "dev2", fmt=get_format("ext4", mountpoint="/boot"), size=Size("500 MiB"), serial="SERIAL", exists=True ) self._add_device(dev2) self.storage.destroy_device(dev2) action_2 = { 'action-type': 'destroy', 'action-description': 'destroy device', 'object-type': 'device', 'object-description': 'blivet', 'device-name': 'dev2', 'device-description': 'dev2', 'attrs': { 'serial': 'SERIAL', 'mount-point': '/boot' }, } self.assertEqual(get_native(self.interface.GetActions()), [ action_2, action_1 ]) dev3 = PartitionDevice( "dev3", fmt=get_format("ext4", mountpoint="/home"), size=Size("500 MiB"), parents=[dev1] ) self.storage.create_device(dev3) dev3.disk = dev1 action_3 = { 'action-type': 'create', 'action-description': 'create device', 'object-type': 'device', 'object-description': 'partition', 'device-name': 'dev3', 'device-description': 'dev3 on VENDOR MODEL', 'attrs': {'mount-point': '/home'}, } action_4 = { 'action-type': 'create', 'action-description': 'create format', 'object-type': 'format', 'object-description': 'ext4', 'device-name': 'dev3', 'device-description': 'dev3 on VENDOR MODEL', 'attrs': {'mount-point': '/home'}, } self.assertEqual(get_native(self.interface.GetActions()), [ action_2, action_1, action_3, action_4, ])
def test_hide_ignored_disks(self): tree = DeviceTree() sda = DiskDevice("sda") sdb = DiskDevice("sdb") sdc = DiskDevice("sdc") 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) # test ignored_disks tree.ignored_disks = ["sdb"] # verify hide is called as expected with patch.object(tree, "hide") as hide: tree._hide_ignored_disks() hide.assert_called_with(sdb) # verify that hide works as expected tree._hide_ignored_disks() self.assertTrue(sda in tree.devices) self.assertFalse(sdb in tree.devices) self.assertTrue(sdc in tree.devices) # unhide sdb and make sure it works tree.unhide(sdb) self.assertTrue(sda in tree.devices) self.assertTrue(sdb in tree.devices) self.assertTrue(sdc in tree.devices) # test exclusive_disks tree.ignored_disks = [] tree.exclusive_disks = ["sdc"] with patch.object(tree, "hide") as hide: tree._hide_ignored_disks() hide.assert_any_call(sda) hide.assert_any_call(sdb) tree._hide_ignored_disks() self.assertFalse(sda in tree.devices) self.assertFalse(sdb in tree.devices) self.assertTrue(sdc in tree.devices) tree.unhide(sda) tree.unhide(sdb) self.assertTrue(sda in tree.devices) self.assertTrue(sdb in tree.devices) self.assertTrue(sdc in tree.devices) # now test exclusive_disks special cases for multipath sda.format = get_format("multipath_member", exists=True) sdb.format = get_format("multipath_member", exists=True) sdc.format = get_format("multipath_member", exists=True) mpatha = MultipathDevice("mpatha", parents=[sda, sdb, sdc]) tree._add_device(mpatha) tree.ignored_disks = [] tree.exclusive_disks = ["mpatha"] with patch.object(tree, "hide") as hide: tree._hide_ignored_disks() self.assertFalse(hide.called) tree._hide_ignored_disks() self.assertTrue(sda in tree.devices) self.assertTrue(sdb in tree.devices) self.assertTrue(sdc in tree.devices) self.assertTrue(mpatha in tree.devices) # all members in exclusive_disks implies the mpath in exclusive_disks tree.exclusive_disks = ["sda", "sdb", "sdc"] with patch.object(tree, "hide") as hide: tree._hide_ignored_disks() self.assertFalse(hide.called) tree._hide_ignored_disks() self.assertTrue(sda in tree.devices) self.assertTrue(sdb in tree.devices) self.assertTrue(sdc in tree.devices) self.assertTrue(mpatha in tree.devices) tree.exclusive_disks = ["sda", "sdb"] with patch.object(tree, "hide") as hide: tree._hide_ignored_disks() hide.assert_any_call(mpatha) hide.assert_any_call(sdc) # verify that hide works as expected tree._hide_ignored_disks() self.assertTrue(sda in tree.devices) self.assertTrue(sdb in tree.devices) self.assertFalse(sdc in tree.devices) self.assertFalse(mpatha in tree.devices)
def validate_selected_disks_test(self): """Test ValidateSelectedDisks.""" storage = create_storage() self.disk_selection_module.on_storage_reset(storage) dev1 = DiskDevice("dev1", exists=False, size=Size("15 GiB"), fmt=get_format("disklabel")) dev2 = DiskDevice("dev2", exists=False, parents=[dev1], size=Size("6 GiB"), fmt=get_format("disklabel")) dev3 = DiskDevice("dev3", exists=False, parents=[dev2], size=Size("6 GiB"), fmt=get_format("disklabel")) storage.devicetree._add_device(dev1) storage.devicetree._add_device(dev2) storage.devicetree._add_device(dev3) report = ValidationReport.from_structure( get_native(self.disk_selection_interface.ValidateSelectedDisks( []))) self.assertEqual(report.is_valid(), True) report = ValidationReport.from_structure( get_native( self.disk_selection_interface.ValidateSelectedDisks(["dev1"]))) self.assertEqual(report.is_valid(), False) self.assertEqual(report.error_messages, [ "You selected disk dev1, which contains devices that also use " "unselected disks dev2, dev3. You must select or de-select " "these disks as a set." ]) self.assertEqual(report.warning_messages, []) report = ValidationReport.from_structure( get_native( self.disk_selection_interface.ValidateSelectedDisks( ["dev1", "dev2"]))) self.assertEqual(report.is_valid(), False) self.assertEqual(report.error_messages, [ "You selected disk dev1, which contains devices that also " "use unselected disk dev3. You must select or de-select " "these disks as a set.", "You selected disk dev2, which contains devices that also " "use unselected disk dev3. You must select or de-select " "these disks as a set." ]) self.assertEqual(report.warning_messages, []) report = ValidationReport.from_structure( get_native( self.disk_selection_interface.ValidateSelectedDisks( ["dev1", "dev2", "dev3"]))) self.assertEqual(report.is_valid(), True)
def setUp(self): disk1 = DiskDevice("testdisk", size=Size("300 GiB"), exists=True, fmt=get_format("disklabel", exists=True)) disk1.format._supported = False if six.PY3: with self.assertLogs("blivet", level="INFO") as cm: partition1 = PartitionDevice("testpart1", size=Size("150 GiB"), exists=True, parents=[disk1], fmt=get_format("ext4", exists=True)) self.assertTrue("disklabel is unsupported" in "\n".join(cm.output)) else: partition1 = PartitionDevice("testpart1", size=Size("150 GiB"), exists=True, parents=[disk1], fmt=get_format("ext4", exists=True)) if six.PY3: with self.assertLogs("blivet", level="INFO") as cm: partition2 = PartitionDevice("testpart2", size=Size("100 GiB"), exists=True, parents=[disk1], fmt=get_format("lvmpv", exists=True)) self.assertTrue("disklabel is unsupported" in "\n".join(cm.output)) else: partition2 = PartitionDevice("testpart2", size=Size("100 GiB"), exists=True, parents=[disk1], fmt=get_format("lvmpv", exists=True)) # To be supported, all of a devices ancestors must be supported. disk2 = DiskDevice("testdisk2", size=Size("300 GiB"), exists=True, fmt=get_format("lvmpv", exists=True)) vg = LVMVolumeGroupDevice("testvg", exists=True, parents=[partition2, disk2]) lv = LVMLogicalVolumeDevice("testlv", exists=True, size=Size("64 GiB"), parents=[vg], fmt=get_format("ext4", exists=True)) with sparsetmpfile("addparttest", Size("50 MiB")) as disk_file: disk3 = DiskFile(disk_file) disk3.format = get_format("disklabel", device=disk3.path, exists=False) self.disk1 = disk1 self.disk2 = disk2 self.disk3 = disk3 self.partition1 = partition1 self.partition2 = partition2 self.vg = vg self.lv = lv
def _run(): device = DiskDevice(info.name, size=info.size, sysfs_path=info.sys_path) self._add_device(device) return device
def test_validate_selected_disks(self): """Test ValidateSelectedDisks.""" storage = create_storage() self.disk_selection_module.on_storage_changed(storage) dev1 = DiskDevice("dev1", exists=False, size=Size("15 GiB"), fmt=get_format("disklabel")) dev2 = DiskDevice("dev2", exists=False, parents=[dev1], size=Size("6 GiB"), fmt=get_format("disklabel")) dev3 = DiskDevice("dev3", exists=False, parents=[dev2], size=Size("6 GiB"), fmt=get_format("disklabel")) storage.devicetree._add_device(dev1) storage.devicetree._add_device(dev2) storage.devicetree._add_device(dev3) report = ValidationReport.from_structure( self.disk_selection_interface.ValidateSelectedDisks([])) assert report.is_valid() == True report = ValidationReport.from_structure( self.disk_selection_interface.ValidateSelectedDisks(["devX"])) assert report.is_valid() == False assert report.error_messages == [ "The selected disk devX is not recognized." ] assert report.warning_messages == [] report = ValidationReport.from_structure( self.disk_selection_interface.ValidateSelectedDisks(["dev1"])) assert report.is_valid() == False assert report.error_messages == [ "You selected disk dev1, which contains devices that also use " "unselected disks dev2, dev3. You must select or de-select " "these disks as a set." ] assert report.warning_messages == [] report = ValidationReport.from_structure( self.disk_selection_interface.ValidateSelectedDisks( ["dev1", "dev2"])) assert report.is_valid() == False assert report.error_messages == [ "You selected disk dev1, which contains devices that also " "use unselected disk dev3. You must select or de-select " "these disks as a set.", "You selected disk dev2, which contains devices that also " "use unselected disk dev3. You must select or de-select " "these disks as a set." ] assert report.warning_messages == [] report = ValidationReport.from_structure( self.disk_selection_interface.ValidateSelectedDisks( ["dev1", "dev2", "dev3"])) assert report.is_valid() == True
def test_hide_ignored_disks(self): tree = DeviceTree() sda = DiskDevice("sda") sdb = DiskDevice("sdb") sdc = DiskDevice("sdc") 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) # test ignored_disks tree.ignored_disks = ["sdb"] # verify hide is called as expected with patch.object(tree, "hide") as hide: tree._hide_ignored_disks() hide.assert_called_with(sdb) # verify that hide works as expected tree._hide_ignored_disks() self.assertTrue(sda in tree.devices) self.assertFalse(sdb in tree.devices) self.assertTrue(sdc in tree.devices) # unhide sdb and make sure it works tree.unhide(sdb) self.assertTrue(sda in tree.devices) self.assertTrue(sdb in tree.devices) self.assertTrue(sdc in tree.devices) # test exclusive_disks tree.ignored_disks = [] tree.exclusive_disks = ["sdc"] with patch.object(tree, "hide") as hide: tree._hide_ignored_disks() hide.assert_any_call(sda) hide.assert_any_call(sdb) tree._hide_ignored_disks() self.assertFalse(sda in tree.devices) self.assertFalse(sdb in tree.devices) self.assertTrue(sdc in tree.devices) tree.unhide(sda) tree.unhide(sdb) self.assertTrue(sda in tree.devices) self.assertTrue(sdb in tree.devices) self.assertTrue(sdc in tree.devices) # now test exclusive_disks special cases for multipath sda.format = get_format("multipath_member", exists=True) sdb.format = get_format("multipath_member", exists=True) sdc.format = get_format("multipath_member", exists=True) mpatha = MultipathDevice("mpatha", parents=[sda, sdb, sdc]) tree._add_device(mpatha) tree.ignored_disks = [] tree.exclusive_disks = ["mpatha"] with patch.object(tree, "hide") as hide: tree._hide_ignored_disks() self.assertFalse(hide.called) tree._hide_ignored_disks() self.assertTrue(sda in tree.devices) self.assertTrue(sdb in tree.devices) self.assertTrue(sdc in tree.devices) self.assertTrue(mpatha in tree.devices) # all members in exclusive_disks implies the mpath in exclusive_disks tree.exclusive_disks = ["sda", "sdb", "sdc"] with patch.object(tree, "hide") as hide: tree._hide_ignored_disks() self.assertFalse(hide.called) tree._hide_ignored_disks() self.assertTrue(sda in tree.devices) self.assertTrue(sdb in tree.devices) self.assertTrue(sdc in tree.devices) self.assertTrue(mpatha in tree.devices) tree.exclusive_disks = ["sda", "sdb"] with patch.object(tree, "hide") as hide: tree._hide_ignored_disks() hide.assert_any_call(mpatha) hide.assert_any_call(sdc) # verify that hide works as expected tree._hide_ignored_disks() self.assertTrue(sda in tree.devices) self.assertTrue(sdb in tree.devices) self.assertFalse(sdc in tree.devices) self.assertFalse(mpatha in tree.devices)
def setUp(self): parents = [ DiskDevice("name1", fmt=getFormat("mdmember")) ] self.dev1 = MDContainerDevice("dev1", level="container", parents=parents) parents = [ DiskDevice("name1", fmt=getFormat("mdmember")), DiskDevice("name2", fmt=getFormat("mdmember")) ] self.dev2 = MDRaidArrayDevice("dev2", level="raid0", parents=parents) parents = [ DiskDevice("name1", fmt=getFormat("mdmember")), DiskDevice("name2", fmt=getFormat("mdmember")) ] self.dev3 = MDRaidArrayDevice("dev3", level="raid1", parents=parents) parents = [ DiskDevice("name1", fmt=getFormat("mdmember")), DiskDevice("name2", fmt=getFormat("mdmember")), DiskDevice("name3", fmt=getFormat("mdmember")) ] self.dev4 = MDRaidArrayDevice("dev4", level="raid4", parents=parents) parents = [ DiskDevice("name1", fmt=getFormat("mdmember")), DiskDevice("name2", fmt=getFormat("mdmember")), DiskDevice("name3", fmt=getFormat("mdmember")) ] self.dev5 = MDRaidArrayDevice("dev5", level="raid5", parents=parents) parents = [ DiskDevice("name1", fmt=getFormat("mdmember")), DiskDevice("name2", fmt=getFormat("mdmember")), DiskDevice("name3", fmt=getFormat("mdmember")), DiskDevice("name4", fmt=getFormat("mdmember")) ] self.dev6 = MDRaidArrayDevice("dev6", level="raid6", parents=parents) parents = [ DiskDevice("name1", fmt=getFormat("mdmember")), DiskDevice("name2", fmt=getFormat("mdmember")), DiskDevice("name3", fmt=getFormat("mdmember")), DiskDevice("name4", fmt=getFormat("mdmember")) ] self.dev7 = MDRaidArrayDevice("dev7", level="raid10", parents=parents) self.dev8 = MDRaidArrayDevice("dev8", level=1, exists=True) parents_1 = [ DiskDevice("name1", fmt=getFormat("mdmember")) ] dev_1 = MDContainerDevice( "parent", level="container", parents=parents_1 ) parents_2 = [ DiskDevice("name1", fmt=getFormat("mdmember")), DiskDevice("name2", fmt=getFormat("mdmember")) ] dev_2 = MDRaidArrayDevice( "other", level=0, fmt=getFormat("mdmember"), parents=parents_2 ) self.dev9 = MDBiosRaidArrayDevice( "dev9", level="raid0", memberDevices=2, parents=[dev_1, dev_2], totalDevices=2 ) parents = [ DiskDevice("name1", fmt=getFormat("mdmember")), DiskDevice("name2", fmt=getFormat("mdmember")) ] self.dev10 = MDRaidArrayDevice( "dev10", level="raid0", parents=parents, size=Size("32 MiB")) parents_1 = [ DiskDevice("name1", fmt=getFormat("mdmember")) ] dev_1 = MDContainerDevice( "parent", level="container", parents=parents ) parents_2 = [ DiskDevice("name1", fmt=getFormat("mdmember")), DiskDevice("name2", fmt=getFormat("mdmember")) ] dev_2 = MDRaidArrayDevice( "other", level=0, fmt=getFormat("mdmember"), parents=parents_2 ) self.dev11 = MDBiosRaidArrayDevice( "dev11", level=1, memberDevices=2, parents=[dev_1, dev_2], size=Size("32 MiB"), totalDevices=2) self.dev12 = MDBiosRaidArrayDevice( "dev12", level=1, memberDevices=2, parents=[ Mock(**{"type": "mdcontainer", "size": Size("4 MiB"), "format": getFormat(None)}), Mock(**{"size": Size("2 MiB"), "format": getFormat("mdmember")})], size=Size("32 MiB"), totalDevices=2) self.dev13 = MDRaidArrayDevice( "dev13", level=0, memberDevices=3, parents=[ Mock(**{"size": Size("4 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("2 MiB"), "format": getFormat("mdmember")})], size=Size("32 MiB"), totalDevices=3) self.dev14 = MDRaidArrayDevice( "dev14", level=4, memberDevices=3, parents=[ Mock(**{"size": Size("4 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("2 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("2 MiB"), "format": getFormat("mdmember")})], totalDevices=3) self.dev15 = MDRaidArrayDevice( "dev15", level=5, memberDevices=3, parents=[ Mock(**{"size": Size("4 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("2 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("2 MiB"), "format": getFormat("mdmember")})], totalDevices=3) self.dev16 = MDRaidArrayDevice( "dev16", level=6, memberDevices=4, parents=[ Mock(**{"size": Size("4 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("4 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("2 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("2 MiB"), "format": getFormat("mdmember")})], totalDevices=4) self.dev17 = MDRaidArrayDevice( "dev17", level=10, memberDevices=4, parents=[ Mock(**{"size": Size("4 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("4 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("2 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("2 MiB"), "format": getFormat("mdmember")})], totalDevices=4) self.dev18 = MDRaidArrayDevice( "dev18", level=10, memberDevices=4, parents=[ Mock(**{"size": Size("4 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("4 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("2 MiB"), "format": getFormat("mdmember")}), Mock(**{"size": Size("2 MiB"), "format": getFormat("mdmember")})], totalDevices=5) parents = [ DiskDevice("name1", fmt=getFormat("mdmember")), DiskDevice("name2", fmt=getFormat("mdmember")) ] self.dev19 = MDRaidArrayDevice( "dev19", level="raid1", parents=parents, uuid='3386ff85-f501-2621-4a43-5f061eb47236' ) parents = [ DiskDevice("name1", fmt=getFormat("mdmember")), DiskDevice("name2", fmt=getFormat("mdmember")) ] self.dev20 = MDRaidArrayDevice( "dev20", level="raid1", parents=parents, uuid='Just-pretending' )