From 477fa2ed6add2fefb379cbf7af2530428c653f35 Mon Sep 17 00:00:00 2001 From: mprahl Date: Tue, 30 Jan 2018 09:05:35 -0500 Subject: [PATCH] Set the owner on Koji CG builds --- .../builder/KojiContentGenerator.py | 4 +++ tests/test_content_generator.py | 26 ++++++++++++++++--- ...st_get_generator_json_expected_output.json | 1 + ...nerator_json_expected_output_with_log.json | 1 + 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/module_build_service/builder/KojiContentGenerator.py b/module_build_service/builder/KojiContentGenerator.py index 3b52440f..5c4bbe00 100644 --- a/module_build_service/builder/KojiContentGenerator.py +++ b/module_build_service/builder/KojiContentGenerator.py @@ -224,6 +224,10 @@ class KojiContentGenerator(object): } } } + session = KojiModuleBuilder.get_session(self.config, None) + # Only add the CG build owner if the user exists in Koji + if session.getUser(self.owner): + ret[u'owner'] = self.owner return ret def _get_buildroot(self): diff --git a/tests/test_content_generator.py b/tests/test_content_generator.py index 21dd7dfd..ad56d2d4 100644 --- a/tests/test_content_generator.py +++ b/tests/test_content_generator.py @@ -38,11 +38,16 @@ from tests import init_data from module_build_service.builder.KojiContentGenerator import KojiContentGenerator +GET_USER_RV = { + "id": 3686, + "krb_principal": "mszyslak@FEDORAPROJECT.ORG", + "name": "Moe Szyslak", + "status": 0, + "usertype": 0 +} base_dir = dirname(dirname(__file__)) cassette_dir = base_dir + '/vcr-request-data/' -user = ('Homer J. Simpson', set(['packager'])) - class TestBuild(unittest.TestCase): @@ -80,14 +85,18 @@ class TestBuild(unittest.TestCase): except OSError: pass + @patch("module_build_service.builder.KojiModuleBuilder.KojiModuleBuilder.get_session") @patch("subprocess.Popen") @patch("pkg_resources.get_distribution") @patch("platform.linux_distribution") @patch("platform.machine") @patch(("module_build_service.builder.KojiContentGenerator.KojiContentGenerator." "_koji_rpms_in_tag")) - def test_get_generator_json(self, rpms_in_tag, machine, distro, pkg_res, popen): + def test_get_generator_json(self, rpms_in_tag, machine, distro, pkg_res, popen, get_session): """ Test generation of content generator json """ + koji_session = MagicMock() + koji_session.getUser.return_value = GET_USER_RV + get_session.return_value = koji_session distro.return_value = ("Fedora", "25", "Twenty Five") self.maxDiff = None machine.return_value = "i686" @@ -121,14 +130,19 @@ class TestBuild(unittest.TestCase): rpms_in_tag.assert_called_once() self.assertEqual(expected_output, ret) + @patch("module_build_service.builder.KojiModuleBuilder.KojiModuleBuilder.get_session") @patch("subprocess.Popen") @patch("pkg_resources.get_distribution") @patch("platform.linux_distribution") @patch("platform.machine") @patch(("module_build_service.builder.KojiContentGenerator.KojiContentGenerator." "_koji_rpms_in_tag")) - def test_get_generator_json_no_log(self, rpms_in_tag, machine, distro, pkg_res, popen): + def test_get_generator_json_no_log(self, rpms_in_tag, machine, distro, pkg_res, popen, + get_session): """ Test generation of content generator json """ + koji_session = MagicMock() + koji_session.getUser.return_value = GET_USER_RV + get_session.return_value = koji_session distro.return_value = ("Fedora", "25", "Twenty Five") machine.return_value = "i686" pkg_res.return_value = Mock() @@ -166,6 +180,7 @@ class TestBuild(unittest.TestCase): def test_tag_cg_build(self, get_session): """ Test that the CG build is tagged. """ koji_session = MagicMock() + koji_session.getUser.return_value = GET_USER_RV koji_session.getTag.return_value = {'id': 123} get_session.return_value = koji_session @@ -178,6 +193,7 @@ class TestBuild(unittest.TestCase): def test_tag_cg_build_fallback_to_default_tag(self, get_session): """ Test that the CG build is tagged to default tag. """ koji_session = MagicMock() + koji_session.getUser.return_value = GET_USER_RV koji_session.getTag.side_effect = [{}, {'id': 123}] get_session.return_value = koji_session @@ -192,6 +208,7 @@ class TestBuild(unittest.TestCase): def test_tag_cg_build_no_tag_set(self, get_session): """ Test that the CG build is not tagged when no tag set. """ koji_session = MagicMock() + koji_session.getUser.return_value = GET_USER_RV koji_session.getTag.side_effect = [{}, {'id': 123}] get_session.return_value = koji_session @@ -204,6 +221,7 @@ class TestBuild(unittest.TestCase): def test_tag_cg_build_no_tag_available(self, get_session): """ Test that the CG build is not tagged when no tag available. """ koji_session = MagicMock() + koji_session.getUser.return_value = GET_USER_RV koji_session.getTag.side_effect = [{}, {}] get_session.return_value = koji_session diff --git a/tests/test_get_generator_json_expected_output.json b/tests/test_get_generator_json_expected_output.json index e7da3604..fb03cf6e 100644 --- a/tests/test_get_generator_json_expected_output.json +++ b/tests/test_get_generator_json_expected_output.json @@ -642,6 +642,7 @@ "end_time": 1472901932, "name": "nginx", "release": "2.00000000", + "owner": "Moe Szyslak", "extra": { "typeinfo": { "module": { diff --git a/tests/test_get_generator_json_expected_output_with_log.json b/tests/test_get_generator_json_expected_output_with_log.json index 92465d28..4aeaf552 100644 --- a/tests/test_get_generator_json_expected_output_with_log.json +++ b/tests/test_get_generator_json_expected_output_with_log.json @@ -651,6 +651,7 @@ "end_time": 1472901932, "name": "nginx", "release": "2.00000000", + "owner": "Moe Szyslak", "extra": { "typeinfo": { "module": {