From 8c922d0de0a9fad4ca5fc53368c2e2c38fbab20d Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Oct 06 2017 21:16:04 +0000 Subject: make cg info in policy data more consistent, and honor it in policy_get_cgs --- diff --git a/hub/kojihub.py b/hub/kojihub.py index d788266..b25bfd8 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -5299,7 +5299,7 @@ class CG_Importer(object): policy_data = { 'package': self.buildinfo['name'], 'source': self.buildinfo['source'], - 'cgs': self.cgs, + 'cg_list': list(self.cgs), 'import': True, 'import_type': 'cg', } @@ -7979,6 +7979,11 @@ def policy_get_brs(data): def policy_get_cgs(data): # pull cg info out # note that br_id will be None if a component had no buildroot + if 'cg_list' in data: + cgs = [lookup_name('content_generator', cg, strict=True) + for cg in data['cg_list']] + return set(cgs) + # otherwise try buildroot data cgs = set() for br_id in policy_get_brs(data): if br_id is None: @@ -11807,7 +11812,6 @@ class HostExports(object): policy_data = { 'build': build_info, 'package': build_info['name'], - 'cgs': [], 'import': True, 'import_type': 'maven', } @@ -11886,7 +11890,6 @@ class HostExports(object): policy_data = { 'build': build_info, 'package': build_info['name'], - 'cgs': [], 'import': True, 'import_type': 'maven', } @@ -12053,7 +12056,6 @@ class HostExports(object): policy_data = { 'build': build_info, 'package': build_info['name'], - 'cgs': [], 'import': True, 'import_type': 'win', } diff --git a/tests/test_hub/test_policy_tests.py b/tests/test_hub/test_policy_tests.py index 64309bc..543863a 100644 --- a/tests/test_hub/test_policy_tests.py +++ b/tests/test_hub/test_policy_tests.py @@ -85,6 +85,7 @@ class TestPolicyGetCGs(unittest.TestCase): self.list_rpms = mock.patch('kojihub.list_rpms').start() self.list_archives = mock.patch('kojihub.list_archives').start() self.get_buildroot = mock.patch('kojihub.get_buildroot').start() + self.lookup_name = mock.patch('kojihub.lookup_name').start() def tearDown(self): mock.patch.stopall() @@ -98,7 +99,7 @@ class TestPolicyGetCGs(unittest.TestCase): return None return 'cg for br %s'% br_id - def test_policy_get_cg_basic(self): + def test_policy_get_cg_from_brs(self): self.get_build.return_value = {'id': 42} br1 = [1,1,1,2,3,4,5,5] br2 = [2,2,7,7,8,8,9,9,None] @@ -109,9 +110,28 @@ class TestPolicyGetCGs(unittest.TestCase): result = kojihub.policy_get_cgs({'build': 'NVR'}) expect = set([self._cgname(n) for n in br1 + br2]) self.assertEqual(result, expect) - self.list_rpms.called_once_with(buildID=42) - self.list_archives.called_once_with(buildID=42) - self.get_build.called_once_with('NVR', strict=True) + self.list_rpms.assert_called_once_with(buildID=42) + self.list_archives.assert_called_once_with(buildID=42) + self.get_build.assert_called_once_with('NVR', strict=True) + + def test_policy_get_cg_from_cgs(self): + data = { + 'cg_list': [1,1,1,2,2,2,3,3,3], + 'build': 'whatever', + 'buildroots': [], + } + def my_lookup_name(table, info, strict=False, create=False): + self.assertEqual(strict, True) + self.assertEqual(create, False) + self.assertEqual(table, 'content_generator') + return "cg %i" % info + self.lookup_name.side_effect = my_lookup_name + + result = kojihub.policy_get_cgs(data) + expect = set(['cg %i' % c for c in data['cg_list']]) + self.assertEqual(result, expect) + self.get_build.assert_not_called() + self.get_buildroot.assert_not_called() def test_policy_get_cg_nobuild(self): result = kojihub.policy_get_cgs({'package': 'foobar'})