From db116aee710a1aa2961cf13de6f1cf733e8b5d94 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Dec 14 2018 07:20:57 +0000 Subject: Fix creation of CG build without any RPM. In case the module did not contain any RPM, _koji_rpms_in_tag still tried to call the session.getRPMHeaders with an empty list. This results in None being returned, which is something _koji_rpms_in_tag did not count with and failed with traceback when trying to iterate that None value. In this commit, the _koji_rpms_in_tag returns an empty list early if Koji tag does not contain any RPM. Therefore the session.getRPMHeaders is not called at all in this case, because it does not make any sense to get RPM Headers when Koji tag does not contain any RPM. --- diff --git a/module_build_service/builder/KojiContentGenerator.py b/module_build_service/builder/KojiContentGenerator.py index dd095d9..6a86e37 100644 --- a/module_build_service/builder/KojiContentGenerator.py +++ b/module_build_service/builder/KojiContentGenerator.py @@ -237,6 +237,10 @@ class KojiContentGenerator(object): # If the tag doesn't exist.. then there are no rpms in that tag. return [] + # Module does not contain any RPM, so return an empty list. + if not rpms: + return [] + # Get the exclusivearch, excludearch and license data for each RPM. # The exclusivearch and excludearch lists are set in source RPM from which the RPM # was built. diff --git a/tests/test_content_generator.py b/tests/test_content_generator.py index e87b244..5979af2 100644 --- a/tests/test_content_generator.py +++ b/tests/test_content_generator.py @@ -420,6 +420,18 @@ class TestBuild: # Listing tagged RPMs does not require to log into a session koji_session.krb_login.assert_not_called() + @patch("koji.ClientSession") + def test_koji_rpms_in_tag_empty_tag(self, ClientSession): + koji_session = ClientSession.return_value + koji_session.getUser.return_value = GET_USER_RV + koji_session.getTag.return_value = {"arches": "x86_64"} + koji_session.listTaggedRPMS.return_value = ([], []) + koji_session.multiCall.side_effect = [[], [], [], []] + + rpms = self.cg._koji_rpms_in_tag("tag") + assert rpms == [] + koji_session.multiCall.assert_not_called() + def _add_test_rpm(self, nevra, srpm_nevra, multilib=None, koji_srpm_nevra=None, excludearch=None, exclusivearch=None, license=None):