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_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 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_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_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 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_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 _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)