Exemplo n.º 1
0
class PayloadsInterfaceTestCase(TestCase):

    def setUp(self):
        """Set up the payload module."""
        self.payload_module = PayloadsService()
        self.payload_interface = PayloadsInterface(self.payload_module)

        self.shared_ks_tests = PayloadKickstartSharedTest(self,
                                                          self.payload_module,
                                                          self.payload_interface)

    def kickstart_properties_test(self):
        """Test kickstart properties."""
        self.assertEqual(self.payload_interface.KickstartCommands, [
            "cdrom",
            "harddrive",
            "hmc",
            "liveimg",
            "nfs",
            "ostreesetup",
            "url"
        ])
        self.assertEqual(self.payload_interface.KickstartSections, [
            "packages"
        ])
        self.assertEqual(self.payload_interface.KickstartAddons, [])

    def no_kickstart_test(self):
        """Test kickstart is not set to the payloads service."""
        ks_in = None
        ks_out = ""
        self.shared_ks_tests.check_kickstart(ks_in, ks_out, expected_publish_calls=0)

    def kickstart_empty_test(self):
        """Test kickstart is empty for the payloads service."""
        ks_in = ""
        ks_out = ""
        self.shared_ks_tests.check_kickstart(ks_in, ks_out, expected_publish_calls=0)

    def no_payload_set_test(self):
        """Test empty string is returned when no payload is set."""
        self.assertEqual(self.payload_interface.ActivePayload, "")

    def generate_kickstart_without_payload_test(self):
        """Test kickstart parsing without payload set."""
        self.assertEqual(self.payload_interface.GenerateKickstart(), "")

    def process_kickstart_with_no_payload_test(self):
        """Test kickstart processing when no payload set or created based on KS data."""
        self.payload_interface.ReadKickstart("")
        self.assertEqual(self.payload_interface.ActivePayload, "")

    @patch_dbus_publish_object
    def create_dnf_payload_test(self, publisher):
        """Test creation and publishing of the DNF payload module."""
        payload_path = self.payload_interface.CreatePayload(PayloadType.DNF.value)
        self.assertEqual(self.payload_interface.CreatedPayloads, [payload_path])

        self.payload_interface.ActivatePayload(payload_path)
        self.assertEqual(self.payload_interface.ActivePayload, payload_path)

        self.assertIsInstance(PayloadContainer.from_object_path(payload_path), DNFModule)
        publisher.assert_called_once()

    @patch_dbus_publish_object
    def create_live_os_payload_test(self, publisher):
        """Test creation and publishing of the Live OS payload module."""
        payload_path = self.payload_interface.CreatePayload(PayloadType.LIVE_OS.value)
        self.assertEqual(self.payload_interface.CreatedPayloads, [payload_path])

        self.payload_interface.ActivatePayload(payload_path)
        self.assertEqual(self.payload_interface.ActivePayload, payload_path)

        self.assertIsInstance(PayloadContainer.from_object_path(payload_path), LiveOSModule)
        publisher.assert_called_once()

    @patch_dbus_publish_object
    def create_live_image_payload_test(self, publisher):
        """Test creation and publishing of the Live image payload module."""
        payload_path = self.payload_interface.CreatePayload(PayloadType.LIVE_IMAGE.value)
        self.assertEqual(self.payload_interface.CreatedPayloads, [payload_path])

        self.payload_interface.ActivatePayload(payload_path)
        self.assertEqual(self.payload_interface.ActivePayload, payload_path)

        self.assertIsInstance(PayloadContainer.from_object_path(payload_path), LiveImageModule)
        publisher.assert_called_once()

    @patch_dbus_publish_object
    def create_invalid_payload_test(self, publisher):
        """Test creation of the not existing payload."""
        with self.assertRaises(ValueError):
            self.payload_interface.CreatePayload("NotAPayload")

    @patch_dbus_publish_object
    def create_multiple_payloads_test(self, publisher):
        """Test creating two payloads."""
        path_1 = self.payload_interface.CreatePayload(PayloadType.DNF.value)
        self.assertEqual(self.payload_interface.CreatedPayloads, [path_1])
        self.assertEqual(self.payload_interface.ActivePayload, "")

        path_2 = self.payload_interface.CreatePayload(PayloadType.LIVE_OS.value)
        self.assertEqual(self.payload_interface.CreatedPayloads, [path_1, path_2])
        self.assertEqual(self.payload_interface.ActivePayload, "")

        self.payload_interface.ActivatePayload(path_1)
        self.assertEqual(self.payload_interface.ActivePayload, path_1)

        self.payload_interface.ActivatePayload(path_2)
        self.assertEqual(self.payload_interface.ActivePayload, path_2)

        self.assertEqual(publisher.call_count, 2)

    @patch_dbus_publish_object
    def create_live_os_source_test(self, publisher):
        """Test creation of the Live OS source module."""
        source_path = self.payload_interface.CreateSource(SOURCE_TYPE_LIVE_OS_IMAGE)

        check_dbus_object_creation(self, source_path, publisher, LiveOSSourceModule)

    @patch_dbus_publish_object
    def create_invalid_source_test(self, publisher):
        """Test creation of the not existing source."""
        with self.assertRaises(ValueError):
            self.payload_interface.CreateSource("NotASource")

    def is_network_required_test(self):
        """Test the IsNetworkRequired method."""
        self.assertEqual(self.payload_interface.IsNetworkRequired(), False)

        payload = self.payload_module.create_payload(PayloadType.DNF)
        self.payload_module.activate_payload(payload)

        self.assertEqual(self.payload_interface.IsNetworkRequired(), False)

        source = self.payload_module.create_source(SourceType.NFS)
        payload.set_sources([source])

        self.assertEqual(self.payload_interface.IsNetworkRequired(), True)

    def calculate_required_space_test(self):
        """Test the CalculateRequiredTest method."""
        self.assertEqual(self.payload_interface.CalculateRequiredSpace(), 0)

        payload = self.payload_module.create_payload(PayloadType.LIVE_IMAGE)
        self.payload_module.activate_payload(payload)

        self.assertEqual(self.payload_interface.CalculateRequiredSpace(), 0)

        source = self.payload_module.create_source(SourceType.LIVE_IMAGE)
        payload.set_sources([source])

        self.assertEqual(self.payload_interface.CalculateRequiredSpace(), 1024 * 1024 * 1024)

    def get_kernel_version_list_test(self):
        """Test the GetKernelVersionList method."""
        self.assertEqual(self.payload_interface.GetKernelVersionList(), [])

        payload = self.payload_module.create_payload(PayloadType.DNF)
        self.payload_module.activate_payload(payload)

        with self.assertRaises(UnavailableValueError):
            self.payload_interface.GetKernelVersionList()

        payload.set_kernel_version_list(["k1", "k2", "k3"])
        self.assertEqual(self.payload_interface.GetKernelVersionList(), ["k1", "k2", "k3"])

    @patch_dbus_publish_object
    def install_with_tasks_test(self, publisher):
        """Test the InstallWithTasks method."""
        self.assertEqual(self.payload_interface.InstallWithTasks(), [])

        payload = self.payload_module.create_payload(PayloadType.DNF)
        self.payload_module.activate_payload(payload)

        tasks_paths = self.payload_interface.InstallWithTasks()
        check_task_creation_list(self, tasks_paths, publisher, [
            PrepareSystemForInstallationTask
        ])

    @patch_dbus_publish_object
    def post_install_with_tasks_test(self, publisher):
        """Test the PostInstallWithTasks method."""
        self.assertEqual(self.payload_interface.PostInstallWithTasks(), [])

        payload = self.payload_module.create_payload(PayloadType.DNF)
        self.payload_module.activate_payload(payload)

        tasks_paths = self.payload_interface.PostInstallWithTasks()
        check_task_creation_list(self, tasks_paths, publisher, [
            CopyDriverDisksFilesTask
        ])

    @patch_dbus_publish_object
    def tear_down_with_tasks_test(self, publisher):
        """Test the TeardownWithTasks method."""
        self.assertEqual(self.payload_interface.TeardownWithTasks(), [])

        payload = self.payload_module.create_payload(PayloadType.DNF)
        self.payload_module.activate_payload(payload)

        source = self.payload_module.create_source(SourceType.CDROM)
        payload.set_sources([source])

        publisher.reset_mock()
        task_paths = self.payload_interface.TeardownWithTasks()
        check_task_creation_list(self, task_paths, publisher, [TearDownSourcesTask])
