def test_generate_treeinfo_repositories_fedora(self): """Test the generate_treeinfo_repositories function with Fedora repos.""" root_url = self._load_treeinfo(TREE_INFO_FEDORA) original = RepoConfigurationData() original.name = "anaconda" original.url = root_url original.proxy = "http://proxy" original.cost = 50 original.excluded_packages = ["p1", "p2"] original.included_packages = ["p2", "p3"] original.ssl_verification_enabled = False original.ssl_configuration.ca_cert_path = "file.cert" original.ssl_configuration.client_key_path = "client.key" original.ssl_configuration.client_cert_path = "client.cert" original.installation_enabled = True generated = generate_treeinfo_repositories(original, self.metadata) everything = RepoConfigurationData() everything.origin = REPO_ORIGIN_TREEINFO everything.name = "Everything" everything.enabled = True everything.url = root_url everything.proxy = "http://proxy" everything.cost = 50 everything.excluded_packages = ["p1", "p2"] everything.included_packages = ["p2", "p3"] everything.ssl_verification_enabled = False everything.ssl_configuration.ca_cert_path = "file.cert" everything.ssl_configuration.client_key_path = "client.key" everything.ssl_configuration.client_cert_path = "client.cert" everything.installation_enabled = False self._assert_repo_list_equal(generated, [everything])
def test_generate_treeinfo_repositories_custom(self, mock_conf): """Test the generate_treeinfo_repositories function with custom repos.""" mock_conf.payload.enabled_repositories_from_treeinfo = ["variant"] root_url = self._load_treeinfo(TREE_INFO_CUSTOM) original = RepoConfigurationData() original.name = "anaconda" original.url = root_url generated = generate_treeinfo_repositories(original, self.metadata) optional = RepoConfigurationData() optional.origin = REPO_ORIGIN_TREEINFO optional.name = "MyOptional" optional.enabled = False optional.url = root_url + "/optional" variant = RepoConfigurationData() variant.origin = REPO_ORIGIN_TREEINFO variant.name = "MyVariant" variant.enabled = True variant.url = root_url + "/variant" # Anaconda ignores addons and child variants. self._assert_repo_list_equal(generated, [optional, variant])
def test_write_multiple_repositories(self): """Write multiple repositories.""" r1 = RepoConfigurationData() r1.name = "r1" r1.url = "http://repo/1" r1.installation_enabled = True r2 = RepoConfigurationData() r2.name = "r2" r2.url = "https://repo/2" r2.installation_enabled = True r3 = RepoConfigurationData() r3.name = "r3" r3.url = "ftp://repo/3" r3.installation_enabled = True r4 = RepoConfigurationData() r4.name = "r4" r4.url = "nfs://repo/4" r4.installation_enabled = True with tempfile.TemporaryDirectory() as sysroot: self._run_task(sysroot, [r1, r2, r3]) self._check_files(sysroot, [ "r1.repo", "r2.repo", "r3.repo", ]) self._check_content( sysroot, "r1.repo", "[r1]\n" "name = r1\n" "enabled = 1\n" "baseurl = http://repo/1\n" ) self._check_content( sysroot, "r2.repo", "[r2]\n" "name = r2\n" "enabled = 1\n" "baseurl = https://repo/2\n" ) self._check_content( sysroot, "r3.repo", "[r3]\n" "name = r3\n" "enabled = 1\n" "baseurl = ftp://repo/3\n" )
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)
def test_add_repository_cost(self): """Test the add_repository method with a cost.""" data = RepoConfigurationData() data.name = "r1" data.cost = 256 self.dnf_manager.add_repository(data) self._check_repo("r1", ["cost = 256"])
def test_set_name_properties(self): data = RepoConfigurationData() data.name = "Saitama" self._check_dbus_property( "RepoConfiguration", RepoConfigurationData.to_structure(data) )
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_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_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", ])
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 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_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 test_generate_treeinfo_repositories_rhel(self): """Test the generate_treeinfo_repositories function with RHEL repos.""" root_url = self._load_treeinfo(TREE_INFO_RHEL) original = RepoConfigurationData() original.name = "anaconda" original.url = root_url generated = generate_treeinfo_repositories(original, self.metadata) appstream = RepoConfigurationData() appstream.origin = REPO_ORIGIN_TREEINFO appstream.name = "AppStream" appstream.enabled = True appstream.url = "file:///tmp/appstream" baseos = RepoConfigurationData() baseos.origin = REPO_ORIGIN_TREEINFO baseos.name = "BaseOS" baseos.enabled = True baseos.url = "file:///tmp/baseos" self._assert_repo_list_equal(generated, [appstream, baseos])
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)
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)
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", ])
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 convert_ks_repo_to_repo_data(ks_data): """Convert the kickstart command into a repo configuration. :param RepoData ks_data: a kickstart data :return RepoConfigurationData: a repo configuration """ if not isinstance(ks_data, RepoData): raise ValueError("Unexpected kickstart data: {}".format(type(ks_data))) repo_data = RepoConfigurationData() repo_data.name = ks_data.name repo_data.enabled = ks_data.enabled if ks_data.baseurl: repo_data.url = ks_data.baseurl repo_data.type = URL_TYPE_BASEURL elif ks_data.mirrorlist: repo_data.url = ks_data.mirrorlist repo_data.type = URL_TYPE_MIRRORLIST elif ks_data.metalink: repo_data.url = ks_data.metalink repo_data.type = URL_TYPE_METALINK else: # Handle the `repo --name=updates` use case. repo_data.url = "" repo_data.type = "NONE" if ks_data.treeinfo_origin: repo_data.origin = REPO_ORIGIN_TREEINFO elif not repo_data.url: repo_data.origin = REPO_ORIGIN_SYSTEM else: repo_data.origin = REPO_ORIGIN_USER repo_data.proxy = ks_data.proxy or "" repo_data.cost = ks_data.cost or DNF_DEFAULT_REPO_COST repo_data.included_packages = ks_data.includepkgs repo_data.excluded_packages = ks_data.excludepkgs repo_data.installation_enabled = ks_data.install repo_data.ssl_verification_enabled = not ks_data.noverifyssl repo_data.ssl_configuration.ca_cert_path = ks_data.sslcacert or "" repo_data.ssl_configuration.client_cert_path = ks_data.sslclientcert or "" repo_data.ssl_configuration.client_key_path = ks_data.sslclientkey or "" return repo_data
def test_generate_repo_file_baseurl(self): """Test the generate_repo_file method with baseurl.""" data = RepoConfigurationData() data.name = "r1" data.type = URL_TYPE_BASEURL data.url = "http://repo" data.proxy = "http://example.com:1234" data.cost = 256 self._check_content( data, """ [r1] name = r1 enabled = 1 baseurl = http://repo proxy = http://example.com:1234 cost = 256 """)
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 = ", ])
def test_generate_repo_file_metalink(self): """Test the generate_repo_file method with metalink.""" data = RepoConfigurationData() data.name = "r1" data.enabled = False data.type = URL_TYPE_METALINK data.url = "http://metalink" data.included_packages = ["p1", "p2"] data.excluded_packages = ["p3", "p4"] self._check_content( data, """ [r1] name = r1 enabled = 0 metalink = http://metalink includepkgs = p1, p2 excludepkgs = p3, p4 """)
def test_write_repository(self): """Write a repository.""" r1 = RepoConfigurationData() r1.name = "r1" r1.url = "http://repo" r1.installation_enabled = True with tempfile.TemporaryDirectory() as sysroot: self._run_task(sysroot, [r1]) self._check_files(sysroot, [ "r1.repo" ]) self._check_content( sysroot, "r1.repo", "[r1]\n" "name = r1\n" "enabled = 1\n" "baseurl = http://repo\n" )
def test_generate_repo_file_mirrorlist(self): """Test the generate_repo_file method with mirrorlist.""" data = RepoConfigurationData() data.name = "r1" data.type = URL_TYPE_MIRRORLIST data.url = "http://mirror" data.ssl_verification_enabled = False data.proxy = "http://*****:*****@example.com:1234" self._check_content( data, """ [r1] name = r1 enabled = 1 mirrorlist = http://mirror sslverify = 0 proxy = http://example.com:1234 proxy_username = user proxy_password = pass """)
def process_kickstart(self, data): """Process the kickstart data.""" repo_data = RepoConfigurationData() repo_data.name = self._url_source_name if data.url.url: repo_data.url = data.url.url repo_data.type = URL_TYPE_BASEURL elif data.url.mirrorlist: repo_data.url = data.url.mirrorlist repo_data.type = URL_TYPE_MIRRORLIST elif data.url.metalink: repo_data.url = data.url.metalink repo_data.type = URL_TYPE_METALINK repo_data.proxy = data.url.proxy repo_data.ssl_verification_enabled = not data.url.noverifyssl repo_data.ssl_configuration.ca_cert_path = data.url.sslcacert or "" repo_data.ssl_configuration.client_cert_path = data.url.sslclientcert or "" repo_data.ssl_configuration.client_key_path = data.url.sslclientkey or "" self.set_repo_configuration(repo_data)
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]
def _set_additional_repos_from_opts(self, opts): """Set additional repositories based on the Anaconda options.""" for repo_name, repo_url in opts.addRepo: try: source = SourceFactory.parse_repo_cmdline_string(repo_url) except PayloadSourceTypeUnrecognized: log.error( "Type for additional repository %s is not recognized!", repo_url) return if self.get_addon_repo(repo_name): log.warning( "Repository name %s is not unique. Only the first " "repo will be used!", repo_name) is_supported = source.is_nfs \ or source.is_http \ or source.is_https \ or source.is_ftp \ or source.is_file \ or source.is_harddrive if not is_supported: log.error( "Source type %s for additional repository %s is not supported!", source.source_type.value, repo_url) continue repo = RepoConfigurationData() repo.name = repo_name repo.enabled = True repo.type = URL_TYPE_BASEURL repo.url = repo_url repo.installation_enabled = False ks_repo = convert_repo_data_to_ks_repo(repo) self.data.repo.dataList().append(ks_repo)