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_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 set_url_base_source_properties_test(self): data = RepoConfigurationData() data.url = "http://example.com/repo" data.type = URL_TYPE_BASEURL self._check_dbus_property("RepoConfiguration", RepoConfigurationData.to_structure(data))
def description_test(self): """Test URL source description.""" rc = RepoConfigurationData() rc.url = "http://example.com/" self.url_source_interface.SetRepoConfiguration(rc.to_structure(rc)) self.assertEqual("http://example.com/", self.url_source_module.description)
def repr_test(self): config = RepoConfigurationData() config.url = "http://some.example.com/repository" self.module.set_repo_configuration(config) self.assertEqual( repr(self.module), "Source(type='URL', url='http://some.example.com/repository')")
def set_url_metalink_properties_test(self): data = RepoConfigurationData() data.url = "https://alianceFTW/metalink?nopesir" data.type = URL_TYPE_METALINK self._check_dbus_property("RepoConfiguration", RepoConfigurationData.to_structure(data))
def set_url_mirrorlist_properties_test(self): data = RepoConfigurationData() data.url = "http://forthehorde.com/mirrorlist?url" data.type = URL_TYPE_MIRRORLIST self._check_dbus_property("RepoConfiguration", RepoConfigurationData.to_structure(data))
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_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_load_data_missing_url(self): """Test the load_data method with a missing URL.""" data = RepoConfigurationData() data.url = "" with self.assertRaises(NoTreeInfoError) as cm: self.metadata.load_data(data) self.assertEqual(str(cm.exception), "No URL specified.")
def test_load_data_missing_url(self): """Test the load_data method with a missing URL.""" data = RepoConfigurationData() data.url = "" with pytest.raises(NoTreeInfoError) as cm: self.metadata.load_data(data) assert str(cm.value) == "No URL specified."
def test_load_data(self): """Test the load_data method.""" # Load the .treeinfo file. with tempfile.TemporaryDirectory() as path: self._create_file(path, ".treeinfo", TREE_INFO_FEDORA) data = RepoConfigurationData() data.url = "file://" + path self.metadata.load_data(data) # Load the treeinfo file. with tempfile.TemporaryDirectory() as path: self._create_file(path, "treeinfo", TREE_INFO_FEDORA) data = RepoConfigurationData() data.url = "file://" + path self.metadata.load_data(data)
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_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_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_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_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 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_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_missing_name(self): """Skip repositories with a missing name.""" r1 = RepoConfigurationData() r1.url = "http://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 name of the repository is not specified." assert msg in "\n".join(cm.output)
def set_invalid_url_type_properties_test(self): data = RepoConfigurationData() data.url = "http://test" data.type = "DOES-NOT-EXISTS" 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.url, "") self.assertEqual(old_data.type, URL_TYPE_BASEURL)
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
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
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 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
def set_source_url(self, url, url_type=constants.URL_TYPE_BASEURL, proxy=None): """ Switch to install source specified by URL """ # clean any old HDD ISO sources self._tear_down_existing_source() url_source_proxy = create_source(constants.SOURCE_TYPE_URL) repo_conf = RepoConfigurationData() repo_conf.url = url repo_conf.type = url_type repo_conf.proxy = proxy or "" url_source_proxy.SetRepoConfiguration( RepoConfigurationData.to_structure(repo_conf) ) set_source(self.payload.proxy, url_source_proxy)
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 """)