Exemplo n.º 1
0
 def setUp(self):
     """Set up the module."""
     self.module = BlivetPartitioningModule()
     self.interface = BlivetPartitioningInterface(self.module)
Exemplo n.º 2
0
    def __init__(self):
        super().__init__()
        # Initialize Blivet.
        enable_installer_mode()

        # The storage model.
        self._storage = None
        self.storage_changed = Signal()

        # Initialize modules.
        self._modules = []

        self._storage_checker_module = StorageCheckerModule()
        self._add_module(self._storage_checker_module)

        self._device_tree_module = DeviceTreeModule()
        self._add_module(self._device_tree_module)

        self._disk_init_module = DiskInitializationModule()
        self._add_module(self._disk_init_module)

        self._disk_selection_module = DiskSelectionModule()
        self._add_module(self._disk_selection_module)

        self._snapshot_module = SnapshotModule()
        self._add_module(self._snapshot_module)

        self._bootloader_module = BootloaderModule()
        self._add_module(self._bootloader_module)

        self._fcoe_module = FCOEModule()
        self._add_module(self._fcoe_module)

        self._iscsi_module = ISCSIModule()
        self._add_module(self._iscsi_module)

        self._nvdimm_module = NVDIMMModule()
        self._add_module(self._nvdimm_module)

        self._dasd_module = None
        self._zfcp_module = None

        if arch.is_s390():
            self._dasd_module = DASDModule()
            self._add_module(self._dasd_module)

            self._zfcp_module = ZFCPModule()
            self._add_module(self._zfcp_module)

        # Initialize the partitioning modules.
        self._partitioning_modules = {}

        self._auto_part_module = AutoPartitioningModule()
        self._add_partitioning_module(AUTO_PARTITIONING.object_path,
                                      self._auto_part_module)

        self._manual_part_module = ManualPartitioningModule()
        self._add_partitioning_module(MANUAL_PARTITIONING.object_path,
                                      self._manual_part_module)

        self._custom_part_module = CustomPartitioningModule()
        self._add_partitioning_module(CUSTOM_PARTITIONING.object_path,
                                      self._custom_part_module)

        self._interactive_part_module = InteractivePartitioningModule()
        self._add_partitioning_module(INTERACTIVE_PARTITIONING.object_path,
                                      self._interactive_part_module)

        self._blivet_part_module = BlivetPartitioningModule()
        self._add_partitioning_module(BLIVET_PARTITIONING.object_path,
                                      self._blivet_part_module)

        # Connect modules to signals.
        self.storage_changed.connect(self._device_tree_module.on_storage_reset)
        self.storage_changed.connect(self._disk_init_module.on_storage_reset)
        self.storage_changed.connect(
            self._disk_selection_module.on_storage_reset)
        self.storage_changed.connect(self._snapshot_module.on_storage_reset)
        self.storage_changed.connect(self._bootloader_module.on_storage_reset)
        self._disk_selection_module.protected_devices_changed.connect(
            self.on_protected_devices_changed)
Exemplo n.º 3
0
class BlivetPartitioningInterfaceTestCase(unittest.TestCase):
    """Test DBus interface of the Blivet partitioning module."""

    def setUp(self):
        """Set up the module."""
        self.module = BlivetPartitioningModule()
        self.interface = BlivetPartitioningInterface(self.module)

    @patch.dict('sys.modules')
    def unsupported_partitioning_test(self):
        """Test the UnsupportedPartitioningError."""
        # Forget imported modules from pyanaconda and blivetgui.
        for name in list(sys.modules):
            if name.startswith('pyanaconda') or name.startswith('blivetgui'):
                sys.modules.pop(name)

        # Disable the blivetgui package.
        sys.modules['blivetgui'] = None

        # Import the StorageModule again.
        from pyanaconda.modules.storage.storage import StorageModule

        # We should be able to create the Storage module
        storage_module = StorageModule()
        self.assertIsNotNone(storage_module.storage)

        # We should be able to access the Blivet module.
        blivet_module = storage_module._blivet_part_module
        self.assertIsNotNone(blivet_module.storage)

        # Import the exception again.
        from pyanaconda.modules.common.errors.storage import UnsupportedPartitioningError

        # Handle the missing support.
        with self.assertRaises(UnsupportedPartitioningError):
            self.assertFalse(blivet_module.storage_handler)

        with self.assertRaises(UnsupportedPartitioningError):
            self.assertFalse(blivet_module.request_handler)

        with self.assertRaises(UnsupportedPartitioningError):
            request = pickle.dumps(("call", "get_disks", []))
            blivet_module.send_request(request)

    def storage_handler_test(self):
        """Test the storage_handler property."""
        self.module.on_storage_reset(Mock())
        self.assertIsNotNone(self.module.storage_handler)
        self.assertEqual(self.module.storage, self.module.storage_handler.storage)

    def request_handler_test(self):
        """Test the request_handler property."""
        self.module.on_storage_reset(Mock())
        self.assertIsNotNone(self.module.request_handler)
        self.assertEqual(self.module.storage_handler, self.module.request_handler.blivet_utils)

    def send_request_test(self):
        """Test SendRequest."""
        self.module.on_storage_reset(Mock())
        request = pickle.dumps(("call", "get_disks", []))

        answer = self.interface.SendRequest(request)
        answer = pickle.loads(answer)

        self.assertIsInstance(answer, ProxyID)
        self.assertEqual(answer.id, 0)

    @patch('pyanaconda.dbus.DBus.publish_object')
    def configure_with_task_test(self, publisher):
        """Test ConfigureWithTask."""
        self.module.on_storage_reset(Mock())
        task_path = self.interface.ConfigureWithTask()

        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, InteractivePartitioningTask)
        self.assertEqual(obj.implementation._storage, self.module.storage)

    @patch('pyanaconda.dbus.DBus.publish_object')
    def validate_with_task_test(self, publisher):
        """Test ValidateWithTask."""
        self.module.on_storage_reset(Mock())
        task_path = self.interface.ValidateWithTask()

        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, StorageValidateTask)
        self.assertEqual(obj.implementation._storage, self.module.storage)