Exemple #1
0
    def setUp(self):
        self.module = DNFModule()
        self.interface = DNFInterface(self.module)

        self.shared_tests = PayloadSharedTest(self,
                                              payload=self.module,
                                              payload_intf=self.interface)
Exemple #2
0
 def _create(cls, object_type):
     if object_type == PayloadType.LIVE_IMAGE:
         from pyanaconda.modules.payloads.payload.live_image.live_image import \
             LiveImageModule
         return LiveImageModule()
     elif object_type == PayloadType.LIVE_OS:
         from pyanaconda.modules.payloads.payload.live_os.live_os import LiveOSModule
         return LiveOSModule()
     elif object_type == PayloadType.DNF:
         from pyanaconda.modules.payloads.payload.dnf.dnf import DNFModule
         return DNFModule()
Exemple #3
0
    def create_payload(payload_type: PayloadType):
        """Create a partitioning module.

        :param payload_type: a payload type
        :return: a payload module
        """
        if payload_type == PayloadType.LIVE_IMAGE:
            from pyanaconda.modules.payloads.payload.live_image.live_image import \
                LiveImageModule
            return LiveImageModule()

        if payload_type == PayloadType.LIVE_OS:
            from pyanaconda.modules.payloads.payload.live_os.live_os import LiveOSModule
            return LiveOSModule()

        if payload_type == PayloadType.DNF:
            from pyanaconda.modules.payloads.payload.dnf.dnf import DNFModule
            return DNFModule()

        raise ValueError("Unknown payload type: {}".format(payload_type))
Exemple #4
0
class DNFModuleTestCase(unittest.TestCase):
    def setUp(self):
        self.module = DNFModule()

    def _create_source(self, source_type, state=SourceState.UNREADY):
        """Create a new source with a mocked state."""
        return PayloadSharedTest.prepare_source(source_type, state)

    def test_is_network_required(self):
        """Test the is_network_required method."""
        assert self.module.is_network_required() is False

        source1 = self._create_source(SourceType.CDROM)
        self.module.set_sources([source1])

        assert self.module.is_network_required() is False

        source2 = self._create_source(SourceType.NFS)
        self.module.set_sources([source1, source2])

        assert self.module.is_network_required() is True
Exemple #5
0
 def setUp(self):
     self.module = DNFModule()
