Ejemplo n.º 1
0
 def test_init_basearch(self, disable_disk_loading):
     '''i686 should be converted to i386'''
     repoinfo = yumrepoinfo.YumRepoInfo(arch='i686', filelist=[])
     if (sys.version_info >= (3, 2)):
         repoinfo.parser.read_file(StringIO(TEST_CONF))
     else:
         repoinfo.parser.readfp(StringIO(TEST_CONF))
     assert '/i386/' in repoinfo.get('rawhide', 'url')
Ejemplo n.º 2
0
 def test_init_arch(self, disable_disk_loading):
     '''Test YumRepoInfo(arch=)'''
     repoinfo = yumrepoinfo.YumRepoInfo(arch='x86_64', filelist=[])
     if (sys.version_info >= (3, 2)):
         repoinfo.parser.read_file(StringIO(TEST_CONF))
     else:
         repoinfo.parser.readfp(StringIO(TEST_CONF))
     assert '/x86_64/' in repoinfo.get('rawhide', 'url')
Ejemplo n.º 3
0
 def setup(self, monkeypatch):
     '''Run this before every test invocation'''
     monkeypatch.setattr(yumrepoinfo.YumRepoInfo, '_switch_to_mirror',
                         mock.Mock())
     # create YumRepoInfo initialized with TEST_CONF
     self.repoinfo = yumrepoinfo.YumRepoInfo(filelist=[])
     if (sys.version_info >= (3, 2)):
         self.repoinfo.parser.read_file(StringIO(TEST_CONF))
     else:
         self.repoinfo.parser.readfp(StringIO(TEST_CONF))
Ejemplo n.º 4
0
    def test_init_empty_filelist(self, monkeypatch):
        '''YumRepoInfo(filelist=[]) should not load anything from disk'''

        # make sure the disk is not read
        def _raise_alarm(x):
            assert False, 'This must not be called'

        monkeypatch.setattr(configparser.RawConfigParser, 'read', _raise_alarm)

        repoinfo = yumrepoinfo.YumRepoInfo(filelist=[])
        assert not repoinfo.repos()
Ejemplo n.º 5
0
    def test_gitref_rawhide(self):
        '''On rawhide, gitref must be "master"'''
        rawhide_tag = yumrepoinfo.YumRepoInfo().get('rawhide', 'tag')
        self.ref_nvr = 'foo-1.2-3.%s' % rawhide_tag.replace('f', 'fc')
        self.ref_input.update({'nvr': self.ref_nvr})
        self.ref_branch = 'master'

        self.helper.process(self.ref_input, None)

        download_calls = self.mock_download.call_args_list
        assert download_calls[0][0][0] == self._get_url(self.ref_path[0])
Ejemplo n.º 6
0
    def test_top_parent_raise(self):
        '''top_parent() must detect an infinite parent cycle'''
        cfg = u'''\
[repo1]
parent = repo2
[repo2]
parent = repo1
'''
        repoinfo = yumrepoinfo.YumRepoInfo(filelist=[])
        if (sys.version_info >= (3, 2)):
            repoinfo.parser.read_file(StringIO(cfg))
        else:
            repoinfo.parser.readfp(StringIO(cfg))

        with pytest.raises(exc.CheckbConfigError):
            repoinfo.top_parent('repo1')
Ejemplo n.º 7
0
    def test_use_arch(self, monkeypatch):
        """Make sure that the arch passed in as an arg is used to create the
        yumrepoinfo object instead of falling back to the default system arch"""
        ref_arch = 'i386'
        repoinfo = yumrepoinfo.YumRepoInfo(filelist=[], arch='x86_64')
        if (sys.version_info >= (3, 2)):
            repoinfo.parser.read_file(StringIO(TEST_CONF))
        else:
            repoinfo.parser.readfp(StringIO(TEST_CONF))

        stub_getrepoinfo = mock.MagicMock(return_value=repoinfo)
        monkeypatch.setattr(yumrepoinfo, 'get_yumrepoinfo', stub_getrepoinfo)

        # don't set the repoinfo object, we've stubbed out the code that would
        # hit the filesystem, so it's not a risk here
        directive = yumrepoinfo_directive.YumrepoinfoDirective()
        ref_input = {"koji_tag": "f20-updates", "arch": ref_arch}

        directive.process(ref_input, None)

        # check the first arg of the first call to the stub object
        assert stub_getrepoinfo.call_args_list[0][0][0] == ref_arch
Ejemplo n.º 8
0
    def process(self, params, arg_data):
        if ('package' not in params and 'nvr' not in params) or 'path' not in params \
            or 'target_dir' not in params:
            detected_args = ', '.join(params.keys())
            raise exc.CheckbDirectiveError(
                "The distgit directive requires 'package' (or 'nvr') and 'path' and 'target_dir' arguments."
                "Detected arguments: %s" % detected_args)

        package = None
        gitref = None
        namespace = None

        if 'nvr' in params:
            nvr = params['nvr']
            package = rpm_utils.rpmformat(nvr, fmt='n')
            gitref = rpm_utils.get_dist_tag(nvr).replace('c', '')
            rawhide_tag = yumrepoinfo.YumRepoInfo(resolve_baseurl=False).get(
                'rawhide', 'tag')
            if gitref == rawhide_tag:
                gitref = 'master'
            namespace = 'rpms'

        # Assign defaults
        package = params.get('package', package)
        gitref = params.get('gitref', gitref or 'master')
        namespace = params.get('namespace', namespace or 'rpms')
        baseurl = params.get('baseurl', BASEURL)
        target_dir = params['target_dir']
        ignore_missing = params.get('ignore_missing', False)

        if not python_utils.iterable(params['path']):
            raise exc.CheckbValueError(
                "Incorrect value type of the 'path' argument: "
                "%s" % type(params['path']))

        target_path = params['path']
        output_data = {}

        if 'localpath' in params:
            if not python_utils.iterable(params['localpath']):
                raise exc.CheckbValueError(
                    "Incorrect value type of the 'localpath' argument: "
                    "%s" % type(params['path']))

            if not len(params['path']) == len(params['localpath']):
                raise exc.CheckbValueError(
                    'path and localpath lists must be of the same '
                    'length.')

            target_path = params['localpath']

        format_fields = {
            'package': package,
            'gitref': gitref,
            'namespace': namespace,
            'baseurl': baseurl,
        }
        output_data['downloaded_files'] = []
        for path, localpath in zip(params['path'], target_path):
            localpath = os.path.join(target_dir, localpath)
            file_utils.makedirs(os.path.dirname(localpath))
            url = URL_FMT.format(path=path, **format_fields)
            try:
                output_data['downloaded_files'].append(
                    file_utils.download(url, '.', localpath))
            except exc.CheckbRemoteError as e:
                if e.errno == 404 and ignore_missing:
                    log.debug('File not found, ignoring: %s', url)
                else:
                    raise e

        return output_data