From ad67fa9069befef3e4ba5180eea6bf56b658e664 Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: May 02 2023 23:37:59 +0000 Subject: `copr-build` passes extra_args to copr-cli command 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 --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 11b8dae..f14b055 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -3576,13 +3576,16 @@ class Commands(object): 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) diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index dc1eb4e..020a247 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1561,6 +1561,10 @@ class cliClient(object): 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 @@ class cliClient(object): 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) diff --git a/tests/test_cli.py b/tests/test_cli.py index 6e4ec6a..f2e68df 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -639,6 +639,30 @@ class TestClone(CliTestCase): @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