From 115aaa045c42c94a2b10819d21cdc2781a6e5a86 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: May 09 2018 08:17:41 +0000 Subject: Pass the -s/--set-default-stream to mbs-manager for module local builds. Signed-off-by: Jan Kaluza --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 4aa47da..814160e 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -2825,7 +2825,7 @@ class Commands(object): def module_local_build(self, file_path, stream, local_builds_nsvs=None, verbose=False, debug=False, skip_tests=False, mbs_config=None, - mbs_config_section=None): + mbs_config_section=None, default_streams=None): """ A wrapper for `mbs-manager build_module_locally`. :param file_path: a string, path of the module's modulemd yaml file. @@ -2837,6 +2837,10 @@ class Commands(object): :kwarg debug: a boolean specifying if mbs-manager should be debug. This is overridden by self.quiet and verbose. :kwarg skip_tests: a boolean determining if the check sections should be skipped + :kwarg mbs_config: a string, path to alternative MBS config file to use. + :kwarg mbs_config_section: a string, name of alternative config section to use. + :kwargs default_streams: a list, contains strings with default name:stream pairs + which are passed to mbs-manager using the '-s' command line argument. :return: None """ command = ['mbs-manager'] @@ -2858,6 +2862,10 @@ class Commands(object): command.extend(['--file', file_path]) command.extend(['--stream', stream]) + if default_streams: + for name_stream in default_streams: + command.extend(['-s', name_stream]) + env = {} if mbs_config: env['MBS_CONFIG_FILE'] = mbs_config diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 9b37829..9dd61de 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -871,6 +871,11 @@ defined, packages will be built sequentially.""" % {'name': self.name}) metavar='N:S:V', help=('Import previously finished local module builds into MBS in ' 'the format of name:stream or name:stream:version')) + self.module_build_local_parser.add_argument( + '-s', '--set-default-stream', action='append', default=[], + dest='default_streams', metavar='N:S', + help=('Set the default stream for given module dependency in case ' + 'there are multiple streams to choose from.')) self.module_build_local_parser.set_defaults( command=self.module_build_local) @@ -1621,7 +1626,8 @@ see API KEY section of copr-cli(1) man page. self.cmd.module_local_build( file_path, stream, self.args.local_builds_nsvs, verbose=self.args.v, debug=self.args.debug, skip_tests=self.args.skiptests, - mbs_config=mbs_config, mbs_config_section=mbs_config_section) + mbs_config=mbs_config, mbs_config_section=mbs_config_section, + default_streams=self.args.default_streams) def module_get_auth_config(self): """ diff --git a/tests/test_cli.py b/tests/test_cli.py index f173af0..dc9dff2 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2429,6 +2429,41 @@ State: failed '--file', file_path, '--stream', 'test'], env={}) @patch.object(Commands, '_run_command') + def test_module_build_local_with_default_streams(self, mock_run): + """ + Test submitting a local module build with skiptests + """ + + file_path = os.path.join(self.cloned_repo_path, "modulemd.yaml") + + cli_cmd = [ + 'rpkg', + '--path', + self.cloned_repo_path, + 'module-build-local', + '--file', + file_path, + '--stream', + 'test', + '-s', + 'foo:bar', + '--set-default-stream', + 'foo2:bar2', + ] + mock_proc = Mock() + mock_proc.returncode = 0 + mock_run.return_value = mock_proc + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + # we create an empty file for the purpose of this test so we don't raise an exception + open(file_path, 'a').close() + cli.module_build_local() + + mock_run.assert_called_once_with(['mbs-manager', 'build_module_locally', + '--file', file_path, '--stream', 'test', + '-s', 'foo:bar', '-s', 'foo2:bar2'], env={}) + + @patch.object(Commands, '_run_command') def test_module_build_local_with_add_local_builds(self, mock_run): """ Test submitting a local module build with add-local-builds