From 16fddc7a58cd2ed61888416248d83b9f27d3e5b5 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Jan 26 2018 11:25:16 +0000 Subject: Handle nonexisting mbs-manager The purpose of this change is to avoid installing all dependent packages that module-build-service requires. Meanwhile, there is no EL6 build for module-build-service, this change can also give user a meaningful message instead of "No such a file or directory". Signed-off-by: Chenxiong Qi --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index af94e32..74cdbfc 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -2868,7 +2868,14 @@ class Commands(object): command.extend(['--file', file_path]) command.extend(['--stream', stream]) - self._run_command(command) + try: + self._run_command(command) + except OSError as e: + if e.errno == errno.ENOENT: + raise rpkgError('mbs-manager is missing. Please install ' + 'module-build-service.') + else: + raise def module_overview(self, api_url, limit=10, finished=True): """ diff --git a/tests/test_cli.py b/tests/test_cli.py index 3fcf36d..fb95e5c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2230,3 +2230,24 @@ State: failed mock_run.assert_called_once_with(['mbs-manager', 'build_module_locally', '--skiptests', '--file', file_path, '--stream', 'test']) + + @patch.object(Commands, '_run_command') + def test_module_build_local_mbs_manager_is_missing(self, mock_run): + e = OSError() + e.errno = 2 + mock_run.side_effect = e + + cli_cmd = [ + 'rpkg', '--path', self.cloned_repo_path, 'module-build-local' + ] + 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 + modulemd_yml = os.path.join(self.cloned_repo_path, + cli.cmd.module_name + '.yaml') + self.write_file(modulemd_yml) + + six.assertRaisesRegex(self, rpkgError, r'mbs-manager is missing.+', + cli.module_build_local)