Exemple #1
0
    def verify_requests(self, storage, constraints, report_error, report_warning):
        """Verify the validity of snapshot requests for the given storage.

        This is a callback for the storage checker.

        :param storage: a storage to check
        :param constraints: a dictionary of constraints
        :param report_error: a function for error reporting
        :param report_warning: a function for warning reporting
        """
        # FIXME: This is an ugly temporary workaround for UI.
        from pyanaconda.modules.storage.snapshot import SnapshotModule
        SnapshotModule.verify_requests(self, storage, constraints, report_error, report_warning)
Exemple #2
0
    def verify_requests(self, storage, constraints, report_error, report_warning):
        """Verify the validity of snapshot requests for the given storage.

        This is a callback for the storage checker.

        :param storage: a storage to check
        :param constraints: a dictionary of constraints
        :param report_error: a function for error reporting
        :param report_warning: a function for warning reporting
        """
        # FIXME: This is an ugly temporary workaround for UI.
        from pyanaconda.modules.storage.snapshot import SnapshotModule
        SnapshotModule.verify_requests(self, storage, constraints, report_error, report_warning)
Exemple #3
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._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._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)

        # Connect modules to signals.
        self.storage_changed.connect(self._snapshot_module.on_storage_reset)
class SnapshotInterfaceTestCase(unittest.TestCase):
    """Test DBus interface of the Snapshot module."""

    def setUp(self):
        """Set up the module."""
        self.module = SnapshotModule()
        self.interface = SnapshotInterface(self.module)

    def test_is_requested(self):
        """Test IsRequested."""
        assert self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL) is False
        assert self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL) is False

        self.module._requests = [Mock(when=SNAPSHOT_WHEN_PRE_INSTALL)]
        assert self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL) is True
        assert self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL) is False

        self.module._requests = [Mock(when=SNAPSHOT_WHEN_POST_INSTALL)]
        assert self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL) is False
        assert self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL) is True

        self.module._requests = [Mock(when=SNAPSHOT_WHEN_PRE_INSTALL),
                                 Mock(when=SNAPSHOT_WHEN_POST_INSTALL)]
        assert self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL) is True
        assert self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL) is True

    @patch_dbus_publish_object
    def test_create_with_task(self, publisher):
        """Test CreateWithTask."""
        with pytest.raises(UnavailableStorageError):
            self.interface.CreateWithTask(SNAPSHOT_WHEN_PRE_INSTALL)

        self.module.on_storage_changed(Mock())
        task_path = self.interface.CreateWithTask(SNAPSHOT_WHEN_PRE_INSTALL)

        obj = check_task_creation(task_path, publisher, SnapshotCreateTask)

        assert obj.implementation._storage == self.module.storage
        assert obj.implementation._requests == []
        assert obj.implementation._when == SNAPSHOT_WHEN_PRE_INSTALL

    @patch('pyanaconda.modules.storage.snapshot.snapshot.get_snapshot_device')
    def test_verify_requests(self, device_getter):
        """Test the verify_requests method."""
        report_error = Mock()
        report_warning = Mock()
        self.module._requests = [Mock(when=SNAPSHOT_WHEN_POST_INSTALL)]

        # Test passing check.
        self.module.verify_requests(Mock(), Mock(), report_error, report_warning)
        report_error.assert_not_called()
        report_warning.assert_not_called()

        # Test failing check.
        device_getter.side_effect = StorageError("Fake error")
        self.module.verify_requests(Mock(), Mock(), report_error, report_warning)
        report_error.assert_called_once_with("Fake error")
        report_warning.assert_not_called()
 def setUp(self):
     """Set up the module."""
     self.module = SnapshotModule()
     self.interface = SnapshotInterface(self.module)