Exemple #6
0
class DNFInterfaceTestCase(unittest.TestCase):
    def setUp(self):
        self.module = DNFModule()
        self.interface = DNFInterface(self.module)

        self.shared_tests = PayloadSharedTest(payload=self.module,
                                              payload_intf=self.interface)

    def test_type(self):
        self.shared_tests.check_type(PayloadType.DNF)

    def test_supported_sources(self):
        """Test DNF supported sources API."""
        assert [SOURCE_TYPE_CDROM,
             SOURCE_TYPE_HDD,
             SOURCE_TYPE_HMC,
             SOURCE_TYPE_NFS,
             SOURCE_TYPE_REPO_FILES,
             SOURCE_TYPE_CLOSEST_MIRROR,
             SOURCE_TYPE_CDN,
             SOURCE_TYPE_URL] == \
            self.interface.SupportedSourceTypes

    def _check_dbus_property(self, *args, **kwargs):
        check_dbus_property(PAYLOAD_DNF, self.interface, *args, **kwargs)

    def test_packages_kickstarted_property(self):
        """Test the PackagesKickstarted property."""
        assert self.interface.PackagesKickstarted is False

        data = KickstartSpecificationHandler(PayloadKickstartSpecification)

        self.module.process_kickstart(data)
        assert self.interface.PackagesKickstarted is False

        data.packages.seen = True
        self.module.process_kickstart(data)
        assert self.interface.PackagesKickstarted is True

    def test_packages_selection_property(self):
        """Test the PackagesSelection property."""
        data = {
            "core-group-enabled":
            get_variant(Bool, False),
            "default-environment-enabled":
            get_variant(Bool, False),
            "environment":
            get_variant(Str, "environment"),
            "groups":
            get_variant(List[Str], ["g1", "g2"]),
            "groups-package-types":
            get_variant(Dict[Str, List[Str]], {
                "g1": GROUP_PACKAGE_TYPES_ALL,
                "g2": GROUP_PACKAGE_TYPES_REQUIRED
            }),
            "excluded-groups":
            get_variant(List[Str], ["g3", "g4"]),
            "packages":
            get_variant(List[Str], ["p1", "p2"]),
            "excluded-packages":
            get_variant(List[Str], ["p3", "p4"]),
            "modules":
            get_variant(List[Str], ["m1", "m2:latest", "m3:1.01"]),
            "disabled-modules":
            get_variant(List[Str], ["m4", "m5:master", "m6:10"]),
        }

        self._check_dbus_property("PackagesSelection", data)

    def test_packages_selection_data(self):
        """Test the PackagesSelectionData structure."""
        data = PackagesSelectionData.to_structure(PackagesSelectionData())

        self._check_dbus_property("PackagesSelection", data)

    def test_packages_configuration_property(self):
        """Test the PackagesConfiguration property."""
        data = {
            "docs-excluded": get_variant(Bool, True),
            "weakdeps-excluded": get_variant(Bool, True),
            "missing-ignored": get_variant(Bool, True),
            "broken-ignored": get_variant(Bool, True),
            "languages": get_variant(Str, "en,es"),
            "multilib-policy": get_variant(Str, MULTILIB_POLICY_ALL),
            "timeout": get_variant(Int, 10),
            "retries": get_variant(Int, 5),
        }

        self._check_dbus_property("PackagesConfiguration", data)

    def test_packages_configuration_data(self):
        """Test the PackagesConfigurationData structure."""
        data = PackagesConfigurationData.to_structure(
            PackagesConfigurationData())

        self._check_dbus_property("PackagesConfiguration", data)

    @staticmethod
    def _generate_expected_repo_configuration_dict(url=""):
        return {
            "name":
            get_variant(Str, ""),
            "enabled":
            get_variant(Bool, True),
            "url":
            get_variant(Str, url),
            "type":
            get_variant(Str, URL_TYPE_BASEURL),
            "ssl-verification-enabled":
            get_variant(Bool, True),
            "ssl-configuration":
            get_variant(
                Structure, {
                    "ca-cert-path": get_variant(Str, ""),
                    "client-cert-path": get_variant(Str, ""),
                    "client-key-path": get_variant(Str, "")
                }),
            "proxy":
            get_variant(Str, ""),
            "cost":
            get_variant(Int, 1000),
            "excluded-packages":
            get_variant(List[Str], []),
            "included-packages":
            get_variant(List[Str], []),
            "installation-enabled":
            get_variant(Bool, False),
        }

    @patch(
        "pyanaconda.modules.payloads.source.cdrom.cdrom.CdromSourceModule.mount_point",
        new_callable=PropertyMock)
    @patch_dbus_publish_object
    def test_cdrom_get_repo_configurations(self, publisher, mount_point):
        """Test DNF GetRepoConfigurations for CDROM source."""
        mount_point.return_value = "/install_source/cdrom"
        source = self.shared_tests.prepare_source(SourceType.CDROM)

        self.shared_tests.set_sources([source])

        expected = [
            self._generate_expected_repo_configuration_dict(
                "file:///install_source/cdrom")
        ]

        assert self.interface.GetRepoConfigurations() == expected

    @patch(
        "pyanaconda.modules.payloads.source.hmc.hmc.HMCSourceModule.mount_point",
        new_callable=PropertyMock)
    @patch_dbus_publish_object
    def test_hmc_get_repo_configurations(self, publisher, mount_point):
        """Test DNF GetRepoConfigurations for CDROM source."""
        mount_point.return_value = "/install_source/hmc"
        source = self.shared_tests.prepare_source(SourceType.HMC)

        self.shared_tests.set_sources([source])

        expected = [
            self._generate_expected_repo_configuration_dict(
                "file:///install_source/hmc")
        ]

        assert self.interface.GetRepoConfigurations() == expected

    @patch(
        "pyanaconda.modules.payloads.source.nfs.nfs.NFSSourceModule.install_tree_path",
        new_callable=PropertyMock)
    @patch_dbus_publish_object
    def test_nfs_get_repo_configurations(self, publisher,
                                         install_tree_path_mock):
        """Test DNF GetRepoConfigurations for NFS source."""
        install_tree_path_mock.return_value = "/install_source/nfs"
        source = self.shared_tests.prepare_source(SourceType.NFS)

        self.shared_tests.set_sources([source])

        expected = [
            self._generate_expected_repo_configuration_dict(
                "file:///install_source/nfs")
        ]

        assert self.interface.GetRepoConfigurations() == expected

    @patch(
        "pyanaconda.modules.payloads.source.harddrive.harddrive.HardDriveSourceModule.install_tree_path",
        new_callable=PropertyMock)
    @patch_dbus_publish_object
    def test_harddrive_get_repo_configurations(self, publisher,
                                               install_tree_path_mock):
        """Test DNF GetRepoConfigurations for HARDDRIVE source."""
        install_tree_path_mock.return_value = "/install_source/harddrive"
        source = self.shared_tests.prepare_source(SourceType.HDD)

        self.shared_tests.set_sources([source])

        expected = [
            self._generate_expected_repo_configuration_dict(
                "file:///install_source/harddrive")
        ]

        assert self.interface.GetRepoConfigurations() == expected

    @patch_dbus_publish_object
    def test_url_get_repo_configurations(self, publisher):
        """Test DNF GetRepoConfigurations for URL source."""
        source = self.shared_tests.prepare_source(SourceType.URL)

        data = RepoConfigurationData()
        data.name = "Bernard Black"
        data.url = "http://library.uk"
        data.ssl_verification_enabled = False
        data.proxy = "http://MannyBianco/"

        source.set_repo_configuration(data)
        self.shared_tests.set_sources([source])

        expected = self._generate_expected_repo_configuration_dict()
        expected.update({
            "name": get_variant(Str, "Bernard Black"),
            "url": get_variant(Str, "http://library.uk"),
            "proxy": get_variant(Str, "http://MannyBianco/"),
            "ssl-verification-enabled": get_variant(Bool, False),
        })

        assert self.interface.GetRepoConfigurations() == [expected]