Exemplo n.º 2
0
class PayloadsInterfaceTestCase(TestCase):
    def setUp(self):
        """Set up the payload module."""
        self.payload_module = PayloadsService()
        self.payload_interface = PayloadsInterface(self.payload_module)

        self.shared_ks_tests = PayloadKickstartSharedTest(
            self, self.payload_module, self.payload_interface)

    def kickstart_properties_test(self):
        """Test kickstart properties."""
        self.assertEqual(self.payload_interface.KickstartCommands, [
            "cdrom", "harddrive", "hmc", "liveimg", "nfs", "ostreesetup", "url"
        ])
        self.assertEqual(self.payload_interface.KickstartSections,
                         ["packages"])
        self.assertEqual(self.payload_interface.KickstartAddons, [])

    def no_kickstart_test(self):
        """Test kickstart is not set to the payloads service."""
        ks_in = None
        ks_out = ""
        self.shared_ks_tests.check_kickstart(ks_in,
                                             ks_out,
                                             expected_publish_calls=0)

    def kickstart_empty_test(self):
        """Test kickstart is empty for the payloads service."""
        ks_in = ""
        ks_out = ""
        self.shared_ks_tests.check_kickstart(ks_in,
                                             ks_out,
                                             expected_publish_calls=0)

    def no_payload_set_test(self):
        """Test empty string is returned when no payload is set."""
        self.assertEqual(self.payload_interface.ActivePayload, "")

    def generate_kickstart_without_payload_test(self):
        """Test kickstart parsing without payload set."""
        self.assertEqual(self.payload_interface.GenerateKickstart(), "")

    def process_kickstart_with_no_payload_test(self):
        """Test kickstart processing when no payload set or created based on KS data."""
        self.payload_interface.ReadKickstart("")
        self.assertEqual(self.payload_interface.ActivePayload, "")

    @patch_dbus_publish_object
    def create_dnf_payload_test(self, publisher):
        """Test creation and publishing of the DNF payload module."""
        payload_path = self.payload_interface.CreatePayload(
            PayloadType.DNF.value)
        self.assertEqual(self.payload_interface.CreatedPayloads,
                         [payload_path])

        self.payload_interface.ActivatePayload(payload_path)
        self.assertEqual(self.payload_interface.ActivePayload, payload_path)

        self.assertIsInstance(PayloadContainer.from_object_path(payload_path),
                              DNFModule)
        publisher.assert_called_once()

    @patch_dbus_publish_object
    def create_live_os_payload_test(self, publisher):
        """Test creation and publishing of the Live OS payload module."""
        payload_path = self.payload_interface.CreatePayload(
            PayloadType.LIVE_OS.value)
        self.assertEqual(self.payload_interface.CreatedPayloads,
                         [payload_path])

        self.payload_interface.ActivatePayload(payload_path)
        self.assertEqual(self.payload_interface.ActivePayload, payload_path)

        self.assertIsInstance(PayloadContainer.from_object_path(payload_path),
                              LiveOSModule)
        publisher.assert_called_once()

    @patch_dbus_publish_object
    def create_live_image_payload_test(self, publisher):
        """Test creation and publishing of the Live image payload module."""
        payload_path = self.payload_interface.CreatePayload(
            PayloadType.LIVE_IMAGE.value)
        self.assertEqual(self.payload_interface.CreatedPayloads,
                         [payload_path])

        self.payload_interface.ActivatePayload(payload_path)
        self.assertEqual(self.payload_interface.ActivePayload, payload_path)

        self.assertIsInstance(PayloadContainer.from_object_path(payload_path),
                              LiveImageModule)
        publisher.assert_called_once()

    @patch_dbus_publish_object
    def create_invalid_payload_test(self, publisher):
        """Test creation of the not existing payload."""
        with self.assertRaises(ValueError):
            self.payload_interface.CreatePayload("NotAPayload")

    @patch_dbus_publish_object
    def create_multiple_payloads_test(self, publisher):
        """Test creating two payloads."""
        path_1 = self.payload_interface.CreatePayload(PayloadType.DNF.value)
        self.assertEqual(self.payload_interface.CreatedPayloads, [path_1])
        self.assertEqual(self.payload_interface.ActivePayload, "")

        path_2 = self.payload_interface.CreatePayload(
            PayloadType.LIVE_OS.value)
        self.assertEqual(self.payload_interface.CreatedPayloads,
                         [path_1, path_2])
        self.assertEqual(self.payload_interface.ActivePayload, "")

        self.payload_interface.ActivatePayload(path_1)
        self.assertEqual(self.payload_interface.ActivePayload, path_1)

        self.payload_interface.ActivatePayload(path_2)
        self.assertEqual(self.payload_interface.ActivePayload, path_2)

        self.assertEqual(publisher.call_count, 2)

    @patch_dbus_publish_object
    def create_live_os_source_test(self, publisher):
        """Test creation of the Live OS source module."""
        source_path = self.payload_interface.CreateSource(
            SOURCE_TYPE_LIVE_OS_IMAGE)

        check_dbus_object_creation(self, source_path, publisher,
                                   LiveOSSourceModule)

    @patch_dbus_publish_object
    def create_invalid_source_test(self, publisher):
        """Test creation of the not existing source."""
        with self.assertRaises(ValueError):
            self.payload_interface.CreateSource("NotASource")
