class DASDInterfaceTestCase(unittest.TestCase): """Test DBus interface of the DASD module.""" def setUp(self): """Set up the module.""" self.dasd_module = DASDModule() self.dasd_interface = DASDInterface(self.dasd_module) @patch('pyanaconda.dbus.DBus.publish_object') def discover_with_task_test(self, publisher): """Test DiscoverWithTask.""" task_path = self.dasd_interface.DiscoverWithTask("0.0.A100") publisher.assert_called_once() object_path, obj = publisher.call_args[0] self.assertEqual(task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, DASDDiscoverTask) self.assertEqual(obj.implementation._device_number, "0.0.A100") @patch('pyanaconda.dbus.DBus.publish_object') def format_with_task_test(self, publisher): """Test the discover task.""" task_path = self.dasd_interface.FormatWithTask( ["/dev/sda", "/dev/sdb"]) publisher.assert_called_once() object_path, obj = publisher.call_args[0] self.assertEqual(task_path, object_path) self.assertIsInstance(obj, TaskInterface) self.assertIsInstance(obj.implementation, DASDFormatTask) self.assertEqual(obj.implementation._dasds, ["/dev/sda", "/dev/sdb"])
class DASDInterfaceTestCase(unittest.TestCase): """Test DBus interface of the DASD module.""" def setUp(self): """Set up the module.""" self.dasd_module = DASDModule() self.dasd_interface = DASDInterface(self.dasd_module) @patch_dbus_publish_object def discover_with_task_test(self, publisher): """Test DiscoverWithTask.""" task_path = self.dasd_interface.DiscoverWithTask("0.0.A100") obj = check_task_creation(self, task_path, publisher, DASDDiscoverTask) self.assertEqual(obj.implementation._device_number, "0.0.A100") @patch_dbus_publish_object def format_with_task_test(self, publisher): """Test the discover task.""" task_path = self.dasd_interface.FormatWithTask( ["/dev/sda", "/dev/sdb"]) obj = check_task_creation(self, task_path, publisher, DASDFormatTask) self.assertEqual(obj.implementation._dasds, ["/dev/sda", "/dev/sdb"]) @patch('pyanaconda.modules.storage.dasd.format.blockdev') def find_formattable_test(self, blockdev): """Test FindFormattable.""" with self.assertRaises(UnavailableStorageError): self.dasd_interface.FindFormattable(["dev1"]) storage = create_storage() self.dasd_module.on_storage_reset(storage) with self.assertRaises(UnknownDeviceError): self.dasd_interface.FindFormattable(["dev1"]) storage.devicetree._add_device( DASDDevice("dev1", fmt=get_format("ext4"), size=Size("10 GiB"), busid="0.0.0201", opts={})) # The policy doesn't allow tp format anything. self.assertEqual(self.dasd_interface.FindFormattable(["dev1"]), []) # The policy allows to format unformatted, but there are none. self.dasd_module.on_format_unrecognized_enabled_changed(True) blockdev.s390.dasd_needs_format.return_value = False self.assertEqual(self.dasd_interface.FindFormattable(["dev1"]), []) # The policy allows to format LDL, but there are none. self.dasd_module.on_format_unrecognized_enabled_changed(False) self.dasd_module.on_format_ldl_enabled_changed(True) blockdev.s390.dasd_is_ldl.return_value = False self.assertEqual(self.dasd_interface.FindFormattable(["dev1"]), []) # The policy allows to format all and there are all. self.dasd_module.on_format_unrecognized_enabled_changed(True) blockdev.s390.dasd_needs_format.return_value = True blockdev.s390.dasd_is_ldl.return_value = True self.assertEqual(self.dasd_interface.FindFormattable(["dev1"]), ["dev1"])