From 481e43c9c35790d0dc63e5dd5e464f7168dc51f5 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Apr 30 2018 08:59:07 +0000 Subject: Allow setting custom MBS config file and config section in rpkg.conf. Signed-off-by: Jan Kaluza --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 50dec6f..1815525 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -2819,7 +2819,8 @@ class Commands(object): return actual_scm_url, actual_branch def module_local_build(self, file_path, stream, local_builds_nsvs=None, verbose=False, - debug=False, skip_tests=False): + debug=False, skip_tests=False, mbs_config=None, + mbs_config_section=None): """ A wrapper for `mbs-manager build_module_locally`. :param file_path: a string, path of the module's modulemd yaml file. @@ -2852,8 +2853,14 @@ class Commands(object): command.extend(['--file', file_path]) command.extend(['--stream', stream]) + env = {} + if mbs_config: + env['MBS_CONFIG_FILE'] = mbs_config + if mbs_config_section: + env['MBS_CONFIG_SECTION'] = mbs_config_section + try: - self._run_command(command) + self._run_command(command, env=env) except rpkgError as e: if str(e) == '[Errno 2] No such file or directory': raise rpkgError('mbs-manager is missing. Please install ' diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index d19a89f..b38f9bb 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1503,9 +1503,18 @@ see API KEY section of copr-cli(1) man page. if not os.path.isfile(file_path): raise IOError("Module metadata yaml file %s not found!" % file_path) + config_section = '{0}.mbs'.format(self.name) + mbs_config = None + if self.config.has_option(config_section, 'config_file'): + mbs_config = self.config.get(config_section, 'config_file') + mbs_config_section = None + if self.config.has_option(config_section, 'config_section'): + mbs_config_section = self.config.get(config_section, 'config_section') + 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) + verbose=self.args.v, debug=self.args.debug, skip_tests=self.args.skiptests, + mbs_config=mbs_config, mbs_config_section=mbs_config_section) def module_get_auth_config(self): """ diff --git a/tests/test_cli.py b/tests/test_cli.py index ae8c1ef..514365e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2317,7 +2317,35 @@ State: failed cli.module_build_local() mock_run.assert_called_once_with(['mbs-manager', 'build_module_locally', '--file', - file_path, '--stream', 'master']) + 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 + """ + cli_cmd = [ + 'rpkg', + '--path', + self.cloned_repo_path, + 'module-build-local' + ] + mock_proc = Mock() + mock_proc.returncode = 0 + mock_run.return_value = mock_proc + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + cli.config.set("rpkg.mbs", "config_file", "/etc/module-build-service/custom.py") + cli.config.set("rpkg.mbs", "config_section", "CustomSection") + file_path = os.path.join(self.cloned_repo_path, cli.cmd.module_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', '--file', file_path, '--stream', 'master'], + env={'MBS_CONFIG_FILE': '/etc/module-build-service/custom.py', + 'MBS_CONFIG_SECTION': 'CustomSection'}) @patch.object(Commands, '_run_command') def test_module_build_local_file_not_found(self, mock_run): @@ -2366,7 +2394,7 @@ State: failed cli.module_build_local() mock_run.assert_called_once_with(['mbs-manager', 'build_module_locally', '--file', - file_path, '--stream', 'test']) + file_path, '--stream', 'test'], env={}) @patch.object(Commands, '_run_command') def test_module_build_local_with_skiptests(self, mock_run): @@ -2397,7 +2425,7 @@ State: failed cli.module_build_local() mock_run.assert_called_once_with(['mbs-manager', 'build_module_locally', '--skiptests', - '--file', file_path, '--stream', 'test']) + '--file', file_path, '--stream', 'test'], env={}) @patch.object(Commands, '_run_command') def test_module_build_local_with_add_local_builds(self, mock_run): @@ -2429,7 +2457,7 @@ State: failed 'mbs-manager', 'build_module_locally', '--add-local-build', 'testmodule:master:12345678', '--add-local-build', 'testmodule2:master:12345678', '--file', file_path, '--stream', - 'test']) + 'test'], env={}) @patch.object(Commands, '_run_command') def test_module_build_local_mbs_manager_is_missing(self, mock_run):