def test_add_repository_no_ssl_configuration(self):
        """Test the add_repository method without the ssl configuration."""
        data = RepoConfigurationData()
        data.name = "r1"
        data.ssl_verification_enabled = False

        self.dnf_manager.add_repository(data)
        self._check_repo("r1", [
            "sslverify = 0",
        ])
    def test_load_data_failed_download(self):
        """Test the load_data method with no metadata."""
        with tempfile.TemporaryDirectory() as path:
            data = RepoConfigurationData()
            data.url = "invalid://" + path

            with pytest.raises(NoTreeInfoError) as cm:
                self.metadata.load_data(data)

            assert str(cm.value) == "Couldn't download treeinfo metadata."
    def test_add_repository_no_auth_proxy(self):
        """Test the add_repository method the no auth proxy configuration."""
        data = RepoConfigurationData()
        data.name = "r1"
        data.proxy = "http://example.com:1234"

        self.dnf_manager.add_repository(data)
        self._check_repo("r1", [
            "proxy = http://example.com:1234",
        ])
    def test_load_data_no_metadata(self):
        """Test the load_data method with no metadata."""
        with tempfile.TemporaryDirectory() as path:
            data = RepoConfigurationData()
            data.url = "file://" + path

            with pytest.raises(NoTreeInfoError) as cm:
                self.metadata.load_data(data)

            assert str(cm.value) == "No treeinfo metadata found (404)."
    def test_add_repository_invalid_proxy(self):
        """Test the add_repository method the invalid proxy configuration."""
        data = RepoConfigurationData()
        data.name = "r1"
        data.proxy = "@:/invalid"

        self.dnf_manager.add_repository(data)
        self._check_repo("r1", [
            "proxy = ",
        ])
    def test_add_repository_disabled(self):
        """Test the add_repository method with disabled repo."""
        data = RepoConfigurationData()
        data.name = "r1"
        data.enabled = False

        self.dnf_manager.add_repository(data)

        self._check_repo("r1", [
            "enabled = 0",
        ])
    def test_add_repository_metalink(self):
        """Test the add_repository method with metalink."""
        data = RepoConfigurationData()
        data.name = "r1"
        data.type = URL_TYPE_METALINK
        data.url = "http://metalink"

        self.dnf_manager.add_repository(data)
        self._check_repo("r1", [
            "metalink = http://metalink",
        ])
    def test_add_repository_mirrorlist(self):
        """Test the add_repository method with mirrorlist."""
        data = RepoConfigurationData()
        data.name = "r1"
        data.type = URL_TYPE_MIRRORLIST
        data.url = "http://mirror"

        self.dnf_manager.add_repository(data)
        self._check_repo("r1", [
            "mirrorlist = http://mirror",
        ])
Beispiel #9
0
    def test_name_uniqueness_properties(self):
        module1 = URLSourceModule()
        interface1 = URLSourceInterface(module1)

        module2 = URLSourceModule()
        interface2 = URLSourceInterface(module2)

        conf1 = RepoConfigurationData.from_structure(interface1.RepoConfiguration)
        conf2 = RepoConfigurationData.from_structure(interface2.RepoConfiguration)

        assert conf1.name != conf2.name