class SnapshotInterfaceTestCase(unittest.TestCase):
    """Test DBus interface of the Snapshot module."""
    def setUp(self):
        """Set up the module."""
        self.module = SnapshotModule()
        self.interface = SnapshotInterface(self.module)

    def is_requested_test(self):
        """Test IsRequested."""
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL),
                         False)
        self.assertEqual(
            self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL), False)

        self.module._requests = [Mock(when=SNAPSHOT_WHEN_PRE_INSTALL)]
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL),
                         True)
        self.assertEqual(
            self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL), False)

        self.module._requests = [Mock(when=SNAPSHOT_WHEN_POST_INSTALL)]
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL),
                         False)
        self.assertEqual(
            self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL), True)

        self.module._requests = [
            Mock(when=SNAPSHOT_WHEN_PRE_INSTALL),
            Mock(when=SNAPSHOT_WHEN_POST_INSTALL)
        ]
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL),
                         True)
        self.assertEqual(
            self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL), True)

    @patch('pyanaconda.dbus.DBus.publish_object')
    def create_with_task_test(self, publisher):
        """Test CreateWithTask."""
        with self.assertRaises(UnavailableStorageError):
            self.interface.CreateWithTask(SNAPSHOT_WHEN_PRE_INSTALL)

        self.module.on_storage_reset(Mock())
        task_path = self.interface.CreateWithTask(SNAPSHOT_WHEN_PRE_INSTALL)

        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, SnapshotCreateTask)
        self.assertEqual(obj.implementation._storage, self.module.storage)
        self.assertEqual(obj.implementation._requests, [])
        self.assertEqual(obj.implementation._when, SNAPSHOT_WHEN_PRE_INSTALL)

    @patch('pyanaconda.modules.storage.snapshot.snapshot.get_snapshot_device')
    def verify_requests_test(self, device_getter):
        """Test the verify_requests method."""
        report_error = Mock()
        report_warning = Mock()
        self.module._requests = [Mock(when=SNAPSHOT_WHEN_POST_INSTALL)]

        # Test passing check.
        self.module.verify_requests(Mock(), Mock(), report_error,
                                    report_warning)
        report_error.assert_not_called()
        report_warning.assert_not_called()

        # Test failing check.
        device_getter.side_effect = KickstartParseError("Fake error")
        self.module.verify_requests(Mock(), Mock(), report_error,
                                    report_warning)
        report_error.assert_called_once_with("Fake error")
        report_warning.assert_not_called()
Exemple #7
0
    def __init__(self):
        super().__init__()
        # Initialize Blivet.
        enable_installer_mode()

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

        # The created partitioning modules.
        self._created_partitioning = []
        self.created_partitioning_changed = Signal()

        # The applied partitioning module.
        self._applied_partitioning = None
        self.applied_partitioning_changed = Signal()
        self.partitioning_reset = 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 = DASDModule()
        self._add_module(self._dasd_module)

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

        # Connect modules to signals.
        self.storage_changed.connect(
            self._device_tree_module.on_storage_changed)
        self.storage_changed.connect(self._disk_init_module.on_storage_changed)
        self.storage_changed.connect(
            self._disk_selection_module.on_storage_changed)
        self.storage_changed.connect(self._snapshot_module.on_storage_changed)
        self.storage_changed.connect(
            self._bootloader_module.on_storage_changed)
        self.storage_changed.connect(self._dasd_module.on_storage_changed)
        self._disk_init_module.format_unrecognized_enabled_changed.connect(
            self._dasd_module.on_format_unrecognized_enabled_changed)
        self._disk_init_module.format_ldl_enabled_changed.connect(
            self._dasd_module.on_format_ldl_enabled_changed)
        self._disk_selection_module.protected_devices_changed.connect(
            self.on_protected_devices_changed)
Exemple #8
0
    def __init__(self):
        super().__init__()
        # Initialize Blivet.
        enable_installer_mode()

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

        # The created partitioning modules.
        self._created_partitioning = []
        self.created_partitioning_changed = Signal()

        # The applied partitioning module.
        self._applied_partitioning = None
        self.applied_partitioning_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.
        # TODO: Remove the static partitioning modules.
        self._add_module(self.create_partitioning(
            PartitioningMethod.AUTOMATIC))
        self._add_module(self.create_partitioning(PartitioningMethod.MANUAL))
        self._add_module(self.create_partitioning(PartitioningMethod.CUSTOM))
        self._add_module(
            self.create_partitioning(PartitioningMethod.INTERACTIVE))
        self._add_module(self.create_partitioning(PartitioningMethod.BLIVET))
        # Forget the static partitioning modules.
        # TODO: Remove with the static partitioning modules.
        self._created_partitioning = []

        # 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)
 def setUp(self):
     """Set up the module."""
     self.module = SnapshotModule()
     self.interface = SnapshotInterface(self.module)
