Beispiel #1
0
 def test_nevr(self):
     '''NEVR as input param'''
     rpmstr = 'foo-1:1.2-3.fc20'
     assert rpmformat(rpmstr, 'nevr') == 'foo-1:1.2-3.fc20'
     # noarch is added when arch requested
     assert rpmformat(rpmstr, 'nevra') == 'foo-1:1.2-3.fc20.noarch'
     assert rpmformat(rpmstr, 'e') == 1
Beispiel #2
0
 def test_nevra_epoch_zero(self):
     '''Zero epoch is valid and it should be treated as no epoch'''
     rpmstr = 'foo-0:1.2-3.fc20.x86_64'
     assert rpmformat(rpmstr, 'nevra', True) == 'foo-1.2-3.fc20.x86_64'
     assert rpmformat(rpmstr, 'nevr', True) == 'foo-1.2-3.fc20'
     assert rpmformat(rpmstr, 'nvra', True) == 'foo-1.2-3.fc20.x86_64'
     assert rpmformat(rpmstr, 'nvr', True) == 'foo-1.2-3.fc20'
     assert rpmformat(rpmstr, 'n', True) == 'foo'
     assert rpmformat(rpmstr, 'e', True) == 0
     assert rpmformat(rpmstr, 'v', True) == '1.2'
     assert rpmformat(rpmstr, 'r', True) == '3.fc20'
     assert rpmformat(rpmstr, 'a', True) == 'x86_64'
Beispiel #3
0
 def test_nevra(self):
     '''NEVRA as input param'''
     rpmstr = 'foo-4:1.2-3.fc20.x86_64'
     assert rpmformat(rpmstr, 'nevra', True) == 'foo-4:1.2-3.fc20.x86_64'
     assert rpmformat(rpmstr, 'nevr', True) == 'foo-4:1.2-3.fc20'
     assert rpmformat(rpmstr, 'nvra', True) == 'foo-1.2-3.fc20.x86_64'
     assert rpmformat(rpmstr, 'nvr', True) == 'foo-1.2-3.fc20'
     assert rpmformat(rpmstr, 'n', True) == 'foo'
     assert rpmformat(rpmstr, 'e', True) == 4
     assert rpmformat(rpmstr, 'v', True) == '1.2'
     assert rpmformat(rpmstr, 'r', True) == '3.fc20'
     assert rpmformat(rpmstr, 'a', True) == 'x86_64'
Beispiel #4
0
    def test_raise(self):
        '''Test incorrect fmt'''
        with pytest.raises(exc.CheckbValueError):
            rpmformat('foo-1.2-3.fc20', 'x')

        with pytest.raises(exc.CheckbValueError):
            rpmformat('foo-1.2-3.fc20', 'envra')

        with pytest.raises(exc.CheckbValueError):
            rpmformat('foo-1.2-3.fc20', 'n-v-r')
Beispiel #5
0
    def process(self, params, arg_data):
        # process params
        valid_actions = ['download', 'download_tag', 'download_latest_stable']
        action = params['action']
        if action not in valid_actions:
            raise exc.CheckbDirectiveError('%s is not a valid action for koji '
                                              'directive' % action)

        if 'arch' not in params or 'target_dir' not in params:
            detected_args = ', '.join(params.keys())
            raise exc.CheckbDirectiveError(
                "The koji directive requires 'arch' and 'target_dir' as an "
                "argument. Detected arguments: %s" % detected_args)

        # convert str to list
        for param in ('arch', 'arch_exclude'):
            if param in params and isinstance(params[param], basestring):
                params[param] = [params[param]]

        arches = list(params['arch'])
        if arches and ('all' not in arches) and ('noarch' not in arches):
            arches.append('noarch')

        arch_exclude = params.get('arch_exclude', [])
        debuginfo = params.get('debuginfo', False)
        src = params.get('src', False)
        build_log = params.get('build_log', False)

        target_dir = params['target_dir']
        file_utils.makedirs(target_dir)

        # download files
        output_data = {}

        if action == 'download':
            if 'koji_build' not in params:
                detected_args = ', '.join(params.keys())
                raise exc.CheckbDirectiveError(
                    "The koji directive requires 'koji_build' for the 'download' "
                    "action. Detected arguments: %s" % detected_args)

            nvr = rpm_utils.rpmformat(params['koji_build'], 'nvr')

            output_data['downloaded_rpms'] = self.koji.get_nvr_rpms(
                nvr, target_dir, arches=arches, arch_exclude=arch_exclude,
                debuginfo=debuginfo, src=src)

        elif action == 'download_tag':
            if 'koji_tag' not in params:
                detected_args = ', '.join(params.keys())
                raise exc.CheckbDirectiveError(
                    "The koji directive requires 'koji_tag' for the 'download_tag' "
                    "action. Detected arguments: %s" % detected_args)

            koji_tag = params['koji_tag']

            output_data['downloaded_rpms'] = self.koji.get_tagged_rpms(
                koji_tag, target_dir, arches=arches, arch_exclude=arch_exclude,
                debuginfo=debuginfo, src=src)

        elif action == 'download_latest_stable':
            if 'koji_build' not in params:
                detected_args = ', '.join(params.keys())
                raise exc.CheckbDirectiveError(
                    "The koji directive requires 'koji_build' for the 'download_latest_stable' "
                    "action. Detected arguments: %s" % detected_args)

            name = rpm_utils.rpmformat(params['koji_build'], 'n')
            disttag = rpm_utils.get_dist_tag(params['koji_build'])
            # we need to do 'fc22' -> 'f22' conversion
            tag = disttag.replace('c', '')

            # first we need to check updates tag and if that fails, the latest
            # stable nvr is in the base repo
            tags = ['%s-updates' % tag, tag]
            nvr = self.koji.latest_by_tag(tags, name)

            if not nvr:
                log.info("There's no previous stable build for %s, skipping.",
                         params['koji_build'])
                assert output_data == {}
                return output_data

            output_data['downloaded_rpms'] = self.koji.get_nvr_rpms(
                nvr, target_dir, arch_exclude=arch_exclude,
                arches=arches, debuginfo=debuginfo, src=src)

        # download build.log if requested
        if build_log:
            if action in ('download', 'download_latest_stable'):
                ret_log = self.koji.get_build_log(
                        nvr, target_dir, arches=arches, arch_exclude=arch_exclude)
                output_data['downloaded_logs'] = ret_log['ok']
                output_data['log_errors'] = ret_log['error']
            else:
                log.warning("Downloading build logs is not supported for action '%s', ignoring.",
                            action)

        return output_data
Beispiel #6
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
Beispiel #7
0
 def test_caps(self):
     '''Letter case should not matter in fmt'''
     assert rpmformat('foo-1.2-3.fc20', 'NVR') == 'foo-1.2-3.fc20'