Beispiel #10
0
    def test_set_ssl_configuration_properties(self):
        data = RepoConfigurationData()
        ssl_conf = data.ssl_configuration
        ssl_conf.ca_cert_path = "file:///my/cool/cert"
        ssl_conf.client_cert_path = "file:///my/cool/client/cert"
        ssl_conf.client_key_path = "file:///my/cool/client/key/"

        self._check_dbus_property(
            "RepoConfiguration",
            RepoConfigurationData.to_structure(data)
        )
    def set_invalid_proxy_properties_test(self):
        data = RepoConfigurationData()
        data.proxy = "https:///no/server/hostname"

        with self.assertRaises(InvalidValueError):
            self._check_dbus_property("RepoConfiguration",
                                      RepoConfigurationData.to_structure(data))

        # new value shouldn't be set
        old_data = self.url_source_interface.RepoConfiguration
        old_data = RepoConfigurationData.from_structure(old_data)
        self.assertEqual(old_data.proxy, "")
    def test_add_repository_packages(self):
        """Test the add_repository method with packages."""
        data = RepoConfigurationData()
        data.name = "r1"
        data.included_packages = ["p1", "p2"]
        data.excluded_packages = ["p3", "p4"]

        self.dnf_manager.add_repository(data)
        self._check_repo("r1", [
            "includepkgs = p1, p2",
            "excludepkgs = p3, p4",
        ])
    def test_add_repository_proxy(self):
        """Test the add_repository method with the proxy configuration."""
        data = RepoConfigurationData()
        data.name = "r1"
        data.proxy = "http://*****:*****@example.com:1234"

        self.dnf_manager.add_repository(data)
        self._check_repo("r1", [
            "proxy = http://example.com:1234",
            "proxy_username = user",
            "proxy_password = pass",
        ])
    def test_add_repository_baseurl(self):
        """Test the add_repository method with baseurl."""
        data = RepoConfigurationData()
        data.name = "r1"
        data.type = URL_TYPE_BASEURL
        data.url = "http://repo"

        self.dnf_manager.add_repository(data)

        self._check_repo("r1", [
            "baseurl = http://repo",
        ])
    def name_uniqueness_properties_test(self):
        module1 = URLSourceModule()
        interface1 = URLSourceInterface(module1)

        module2 = URLSourceModule()
        interface2 = URLSourceInterface(module2)

        conf1 = RepoConfigurationData.from_structure(
            interface1.RepoConfiguration)
        conf2 = RepoConfigurationData.from_structure(
            interface2.RepoConfiguration)

        self.assertNotEqual(conf1.name, conf2.name)
    def _load_treeinfo(self, content):
        """Load the specified treeinfo."""
        with tempfile.TemporaryDirectory(dir="/tmp") as root_path:
            self._create_file(root_path=root_path,
                              file_name=".treeinfo",
                              content=content)

            self._create_directory(root_path=root_path, dir_name="repodata")

            repo_data = RepoConfigurationData()
            repo_data.url = "file://" + root_path
            self.metadata.load_data(repo_data)

        return repo_data.url
Beispiel #17
0
    def test_missing_url(self):
        """Skip repositories with a missing URL."""
        r1 = RepoConfigurationData()
        r1.name = "r1"
        r1.installation_enabled = True

        with tempfile.TemporaryDirectory() as sysroot:
            with self.assertLogs(level="DEBUG") as cm:
                self._run_task(sysroot, [r1])

            self._check_files(sysroot, [])

        msg = "The URL of the repository is not specified."
        assert msg in "\n".join(cm.output)
    def ssl_configuration_is_not_empty_properties_test(self):
        ssl_conf = SSLConfigurationData()
        ssl_conf.ca_cert_path = "file:///my/root/house"
        ssl_conf.client_cert_path = "file:///badge/with/yellow/access"
        ssl_conf.client_key_path = "file:///skeleton/head/key"

        repo_data = RepoConfigurationData()
        repo_data.ssl_configuration = ssl_conf
        self.url_source_interface.SetRepoConfiguration(
            RepoConfigurationData.to_structure(repo_data))

        repo_data_2 = RepoConfigurationData.from_structure(
            self.url_source_interface.RepoConfiguration)

        self.assertFalse(repo_data_2.ssl_configuration.is_empty())
Beispiel #19
0
    def create_proxy(self):
        """Create and set up a DBus source.

        :return: a DBus proxy of a source
        """
        source_proxy = create_source(SOURCE_TYPE_URL)

        repo_configuration = RepoConfigurationData()
        repo_configuration.type = self.url_type
        repo_configuration.url = self.url

        source_proxy.RepoConfiguration = \
            RepoConfigurationData.to_structure(repo_configuration)

        return source_proxy
Beispiel #20
0
    def test_unsupported_protocol(self):
        """Skip repositories with an unsupported protocol."""
        r1 = RepoConfigurationData()
        r1.name = "r1"
        r1.url = "nfs://server:/repo"
        r1.installation_enabled = True

        with tempfile.TemporaryDirectory() as sysroot:
            with self.assertLogs(level="DEBUG") as cm:
                self._run_task(sysroot, [r1])

            self._check_files(sysroot, [])

        msg = "The repository uses an unsupported protocol."
        assert msg in "\n".join(cm.output)
Beispiel #21
0
    def test_installation_disabled(self):
        """Skip repositories that are not allowed."""
        r1 = RepoConfigurationData()
        r1.name = "r1"
        r1.url = "http://repo"
        r1.installation_enabled = False

        with tempfile.TemporaryDirectory() as sysroot:
            with self.assertLogs(level="DEBUG") as cm:
                self._run_task(sysroot, [r1])

            self._check_files(sysroot, [])

        msg = "Installation of the repository is not allowed."
        assert msg in "\n".join(cm.output)