class PayloadsInterfaceTestCase(TestCase):
    def setUp(self):
        """Set up the payload module."""
        self.payload_module = PayloadsService()
        self.payload_interface = PayloadsInterface(self.payload_module)

    def kickstart_properties_test(self):
        """Test kickstart properties."""
        self.assertEqual(self.payload_interface.KickstartCommands, ['liveimg'])
        self.assertEqual(self.payload_interface.KickstartSections,
                         ["packages"])
        self.assertEqual(self.payload_interface.KickstartAddons, [])

    def no_payload_set_test(self):
        """Test empty string is returned when no payload is set."""
        self.assertEqual(self.payload_interface.GetActivePayloadPath(), "")

    def generate_kickstart_without_payload_test(self):
        """Test kickstart parsing without payload set."""
        self.assertEqual(self.payload_interface.GenerateKickstart(), "")

    def process_kickstart_with_no_payload_test(self):
        """Test kickstart processing when no payload set or created based on KS data."""
        with self.assertLogs('anaconda.modules.payloads.payloads',
                             level="WARNING") as log:
            self.payload_interface.ReadKickstart("")

            self.assertTrue(
                any(map(lambda x: "No payload was created" in x, log.output)))

    @patch_dbus_publish_object
    def is_payload_set_test(self, publisher):
        """Test IsPayloadSet API."""
        self.assertFalse(self.payload_interface.IsPayloadSet())

        self.payload_interface.CreatePayload(PayloadType.DNF.value)
        self.assertTrue(self.payload_interface.IsPayloadSet())

    @patch_dbus_publish_object
    def create_dnf_payload_test(self, publisher):
        """Test creation and publishing of the DNF payload module."""
        self.payload_interface.CreatePayload(PayloadType.DNF.value)
        self.assertEqual(self.payload_interface.GetActivePayloadPath(),
                         PAYLOAD_DEFAULT.object_path)
        # here the publisher is called twice because the Packages section is also published
        self.assertEqual(publisher.call_count, 2)

    @patch_dbus_publish_object
    def create_live_os_payload_test(self, publisher):
        """Test creation and publishing of the Live OS payload module."""
        self.payload_interface.CreatePayload(PayloadType.LIVE_OS.value)
        self.assertEqual(self.payload_interface.GetActivePayloadPath(),
                         PAYLOAD_LIVE_OS.object_path)
        publisher.assert_called_once()

    @patch_dbus_publish_object
    def create_live_image_payload_test(self, publisher):
        """Test creation and publishing of the Live image payload module."""
        self.payload_interface.CreatePayload(PayloadType.LIVE_IMAGE.value)
        self.assertEqual(self.payload_interface.GetActivePayloadPath(),
                         PAYLOAD_LIVE_IMAGE.object_path)
        publisher.assert_called_once()

    @patch_dbus_publish_object
    def create_invalid_payload_test(self, publisher):
        """Test creation of the not existing payload."""
        with self.assertRaises(ValueError):
            self.payload_interface.CreatePayload("NotAPayload")

    @patch_dbus_publish_object
    def create_multiple_payloads_test(self, publisher):
        """Test creating two payloads."""
        self.payload_interface.CreatePayload(PayloadType.DNF.value)
        self.payload_interface.CreatePayload(PayloadType.LIVE_OS.value)

        # The last one should win
        self.assertEqual(self.payload_interface.GetActivePayloadPath(),
                         PAYLOAD_LIVE_OS.object_path)
        self.assertEqual(publisher.call_count, 3)

    @patch_dbus_publish_object
    def create_live_os_source_test(self, publisher):
        """Test creation of the Live OS source module."""
        source_path = self.payload_interface.CreateSource(
            SourceType.LIVE_OS_IMAGE.value)

        check_dbus_object_creation(self, source_path, publisher,
                                   LiveOSSourceModule)

    @patch_dbus_publish_object
    def create_invalid_source_test(self, publisher):
        """Test creation of the not existing source."""
        with self.assertRaises(ValueError):
            self.payload_interface.CreateSource("NotASource")
