def info(pkgs=None, local_info=None, info_file=None, apply_tag=None, force_fetch=False): if not info_file: info_file = rdoinfo.info_file() if local_info: di = DistroInfo(info_file, local_info=local_info) else: di = rdoinfo.get_distroinfo() if force_fetch: di.fetcher.cache_ttl = 0 _info = di.get_info(apply_tag=apply_tag) if pkgs: filters = {} for pf in pkgs: attr, sep, rex = pf.partition(':') if not sep: # filter by name by default attr = 'name' rex = pf filters[attr] = rex rdoinfo.print_pkgs(_info, filters) else: rdoinfo.print_summary(_info) print('') print("Supply regex filter(s) to list package details, e.g.:\n{t.cmd}" " rdopkg info nova\n" " rdopkg info conf:client maintainers:jruzicka\n" " rdopkg info '.*'" "{t.normal}".format(t=log.term))
def test_dict_conversion(): di = DistroInfo('rdo.yml', local_info=common.get_test_info_path('rdoinfo')) info = di.get_info() info_dicts = di.get_info(info_dicts=True) assert parse.info2dicts(info) == info_dicts assert parse.info2lists(info_dicts) == info
def test_find_element_ok(): di = DistroInfo('minimal.yml', local_info=common.get_test_info_path('minimal')) info = di.get_info() finding = query.find_element(info, 'queens', info_key='releases') assert (finding) assert (finding == info['releases'][1])
def test_find_element_in_sub_dict_list(): di = DistroInfo('minimal.yml', local_info=common.get_test_info_path('minimal')) info = di.get_info() finding = query.find_element(info, 'cloud7-openstack-rocky-testing', info_key='releases') assert (finding) assert (finding == info['releases'][0])
def test_attr_diff_nosuchattr(): di = DistroInfo('rdo.yml', local_info=common.get_test_info_path('rdoinfo')) info = di.get_info() info2 = copy.deepcopy(info) # Update distgit for nova for pkg in info2['packages']: if pkg['project'] == 'nova': pkg['upstream'] = 'https://opendev.org/openstack/foo' diff = query.attr_diff(info, info2, 'fooattr') assert (len(diff) == 0)
def findpkg(query, strict=False, local_info=None, info_file=None, force_fetch=False): if not info_file: info_file = rdoinfo.info_file() if local_info: di = DistroInfo(info_file, local_info=local_info) else: di = rdoinfo.get_distroinfo() if force_fetch: di.fetcher.cache_ttl = 0 _info = di.get_info() pkg = distroinfo.query.find_package(_info, query, strict=strict) if not pkg: raise exception.InvalidPackage( msg="No package found in rdoinfo for query: %s" % query) rdoinfo.print_pkg(pkg)
def test_remote_info(): di = DistroInfo('remote.yml', local_info=common.get_test_info_path('minimal')) info = di.get_info() edf = info['package-default'].get('extra-default-field') assert edf == 'foo-default-%(project)s' nova = get_package(info, 'openstack-nova') assert nova['extra-default-field'] == 'foo-default-nova' assert nova['extra-conf-field'] == 'foo-conf-nova' assert nova['master-distgit'] == 'overriden-nova' assert '*****@*****.**' in nova['maintainers'] rocky = get_release(info, 'rocky') assert rocky['branch'] == 'overriden-branch'
def test_attr_diff_newpkg(): di = DistroInfo('rdo.yml', local_info=common.get_test_info_path('rdoinfo')) info = di.get_info() info2 = copy.deepcopy(info) # Add package newpkg = { 'project': 'newproject', 'name': 'openstack-newproject', 'master-distgit': 'https://github.com/rdo-packages/new-distgit', 'upstream': 'https://opendev.org/openstack/newproject' } info2['packages'].append(newpkg) diff = query.attr_diff(info, info2, 'master-distgit') assert (len(diff) == 1) assert (diff[0][0] == 'openstack-newproject') assert (diff[0][1] == 'https://github.com/rdo-packages/new-distgit')
def test_rdoinfo_remote_fetch(tmpdir): log_stream = common.capture_distroinfo_logger() remote_di = DistroInfo('rdo-full.yml', remote_info=RDOINFO_RAW_URL, cache_base_path=str(tmpdir)) # first fetch remote_info = remote_di.get_info() out = log_stream.getvalue() assert 'Fetching remote file:' in out # NOTE(jpena): with the current rdoinfo structure, we import tags.yml # twice, so it would fail the assertion # assert 'cached' not in out common.assert_rdoinfo_full(remote_info) # second fetch should be cached remote_info = remote_di.get_info() out = log_stream.getvalue() assert re.search(r'Using \d+ s old cached version of [^\n]+$', out) common.assert_rdoinfo_full(remote_info) # also load and parse the local repo copy (cache) using local fetcher cached_di = DistroInfo('rdo-full.yml', local_info=remote_di.fetcher.cache_path) cached_info = cached_di.get_info() common.assert_rdoinfo_full(cached_info) # make sure results from both fetchers are identical assert remote_info == cached_info
def info_tags_diff(local_info, info_file=None, buildsys_tags=False): if not info_file: info_file = rdoinfo.info_file() di = DistroInfo(info_file, local_info=local_info) if buildsys_tags: tagsname = 'buildsys-tags' else: tagsname = 'tags' info2 = di.get_info() with helpers.cdir(di.fetcher.source): with git.git_revision('HEAD~'): info1 = di.get_info() tdiff = distroinfo.query.tags_diff(info1, info2, tagsname=tagsname) if not tdiff: sys.stderr.write("No tag changes detected.\n") else: for pkg, changes in tdiff: print("%s %s" % (pkg, changes))
def get_distroinfo(info_url, info_files, fetcher=None, cache_dir=None): kwargs = {} # use desired distroinfo fetcher if fetcher == 'local': kwargs['local_info'] = info_url elif fetcher == 'git': kwargs['remote_git_info'] = info_url else: kwargs['remote_info'] = info_url if cache_dir: kwargs['cache_base_path'] = cache_dir return DistroInfo(info_files, **kwargs)
def test_rdoinfo_git_fetch(tmpdir): log_stream = common.capture_distroinfo_logger() git_di = DistroInfo('rdo-full.yml', remote_git_info=RDOINFO_GIT_URL, cache_base_path=str(tmpdir)) # first fetch should clone the git repo git_info = git_di.get_info() out = log_stream.getvalue() assert u"Cloning git repo" in out common.assert_rdoinfo_full(git_info) # second fetch with the same instance uses the already synced repo # without additional checks log_stream = common.capture_distroinfo_logger() git_info = git_di.get_info() assert log_stream.getvalue() == '' common.assert_rdoinfo_full(git_info) # a followup fetch with a new instance should reuse previously synced repo # after ttl checks git_di = DistroInfo('rdo-full.yml', remote_git_info=RDOINFO_GIT_URL, cache_base_path=str(tmpdir)) git_info = git_di.get_info() out = log_stream.getvalue() assert u"git repo is fresh" in out assert u"Cloning git repo" not in out assert u"Fetching git repo" not in out assert u"git resp is too old" not in out common.assert_rdoinfo_full(git_info) # also load and parse the local repo copy (cache) using local fetcher cached_di = DistroInfo('rdo-full.yml', local_info=git_di.fetcher.cache_path) cached_info = cached_di.get_info() common.assert_rdoinfo_full(cached_info) # make sure results from both fetchers are identical assert git_info == cached_info
def test_rdoinfo_base(): di = DistroInfo('rdo.yml', local_info=common.get_test_info_path('rdoinfo')) info = di.get_info() common.assert_rdoinfo_base(info)
def test_rdoinfo_merge(): di = DistroInfo(['rdo.yml', 'deps.yml'], local_info=common.get_test_info_path('rdoinfo')) info = di.get_info() common.assert_rdoinfo_full(info)
def test_find_element_not_found(): di = DistroInfo('minimal.yml', local_info=common.get_test_info_path('minimal')) info = di.get_info() finding = query.find_element(info, 'aabb', info_key='releases') assert (not finding)
def test_invalid_import(): di = DistroInfo('invalid-import.yml', local_info=common.get_test_info_path('broken')) with pytest.raises(IOError): info = di.get_info()
def test_self_import(): di = DistroInfo('self.yml', local_info=common.get_test_info_path('broken')) with pytest.raises(exception.CircularInfoInclude): info = di.get_info()
def test_attr_diff_nochanges(): di = DistroInfo('rdo.yml', local_info=common.get_test_info_path('rdoinfo')) info = di.get_info() info2 = copy.deepcopy(info) diff = query.attr_diff(info, info2, 'upstream') assert (len(diff) == 0)
def test_invalid_info_file(): di = DistroInfo('wololo.yml', local_info=common.get_test_info_path('broken')) with pytest.raises(IOError): info = di.get_info()