diff --git a/esrally/rally.py b/esrally/rally.py index c5459d8f1..dc38fea95 100644 --- a/esrally/rally.py +++ b/esrally/rally.py @@ -1057,10 +1057,9 @@ def main(): if not args.offline: probing_url = cfg.opts("system", "probing.url", default_value="https://github.com", mandatory=False) if not net.has_internet_connection(probing_url): - console.warn("No Internet connection detected. Automatic download of track data sets etc. is disabled.", logger=logger) - cfg.add(config.Scope.applicationOverride, "system", "offline.mode", True) - else: - logger.info("Detected a working Internet connection.") + console.warn("No Internet connection detected. Specify --offline to run without it.", logger=logger) + sys.exit(0) + logger.info("Detected a working Internet connection.") result = dispatch_sub_command(arg_parser, args, cfg) diff --git a/esrally/utils/process.py b/esrally/utils/process.py index a2b7dcf67..38631eb73 100644 --- a/esrally/utils/process.py +++ b/esrally/utils/process.py @@ -28,11 +28,15 @@ def run_subprocess(command_line): return os.system(command_line) -def run_subprocess_with_output(command_line): +def run_subprocess_with_output(command_line, env_vars=None): logger = logging.getLogger(__name__) logger.debug("Running subprocess [%s] with output.", command_line) command_line_args = shlex.split(command_line) - with subprocess.Popen(command_line_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as command_line_process: + env = None + if env_vars: + env = os.environ.copy() + env.update(env_vars) + with subprocess.Popen(command_line_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) as command_line_process: has_output = True lines = [] while has_output: diff --git a/it/basic_test.py b/it/basic_test.py index 03d808196..cd43ca23d 100644 --- a/it/basic_test.py +++ b/it/basic_test.py @@ -33,3 +33,11 @@ def test_run_with_help(cfg): output = process.run_subprocess_with_output(cmd) expected = "usage: esrally [-h] [--version]" assert expected in "\n".join(output) + + +@it.rally_in_mem +def test_run_without_http_connection(cfg): + cmd = it.esrally_command_line_for(cfg, "list races") + output = process.run_subprocess_with_output(cmd, {"http_proxy": "http://invalid"}) + expected = "No Internet connection detected. Specify --offline" + assert expected in "\n".join(output) diff --git a/it/proxy_test.py b/it/proxy_test.py index fd9759be0..9ed6eff6c 100644 --- a/it/proxy_test.py +++ b/it/proxy_test.py @@ -81,7 +81,7 @@ def test_anonymous_proxy_no_connection(cfg, http_proxy, fresh_log_file): assert process.run_subprocess_with_logging(it.esrally_command_line_for(cfg, "list tracks"), env=env) == 0 assert_log_line_present(fresh_log_file, f"Connecting via proxy URL [{http_proxy.anonymous_url}] to the Internet") # unauthenticated proxy access is prevented - assert_log_line_present(fresh_log_file, "No Internet connection detected") + assert_log_line_present(fresh_log_file, "No Internet connection detected. Specify --offline") @it.rally_in_mem