class PayloadBaseInterfaceTestCase(unittest.TestCase):
    def setUp(self):
        self.module = DNFModule()
        self.interface = DNFInterface(self.module)

        self.shared_tests = PayloadSharedTest(self,
                                              payload=self.module,
                                              payload_intf=self.interface)

    def type_test(self):
        self.shared_tests.check_type(PayloadType.DNF)

    def required_space_test(self):
        """Test required space."""
        self.module._required_space = 100

        self.assertEqual(self.interface.RequiredSpace, 100)

    def required_default_space_test(self):
        """Test default value for required space.

        This is used when space is not known.
        """
        self.module._required_space = None

        self.assertEqual(self.interface.RequiredSpace,
                         self.module.default_required_space)

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL])
    def supported_sources_test(self):
        """Test supported sources API."""
        self.assertEqual([SourceType.URL.value],
                         self.interface.SupportedSourceTypes)

    def sources_empty_test(self):
        """Test sources API for emptiness."""
        self.shared_tests.check_empty_sources()

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL])
    @patch_dbus_publish_object
    def set_source_test(self, publisher):
        """Test if set source API payload."""
        sources = [self.shared_tests.prepare_source(SourceType.URL)]

        self.shared_tests.set_and_check_sources(sources)

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL])
    @patch_dbus_publish_object
    def add_source_test(self, publisher):
        """Test module API to add source."""
        source1 = self.shared_tests.prepare_source(SourceType.URL,
                                                   SourceState.NOT_APPLICABLE)

        sources = [source1]
        self.shared_tests.set_and_check_sources(sources)

        source2 = self.shared_tests.prepare_source(SourceType.URL)
        self.module.add_source(source2)

        sources.append(source2)
        self.shared_tests.check_sources(sources)

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL])
    @patch_dbus_publish_object
    def add_source_incompatible_source_failed_test(self, publisher):
        """Test module API to add source failed with incompatible source."""
        source1 = self.shared_tests.prepare_source(SourceType.URL,
                                                   SourceState.NOT_APPLICABLE)

        sources = [source1]
        self.shared_tests.set_and_check_sources(sources)

        source2 = self.shared_tests.prepare_source(SourceType.NFS)
        with self.assertRaises(IncompatibleSourceError):
            self.module.add_source(source2)

        self.shared_tests.check_sources(sources)

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL])
    @patch_dbus_publish_object
    def add_source_ready_failed_test(self, publisher):
        """Test module API to add source failed with ready source."""
        source1 = self.shared_tests.prepare_source(SourceType.URL,
                                                   SourceState.READY)

        sources = [source1]
        self.shared_tests.set_and_check_sources(sources)

        source2 = self.shared_tests.prepare_source(SourceType.URL)
        with self.assertRaises(SourceSetupError):
            self.module.add_source(source2)

        self.shared_tests.check_sources(sources)

    @patch.object(DNFModule, "supported_source_types",
                  [SourceType.URL, SourceType.NFS])
    @patch_dbus_publish_object
    def set_multiple_source_test(self, publisher):
        """Test payload setting multiple compatible sources."""
        sources = [
            self.shared_tests.prepare_source(SourceType.NFS),
            self.shared_tests.prepare_source(SourceType.URL),
            self.shared_tests.prepare_source(SourceType.URL),
        ]

        self.shared_tests.set_and_check_sources(sources)

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL])
    @patch_dbus_publish_object
    def set_incompatible_source_test(self, publisher):
        """Test payload setting incompatible sources."""
        sources = [self.shared_tests.prepare_source(SourceType.LIVE_OS_IMAGE)]

        cm = self.shared_tests.set_and_check_sources(
            sources, exception=IncompatibleSourceError)

        msg = "Source type {} is not supported by this payload.".format(
            SourceType.LIVE_OS_IMAGE.value)
        self.assertEqual(str(cm.exception), msg)

    @patch.object(DNFModule, "supported_source_types",
                  [SourceType.NFS, SourceType.URL])
    @patch_dbus_publish_object
    def set_when_initialized_source_fail_test(self, publisher):
        """Test payload can't set new sources if the old ones are initialized."""
        source1 = self.shared_tests.prepare_source(SourceType.NFS)
        source2 = self.shared_tests.prepare_source(
            SourceType.URL, state=SourceState.NOT_APPLICABLE)

        self.shared_tests.set_and_check_sources([source1])

        # can't switch source if attached source is ready
        source1.get_state.return_value = SourceState.READY
        self.shared_tests.set_sources([source2], SourceSetupError)
        self.shared_tests.check_sources([source1])

        # change to source2 when attached source state is UNREADY
        source1.get_state.return_value = SourceState.UNREADY
        self.shared_tests.set_and_check_sources([source2])

        # can change back anytime because source2 has state NOT_APPLICABLE
        self.shared_tests.set_and_check_sources([source1])
