Exemple #1
0
class DNFInterfaceTestCase(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 supported_sources_test(self):
        """Test DNF supported sources API."""
        self.assertEqual(
            [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)

    @staticmethod
    def _generate_expected_repo_configuration_dict(mount_path):
        return {
            "name": get_variant(Str, ""),
            "url": get_variant(Str, mount_path),
            "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], [])
        }

    @patch("pyanaconda.modules.payloads.source.cdrom.cdrom.CdromSourceModule.mount_point",
           new_callable=PropertyMock)
    @patch_dbus_publish_object
    def cdrom_get_repo_configurations_test(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")]

        self.assertEqual(self.interface.GetRepoConfigurations(), expected)

    @patch("pyanaconda.modules.payloads.source.hmc.hmc.HMCSourceModule.mount_point",
           new_callable=PropertyMock)
    @patch_dbus_publish_object
    def hmc_get_repo_configurations_test(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")]

        self.assertEqual(self.interface.GetRepoConfigurations(), expected)

    @patch("pyanaconda.modules.payloads.source.nfs.nfs.NFSSourceModule.mount_point",
           new_callable=PropertyMock)
    @patch_dbus_publish_object
    def nfs_get_repo_configurations_test(self, publisher, mount_point):
        """Test DNF GetRepoConfigurations for NFS source."""
        mount_point.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")]

        self.assertEqual(self.interface.GetRepoConfigurations(), expected)

    @patch("pyanaconda.modules.payloads.source.harddrive.harddrive.HardDriveSourceModule.install_tree_path",
           new_callable=PropertyMock)
    @patch_dbus_publish_object
    def harddrive_get_repo_configurations_test(self, publisher, mount_point):
        """Test DNF GetRepoConfigurations for HARDDRIVE source."""
        mount_point.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")]

        self.assertEqual(self.interface.GetRepoConfigurations(), expected)

    @patch_dbus_publish_object
    def url_get_repo_configurations_test(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 = [{
            "name": get_variant(Str, "Bernard Black"),
            "url": get_variant(Str, "http://library.uk"),
            "type": get_variant(Str, URL_TYPE_BASEURL),
            "ssl-verification-enabled": get_variant(Bool, False),
            "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, "http://MannyBianco/"),
            "cost": get_variant(Int, 1000),
            "excluded-packages": get_variant(List[Str], []),
            "included-packages": get_variant(List[Str], [])
        }]

        self.assertEqual(self.interface.GetRepoConfigurations(), expected)
Exemple #2
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]