From e04643082fb0f1ed282cdc7df50e642245ec1f50 Mon Sep 17 00:00:00 2001 From: Govind Kamat Date: Wed, 31 Jan 2024 11:24:17 -0800 Subject: [PATCH] Emit a more informative error message if git is not installed at startup. Signed-off-by: Govind Kamat --- it/__init__.py | 4 +++- osbenchmark/utils/git.py | 5 ++--- tests/utils/git_test.py | 12 ++++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/it/__init__.py b/it/__init__.py index 73701940d..28005c2ea 100644 --- a/it/__init__.py +++ b/it/__init__.py @@ -86,7 +86,9 @@ def osbenchmark(cfg, command_line): This method should be used for benchmark invocations of the all commands besides test_execution. These commands may have different CLI options than test_execution. """ - err, retcode = process.run_subprocess_with_stderr(osbenchmark_command_line_for(cfg, command_line)) + cmd = osbenchmark_command_line_for(cfg, command_line) + print("\nInvoking OSB:", cmd) + err, retcode = process.run_subprocess_with_stderr(cmd) if retcode != 0: print(err) return retcode diff --git a/osbenchmark/utils/git.py b/osbenchmark/utils/git.py index d6d76fae1..159a7fb76 100644 --- a/osbenchmark/utils/git.py +++ b/osbenchmark/utils/git.py @@ -33,10 +33,8 @@ def probed(f): def probe(src, *args, **kwargs): - # Probe for -C try: - out, _, status = process.run_subprocess_with_out_and_err( - "git -C {} --version".format(io.escape_path(src))) + out, _, status = process.run_subprocess_with_out_and_err("git --version") except FileNotFoundError: status = 1 if status != 0: @@ -58,6 +56,7 @@ def is_working_copy(src): return os.path.exists(src) and os.path.exists(os.path.join(src, ".git")) +@probed def clone(src, remote): io.ensure_dir(src) # Don't swallow subprocess output, user might need to enter credentials... diff --git a/tests/utils/git_test.py b/tests/utils/git_test.py index cc38a2c75..897cc5fb8 100644 --- a/tests/utils/git_test.py +++ b/tests/utils/git_test.py @@ -44,12 +44,14 @@ def test_version_too_old(self, run_subprocess_with_out_and_err): git.head_revision("/src") self.assertEqual("OpenSearch Benchmark requires at least version 2 of git. You have git version 1.4.0. Please update git.", ctx.exception.args[0]) - run_subprocess_with_out_and_err.assert_called_with("git -C /src --version") + run_subprocess_with_out_and_err.assert_called_with("git --version") @mock.patch("osbenchmark.utils.io.ensure_dir") + @mock.patch("osbenchmark.utils.process.run_subprocess_with_out_and_err") @mock.patch("osbenchmark.utils.process.run_subprocess_with_logging") - def test_clone_successful(self, run_subprocess_with_logging, ensure_dir): + def test_clone_successful(self, run_subprocess_with_logging, run_subprocess_with_out_and_err, ensure_dir): run_subprocess_with_logging.return_value = 0 + run_subprocess_with_out_and_err.return_value = ("git version 2.0.0", "", 0) src = "/src" remote = "http://github.com/some/project" @@ -59,9 +61,11 @@ def test_clone_successful(self, run_subprocess_with_logging, ensure_dir): run_subprocess_with_logging.assert_called_with("git clone http://github.com/some/project /src") @mock.patch("osbenchmark.utils.io.ensure_dir") + @mock.patch("osbenchmark.utils.process.run_subprocess_with_out_and_err") @mock.patch("osbenchmark.utils.process.run_subprocess_with_logging") - def test_clone_with_error(self, run_subprocess_with_logging, ensure_dir): + def test_clone_with_error(self, run_subprocess_with_logging, run_subprocess_with_out_and_err, ensure_dir): run_subprocess_with_logging.return_value = 128 + run_subprocess_with_out_and_err.return_value = ("git version 2.0.0", "", 0) src = "/src" remote = "http://github.com/some/project" @@ -128,7 +132,7 @@ def test_pull(self, run_subprocess_with_out_and_err, run_subprocess_with_logging git.pull("/src", remote="my-origin", branch="feature-branch") run_subprocess_with_out_and_err.assert_has_calls([ # pull, fetch, rebase, checkout - mock.call("git -C /src --version") + mock.call("git --version") ] * 4) calls = [ mock.call("git -C /src fetch --prune --tags my-origin"),