Beispiel #22
0
    def create_proxy(self):
        """Create and set up a DBus source.

        :return: a DBus proxy of a source
        """
        source_proxy = create_source(SOURCE_TYPE_URL)

        repo_configuration = RepoConfigurationData()
        repo_configuration.type = URL_TYPE_BASEURL
        repo_configuration.url = self.path

        source_proxy.SetRepoConfiguration(
            RepoConfigurationData.to_structure(repo_configuration))

        return source_proxy
Beispiel #23
0
    def _add_base_repository(self):
        """Add the base repository.

        Try to add a valid base repository to the DNF base.

        :raise: DNFManagerError if the repo is invalid
        """
        # Get the repo configuration of the first source.
        data = RepoConfigurationData.from_structure(
            self.proxy.GetRepoConfigurations()[0])

        log.debug("Using the repo configuration: %s", data)
        data.name = constants.BASE_REPO_NAME

        # Process the treeinfo metadata.
        treeinfo_base_repo_url = self._reload_treeinfo_metadata(data)

        if treeinfo_base_repo_url:
            data.type = URL_TYPE_BASEURL
            data.url = treeinfo_base_repo_url

        log.debug("Add the base repository at %s.", data.url)

        try:
            self._dnf_manager.add_repository(data)
            self._dnf_manager.load_repository(data.name)
        except DNFManagerError as e:
            log.error("The base repository is invalid: %s", str(e))
            self._dnf_manager.remove_repository(data.name)
            raise e
Beispiel #24
0
    def RepoConfiguration(self) -> Structure:
        """Get this repository configuration.

        :rtype: RepoConfigurationData data structure
        """
        return RepoConfigurationData.to_structure(
            self.implementation.repo_configuration)
Beispiel #25
0
    def GetRepoConfigurations(self) -> List[Structure]:
        """Get RepoConfigurationData structures for all attached sources.

        FIXME: This is a temporary solution. Will be removed after DNF payload logic is moved.
        """
        return RepoConfigurationData.to_structure_list(
            self.implementation.get_repo_configurations())
    def test_add_repository_ssl_configuration(self):
        """Test the add_repository method with the ssl configuration."""
        data = RepoConfigurationData()
        data.name = "r1"
        data.ssl_verification_enabled = True
        data.ssl_configuration.ca_cert_path = "file:///ca-cert"
        data.ssl_configuration.client_cert_path = "file:///client-cert"
        data.ssl_configuration.client_key_path = "file:///client-key"

        self.dnf_manager.add_repository(data)
        self._check_repo("r1", [
            "sslverify = 1",
            "sslcacert = file:///ca-cert",
            "sslclientcert = file:///client-cert",
            "sslclientkey = file:///client-key",
        ])
Beispiel #27
0
    def SetRepoConfiguration(self, repo_configuration: Structure):
        """Set this repository configuration.

        :param repo_configuration: configuration structure of this repository
        :type repo_configuration: RepoConfigurationData structure
        """
        self.implementation.set_repo_configuration(
            RepoConfigurationData.from_structure(repo_configuration))
    def test_add_repository_replace(self):
        """Test the add_repository method with a replacement."""
        data = RepoConfigurationData()
        data.name = "r1"
        data.url = "http://u1"

        self.dnf_manager.add_repository(data)
        self._check_repo("r1", [
            "baseurl = http://u1",
        ])

        data.url = "http://u2"

        self.dnf_manager.add_repository(data)
        self._check_repo("r1", [
            "baseurl = http://u2",
        ])
    def test_load_data_invalid_proxy(self, session_getter):
        """Test the load_data method with invalid proxy configuration."""
        session_getter.return_value.__enter__.return_value = \
            Mock(status_code=200, text=TREE_INFO_FEDORA)

        data = RepoConfigurationData()
        data.url = "http://path"
        data.proxy = "@:/invalid"

        self.metadata.load_data(data)

        session_getter.assert_called_once_with(
            "http://path/.treeinfo",
            headers={"user-agent": "anaconda (anaconda)/bluesky"},
            proxies={},
            verify=True,
            cert=None,
            timeout=NETWORK_CONNECTION_TIMEOUT)
    def test_add_repository_default(self):
        """Test the add_repository method with defaults."""
        data = RepoConfigurationData()
        data.name = "r1"

        self.dnf_manager.add_repository(data)

        self._check_repo("r1", [
            "baseurl = ",
            "proxy = ",
            "sslverify = 1",
            "sslcacert = ",
            "sslclientcert = ",
            "sslclientkey = ",
            "cost = 1000",
            "includepkgs = ",
            "excludepkgs = ",
        ])