hub: getBuildConfig - return inheritance info

This commit is contained in:
Tomas Kopecek 2020-09-17 14:04:47 +02:00
parent 146d3c0766
commit 172c861442
2 changed files with 124 additions and 0 deletions

View file

@ -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]:

View file

@ -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'
})