From 2e6589ae41d729b79216a4a3e4fbc04e8dc942d5 Mon Sep 17 00:00:00 2001 From: mprahl Date: Thu, 31 May 2018 13:38:29 -0400 Subject: [PATCH] Check the libmodulemd version instead of modulemd --- .../builder/KojiContentGenerator.py | 20 ++++++++++++------- tests/test_content_generator.py | 7 +++++-- ...st_get_generator_json_expected_output.json | 4 ++-- ...nerator_json_expected_output_with_log.json | 4 ++-- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/module_build_service/builder/KojiContentGenerator.py b/module_build_service/builder/KojiContentGenerator.py index 12d49029..c04a1ba6 100644 --- a/module_build_service/builder/KojiContentGenerator.py +++ b/module_build_service/builder/KojiContentGenerator.py @@ -167,13 +167,19 @@ class KojiContentGenerator(object): def __get_tools(self): """Return list of tools which are important for reproducing mbs outputs""" - tools = [u"modulemd"] - ret = [] - for tool in tools: - version = text_type(pkg_resources.get_distribution(tool).version) - ret.append({u"name": tool, - u"version": version}) - return ret + # TODO: In libmodulemd v1.5, there'll be a property we can check instead + # of using RPM + try: + libmodulemd_version = subprocess.check_output( + ['rpm', '--queryformat', '%{VERSION}', '-q', 'libmodulemd'], + universal_newlines=True).strip() + except subprocess.CalledProcessError: + libmodulemd_version = 'unknown' + + return [{ + 'name': 'libmodulemd', + 'version': libmodulemd_version + }] def _koji_rpms_in_tag(self, tag): """ Return the list of koji rpms in a tag. """ diff --git a/tests/test_content_generator.py b/tests/test_content_generator.py index 5cf7cde1..533f7dd7 100644 --- a/tests/test_content_generator.py +++ b/tests/test_content_generator.py @@ -74,12 +74,14 @@ class TestBuild: @patch("module_build_service.builder.KojiModuleBuilder.KojiModuleBuilder.get_session") @patch("subprocess.Popen") + @patch("subprocess.check_output", return_value='1.4') @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, get_session): + def test_get_generator_json(self, rpms_in_tag, machine, distro, pkg_res, coutput, popen, + get_session): """ Test generation of content generator json """ koji_session = MagicMock() koji_session.getUser.return_value = GET_USER_RV @@ -118,12 +120,13 @@ class TestBuild: @patch("module_build_service.builder.KojiModuleBuilder.KojiModuleBuilder.get_session") @patch("subprocess.Popen") + @patch("subprocess.check_output", return_value='1.4') @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, coutput, popen, get_session): """ Test generation of content generator json """ koji_session = MagicMock() diff --git a/tests/test_get_generator_json_expected_output.json b/tests/test_get_generator_json_expected_output.json index 7cf70f40..d0188a17 100644 --- a/tests/test_get_generator_json_expected_output.json +++ b/tests/test_get_generator_json_expected_output.json @@ -11,8 +11,8 @@ }, "tools": [ { - "name": "modulemd", - "version": "current-tested-version" + "name": "libmodulemd", + "version": "1.4" } ], "components": [ 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 2d5ff49b..7bf13f0b 100644 --- a/tests/test_get_generator_json_expected_output_with_log.json +++ b/tests/test_get_generator_json_expected_output_with_log.json @@ -11,8 +11,8 @@ }, "tools": [ { - "name": "modulemd", - "version": "current-tested-version" + "name": "libmodulemd", + "version": "1.4" } ], "components": [