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()
예제 #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)
예제 #3
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)
예제 #4
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 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()
예제 #5
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 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()