def __init__(self, arch=None, filelist=None, resolve_baseurl=True, resolve_retry=3): ''' :param str arch: architecture for which to adjust repo URLs. By default it refers to the architecture of the current machine. It's always converted to basearch. :param filelist: list of config files to read information from. The first available config file is used. If ``None``, then the default list of locations is used. :type filelist: iterable of str :param bool resolve_baseurl: if baseurl is a known redirect, resolve it for each section during initialization. If this is ``False``, you must call :meth:`_switch_to_mirror` manually. :param int resolve_retry: how many tries to retry resolving the URL for each section in case the network request fails :raise CheckbConfigError: if no YUM repositories data is found (empty or non-existent config file). It's not raised if you specifically request no data to load (``filelist=[]``). :raise CheckbRemoteError: if url resolving fails ''' if config.get_config().profile == config.ProfileName.TESTING: resolve_baseurl = False self.arch = arch_utils.basearch(arch) self.filelist = (filelist if filelist is not None else [ os.path.join(confdir, 'yumrepoinfo.conf') for confdir in config.CONF_DIRS ]) self.resolve_retry = resolve_retry self.parser = PARSER_CLASS(defaults={'arch': self.arch}) if not self.filelist: # no data should be loaded return self._read() if not self.repos(): msg = ("No YUM repo definitions found in the following locations: " "%s" % self.filelist) log.critical(msg) raise exc.CheckbConfigError(msg) self._adjust_baseurl() # download.fp.o is a known redirect if resolve_baseurl and ('download.fedoraproject.org' in self.parser.get('DEFAULT', 'baseurl')): self._switch_to_mirror()
def get_yumrepoinfo(arch=None, filelist=None): '''Get YumRepoInfo instance. This method is implemented using the singleton pattern - you will always receive the same instance, which will get auto-initialized on the first method call. :param str arch: architecture to return the YumRepoInfo for. It's always converted to basearch. If ``None``, then local machine arch is used. :param filelist: list of config files to read information from. The first available config file is used. If ``None``, then the default list of locations is used. :return: shared :class:`YumRepoInfo` instance :raise CheckbConfigError: if file config parsing and handling failed ''' # converts to basearch, returns local arch for None arch = arch_utils.basearch(arch) if not arch in _yumrepoinfo: _yumrepoinfo[arch] = YumRepoInfo(arch, filelist) return _yumrepoinfo[arch]
def test_basearch_unknown(self): '''Unknown arch is just returned''' assert basearch('some_arch') == 'some_arch'
def test_basearch_local(self): '''When no arch specified, local arch should be returned''' # let's say we're satisfied if /something/ is returned. Otherwise we # would have to copy most of the method's code in order to check it :-) assert basearch() == basearch(os.uname()[4])
def test_basearch_x86_64(self): '''x86_64 arch''' assert basearch('x86_64') == 'x86_64'
def test_basearch_i386(self): '''i386-like archs''' assert basearch('i386') == 'i386' assert basearch('i486') == 'i386' assert basearch('i586') == 'i386' assert basearch('i686') == 'i386'