def test_availability_mdraidplugin(self): availability.CACHE_AVAILABILITY = False availability.BLOCKDEV_DM_PLUGIN._method = availability.AvailableMethod # if the plugin is not in, there's nothing to test self.assertIn(availability.BLOCKDEV_MDRAID_PLUGIN, self.luks.external_dependencies) # dev is not among its unavailable dependencies availability.BLOCKDEV_MDRAID_PLUGIN._method = availability.AvailableMethod availability.MKFS_HFSPLUS_APP._method = availability.AvailableMethod # macefi self.assertNotIn(availability.BLOCKDEV_MDRAID_PLUGIN, self.luks.unavailable_dependencies) self.assertIsNotNone(ActionCreateDevice(self.luks)) self.assertIsNotNone(ActionDestroyDevice(self.luks)) self.assertIsNotNone( ActionCreateFormat(self.luks, fmt=get_format("macefi"))) self.assertIsNotNone(ActionDestroyFormat(self.luks)) # dev is among the unavailable dependencies availability.BLOCKDEV_MDRAID_PLUGIN._method = availability.UnavailableMethod self.assertIn(availability.BLOCKDEV_MDRAID_PLUGIN, self.luks.unavailable_dependencies) with self.assertRaises(ValueError): ActionCreateDevice(self.luks) with self.assertRaises(ValueError): ActionDestroyDevice(self.dev) with self.assertRaises(ValueError): ActionCreateFormat(self.dev) with self.assertRaises(ValueError): ActionDestroyFormat(self.dev)
def test_dependencies_handling(self): device = StorageDevice("testdev1") self.assertTrue(device.controllable) self.assertIsNotNone(ActionCreateDevice(device)) device.exists = True self.assertIsNotNone(ActionDestroyDevice(device)) with patch.object(StorageDevice, "resizable", new_callable=PropertyMock(return_value=True)): self.assertIsNotNone(ActionResizeDevice(device, Size("1 GiB"))) # if any external dependency is missing, it should be impossible to create, destroy, setup, # teardown, or resize the device (controllable encompasses setup & teardown) with patch.object(StorageDevice, "_external_dependencies", new_callable=PropertyMock(return_value=[ availability.unavailable_resource("testing") ])): device = StorageDevice("testdev1") self.assertFalse(device.controllable) self.assertRaises(DependencyError, ActionCreateDevice, device) device.exists = True self.assertRaises(DependencyError, ActionDestroyDevice, device) self.assertRaises(ValueError, ActionResizeDevice, device, Size("1 GiB")) # same goes for formats, except that the properties they affect vary by format class fmt = get_format("lvmpv") fmt._plugin = availability.available_resource("lvm-testing") self.assertTrue(fmt.supported) self.assertTrue(fmt.formattable) self.assertTrue(fmt.destroyable) fmt._plugin = availability.unavailable_resource("lvm-testing") self.assertFalse(fmt.supported) self.assertFalse(fmt.formattable) self.assertFalse(fmt.destroyable)
def testActionObsoletes(self): """ Verify correct operation of DeviceAction.obsoletes. """ self.destroyAllDevices(disks=["sdc"]) sdc = self.storage.devicetree.getDeviceByName("sdc") self.assertNotEqual(sdc, None) sdc1 = self.newDevice(device_class=PartitionDevice, name="sdc1", parents=[sdc], size=Size("40 GiB")) # ActionCreateDevice # # - obsoletes other ActionCreateDevice instances w/ lower id and same # device create_device_1 = ActionCreateDevice(sdc1) create_device_1.apply() create_device_2 = ActionCreateDevice(sdc1) create_device_2.apply() self.assertEqual(create_device_2.obsoletes(create_device_1), True) self.assertEqual(create_device_1.obsoletes(create_device_2), False) # ActionCreateFormat # # - obsoletes other ActionCreateFormat instances w/ lower id and same # device format_1 = self.newFormat("ext3", mountpoint="/home", device=sdc1.path) format_2 = self.newFormat("ext3", mountpoint="/opt", device=sdc1.path) create_format_1 = ActionCreateFormat(sdc1, format_1) create_format_1.apply() create_format_2 = ActionCreateFormat(sdc1, format_2) create_format_2.apply() self.assertEqual(create_format_2.obsoletes(create_format_1), True) self.assertEqual(create_format_1.obsoletes(create_format_2), False) # ActionResizeFormat # # - obsoletes other ActionResizeFormat instances w/ lower id and same # device sdc1.exists = True sdc1.format.exists = True sdc1.format._resizable = True resize_format_1 = ActionResizeFormat(sdc1, sdc1.size - Size("1000 MiB")) resize_format_1.apply() resize_format_2 = ActionResizeFormat(sdc1, sdc1.size - Size("5000 MiB")) resize_format_2.apply() self.assertEqual(resize_format_2.obsoletes(resize_format_1), True) self.assertEqual(resize_format_1.obsoletes(resize_format_2), False) sdc1.exists = False sdc1.format.exists = False # ActionCreateFormat # # - obsoletes resize format actions w/ lower id on same device new_format = self.newFormat("ext4", mountpoint="/foo", device=sdc1.path) create_format_3 = ActionCreateFormat(sdc1, new_format) create_format_3.apply() self.assertEqual(create_format_3.obsoletes(resize_format_1), True) self.assertEqual(create_format_3.obsoletes(resize_format_2), True) # ActionResizeDevice # # - obsoletes other ActionResizeDevice instances w/ lower id and same # device sdc1.exists = True sdc1.format.exists = True sdc1.format._resizable = True resize_device_1 = ActionResizeDevice(sdc1, sdc1.size + Size("10 GiB")) resize_device_1.apply() resize_device_2 = ActionResizeDevice(sdc1, sdc1.size - Size("10 GiB")) resize_device_2.apply() self.assertEqual(resize_device_2.obsoletes(resize_device_1), True) self.assertEqual(resize_device_1.obsoletes(resize_device_2), False) sdc1.exists = False sdc1.format.exists = False # ActionDestroyFormat # # - obsoletes all format actions w/ higher id on same device (including # self if format does not exist) destroy_format_1 = ActionDestroyFormat(sdc1) destroy_format_1.apply() destroy_format_2 = ActionDestroyFormat(sdc1) destroy_format_2.apply() self.assertEqual(destroy_format_1.obsoletes(create_format_1), True) self.assertEqual(destroy_format_1.obsoletes(resize_format_1), True) self.assertEqual(destroy_format_1.obsoletes(destroy_format_1), True) self.assertEqual(destroy_format_2.obsoletes(destroy_format_1), False) self.assertEqual(destroy_format_1.obsoletes(destroy_format_2), True) # ActionDestroyDevice # # - obsoletes all actions w/ lower id that act on the same non-existent # device (including self) # sdc1 does not exist destroy_sdc1 = ActionDestroyDevice(sdc1) destroy_sdc1.apply() self.assertEqual(destroy_sdc1.obsoletes(create_format_2), True) self.assertEqual(destroy_sdc1.obsoletes(resize_format_2), True) self.assertEqual(destroy_sdc1.obsoletes(create_device_1), True) self.assertEqual(destroy_sdc1.obsoletes(resize_device_1), True) self.assertEqual(destroy_sdc1.obsoletes(destroy_sdc1), True) # ActionDestroyDevice # # - obsoletes all but ActionDestroyFormat actions w/ lower id on the # same existing device # sda1 exists sda1 = self.storage.devicetree.getDeviceByName("sda1") self.assertNotEqual(sda1, None) # sda1.format._resizable = True resize_sda1_format = ActionResizeFormat(sda1, sda1.size - Size("50 MiB")) resize_sda1_format.apply() resize_sda1 = ActionResizeDevice(sda1, sda1.size - Size("50 MiB")) resize_sda1.apply() destroy_sda1_format = ActionDestroyFormat(sda1) destroy_sda1_format.apply() destroy_sda1 = ActionDestroyDevice(sda1) destroy_sda1.apply() self.assertEqual(destroy_sda1.obsoletes(resize_sda1_format), True) self.assertEqual(destroy_sda1.obsoletes(resize_sda1), True) self.assertEqual(destroy_sda1.obsoletes(destroy_sda1), False) self.assertEqual(destroy_sda1.obsoletes(destroy_sda1_format), False)