#339 Fix traceback in handling of empty container.yaml and content_sets.yml.
Merged 3 months ago by jkaluza. Opened 3 months ago by jkaluza.
jkaluza/freshmaker empty-container-yaml  into  master

file modified
+14 -4

@@ -385,6 +385,12 @@ 

              data["generate_pulp_repos"] = True

              return data

  

+         if not content_sets_yaml:

+             log.warning("%s: Should generate Pulp repo, content_sets.yml is "

+                         "empty" % nvr)

+             data["generate_pulp_repos"] = True

+             return data

+ 

          for content_sets in content_sets_yaml.values():

              data["content_sets"] += content_sets

  

@@ -396,7 +402,7 @@ 

  

          container_yaml = yaml.safe_load(container_data)

  

-         if ("compose" not in container_yaml or

+         if (not container_yaml or "compose" not in container_yaml or

                  "pulp_repos" not in container_yaml["compose"] or

                  not container_yaml["compose"]["pulp_repos"]):

              log.debug("%s: Should generate Pulp repo, pulp_repos not "

@@ -509,9 +515,13 @@ 

  

          Calls self.resolve_commit() and self.resolve_content_sets().

          """

-         self.resolve_commit()

-         self.resolve_content_sets(lb_instance, children)

-         self.resolve_published(lb_instance)

+         try:

+             self.resolve_commit()

+             self.resolve_content_sets(lb_instance, children)

+             self.resolve_published(lb_instance)

+         except Exception as e:

+             err = "Cannot resolve the container image: %s" % e

+             self.log_error(err)

  

  

  class LightBlue(object):

file modified
+30

@@ -250,6 +250,28 @@ 

              "rpms/foo-docker", "branch", "commit")

          self.assertEqual(ret["generate_pulp_repos"], True)

  

+     def test_generate_content_sets_yml_empty(self):

+         self.get_distgit_files.return_value = {

+             "content_sets.yml": "",

+             "container.yaml": "compose:\n  pulp_repos: False",

+         }

+ 

+         image = ContainerImage.create({"brew": {"build": "nvr"}})

+         ret = image._get_additional_data_from_distgit(

+             "rpms/foo-docker", "branch", "commit")

+         self.assertEqual(ret["generate_pulp_repos"], True)

+ 

+     def test_generate_container_yaml_empty(self):

+         self.get_distgit_files.return_value = {

+             "content_sets.yml": "x86_64:\n  - content_set",

+             "container.yaml": "",

+         }

+ 

+         image = ContainerImage.create({"brew": {"build": "nvr"}})

+         ret = image._get_additional_data_from_distgit(

+             "rpms/foo-docker", "branch", "commit")

+         self.assertEqual(ret["generate_pulp_repos"], True)

+ 

  

  class TestContainerImageObject(helpers.FreshmakerTestCase):

  

@@ -407,6 +429,14 @@ 

          self.assertTrue(self.dummy_image["error"].find(

              "Cannot find valid source of Koji build") != -1)

  

+     @patch('freshmaker.lightblue.ContainerImage.resolve_commit')

+     def test_resolve_commit_exception(self, resolve_commit):

+         resolve_commit.side_effect = ValueError("Expected exception.")

+         self.dummy_image.resolve(None)

+         self.assertEqual(

+             self.dummy_image["error"],

+             "Cannot resolve the container image: Expected exception.")

+ 

      def test_resolve_content_sets_already_included_in_lb_response(self):

          image = ContainerImage.create({

              '_id': '1233829',

When file is empty, yaml.safe_load returns None which Freshmaker did
not expect.

This also puts the ContainerImage.resolve() code into try/except block,
so similar issues in this part of code won't mark the whole Freshmaker
Event as failed, but only marks particular ContainerImage as failed.

Pull-Request has been merged by jkaluza

3 months ago