From a1fab506dd5720f620276889ac982c76a504df54 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Apr 05 2019 11:52:42 +0000 Subject: Allow passing --offline and -r to mbs-manager build_module_locally. It is now possible to build modules offline without any external infrastructure using the MBS. This is done by passing `--offline` flag to mbs-manager and the list of repositories for the base module. In this commit, the support for these new flags (`--offline` and `-r`) is added to pyrpkg. Signed-off-by: Jan Kaluza --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index d692366..94138b8 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -3356,7 +3356,8 @@ 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, default_streams=None): + mbs_config_section=None, default_streams=None, + offline=False, base_module_repositories=None): """ A wrapper for `mbs-manager build_module_locally`. @@ -3378,6 +3379,11 @@ class Commands(object): `name:stream` pairs which are passed to mbs-manager using the '-s' command line argument. :type default_streams: list[str] + :param bool offline: when True, the module is built offline without + accessing any external infrastructure. + :param list base_module_repositories: a list of full paths to local + .repo files defining the repositories for base module when + building with offline set to True. :return: None """ command = ['mbs-manager'] @@ -3396,6 +3402,13 @@ class Commands(object): if skip_tests: command.append('--skiptests') + if offline: + command.append('--offline') + + if base_module_repositories: + for repo in base_module_repositories: + command.extend(['-r', repo]) + command.extend(['--file', file_path]) command.extend(['--stream', stream]) diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 384f7cb..1f068a1 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1172,6 +1172,15 @@ defined, packages will be built sequentially.""" % {'name': self.name}) 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.add_argument( + '--offline', + help='Builds module offline without any external infrastructure', + action='store_true', dest='offline') + self.module_build_local_parser.add_argument( + '-r', '--repository', action='append', dest='base_module_repositories', + metavar='PATH', + help=('Full path to .repo file defining the base module repository ' + 'to use when --offline is used.')) self.module_build_local_parser.set_defaults( command=self.module_build_local) @@ -2150,7 +2159,9 @@ see API KEY section of copr-cli(1) man page. 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, - default_streams=self.args.default_streams) + default_streams=self.args.default_streams, + offline=self.args.offline, + base_module_repositories=self.args.base_module_repositories) def module_get_auth_config(self): """Get the authentication configuration for the MBS diff --git a/tests/test_cli.py b/tests/test_cli.py index 93b3a2e..4d2aa3d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2592,6 +2592,35 @@ State: failed file_path, '--stream', 'master'], env={}) @patch.object(Commands, '_run_command') + def test_module_build_local_offline_with_repositories(self, mock_run): + """ + Test submitting a local module build + """ + cli_cmd = [ + 'rpkg', + '--path', + self.cloned_repo_path, + 'module-build-local', + '--offline', + '-r', '/etc/yum.repos.d/fedora.repo', + '-r', '/etc/yum.repos.d/fedora-updates.repo', + ] + mock_proc = Mock() + mock_proc.returncode = 0 + mock_run.return_value = mock_proc + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + file_path = os.path.join(self.cloned_repo_path, cli.cmd.repo_name + '.yaml') + # 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', + '--offline', '-r', '/etc/yum.repos.d/fedora.repo', + '-r', '/etc/yum.repos.d/fedora-updates.repo', '--file', + file_path, '--stream', 'master'], env={}) + + @patch.object(Commands, '_run_command') def test_module_build_local_custom_config(self, mock_run): """ Test submitting a local module build