class PayloadBaseInterfaceTestCase(unittest.TestCase):

    def setUp(self):
        self.module = DNFModule()
        self.interface = DNFInterface(self.module)

        self.shared_tests = PayloadSharedTest(self,
                                              payload=self.module,
                                              payload_intf=self.interface)

    def type_test(self):
        self.shared_tests.check_type(PayloadType.DNF)

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL])
    def supported_sources_test(self):
        """Test supported sources API."""
        self.assertEqual(
            [SourceType.URL.value],
            self.interface.SupportedSourceTypes)

    def sources_empty_test(self):
        """Test sources API for emptiness."""
        self.shared_tests.check_empty_sources()

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL])
    @patch_dbus_publish_object
    def set_source_test(self, publisher):
        """Test if set source API payload."""
        sources = [self.shared_tests.prepare_source(SourceType.URL)]

        self.shared_tests.set_and_check_sources(sources)

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL])
    @patch_dbus_publish_object
    def add_source_test(self, publisher):
        """Test module API to add source."""
        source1 = self.shared_tests.prepare_source(SourceType.URL, SourceState.NOT_APPLICABLE)

        sources = [source1]
        self.shared_tests.set_and_check_sources(sources)

        source2 = self.shared_tests.prepare_source(SourceType.URL)
        self.module.add_source(source2)

        sources.append(source2)
        self.shared_tests.check_sources(sources)

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL])
    @patch_dbus_publish_object
    def add_source_incompatible_source_failed_test(self, publisher):
        """Test module API to add source failed with incompatible source."""
        source1 = self.shared_tests.prepare_source(SourceType.URL, SourceState.NOT_APPLICABLE)

        sources = [source1]
        self.shared_tests.set_and_check_sources(sources)

        source2 = self.shared_tests.prepare_source(SourceType.NFS)
        with self.assertRaises(IncompatibleSourceError):
            self.module.add_source(source2)

        self.shared_tests.check_sources(sources)

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL])
    @patch_dbus_publish_object
    def add_source_ready_failed_test(self, publisher):
        """Test module API to add source failed with ready source."""
        source1 = self.shared_tests.prepare_source(SourceType.URL, SourceState.READY)

        sources = [source1]
        self.shared_tests.set_and_check_sources(sources)

        source2 = self.shared_tests.prepare_source(SourceType.URL)
        with self.assertRaises(SourceSetupError):
            self.module.add_source(source2)

        self.shared_tests.check_sources(sources)

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL, SourceType.NFS])
    @patch_dbus_publish_object
    def set_multiple_source_test(self, publisher):
        """Test payload setting multiple compatible sources."""
        sources = [
            self.shared_tests.prepare_source(SourceType.NFS),
            self.shared_tests.prepare_source(SourceType.URL),
            self.shared_tests.prepare_source(SourceType.URL),
        ]

        self.shared_tests.set_and_check_sources(sources)

    @patch.object(DNFModule, "supported_source_types", [SourceType.URL])
    @patch_dbus_publish_object
    def set_incompatible_source_test(self, publisher):
        """Test payload setting incompatible sources."""
        sources = [self.shared_tests.prepare_source(SourceType.LIVE_OS_IMAGE)]

        cm = self.shared_tests.set_and_check_sources(sources, exception=IncompatibleSourceError)

        msg = "Source type {} is not supported by this payload.".format(
            SourceType.LIVE_OS_IMAGE.value)
        self.assertEqual(str(cm.exception), msg)

    @patch.object(DNFModule, "supported_source_types", [SourceType.NFS, SourceType.URL])
    @patch_dbus_publish_object
    def set_when_initialized_source_fail_test(self, publisher):
        """Test payload can't set new sources if the old ones are initialized."""
        source1 = self.shared_tests.prepare_source(SourceType.NFS)
        source2 = self.shared_tests.prepare_source(SourceType.URL, state=SourceState.NOT_APPLICABLE)

        self.shared_tests.set_and_check_sources([source1])

        # can't switch source if attached source is ready
        source1.get_state.return_value = SourceState.READY
        self.shared_tests.set_sources([source2], SourceSetupError)
        self.shared_tests.check_sources([source1])

        # change to source2 when attached source state is UNREADY
        source1.get_state.return_value = SourceState.UNREADY
        self.shared_tests.set_and_check_sources([source2])

        # can change back anytime because source2 has state NOT_APPLICABLE
        self.shared_tests.set_and_check_sources([source1])

    @patch_dbus_publish_object
    def is_network_required_test(self, publisher):
        """Test IsNetworkRequired."""
        self.assertEqual(self.interface.IsNetworkRequired(), False)

        source1 = self.shared_tests.prepare_source(SourceType.CDROM, state=SourceState.UNREADY)
        self.shared_tests.set_sources([source1])

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

        source2 = self.shared_tests.prepare_source(SourceType.NFS, state=SourceState.UNREADY)
        self.shared_tests.set_sources([source1, source2])

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

    @patch_dbus_publish_object
    def calculate_required_space_test(self, publisher):
        """Test CalculateRequiredTest."""
        self.assertEqual(self.interface.CalculateRequiredSpace(), 0)

        source1 = self.shared_tests.prepare_source(SourceType.CDROM, state=SourceState.UNREADY)
        self.shared_tests.set_sources([source1])

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

    @patch_dbus_publish_object
    def set_up_sources_with_task_test(self, publisher):
        """Test SetUpSourcesWithTask."""
        source = SourceFactory.create_source(SourceType.CDROM)
        self.module.add_source(source)

        task_path = self.interface.SetUpSourcesWithTask()
        obj = check_task_creation(self, task_path, publisher, SetUpSourcesTask)
        self.assertEqual(obj.implementation._sources, [source])

    @patch_dbus_publish_object
    def tear_down_sources_with_task_test(self, publisher):
        """Test TearDownSourcesWithTask."""
        source = SourceFactory.create_source(SourceType.CDROM)
        self.module.add_source(source)

        task_path = self.interface.TearDownSourcesWithTask()
        obj = check_task_creation(self, task_path, publisher, TearDownSourcesTask)
        self.assertEqual(obj.implementation._sources, [source])