#692 `copr-build` passes extra_args to copr-cli command
Merged 2 years ago by onosek. Opened 2 years ago by onosek.
onosek/rpkg copr-build_extra  into  master

file modified
+4 -1
@@ -3576,13 +3576,16 @@ 

          else:

              self.log.info('Nothing to be done')

  

-     def copr_build(self, project, srpm_name, nowait, config_file):

+     def copr_build(self, project, srpm_name, nowait, config_file, extra_args=None):

          cmd = ['copr-cli']

          if config_file:

              cmd.extend(['--config', config_file])

          cmd.append('build')

          if nowait:

              cmd.append('--nowait')

+         if extra_args:

+             cmd.extend(extra_args)

+             self.log.debug("Extra args '{0}' are passed to copr-cli command".format(extra_args))

          cmd.extend([project, srpm_name])

          self._run_command(cmd)

  

file modified
+10 -1
@@ -1561,6 +1561,10 @@ 

              help="Don't wait on build")

          copr_parser.add_argument(

              'project', nargs=1, help='Name of the project in format USER/PROJECT')

+         copr_parser.add_argument(

+             "extra_args", default=None, nargs=argparse.REMAINDER,

+             help="Custom arguments that are passed to the 'copr-cli'. "

+                  "Use '--' to separate them from other arguments.")

          copr_parser.set_defaults(command=self.copr_build)

  

      def register_switch_branch(self):
@@ -2354,12 +2358,17 @@ 

      def copr_build(self):

          self.log.debug('Generating an srpm')

          self.args.hash = None

+         # do not pass 'extra_args' to 'rpmbuild' command in 'srpm' method; Pass it to copr-cli.

+         extra_args_backup = self.extra_args

+         self.extra_args = None

          self.srpm()

+         self.extra_args = extra_args_backup

          srpm_name = '%s.src.rpm' % self.cmd.nvr

          self.cmd.copr_build(self.args.project[0],

                              srpm_name,

                              self.args.nowait,

-                             self.args.copr_config)

+                             self.args.copr_config,

+                             extra_args=self.extra_args)

  

      def diff(self):

          self.cmd.diff(self.args.cached, self.args.files)

file modified
+24
@@ -639,6 +639,30 @@ 

      @patch('sys.stderr', new=StringIO())

      @patch('pyrpkg.Commands._clone_config', new_callable=Mock())

      @patch('pyrpkg.Commands._run_command')

+     def test_extra_args_copr(self, _run_command, _clone_config):

+         # copr-build is the command that has two subcommands (rpmbuild and copr-cli)

+         # that might accept the extra args. This tests requies extra_args at copr-cli.

+         cli_cmd = ['rpkg', '--user', 'dude', '--path', self.cloned_repo_path,

+                    '--release', 'rhel-6', 'copr-build', 'COPR-REPO',

+                    '--', '--after-build-id', 'ID']

+ 

+         with patch('sys.argv', new=cli_cmd):

+             cli = self.new_cli()

+             cli.copr_build()

+ 

+         expected_cmd = ['copr-cli', 'build', '--after-build-id', 'ID', 'COPR-REPO']

+         self.assertEqual(2, _run_command.call_count)

+         copr_cli_call = _run_command.mock_calls[1]

+         if 'args' in dir(copr_cli_call):  # doesn't work in <=py36

+             # strip the last argument - it contains dynamically generated src.rpm filename

+             self.assertEqual(expected_cmd, copr_cli_call.args[0][:-1])

+ 

+         output = sys.stderr.getvalue().strip()

+         self.assertEqual('', output)

+ 

+     @patch('sys.stderr', new=StringIO())

+     @patch('pyrpkg.Commands._clone_config', new_callable=Mock())

+     @patch('pyrpkg.Commands._run_command')

      def test_extra_args_incorrect(self, _run_command, _clone_config):

          """Missing '--' separator between standard arguments and extra

          arguments. This can be valid command but might have different

The right target for passing extra_args (arguments that are placed
after '--' on the command line) is the command copr-cli instead
of rpmbuild command.

Fixes: https://pagure.io/fedpkg/issue/510
JIRA: RHELCMP-11429

Signed-off-by: Ondrej Nosek onosek@redhat.com

rebased onto ad67fa9

2 years ago

Pull-Request has been merged by onosek

2 years ago