def test_conf_from_file(self): conf = Conf() # defaults self.assertFalse(conf.gpgcheck) self.assertEqual(conf.installonly_limit, 3) self.assertTrue(conf.clean_requirements_on_remove) conf.config_file_path = '%s/etc/dnf/dnf.conf' % tests.support.dnf_toplevel() conf.read(priority=dnf.conf.PRIO_MAINCONFIG) self.assertTrue(conf.gpgcheck) self.assertEqual(conf.installonly_limit, 3) self.assertTrue(conf.clean_requirements_on_remove)
def test_inheritance1(self): conf = Conf() repo = RepoConf(conf) # minrate is inherited from conf # default should be the same self.assertEqual(conf.minrate, 1000) self.assertEqual(repo.minrate, 1000) # after conf change, repoconf still should inherit its value conf.minrate = 2000 self.assertEqual(conf.minrate, 2000) self.assertEqual(repo.minrate, 2000)
def test_inheritance2(self): conf = Conf() # if repoconf reads value from config it no more inherits changes from conf conf.config_file_path = tests.support.resource_path('etc/repos.conf') with mock.patch('logging.Logger.warning'): reader = dnf.conf.read.RepoReader(conf, {}) repo = list(reader)[0] self.assertEqual(conf.minrate, 1000) self.assertEqual(repo.minrate, 4096) # after global change conf.minrate = 2000 self.assertEqual(conf.minrate, 2000) self.assertEqual(repo.minrate, 4096)
def get_base(cls): """Initialize the configuration from dnf. Returns: An instance of the BaseCli class. """ cls.base = dnf.cli.cli.BaseCli(Conf()) return cls.base
def test_order_insensitive(self): conf = Conf() conf.config_file_path = '%s/etc/dnf/dnf.conf' % support.dnf_toplevel() opts = argparse.Namespace(gpgcheck=False, main_setopts=argparse.Namespace(installonly_limit=5)) # read config conf.read(priority=dnf.conf.PRIO_MAINCONFIG) # update from commandline conf._configure_from_options(opts) self.assertFalse(conf.gpgcheck) self.assertEqual(conf.installonly_limit, 5) # and the other way round should have the same result # update from commandline conf._configure_from_options(opts) # read config conf.read(priority=dnf.conf.PRIO_MAINCONFIG) self.assertFalse(conf.gpgcheck) self.assertEqual(conf.installonly_limit, 5)
def test_overrides(self): conf = Conf() self.assertFalse(conf.assumeyes) self.assertFalse(conf.assumeno) self.assertEqual(conf.color, 'auto') opts = argparse.Namespace(assumeyes=True, color='never') conf._configure_from_options(opts) self.assertTrue(conf.assumeyes) self.assertFalse(conf.assumeno) # no change self.assertEqual(conf.color, 'never')
def test_order_insensitive(self): conf = Conf() conf.config_file_path = '%s/etc/dnf/dnf.conf' % tests.support.dnf_toplevel( ) opts = argparse.Namespace(gpgcheck=False, main_setopts={'installonly_limit': ['5']}) # read config conf.read(priority=dnf.conf.PRIO_MAINCONFIG) # update from commandline conf._configure_from_options(opts) self.assertFalse(conf.gpgcheck) self.assertEqual(conf.installonly_limit, 5) # and the other way round should have the same result # update from commandline conf._configure_from_options(opts) # read config conf.read(priority=dnf.conf.PRIO_MAINCONFIG) self.assertFalse(conf.gpgcheck) self.assertEqual(conf.installonly_limit, 5)
def test_bugtracker(self): conf = Conf() self.assertEqual(conf.bugtracker_url, "https://bugzilla.redhat.com/enter_bug.cgi" + "?product=Fedora&component=dnf")
def test_ranges(self): conf = Conf() with self.assertRaises(dnf.exceptions.ConfigError): conf.debuglevel = '11'
def test_prepend_installroot(self): conf = Conf() conf.installroot = '/mnt/root' conf.prepend_installroot('persistdir') self.assertEqual(conf.persistdir, '/mnt/root/var/lib/dnf')
def setup(self): """ Setup DNF builder. """ dnf_conf = Conf() dnf_conf.debuglevel = 10 dnf_conf.logdir = self.log_path dnf_conf.assumeyes = True dnf_conf.installroot = self.image_path pdir = os.path.join(self.image_path, "var", "lib", "dnf") dnf_conf.persistdir = pdir dnf_conf.cachedir = os.path.join(pdir, "cache") dnf_conf.keepcache = not self.cleanall dnf_conf.releasever = str(self.config["releasever"]) for arch in ("arch", "basearch"): dnf_conf.substitutions[arch] = self.config["architecture"] for conf in ("proxy", "proxy_username", "proxy_password"): if conf in self.runtime: setattr(dnf_conf, conf, self.runtime[conf]) self.dnf_builder = Base(dnf_conf) self.dnf_builder.read_all_repos() all_repos = self.config["repo"].get("*", False) runtime_all_repos = self.runtime["repo"].get("*", False) for repo_name, repo in self.dnf_builder.repos.items(): repo_conf = None if all_repos or runtime_all_repos: repo_conf = configfile.merge(self.config["repo"].get("*", {}), self.runtime["repo"].get("*", {})) if repo_conf.get("baseurl"): del repo_conf["baseurl"] if (repo_name in self.config["repo"] or repo_name in self.runtime["repo"]): merge_conf = configfile.merge( self.config["repo"].get(repo_name, {}), self.runtime["repo"].get(repo_name, {})) if not merge_conf: continue if repo_conf: repo_conf = configfile.merge(merge_conf, repo_conf) else: repo_conf = merge_conf if repo_conf: if "baseurl" in repo_conf: repo.baseurl = repo_conf["baseurl"] # Explicitly remove these as # they can override the baseurl settings repo.mirrorlist = None repo.metalink = None if "enabled" in repo_conf: if not repo_conf["enabled"]: repo.disable() else: repo.enable() else: repo.enable() # If the RPM DBs aren't initialised, # hawkey doesn't fill the sack correctly and fails. # But we don't want to overwrite any already setup RPM DBs. rpm_path = os.path.join(self.image_path, "var", "lib", "rpm") if not os.path.exists(rpm_path): self.dnf_builder.ts.ts.initDB() self.dnf_builder.fill_sack()