Exemplo n.º 4
0
class PayloadsInterfaceTestCase(TestCase):
    def setUp(self):
        """Set up the payload module."""
        self.payload_module = PayloadsService()
        self.payload_interface = PayloadsInterface(self.payload_module)

    def kickstart_properties_test(self):
        """Test kickstart properties."""
        self.assertEqual(self.payload_interface.KickstartCommands, ['liveimg'])
        self.assertEqual(self.payload_interface.KickstartSections,
                         ["packages"])
        self.assertEqual(self.payload_interface.KickstartAddons, [])

    def no_payload_set_test(self):
        """Test empty string is returned when no payload is set."""
        with self.assertRaises(PayloadNotSetError):
            self.payload_interface.GetActivePayload()

    def generate_kickstart_without_payload_test(self):
        """Test kickstart parsing without payload set."""
        self.assertEqual(self.payload_interface.GenerateKickstart(), "")

    def process_kickstart_with_no_payload_test(self):
        """Test kickstart processing when no payload set or created based on KS data."""
        self.payload_interface.ReadKickstart("")

        with self.assertRaises(PayloadNotSetError):
            self.payload_interface.GetActivePayload()

    @patch_dbus_publish_object
    def is_payload_set_test(self, publisher):
        """Test IsPayloadSet API."""
        self.assertFalse(self.payload_interface.IsPayloadSet())

        self.payload_interface.CreatePayload(PayloadType.DNF.value)
        self.assertTrue(self.payload_interface.IsPayloadSet())

    @patch_dbus_publish_object
    def create_dnf_payload_test(self, publisher):
        """Test creation and publishing of the DNF payload module."""
        payload_path = self.payload_interface.CreatePayload(
            PayloadType.DNF.value)
        self.assertEqual(self.payload_interface.GetActivePayload(),
                         payload_path)
        self.assertIsInstance(PayloadContainer.from_object_path(payload_path),
                              DNFModule)
        publisher.assert_called_once()

    @patch_dbus_publish_object
    def create_live_os_payload_test(self, publisher):
        """Test creation and publishing of the Live OS payload module."""
        payload_path = self.payload_interface.CreatePayload(
            PayloadType.LIVE_OS.value)
        self.assertEqual(self.payload_interface.GetActivePayload(),
                         payload_path)
        self.assertIsInstance(PayloadContainer.from_object_path(payload_path),
                              LiveOSModule)
        publisher.assert_called_once()

    @patch_dbus_publish_object
    def create_live_image_payload_test(self, publisher):
        """Test creation and publishing of the Live image payload module."""
        payload_path = self.payload_interface.CreatePayload(
            PayloadType.LIVE_IMAGE.value)
        self.assertEqual(self.payload_interface.GetActivePayload(),
                         payload_path)
        self.assertIsInstance(PayloadContainer.from_object_path(payload_path),
                              LiveImageModule)
        publisher.assert_called_once()

    @patch_dbus_publish_object
    def create_invalid_payload_test(self, publisher):
        """Test creation of the not existing payload."""
        with self.assertRaises(ValueError):
            self.payload_interface.CreatePayload("NotAPayload")

    @patch_dbus_publish_object
    def create_multiple_payloads_test(self, publisher):
        """Test creating two payloads."""
        self.payload_interface.CreatePayload(PayloadType.DNF.value)
        path = self.payload_interface.CreatePayload(PayloadType.LIVE_OS.value)

        # The last one should win
        self.assertEqual(self.payload_interface.GetActivePayload(), path)
        self.assertEqual(publisher.call_count, 2)

    @patch_dbus_publish_object
    def create_live_os_source_test(self, publisher):
        """Test creation of the Live OS source module."""
        source_path = self.payload_interface.CreateSource(
            SourceType.LIVE_OS_IMAGE.value)

        check_dbus_object_creation(self, source_path, publisher,
                                   LiveOSSourceModule)

    @patch_dbus_publish_object
    def create_invalid_source_test(self, publisher):
        """Test creation of the not existing source."""
        with self.assertRaises(ValueError):
            self.payload_interface.CreateSource("NotASource")