From 172c8614426bcf7c15656b4310fd7a30339d243e Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Oct 05 2020 10:34:57 +0000 Subject: [PATCH 1/5] hub: getBuildConfig - return inheritance info --- diff --git a/hub/kojihub.py b/hub/kojihub.py index aa18a8d..aa83bd1 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -11949,6 +11949,7 @@ class RootExports(object): def getBuildConfig(self, tag, event=None): """Return build configuration associated with a tag""" taginfo = get_tag(tag, strict=True, event=event, blocked=True) + taginfo['extra_inheritance'] = {} order = readFullInheritance(taginfo['id'], event=event) # follow inheritance for arches and extra for link in order: @@ -11960,6 +11961,7 @@ class RootExports(object): for key in ancestor['extra']: if key not in taginfo['extra']: taginfo['extra'][key] = ancestor['extra'][key] + taginfo['extra_inheritance'][key] = dslice(ancestor, ('id', 'name')) # cleanup extras by blocked for k, v in list(taginfo['extra'].items()): if v[0]: diff --git a/tests/test_hub/test_get_build_config.py b/tests/test_hub/test_get_build_config.py new file mode 100644 index 0000000..6fb2ebf --- /dev/null +++ b/tests/test_hub/test_get_build_config.py @@ -0,0 +1,122 @@ +import mock +import unittest + +import kojihub + +class TestGetBuildConfig(unittest.TestCase): + + @mock.patch('kojihub.readFullInheritance') + @mock.patch('kojihub.get_tag') + def test_simple_tag(self, get_tag, readFullInheritance): + tag = 'tag_name' + get_tag.return_value = {'id': 123, 'name': tag, 'extra': {}} + readFullInheritance.return_value = [] + + taginfo = kojihub.RootExports().getBuildConfig(tag) + + get_tag.assert_called_with(tag, event=None, strict=True) + readFullInheritance.assert_called_with(123, event=None) + + self.assertEqual(taginfo, { + 'id': 123, + 'name': tag, + 'extra': {}, + 'extra_inheritance': {}, + }) + + @mock.patch('kojihub.readFullInheritance') + @mock.patch('kojihub.get_tag') + def test_basic_inherited(self, get_tag, readFullInheritance): + tag = 'tag_name' + get_tag.side_effect = [ + { + 'id': 123, + 'name': tag, + 'extra': {}, + 'arches': None, + }, + { + 'id': 1234, + 'name': 'parent', + 'extra': {'value': 'inherited'}, + 'arches': 'x86_64', + }, + ] + readFullInheritance.return_value = [ + { + 'child_id': 123, + 'currdepth': 1, + 'filter': [], + 'intransitive': False, + 'maxdepth': None, + 'name': tag, + 'nextdepth': None, + 'noconfig': False, + 'parent_id': 1234, + 'pkg_filter': '', + 'priority': 0 + } + ] + + taginfo = kojihub.RootExports().getBuildConfig(tag, event=1111) + + get_tag.assert_has_calls([ + mock.call(tag, event=1111, strict=True), + mock.call(1234, event=1111, strict=True), + ]) + readFullInheritance.assert_called_with(123, event=1111) + + self.assertEqual(taginfo, { + 'arches': 'x86_64', + 'extra': {'value': 'inherited'}, + 'extra_inheritance': {'value': {'id': 1234, 'name': 'parent'}}, + 'id': 123, + 'name': 'tag_name' + }) + + @mock.patch('kojihub.readFullInheritance') + @mock.patch('kojihub.get_tag') + def test_inherited_noconfig(self, get_tag, readFullInheritance): + tag = 'tag_name' + get_tag.side_effect = [ + { + 'id': 123, + 'name': tag, + 'extra': {}, + 'arches': None, + }, + { + 'id': 1234, + 'name': 'parent', + 'extra': {'value': 'inherited'}, + 'arches': 'x86_64', + }, + ] + readFullInheritance.return_value = [ + { + 'child_id': 123, + 'currdepth': 1, + 'filter': [], + 'intransitive': False, + 'maxdepth': None, + 'name': tag, + 'nextdepth': None, + 'noconfig': True, + 'parent_id': 1234, + 'pkg_filter': '', + 'priority': 0 + } + ] + + taginfo = kojihub.RootExports().getBuildConfig(tag, event=1111) + + get_tag.assert_called_once_with(tag, event=1111, strict=True) + readFullInheritance.assert_called_with(123, event=1111) + + self.assertEqual(taginfo, { + 'arches': None, + 'extra': {}, + 'extra_inheritance': {}, + 'id': 123, + 'name': 'tag_name' + }) From c2570f76bddcdab7a3c273a4498662b881629b2f Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Oct 05 2020 10:34:59 +0000 Subject: [PATCH 2/5] cli: taginfo displays inherited extra Fixes: https://pagure.io/koji/issue/1870 --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index b5b5a4c..185bd57 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -4866,10 +4866,10 @@ def anon_handle_taginfo(goptions, session, args): tags = [] for tag in args: - info = session.getTag(tag, **event_opts) + info = session.getBuildConfig(tag, **event_opts) if info is None: try: - info = session.getTag(int(tag), **event_opts) + info = session.getBuildConfig(int(tag), **event_opts) except ValueError: info = None if info is None: @@ -4896,7 +4896,10 @@ def anon_handle_taginfo(goptions, session, args): if 'extra' in info: print("Tag options:") for key in sorted(info['extra'].keys()): - print(" %s : %s" % (key, pprint.pformat(info['extra'][key]))) + line = " %s : %s" % (key, pprint.pformat(info['extra'][key])) + if key in info['extra_inheritance']: + line = "%-30s [%s]" % (line, info['extra_inheritance'][key]['name']) + print(line) dest_targets = session.getBuildTargets(destTagID=info['id'], **event_opts) build_targets = session.getBuildTargets(buildTagID=info['id'], **event_opts) repos = {} From 90ab8e7266b2f4f95b93b09328d606cd723bc524 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Oct 05 2020 10:34:59 +0000 Subject: [PATCH 3/5] fix backward compatibility --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 185bd57..c610f09 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -4897,7 +4897,7 @@ def anon_handle_taginfo(goptions, session, args): print("Tag options:") for key in sorted(info['extra'].keys()): line = " %s : %s" % (key, pprint.pformat(info['extra'][key])) - if key in info['extra_inheritance']: + if key in info.get('extra_inheritance', []): line = "%-30s [%s]" % (line, info['extra_inheritance'][key]['name']) print(line) dest_targets = session.getBuildTargets(destTagID=info['id'], **event_opts) From 73aa437d45ec9ec24cc453bcd297b4a827a58f4d Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Oct 05 2020 10:34:59 +0000 Subject: [PATCH 4/5] flake8 fix --- diff --git a/tests/test_hub/test_get_build_config.py b/tests/test_hub/test_get_build_config.py index 6fb2ebf..5ce9ce4 100644 --- a/tests/test_hub/test_get_build_config.py +++ b/tests/test_hub/test_get_build_config.py @@ -3,6 +3,7 @@ import unittest import kojihub + class TestGetBuildConfig(unittest.TestCase): @mock.patch('kojihub.readFullInheritance') From fedf3ee9f9238ed74c34d51c5458a834732b3346 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Oct 05 2020 10:35:07 +0000 Subject: [PATCH 5/5] extend to config_inheritance --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index c610f09..bc09cc2 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -4897,8 +4897,8 @@ def anon_handle_taginfo(goptions, session, args): print("Tag options:") for key in sorted(info['extra'].keys()): line = " %s : %s" % (key, pprint.pformat(info['extra'][key])) - if key in info.get('extra_inheritance', []): - line = "%-30s [%s]" % (line, info['extra_inheritance'][key]['name']) + if key in info.get('config_inheritance', {}).get('extra', []): + line = "%-30s [%s]" % (line, info['config_inheritance']['extra'][key]['name']) print(line) dest_targets = session.getBuildTargets(destTagID=info['id'], **event_opts) build_targets = session.getBuildTargets(buildTagID=info['id'], **event_opts) diff --git a/hub/kojihub.py b/hub/kojihub.py index aa83bd1..c142af5 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -11949,7 +11949,7 @@ class RootExports(object): def getBuildConfig(self, tag, event=None): """Return build configuration associated with a tag""" taginfo = get_tag(tag, strict=True, event=event, blocked=True) - taginfo['extra_inheritance'] = {} + taginfo['config_inheritance'] = {'extra': {}, 'arches': None} order = readFullInheritance(taginfo['id'], event=event) # follow inheritance for arches and extra for link in order: @@ -11958,10 +11958,11 @@ class RootExports(object): ancestor = get_tag(link['parent_id'], strict=True, event=event, blocked=True) if taginfo['arches'] is None and ancestor['arches'] is not None: taginfo['arches'] = ancestor['arches'] + taginfo['config_inheritance']['arches'] = dslice(ancestor, ('id', 'name')) for key in ancestor['extra']: if key not in taginfo['extra']: taginfo['extra'][key] = ancestor['extra'][key] - taginfo['extra_inheritance'][key] = dslice(ancestor, ('id', 'name')) + taginfo['config_inheritance']['extra'][key] = dslice(ancestor, ('id', 'name')) # cleanup extras by blocked for k, v in list(taginfo['extra'].items()): if v[0]: diff --git a/tests/test_hub/test_get_build_config.py b/tests/test_hub/test_get_build_config.py index 5ce9ce4..f3e6eb3 100644 --- a/tests/test_hub/test_get_build_config.py +++ b/tests/test_hub/test_get_build_config.py @@ -22,7 +22,7 @@ class TestGetBuildConfig(unittest.TestCase): 'id': 123, 'name': tag, 'extra': {}, - 'extra_inheritance': {}, + 'config_inheritance': {'extra': {}, 'arches': None}, }) @mock.patch('kojihub.readFullInheritance') @@ -70,7 +70,10 @@ class TestGetBuildConfig(unittest.TestCase): self.assertEqual(taginfo, { 'arches': 'x86_64', 'extra': {'value': 'inherited'}, - 'extra_inheritance': {'value': {'id': 1234, 'name': 'parent'}}, + 'config_inheritance': { + 'arches': {'id': 1234, 'name': 'parent'}, + 'extra' : {'value': {'id': 1234, 'name': 'parent'}} + }, 'id': 123, 'name': 'tag_name' }) @@ -117,7 +120,7 @@ class TestGetBuildConfig(unittest.TestCase): self.assertEqual(taginfo, { 'arches': None, 'extra': {}, - 'extra_inheritance': {}, + 'config_inheritance': {'extra': {}, 'arches': None}, 'id': 123, 'name': 'tag_name' })