class SnapshotInterfaceTestCase(unittest.TestCase):
    """Test DBus interface of the Snapshot module."""

    def setUp(self):
        """Set up the module."""
        self.module = SnapshotModule()
        self.interface = SnapshotInterface(self.module)

    def is_requested_test(self):
        """Test IsRequested."""
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL), False)
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL), False)

        self.module._requests = [Mock(when=SNAPSHOT_WHEN_PRE_INSTALL)]
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL), True)
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL), False)

        self.module._requests = [Mock(when=SNAPSHOT_WHEN_POST_INSTALL)]
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL), False)
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL), True)

        self.module._requests = [Mock(when=SNAPSHOT_WHEN_PRE_INSTALL),
                                 Mock(when=SNAPSHOT_WHEN_POST_INSTALL)]
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL), True)
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL), True)

    @patch('pyanaconda.dbus.DBus.publish_object')
    def create_with_task_test(self, publisher):
        """Test CreateWithTask."""
        with self.assertRaises(UnavailableStorageError):
            self.interface.CreateWithTask(SNAPSHOT_WHEN_PRE_INSTALL)

        self.module.on_storage_reset(Mock())
        task_path = self.interface.CreateWithTask(SNAPSHOT_WHEN_PRE_INSTALL)

        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, SnapshotCreateTask)
        self.assertEqual(obj.implementation._storage, self.module.storage)
        self.assertEqual(obj.implementation._requests, [])
        self.assertEqual(obj.implementation._when, SNAPSHOT_WHEN_PRE_INSTALL)

    @patch('pyanaconda.modules.storage.snapshot.snapshot.get_snapshot_device')
    def verify_requests_test(self, device_getter):
        """Test the verify_requests method."""
        report_error = Mock()
        report_warning = Mock()
        self.module._requests = [Mock(when=SNAPSHOT_WHEN_POST_INSTALL)]

        # Test passing check.
        self.module.verify_requests(Mock(), Mock(), report_error, report_warning)
        report_error.assert_not_called()
        report_warning.assert_not_called()

        # Test failing check.
        device_getter.side_effect = KickstartParseError("Fake error")
        self.module.verify_requests(Mock(), Mock(), report_error, report_warning)
        report_error.assert_called_once_with("Fake error")
        report_warning.assert_not_called()
Exemple #11
0
class SnapshotInterfaceTestCase(unittest.TestCase):
    """Test DBus interface of the Snapshot module."""
    def setUp(self):
        """Set up the module."""
        self.module = SnapshotModule()
        self.interface = SnapshotInterface(self.module)

    def is_requested_test(self):
        """Test IsRequested."""
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL),
                         False)
        self.assertEqual(
            self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL), False)

        self.module._requests = [Mock(when=SNAPSHOT_WHEN_PRE_INSTALL)]
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL),
                         True)
        self.assertEqual(
            self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL), False)

        self.module._requests = [Mock(when=SNAPSHOT_WHEN_POST_INSTALL)]
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL),
                         False)
        self.assertEqual(
            self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL), True)

        self.module._requests = [
            Mock(when=SNAPSHOT_WHEN_PRE_INSTALL),
            Mock(when=SNAPSHOT_WHEN_POST_INSTALL)
        ]
        self.assertEqual(self.interface.IsRequested(SNAPSHOT_WHEN_PRE_INSTALL),
                         True)
        self.assertEqual(
            self.interface.IsRequested(SNAPSHOT_WHEN_POST_INSTALL), True)

    @patch('pyanaconda.dbus.DBus.publish_object')
    def validate_with_task_test(self, publisher):
        """Test ValidateWithTask."""
        with self.assertRaises(UnavailableStorageError):
            self.interface.ValidateWithTask(SNAPSHOT_WHEN_POST_INSTALL)

        self.module.on_storage_reset(Mock())
        task_path = self.interface.ValidateWithTask(SNAPSHOT_WHEN_POST_INSTALL)

        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, SnapshotValidateTask)
        self.assertEqual(obj.implementation._storage, self.module.storage)
        self.assertEqual(obj.implementation._requests, [])
        self.assertEqual(obj.implementation._when, SNAPSHOT_WHEN_POST_INSTALL)

    @patch('pyanaconda.dbus.DBus.publish_object')
    def create_with_task_test(self, publisher):
        """Test CreateWithTask."""
        with self.assertRaises(UnavailableStorageError):
            self.interface.CreateWithTask(SNAPSHOT_WHEN_PRE_INSTALL)

        self.module.on_storage_reset(Mock())
        task_path = self.interface.CreateWithTask(SNAPSHOT_WHEN_PRE_INSTALL)

        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, SnapshotCreateTask)
        self.assertEqual(obj.implementation._storage, self.module.storage)
        self.assertEqual(obj.implementation._requests, [])
        self.assertEqual(obj.implementation._when, SNAPSHOT_WHEN_PRE_INSTALL)