#377 Add the --nightly/--ci/--test/--production Pungi options according to compose_type.
Merged 3 years ago by lsedlar. Opened 3 years ago by jkaluza.
jkaluza/odcs watch-logs  into  master

file modified
+1 -1
@@ -143,7 +143,7 @@ 

      # }

  

      # Command line arguments used to construct pungi-koji command.

-     PUNGI_KOJI_ARGS = ['--nightly']

+     PUNGI_KOJI_ARGS = []

  

      # Command line argument for raw_config source type, which overwrite

      # arguments listed PUNGI_KOJI_ARGS.

file modified
+17 -3
@@ -312,7 +312,7 @@ 

          """

          self.pungi_cfg.write_config_files(topdir)

  

-     def get_pungi_cmd(self, conf_topdir, targetdir, compose_dir=None):

+     def get_pungi_cmd(self, conf_topdir, compose, compose_dir=None):

          """

          Returns list with pungi command line arguments needed to generate

          the compose.
@@ -332,7 +332,7 @@ 

          if compose_dir:

              pungi_cmd.append("--compose-dir=%s" % compose_dir)

          else:

-             pungi_cmd.append("--target-dir=%s" % targetdir)

+             pungi_cmd.append("--target-dir=%s" % compose.target_dir)

  

          if isinstance(self.pungi_cfg, RawPungiConfig):

              pungi_cmd += self.pungi_cfg.pungi_koji_args
@@ -341,6 +341,20 @@ 

          else:

              raise RuntimeError('Unknown pungi config type to handle.')

  

+         compose_type_to_arg = {

+             "test": "--test",

+             "ci": "--ci",

+             "nightly": "--nightly",

+             "production": "--production",

+         }

+         compose_type = compose.compose_type or "test"

+ 

+         # Add compose_type arg to pungi_cmd only if it's not set already

+         # directly in the configuration.

+         if not set(pungi_cmd).intersection(set(compose_type_to_arg.values())):

+             # For unknown compose_type, fallback to --test to be safe.

+             pungi_cmd.append(compose_type_to_arg.get(compose_type, "--test"))

+ 

          if self.koji_event:

              pungi_cmd += ["--koji-event", str(self.koji_event)]

          if self.old_compose:
@@ -402,7 +416,7 @@ 

              self._write_cfgs(td)

              compose_dir = self._prepare_compose_dir(compose, td)

              self.pungi_cfg.validate(td, compose_dir)

-             pungi_cmd = self.get_pungi_cmd(td, compose.target_dir, compose_dir)

+             pungi_cmd = self.get_pungi_cmd(td, compose, compose_dir)

  

              # Commit the session to ensure that all the `compose` changes are

              # stored database before executing the compose and are not just

file modified
+1 -1
@@ -136,7 +136,7 @@ 

          db.session.commit()

  

          Message.assert_called_once_with(

-             topic="compose.state-changed",

+             topic="odcs.compose.state-changed",

              body={'event': 'state-changed', 'compose': compose.json()})

  

          publish.assert_called_once_with(Message.return_value)

file modified
+30 -2
@@ -398,12 +398,40 @@ 

  

          execute_cmd.assert_called_once_with(

              ['pungi-koji', AnyStringWith('pungi.conf'),

-              AnyStringWith('--compose-dir='), '--nightly'],

+              AnyStringWith('--compose-dir='), '--test'],

              cwd=AnyStringWith('/tmp/'), timeout=3600,

              stderr=AnyStringWith("pungi-stderr.log"),

              stdout=AnyStringWith("pungi-stdout.log"))

  

      @patch("odcs.server.utils.execute_cmd")

+     def test_pungi_run_compose_type(self, execute_cmd):

+         for compose_type in [None, "test", "ci", "nightly", "production"]:

+             self.makedirs.reset_mock()

+             self.ci_dump.reset_mock()

+             execute_cmd.reset_mock()

+ 

+             self.compose.compose_type = compose_type

+             pungi_cfg = PungiConfig("MBS-512", "1", PungiSourceType.MODULE,

+                                     "testmodule:master:1:1")

+             pungi = Pungi(1, pungi_cfg)

+             pungi.run(self.compose)

+ 

+             self.makedirs.assert_called_with(

+                 AnyStringWith("test_composes/odcs-1/"))

+             self.makedirs.assert_called_with(

+                 AnyStringWith("work/global"))

+             self.ci_dump.assert_called_once_with(

+                 AnyStringWith("work/global/composeinfo-base.json"))

+ 

+             execute_cmd.assert_called_once_with(

+                 ['pungi-koji', AnyStringWith('pungi.conf'),

+                  AnyStringWith('--compose-dir='),

+                  '--%s' % (compose_type or "test")],

+                 cwd=AnyStringWith('/tmp/'), timeout=3600,

+                 stderr=AnyStringWith("pungi-stderr.log"),

+                 stdout=AnyStringWith("pungi-stdout.log"))

+ 

+     @patch("odcs.server.utils.execute_cmd")

      def test_pungi_run_raw_config(self, execute_cmd):

          def mocked_execute_cmd(*args, **kwargs):

              topdir = kwargs["cwd"]
@@ -530,7 +558,7 @@ 

  

          execute_cmd.assert_called_once_with(

              ['pungi-koji', AnyStringWith('pungi.conf'),

-              AnyStringWith('--compose-dir='), '--nightly'],

+              AnyStringWith('--compose-dir='), '--test'],

              cwd=AnyStringWith('/tmp/'), timeout=7200,

              stderr=AnyStringWith("pungi-stderr.log"),

              stdout=AnyStringWith("pungi-stdout.log"))

In this commit, the --nightly, --ci, --test or --production Pungi arguments
are added automatically when generating the compose based on the compose_type.

It is however still possible to set them in PUNGI_KOJI_ARGS or
RAW_CONFIG_PUNGI_KOJI_ARGS and in this case, they are not overriden.

rebased onto 796796c

3 years ago

Pull-Request has been merged by lsedlar

3 years ago