From bebec28dea9ff3d2847653a2c11ba88871811676 Mon Sep 17 00:00:00 2001 From: Brian Neradt Date: Tue, 12 Oct 2021 23:13:49 +0000 Subject: [PATCH] AuTest: Execute Test Python Scripts with sys.executable A handful of our AuTests execute their own Python scripts. Generally these just ran with whatever `python3` picked up. This changes those to use {sys.executable} which will run those scripts with the same Python being used for autest itself rather than some other system Python which may not have the required dependencies installed in it. This way any requirements for the scripts can be placed in the tests/Pipfile and it should be available for those scripts. --- tests/Pipfile | 1 + tests/gold_tests/basic/deny0.test.py | 11 +- tests/gold_tests/h2/http2.test.py | 15 ++- tests/gold_tests/h2/httpbin.test.py | 5 +- .../headers/domain-blacklist-30x.test.py | 31 ++--- .../general-connection-failure-502.test.py | 6 +- tests/gold_tests/headers/http408.test.py | 5 +- tests/gold_tests/logging/all_headers.test.py | 19 +-- tests/gold_tests/logging/log_pipe.test.py | 3 +- tests/gold_tests/logging/new_log_flds.test.py | 7 +- tests/gold_tests/logging/sigusr2.test.py | 5 +- .../combo_handler/combo_handler.test.py | 9 +- .../traffic_dump/traffic_dump.test.py | 126 +++++++----------- .../traffic_dump/traffic_dump_http3.test.py | 26 ++-- .../traffic_dump_ip_filter.test.py | 3 +- .../traffic_dump_response_body.test.py | 3 +- .../traffic_dump_sni_filter.test.py | 26 ++-- .../xdebug/x_cache_info/x_cache_info.test.py | 4 +- .../x_effective_url/x_effective_url.test.py | 8 +- .../pluginTest/xdebug/x_remap/x_remap.test.py | 8 +- tests/gold_tests/redirect/redirect.test.py | 26 ++-- .../redirect/redirect_actions.test.py | 12 +- tests/gold_tests/slow_post/slow_post.test.py | 5 +- .../thread_config/thread_config.test.py | 41 +++--- tests/gold_tests/tls/tls_0rtt_server.test.py | 20 ++- 25 files changed, 213 insertions(+), 212 deletions(-) diff --git a/tests/Pipfile b/tests/Pipfile index 321872ecd43..4c810ba1fc8 100644 --- a/tests/Pipfile +++ b/tests/Pipfile @@ -35,6 +35,7 @@ dnslib = "*" requests = "*" gunicorn = "*" httpbin = "*" +psutil = "*" # Keep init.cli.ext updated with this required microserver version. microserver = ">=1.0.6" diff --git a/tests/gold_tests/basic/deny0.test.py b/tests/gold_tests/basic/deny0.test.py index 285ad4c0773..ecb9f486ae0 100644 --- a/tests/gold_tests/basic/deny0.test.py +++ b/tests/gold_tests/basic/deny0.test.py @@ -18,6 +18,8 @@ # limitations under the License. import os +import sys + Test.Summary = ''' Test that Trafficserver rejects requests for host 0 ''' @@ -61,10 +63,13 @@ def buildMetaTest(testName, requestString): tr.Processes.Default.StartBefore(ts) tr.Processes.Default.StartBefore(redirect_serv, ready=When.PortOpen(redirect_serv.Variables.Port)) tr.Processes.Default.StartBefore(dns) - with open(os.path.join(data_path, tr.Name), 'w') as f: + + requestCommandPath = os.path.join(data_path, tr.Name) + with open(requestCommandPath, 'w') as f: f.write(requestString) - tr.Processes.Default.Command = "python3 tcp_client.py 127.0.0.1 {0} {1} | head -1".format( - ts.Variables.port, os.path.join(data_dirname, tr.Name)) + tr.Processes.Default.Command = \ + (f"{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} " + f"{requestCommandPath} | head -1") tr.ReturnCode = 0 tr.Processes.Default.Streams.stdout = gold_filepath tr.StillRunningAfter = ts diff --git a/tests/gold_tests/h2/http2.test.py b/tests/gold_tests/h2/http2.test.py index e6d2801ae35..38476191d61 100644 --- a/tests/gold_tests/h2/http2.test.py +++ b/tests/gold_tests/h2/http2.test.py @@ -17,6 +17,8 @@ # limitations under the License. import os +import sys + Test.Summary = ''' Test a basic remap of a http/2 connection ''' @@ -143,7 +145,7 @@ # Test Case 1: basic H2 interaction tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 h2client.py -p {0}'.format(ts.Variables.ssl_port) +tr.Processes.Default.Command = f'{sys.executable} h2client.py -p {ts.Variables.ssl_port}' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(server) tr.Processes.Default.StartBefore(Test.Processes.ts) @@ -152,14 +154,14 @@ # Test Case 2: Make sure all the big file gets back. Regression test for issue 1646 tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 h2bigclient.py -p {0}'.format(ts.Variables.ssl_port) +tr.Processes.Default.Command = f'{sys.executable} h2bigclient.py -p {ts.Variables.ssl_port}' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.Streams.stdout = "gold/bigfile.gold" tr.StillRunningAfter = server # Test Case 3: Chunked content tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 h2chunked.py -p {0} -u /test2'.format(ts.Variables.ssl_port) +tr.Processes.Default.Command = f'{sys.executable} h2chunked.py -p {ts.Variables.ssl_port} -u /test2' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.Streams.stdout = "gold/chunked.gold" tr.StillRunningAfter = server @@ -168,15 +170,16 @@ # Test Case 4: Multiple request # client_path = os.path.join(Test.Variables.AtsTestToolsDir, 'traffic-replay/') # tr = Test.AddTestRun() -# tr.Processes.Default.Command = "python3 {0} -type {1} -log_dir {2} -port {3} -host '127.0.0.1' -s_port {4} -v -colorize False".format( -# client_path, 'h2', server.Variables.DataDir, ts.Variables.port, ts.Variables.ssl_port) +# tr.Processes.Default.Command = \ +# (f"{sys.executable} {client_path} -type h2 -log_dir {server.Variables.DataDir} " +# f"-port {ts.Variables.port} -host '127.0.0.1' -s_port {ts.Variables.ssl_port} -v -colorize False") # tr.Processes.Default.ReturnCode = 0 # tr.Processes.Default.Streams.stdout = "gold/replay.gold" # tr.StillRunningAfter = server # Test Case 5: h2_active_timeout tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 h2active_timeout.py -p {0} -d 4'.format(ts.Variables.ssl_port) +tr.Processes.Default.Command = f'{sys.executable} h2active_timeout.py -p {ts.Variables.ssl_port} -d 4' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.Streams.All = "gold/active_timeout.gold" tr.StillRunningAfter = server diff --git a/tests/gold_tests/h2/httpbin.test.py b/tests/gold_tests/h2/httpbin.test.py index ff8eb95a712..147b6551f32 100644 --- a/tests/gold_tests/h2/httpbin.test.py +++ b/tests/gold_tests/h2/httpbin.test.py @@ -17,6 +17,7 @@ # limitations under the License. import os +import sys # ---- # Setup Test @@ -75,8 +76,8 @@ Test.Disk.File(os.path.join(ts.Variables.LOGDIR, 'access.log'), exists=True, content='gold/httpbin_access.gold') # TODO: when httpbin 0.8.0 or later is released, remove below json pretty print hack -json_printer = ''' -python3 -c "import sys,json; print(json.dumps(json.load(sys.stdin), indent=2, separators=(',', ': ')))" +json_printer = f''' +{sys.executable} -c "import sys,json; print(json.dumps(json.load(sys.stdin), indent=2, separators=(',', ': ')))" ''' # ---- diff --git a/tests/gold_tests/headers/domain-blacklist-30x.test.py b/tests/gold_tests/headers/domain-blacklist-30x.test.py index 275c3425890..0280ea0b8f6 100644 --- a/tests/gold_tests/headers/domain-blacklist-30x.test.py +++ b/tests/gold_tests/headers/domain-blacklist-30x.test.py @@ -18,6 +18,7 @@ # limitations under the License. import os +import sys Test.Summary = ''' Tests 30x responses are returned for matching domains @@ -56,57 +57,51 @@ Test.Setup.Copy(os.path.join(os.pardir, os.pardir, 'tools', 'tcp_client.py')) Test.Setup.Copy('data') -redirect301tr = Test.AddTestRun("Test domain {0}".format(REDIRECT_301_HOST)) +redirect301tr = Test.AddTestRun(f"Test domain {REDIRECT_301_HOST}") redirect301tr.Processes.Default.StartBefore(Test.Processes.ts) redirect301tr.StillRunningAfter = ts -redirect301tr.Processes.Default.Command = "python3 tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\ - format(ts.Variables.port, 'data/{0}_get.txt'.format(REDIRECT_301_HOST)) +redirect301tr.Processes.Default.Command = f"{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} data/{REDIRECT_301_HOST}_get.txt | grep -v '^Date: '| grep -v '^Server: ATS/'" redirect301tr.Processes.Default.TimeOut = 5 # seconds redirect301tr.Processes.Default.ReturnCode = 0 redirect301tr.Processes.Default.Streams.stdout = "redirect301_get.gold" -redirect302tr = Test.AddTestRun("Test domain {0}".format(REDIRECT_302_HOST)) +redirect302tr = Test.AddTestRun(f"Test domain {REDIRECT_302_HOST}") redirect302tr.StillRunningBefore = ts redirect302tr.StillRunningAfter = ts -redirect302tr.Processes.Default.Command = "python3 tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\ - format(ts.Variables.port, 'data/{0}_get.txt'.format(REDIRECT_302_HOST)) +redirect302tr.Processes.Default.Command = f"{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} data/{REDIRECT_302_HOST}_get.txt | grep -v '^Date: '| grep -v '^Server: ATS/'" redirect302tr.Processes.Default.TimeOut = 5 # seconds redirect302tr.Processes.Default.ReturnCode = 0 redirect302tr.Processes.Default.Streams.stdout = "redirect302_get.gold" -redirect307tr = Test.AddTestRun("Test domain {0}".format(REDIRECT_307_HOST)) +redirect307tr = Test.AddTestRun(f"Test domain {REDIRECT_307_HOST}") redirect302tr.StillRunningBefore = ts redirect307tr.StillRunningAfter = ts -redirect307tr.Processes.Default.Command = "python3 tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\ - format(ts.Variables.port, 'data/{0}_get.txt'.format(REDIRECT_307_HOST)) +redirect307tr.Processes.Default.Command = f"{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} data/{REDIRECT_307_HOST}_get.txt | grep -v '^Date: '| grep -v '^Server: ATS/'" redirect307tr.Processes.Default.TimeOut = 5 # seconds redirect307tr.Processes.Default.ReturnCode = 0 redirect307tr.Processes.Default.Streams.stdout = "redirect307_get.gold" -redirect308tr = Test.AddTestRun("Test domain {0}".format(REDIRECT_308_HOST)) +redirect308tr = Test.AddTestRun(f"Test domain {REDIRECT_308_HOST}") redirect308tr.StillRunningBefore = ts redirect308tr.StillRunningAfter = ts -redirect308tr.Processes.Default.Command = "python3 tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\ - format(ts.Variables.port, 'data/{0}_get.txt'.format(REDIRECT_308_HOST)) +redirect308tr.Processes.Default.Command = f"{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} data/{REDIRECT_308_HOST}_get.txt | grep -v '^Date: '| grep -v '^Server: ATS/'" redirect308tr.Processes.Default.TimeOut = 5 # seconds redirect308tr.Processes.Default.ReturnCode = 0 redirect308tr.Processes.Default.Streams.stdout = "redirect308_get.gold" -redirect0tr = Test.AddTestRun("Test domain {0}".format(REDIRECT_0_HOST)) +redirect0tr = Test.AddTestRun(f"Test domain {REDIRECT_0_HOST}") redirect0tr.StillRunningBefore = ts redirect0tr.StillRunningAfter = ts -redirect0tr.Processes.Default.Command = "python3 tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\ - format(ts.Variables.port, 'data/{0}_get.txt'.format(REDIRECT_0_HOST)) +redirect0tr.Processes.Default.Command = f"{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} data/{REDIRECT_0_HOST}_get.txt | grep -v '^Date: '| grep -v '^Server: ATS/'" redirect0tr.Processes.Default.TimeOut = 5 # seconds redirect0tr.Processes.Default.ReturnCode = 0 redirect0tr.Processes.Default.Streams.stdout = "redirect0_get.gold" -passthroughtr = Test.AddTestRun("Test domain {0}".format(PASSTHRU_HOST)) +passthroughtr = Test.AddTestRun(f"Test domain {PASSTHRU_HOST}") passthroughtr.StillRunningBefore = ts passthroughtr.StillRunningAfter = ts -passthroughtr.Processes.Default.Command = "python3 tcp_client.py 127.0.0.1 {0} {1} | grep -v '^Date: '| grep -v '^Server: ATS/'".\ - format(ts.Variables.port, 'data/{0}_get.txt'.format(PASSTHRU_HOST)) +passthroughtr.Processes.Default.Command = f"{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} data/{PASSTHRU_HOST}_get.txt | grep -v '^Date: '| grep -v '^Server: ATS/'" passthroughtr.Processes.Default.TimeOut = 5 # seconds passthroughtr.Processes.Default.ReturnCode = 0 passthroughtr.Processes.Default.Streams.stdout = "passthrough_get.gold" diff --git a/tests/gold_tests/headers/general-connection-failure-502.test.py b/tests/gold_tests/headers/general-connection-failure-502.test.py index 4cb06c3b449..e0f28f56edd 100644 --- a/tests/gold_tests/headers/general-connection-failure-502.test.py +++ b/tests/gold_tests/headers/general-connection-failure-502.test.py @@ -18,6 +18,7 @@ # limitations under the License. import os +import sys Test.Summary = ''' Test response when connection to origin fails @@ -39,7 +40,8 @@ tr = Test.AddTestRun() tr.Processes.Default.StartBefore(Test.Processes.ts) # Do not start the origin server: We wish to simulate connection refused while hopefully no one else uses this port. -tr.Processes.Default.Command = "python3 tcp_client.py 127.0.0.1 {0} {1} | sed -e '/^Date: /d' -e '/^Server: ATS\//d'"\ - .format(ts.Variables.port, "www.connectfail502.test-get.txt") +tr.Processes.Default.Command = \ + (f"{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} www.connectfail502.test-get.txt | " + "sed -e '/^Date: /d' -e '/^Server: ATS\//d'") tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.Streams.stdout = 'general-connection-failure-502.gold' diff --git a/tests/gold_tests/headers/http408.test.py b/tests/gold_tests/headers/http408.test.py index e3c2d9cd697..c841bfafe77 100644 --- a/tests/gold_tests/headers/http408.test.py +++ b/tests/gold_tests/headers/http408.test.py @@ -18,6 +18,7 @@ # limitations under the License. import os +import sys Test.Summary = ''' Check 408 response header for protocol stack data. @@ -50,8 +51,8 @@ tr = Test.AddTestRun() tr.Processes.Default.StartBefore(server) tr.Processes.Default.StartBefore(Test.Processes.ts) -tr.Processes.Default.Command = 'python3 tcp_client.py 127.0.0.1 {0} {1} --delay-after-send {2}'\ - .format(ts.Variables.port, 'data/{0}.txt'.format(HTTP_408_HOST), TIMEOUT + 2) +DELAY = TIMEOUT + 2 +tr.Processes.Default.Command = f'{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} data/{HTTP_408_HOST}.txt --delay-after-send {DELAY}' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.TimeOut = 10 tr.Processes.Default.Streams.stdout = "http408.gold" diff --git a/tests/gold_tests/logging/all_headers.test.py b/tests/gold_tests/logging/all_headers.test.py index c5f6a930ece..45bb984108e 100644 --- a/tests/gold_tests/logging/all_headers.test.py +++ b/tests/gold_tests/logging/all_headers.test.py @@ -17,6 +17,7 @@ # limitations under the License. import os +import sys Test.Summary = ''' Test new "all headers" log fields @@ -60,8 +61,8 @@ # Configure comparison of "sanitized" log file with gold file at end of test. # -Test.Disk.File(os.path.join(ts.Variables.LOGDIR, 'test_all_headers.log.san'), - exists=True, content='gold/test_all_headers.gold') +sanitized_log_path = os.path.join(ts.Variables.LOGDIR, 'test_all_headers.log.san') +Test.Disk.File(sanitized_log_path, exists=True, content='gold/test_all_headers.gold') def reallyLong(): @@ -94,10 +95,12 @@ def reallyLong(): # Delay to allow TS to flush report to disk, then "sanitize" generated log. # tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 {0} {2} {4} | sh {1} > {3}'.format( - os.path.join(Test.TestDirectory, 'all_headers_sanitizer.py'), - os.path.join(Test.TestDirectory, 'all_headers_sanitizer.sh'), - os.path.join(ts.Variables.LOGDIR, 'test_all_headers.log'), - os.path.join(ts.Variables.LOGDIR, 'test_all_headers.log.san'), - server.Variables.Port) + +log_path = os.path.join(ts.Variables.LOGDIR, 'test_all_headers.log') +sanitizer_python_script = os.path.join(Test.TestDirectory, 'all_headers_sanitizer.py') +sanitizer_shell_script = os.path.join(Test.TestDirectory, 'all_headers_sanitizer.sh') + +tr.Processes.Default.Command = \ + (f'{sys.executable} {sanitizer_python_script} {log_path} {server.Variables.Port} | ' + f'sh {sanitizer_shell_script} > {sanitized_log_path}') tr.Processes.Default.ReturnCode = 0 diff --git a/tests/gold_tests/logging/log_pipe.test.py b/tests/gold_tests/logging/log_pipe.test.py index fae1bce366c..7488c4031ea 100644 --- a/tests/gold_tests/logging/log_pipe.test.py +++ b/tests/gold_tests/logging/log_pipe.test.py @@ -17,6 +17,7 @@ # limitations under the License. import os +import sys Test.Summary = ''' Test custom log file format @@ -162,7 +163,7 @@ def get_ts(logging_config): tr.Setup.Copy(buffer_verifier) verify_buffer_size = tr.Processes.Process( "verify_buffer_size", - "python3 {} {} {}".format(buffer_verifier, pipe_path, pipe_size)) + f"{sys.executable} {buffer_verifier} {pipe_path} {pipe_size}") verify_buffer_size.Return = 0 verify_buffer_size.Streams.All += Testers.ContainsExpression( "Success", diff --git a/tests/gold_tests/logging/new_log_flds.test.py b/tests/gold_tests/logging/new_log_flds.test.py index c38da40f6f6..3a4e3ea2fb5 100644 --- a/tests/gold_tests/logging/new_log_flds.test.py +++ b/tests/gold_tests/logging/new_log_flds.test.py @@ -17,6 +17,7 @@ # limitations under the License. import os +import sys Test.Summary = ''' Test new log fields @@ -117,7 +118,7 @@ # Validate generated log. # tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 {0} < {1}'.format( - os.path.join(Test.TestDirectory, 'new_log_flds_observer.py'), - os.path.join(ts.Variables.LOGDIR, 'test_new_log_flds.log')) +observer_script = os.path.join(Test.TestDirectory, 'new_log_flds_observer.py') +log_path = os.path.join(ts.Variables.LOGDIR, 'test_new_log_flds.log') +tr.Processes.Default.Command = f'{sys.executable} {observer_script} < {log_path}' tr.Processes.Default.ReturnCode = 0 diff --git a/tests/gold_tests/logging/sigusr2.test.py b/tests/gold_tests/logging/sigusr2.test.py index a02c302dc07..fae67e051c4 100644 --- a/tests/gold_tests/logging/sigusr2.test.py +++ b/tests/gold_tests/logging/sigusr2.test.py @@ -18,6 +18,7 @@ # limitations under the License. import os +import sys TRAFFIC_MANAGER_PID_SCRIPT = 'ts_process_handler.py' @@ -107,8 +108,8 @@ def get_sigusr2_signal_command(self): Return the command that will send a USR2 signal to the traffic manager process. """ - return r"python3 {} --parent --signal SIGUSR2 {}".format( - TRAFFIC_MANAGER_PID_SCRIPT, self._ts_name) + return (f"{sys.executable} {TRAFFIC_MANAGER_PID_SCRIPT} --parent " + f"--signal SIGUSR2 {self._ts_name}") Test.Summary = ''' diff --git a/tests/gold_tests/pluginTest/combo_handler/combo_handler.test.py b/tests/gold_tests/pluginTest/combo_handler/combo_handler.test.py index b4a5a3e2c44..d785bf53e31 100644 --- a/tests/gold_tests/pluginTest/combo_handler/combo_handler.test.py +++ b/tests/gold_tests/pluginTest/combo_handler/combo_handler.test.py @@ -17,6 +17,7 @@ # limitations under the License. import os +import sys Test.Summary = ''' Test combo_handler plugin @@ -36,7 +37,7 @@ def data_file(data): global _data_file__file_count - file_path = Test.RunDirectory + "/tcp_client_in_{}".format(_data_file__file_count) + file_path = Test.RunDirectory + f"/tcp_client_in_{_data_file__file_count}" _data_file__file_count += 1 with open(file_path, "x") as f: f.write(data) @@ -47,7 +48,7 @@ def data_file(data): def tcp_client_cmd(host, port, file_path): - return "python3 {}/tcp_client.py {} {} {}".format(Test.Variables.AtsTestToolsDir, host, port, file_path) + return f"{sys.executable} {Test.Variables.AtsTestToolsDir}/tcp_client.py {host} {port} {file_path}" # Function to return command (string) to run tcp_client.py tool. 'host' and 'port' are the first two parameters to tcp_client. # 'data' is the data to put in the data file input to tcp_client. @@ -100,10 +101,10 @@ def add_server_obj(content_type, path): 'map http://xyz/ http://127.0.0.1/ @plugin=combo_handler.so' ) ts.Disk.remap_config.AddLine( - 'map http://localhost/127.0.0.1/ http://127.0.0.1:{}/'.format(server.Variables.Port) + f'map http://localhost/127.0.0.1/ http://127.0.0.1:{server.Variables.Port}/' ) ts.Disk.remap_config.AddLine( - 'map http://localhost/sub/ http://127.0.0.1:{}/sub/'.format(server.Variables.Port) + f'map http://localhost/sub/ http://127.0.0.1:{server.Variables.Port}/sub/' ) # Configure the combo_handler's configuration file. diff --git a/tests/gold_tests/pluginTest/traffic_dump/traffic_dump.test.py b/tests/gold_tests/pluginTest/traffic_dump/traffic_dump.test.py index 93db6d59f83..1aa57e47f1a 100644 --- a/tests/gold_tests/pluginTest/traffic_dump/traffic_dump.test.py +++ b/tests/gold_tests/pluginTest/traffic_dump/traffic_dump.test.py @@ -18,6 +18,7 @@ # limitations under the License. import os +import sys Test.Summary = ''' Verify traffic_dump functionality. @@ -27,6 +28,8 @@ Condition.PluginExists('traffic_dump.so'), ) +schema_path = os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json') + # Configure the origin server. replay_file = "replay/traffic_dump.yaml" server = Test.MakeVerifierServerProcess( @@ -50,10 +53,10 @@ 'proxy.config.diags.debug.tags': 'traffic_dump', 'proxy.config.http.insert_age_in_response': 0, - 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir), - 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir), + 'proxy.config.ssl.server.cert.path': ts.Variables.SSLDir, + 'proxy.config.ssl.server.private_key.path': ts.Variables.SSLDir, 'proxy.config.url_remap.pristine_host_hdr': 1, - 'proxy.config.ssl.CA.cert.filename': '{0}/signer.pem'.format(ts.Variables.SSLDir), + 'proxy.config.ssl.CA.cert.filename': f'{ts.Variables.SSLDir}/signer.pem', 'proxy.config.exec_thread.autoconfig.scale': 1.0, 'proxy.config.http.host_sni_policy': 2, 'proxy.config.ssl.TLSv1_3': 0, @@ -65,19 +68,19 @@ ) ts.Disk.remap_config.AddLine( - 'map https://www.client_only_tls.com/ http://127.0.0.1:{0}'.format(server.Variables.http_port) + f'map https://www.client_only_tls.com/ http://127.0.0.1:{server.Variables.http_port}' ) ts.Disk.remap_config.AddLine( - 'map https://www.tls.com/ https://127.0.0.1:{0}'.format(server.Variables.https_port) + f'map https://www.tls.com/ https://127.0.0.1:{server.Variables.https_port}' ) ts.Disk.remap_config.AddLine( - 'map / http://127.0.0.1:{0}'.format(server.Variables.http_port) + f'map / http://127.0.0.1:{server.Variables.http_port}' ) # Configure traffic_dump. ts.Disk.plugin_config.AddLine( - 'traffic_dump.so --logdir {0} --sample 1 --limit 1000000000 ' - '--sensitive-fields "cookie,set-cookie,x-request-1,x-request-2"'.format(replay_dir) + f'traffic_dump.so --logdir {replay_dir} --sample 1 --limit 1000000000 ' + '--sensitive-fields "cookie,set-cookie,x-request-1,x-request-2"' ) # Configure logging of transactions. This is helpful for the cache test below. ts.Disk.logging_yaml.AddLines( @@ -96,7 +99,7 @@ "loading plugin.*traffic_dump.so", "Verify the traffic_dump plugin got loaded.") ts.Streams.stderr = Testers.ContainsExpression( - "Initialized with log directory: {0}".format(replay_dir), + f"Initialized with log directory: {replay_dir}", "Verify traffic_dump initialized with the configured directory.") ts.Streams.stderr += Testers.ContainsExpression( "Initialized with sample pool size 1 bytes and disk limit 1000000000 bytes", @@ -158,13 +161,9 @@ "--sensitive-fields x-request-2 ") tr.Setup.CopyAs(verify_replay, Test.RunDirectory) tr.Processes.Default.Command = \ - ('python3 {0} {1} {2} {3} --client-http-version "1.1" ' - '--client-protocols "{4}"'.format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_1, - sensitive_fields_arg, - http_protocols)) + (f'{sys.executable} {verify_replay} {schema_path} {replay_file_session_1} ' + f'{sensitive_fields_arg} --client-http-version "1.1" ' + f'--client-protocols "{http_protocols}"') tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts @@ -173,12 +172,9 @@ tr = Test.AddTestRun("Verify the json content of the second session") tr.Setup.CopyAs(verify_replay, Test.RunDirectory) tr.Processes.Default.Command = \ - ('python3 {0} {1} {2} {3} --client-http-version "1.1" ' - '--request-target "/two"'.format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_2, - sensitive_fields_arg)) + (f'{sys.executable} {verify_replay} {schema_path} {replay_file_session_2} ' + f'{sensitive_fields_arg} --client-http-version "1.1" ' + '--request-target "/two"') tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts @@ -191,12 +187,9 @@ tr = Test.AddTestRun("Verify the replay file has the explicit target.") tr.Setup.CopyAs(verify_replay, Test.RunDirectory) -tr.Processes.Default.Command = "python3 {0} {1} {2} {3} --request-target '{4}'".format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_3, - sensitive_fields_arg, - "http://www.some.host.com/candy") +tr.Processes.Default.Command = \ + (f"{sys.executable} {verify_replay} {schema_path} {replay_file_session_3} {sensitive_fields_arg} " + "--request-target 'http://www.some.host.com/candy'") tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts @@ -211,12 +204,8 @@ size_of_verify_replay_file = os.path.getsize(os.path.join(Test.TestDirectory, verify_replay)) expected_body_size = 12345 tr.Processes.Default.Command = \ - "python3 {0} {1} {2} {3} --client-request-size {4}".format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_4, - sensitive_fields_arg, - expected_body_size) + (f"{sys.executable} {verify_replay} {schema_path} {replay_file_session_4} {sensitive_fields_arg} " + f"--client-request-size {expected_body_size}") tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts @@ -226,11 +215,9 @@ # tr = Test.AddTestRun("Verify that the cached response's replay file looks appropriate.") tr.Setup.CopyAs(verify_replay, Test.RunDirectory) -tr.Processes.Default.Command = 'python3 {0} {1} {2} --client-protocols "{3}"'.format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_6, - http_protocols) +tr.Processes.Default.Command = \ + (f'{sys.executable} {verify_replay} {schema_path} {replay_file_session_6} ' + f'--client-protocols "{http_protocols}"') tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts @@ -240,11 +227,9 @@ # tr = Test.AddTestRun("Verify the dump file of two transactions in a session.") tr.Setup.CopyAs(verify_replay, Test.RunDirectory) -tr.Processes.Default.Command = 'python3 {0} {1} {2} --client-protocols "{3}"'.format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_7, - http_protocols) +tr.Processes.Default.Command = \ + (f'{sys.executable} {verify_replay} {schema_path} {replay_file_session_7} ' + f'--client-protocols "{http_protocols}"') tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts @@ -256,12 +241,9 @@ https_protocols = "tls,tcp,ip" client_tls_features = "sni:www.tls.com,proxy-verify-mode:0,proxy-provided-cert:true" tr.Setup.CopyAs(verify_replay, Test.RunDirectory) -tr.Processes.Default.Command = 'python3 {0} {1} {2} --client-protocols "{3}" --client-tls-features "{4}"'.format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_8, - https_protocols, - client_tls_features) +tr.Processes.Default.Command = \ + (f'{sys.executable} {verify_replay} {schema_path} {replay_file_session_8} ' + f'--client-protocols "{https_protocols}" --client-tls-features "{client_tls_features}"') tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts @@ -270,12 +252,9 @@ https_server_stack = "http,tls,tcp,ip" tr.Setup.CopyAs(verify_replay, Test.RunDirectory) server_tls_features = 'proxy-provided-cert:false,sni:www.tls.com,proxy-verify-mode:1' -tr.Processes.Default.Command = 'python3 {0} {1} {2} --server-protocols "{3}" --server-tls-features "{4}"'.format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_8, - https_server_stack, - server_tls_features) +tr.Processes.Default.Command = \ + (f'{sys.executable} {verify_replay} {schema_path} {replay_file_session_8} --server-protocols ' + f'"{https_server_stack}" --server-tls-features "{server_tls_features}"') tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts @@ -287,25 +266,18 @@ h2_protocols = "http,tls,tcp,ip" tr.Setup.CopyAs(verify_replay, Test.RunDirectory) tr.Processes.Default.Command = \ - ('python3 {0} {1} {2} --client-http-version "2" ' - '--client-protocols "{3}" --client-tls-features "{4}"'.format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_9, - h2_protocols, - client_tls_features)) + (f'{sys.executable} {verify_replay} {schema_path} {replay_file_session_9} ' + f'--client-http-version "2" --client-protocols "{h2_protocols}" ' + f'--client-tls-features "{client_tls_features}"') tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts tr = Test.AddTestRun("Verify the server HTTP/2 protocol stack.") tr.Setup.CopyAs(verify_replay, Test.RunDirectory) -tr.Processes.Default.Command = 'python3 {0} {1} {2} --server-protocols "{3}" --server-tls-features "{4}"'.format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_9, - https_server_stack, - server_tls_features) +tr.Processes.Default.Command = \ + (f'{sys.executable} {verify_replay} {schema_path} {replay_file_session_9} ' + f'--server-protocols "{https_server_stack}" --server-tls-features "{server_tls_features}"') tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts @@ -315,11 +287,9 @@ # tr = Test.AddTestRun("Verify the client TLS protocol stack.") tr.Setup.CopyAs(verify_replay, Test.RunDirectory) -tr.Processes.Default.Command = 'python3 {0} {1} {2} --client-http-version "1.1" --client-protocols "{3}"'.format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_10, - https_protocols) +tr.Processes.Default.Command = \ + (f'{sys.executable} {verify_replay} {schema_path} {replay_file_session_10} ' + f'--client-http-version "1.1" --client-protocols "{https_protocols}"') tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts @@ -327,11 +297,9 @@ tr = Test.AddTestRun("Verify the server HTTP protocol stack.") tr.Setup.CopyAs(verify_replay, Test.RunDirectory) http_server_stack = "http,tcp,ip" -tr.Processes.Default.Command = 'python3 {0} {1} {2} --server-protocols "{3}"'.format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_10, - http_server_stack) +tr.Processes.Default.Command = \ + (f'{sys.executable} {verify_replay} {schema_path} {replay_file_session_10} ' + f'--server-protocols "{http_server_stack}"') tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts diff --git a/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_http3.test.py b/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_http3.test.py index b3c31b09206..c4c9bbfaaed 100644 --- a/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_http3.test.py +++ b/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_http3.test.py @@ -18,6 +18,8 @@ # limitations under the License. import os +import sys + Test.Summary = ''' Verify traffic_dump HTTP/3 functionality. ''' @@ -30,6 +32,8 @@ Condition.true("Skip this test until the TS_EVENT_HTTP_SSN are supported for QUIC connections."), ) +schema_path = os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json') + # Configure the origin server. replay_file = "replay/http3.yaml" server = Test.MakeVerifierServerProcess( @@ -53,10 +57,10 @@ 'proxy.config.quic.qlog_dir': qlog_dir, - 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir), - 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir), + 'proxy.config.ssl.server.cert.path': ts.Variables.SSLDir, + 'proxy.config.ssl.server.private_key.path': ts.Variables.SSLDir, 'proxy.config.url_remap.pristine_host_hdr': 1, - 'proxy.config.ssl.CA.cert.filename': '{0}/signer.pem'.format(ts.Variables.SSLDir), + 'proxy.config.ssl.CA.cert.filename': f'{ts.Variables.SSLDir}/signer.pem', 'proxy.config.exec_thread.autoconfig.scale': 1.0, 'proxy.config.http.host_sni_policy': 2, 'proxy.config.ssl.client.verify.server.policy': 'PERMISSIVE', @@ -67,13 +71,13 @@ ) ts.Disk.remap_config.AddLine( - 'map https://www.client_only_tls.com/ http://127.0.0.1:{0}'.format(server.Variables.http_port) + f'map https://www.client_only_tls.com/ http://127.0.0.1:{server.Variables.http_port}' ) ts.Disk.remap_config.AddLine( - 'map https://www.tls.com/ https://127.0.0.1:{0}'.format(server.Variables.https_port) + f'map https://www.tls.com/ https://127.0.0.1:{server.Variables.https_port}' ) ts.Disk.remap_config.AddLine( - 'map / http://127.0.0.1:{0}'.format(server.Variables.http_port) + f'map / http://127.0.0.1:{server.Variables.http_port}' ) # Configure traffic_dump. @@ -141,13 +145,9 @@ "--sensitive-fields x-request-2 ") tr.Setup.CopyAs(verify_replay, Test.RunDirectory) tr.Processes.Default.Command = \ - ('python3 {0} {1} {2} {3} --client-http-version "3" ' - '--client-protocols "{4}"'.format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_1, - sensitive_fields_arg, - http_protocols)) + (f'{sys.executable} {verify_replay} {schema_path} {replay_file_session_1} ' + f'{sensitive_fields_arg} --client-http-version "3" ' + f'--client-protocols "{http_protocols}"') tr.Processes.Default.ReturnCode = 0 tr.StillRunningAfter = server tr.StillRunningAfter = ts diff --git a/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_ip_filter.test.py b/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_ip_filter.test.py index 9cc61b2c6b0..12eeae0e15c 100644 --- a/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_ip_filter.test.py +++ b/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_ip_filter.test.py @@ -18,6 +18,7 @@ # limitations under the License. import os +import sys Test.Summary = ''' Verify traffic_dump IP filter functionality. @@ -64,7 +65,7 @@ def get_common_ats_process(name, plugin_command, replay_exists): # Common verification variables. verify_replay = "verify_replay.py" schema = os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json') -verify_command_prefix = f'python3 {verify_replay} {schema}' +verify_command_prefix = f'{sys.executable} {verify_replay} {schema}' # # Test 1: Verify -4 works for a specified address. diff --git a/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_response_body.test.py b/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_response_body.test.py index a1fda20b0af..61538d13b71 100644 --- a/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_response_body.test.py +++ b/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_response_body.test.py @@ -18,6 +18,7 @@ # limitations under the License. import os +import sys Test.Summary = ''' Verify traffic_dump response body functionality. @@ -99,7 +100,7 @@ # Common verification variables. verify_replay = "verify_replay.py" schema = os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json') -verify_command_prefix = f'python3 {verify_replay} {schema}' +verify_command_prefix = f'{sys.executable} {verify_replay} {schema}' # # Verify a response without a body is dumped correctly. diff --git a/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_sni_filter.test.py b/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_sni_filter.test.py index 03a52b87b42..3f8b89c1b89 100644 --- a/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_sni_filter.test.py +++ b/tests/gold_tests/pluginTest/traffic_dump/traffic_dump_sni_filter.test.py @@ -18,6 +18,8 @@ # limitations under the License. import os +import sys + Test.Summary = ''' Verify traffic_dump functionality. ''' @@ -26,6 +28,7 @@ Condition.PluginExists('traffic_dump.so'), ) +schema_path = os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json') replay_file = "replay/various_sni.yaml" server = Test.MakeVerifierServerProcess( "server-various-sni", replay_file, @@ -43,10 +46,10 @@ 'proxy.config.diags.debug.enabled': 1, 'proxy.config.diags.debug.tags': 'traffic_dump', - 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir), - 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir), + 'proxy.config.ssl.server.cert.path': ts.Variables.SSLDir, + 'proxy.config.ssl.server.private_key.path': ts.Variables.SSLDir, 'proxy.config.url_remap.pristine_host_hdr': 1, - 'proxy.config.ssl.CA.cert.filename': '{0}/signer.pem'.format(ts.Variables.SSLDir), + 'proxy.config.ssl.CA.cert.filename': f'{ts.Variables.SSLDir}/signer.pem', 'proxy.config.exec_thread.autoconfig.scale': 1.0, 'proxy.config.http.host_sni_policy': 2, 'proxy.config.ssl.TLSv1_3': 0, @@ -58,7 +61,7 @@ ) ts.Disk.remap_config.AddLine( - 'map / https://127.0.0.1:{0}'.format(server.Variables.https_port) + f'map / https://127.0.0.1:{server.Variables.https_port}' ) ts.Disk.sni_yaml.AddLines([ @@ -71,13 +74,13 @@ # Configure traffic_dump's SNI filter to only dump connections with SNI bob.com. sni_filter = "bob.com" ts.Disk.plugin_config.AddLine( - 'traffic_dump.so --logdir {0} --sample 1 --limit 1000000000 ' - '--sni-filter "{1}"'.format(replay_dir, sni_filter) + f'traffic_dump.so --logdir {replay_dir} --sample 1 --limit 1000000000 ' + f'--sni-filter "{sni_filter}"' ) # Set up trafficserver expectations. ts.Streams.stderr += Testers.ContainsExpression( - "Filtering to only dump connections with SNI: {}".format(sni_filter), + f"Filtering to only dump connections with SNI: {sni_filter}", "Verify filtering for the expected SNI.") ts.Streams.stderr += Testers.ContainsExpression( @@ -117,10 +120,7 @@ session_1_tls_features = 'sni:bob.com,proxy-verify-mode:0,proxy-provided-cert:true' verify_replay = "verify_replay.py" tr.Setup.CopyAs(verify_replay, Test.RunDirectory) -tr.Processes.Default.Command = 'python3 {0} {1} {2} --client-protocols "{3}" --client-tls-features "{4}"'.format( - verify_replay, - os.path.join(Test.Variables.AtsTestToolsDir, 'lib', 'replay_schema.json'), - replay_file_session_1, - session_1_protocols, - session_1_tls_features) +tr.Processes.Default.Command = \ + (f'{sys.executable} {verify_replay} {schema_path} {replay_file_session_1} ' + f'--client-protocols "{session_1_protocols}" --client-tls-features "{session_1_tls_features}"') tr.Processes.Default.ReturnCode = 0 diff --git a/tests/gold_tests/pluginTest/xdebug/x_cache_info/x_cache_info.test.py b/tests/gold_tests/pluginTest/xdebug/x_cache_info/x_cache_info.test.py index 892297bb6dd..5d6529b1846 100644 --- a/tests/gold_tests/pluginTest/xdebug/x_cache_info/x_cache_info.test.py +++ b/tests/gold_tests/pluginTest/xdebug/x_cache_info/x_cache_info.test.py @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys + Test.Summary = ''' Test xdebug plugin X-Cache-Info header ''' @@ -57,7 +59,7 @@ def sendMsg(msgFile): global started tr = Test.AddTestRun() - tr.Processes.Default.Command = f"( python3 tools/tcp_client.py 127.0.0.1 {ts.Variables.port} {msgFile}.in ; echo '======' ) | sed 's/:{server.Variables.Port}/:SERVER_PORT/' >> out.log 2>&1" + tr.Processes.Default.Command = f"( {sys.executable} tools/tcp_client.py 127.0.0.1 {ts.Variables.port} {msgFile}.in ; echo '======' ) | sed 's/:{server.Variables.Port}/:SERVER_PORT/' >> out.log 2>&1" tr.Processes.Default.ReturnCode = 0 if not started: diff --git a/tests/gold_tests/pluginTest/xdebug/x_effective_url/x_effective_url.test.py b/tests/gold_tests/pluginTest/xdebug/x_effective_url/x_effective_url.test.py index ed1c3b54300..29c09c51605 100644 --- a/tests/gold_tests/pluginTest/xdebug/x_effective_url/x_effective_url.test.py +++ b/tests/gold_tests/pluginTest/xdebug/x_effective_url/x_effective_url.test.py @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys + Test.Summary = ''' Test xdebug plugin X-Effective header ''' @@ -61,10 +63,8 @@ def sendMsg(msgFile): tr = Test.AddTestRun() tr.Processes.Default.Command = ( - "( python3 {}/tcp_client.py 127.0.0.1 {} {}/{}.in".format( - Test.RunDirectory, ts.Variables.port, Test.TestDirectory, msgFile) + - " ; echo '======' ) | sed 's/:{}/:SERVER_PORT/' >> {}/out.log 2>&1 ".format( - server.Variables.Port, Test.RunDirectory) + f"( {sys.executable} {Test.RunDirectory}/tcp_client.py 127.0.0.1 {ts.Variables.port} {Test.TestDirectory}/{msgFile}.in" + f" ; echo '======' ) | sed 's/:{server.Variables.Port}/:SERVER_PORT/' >> {Test.RunDirectory}/out.log 2>&1 " ) tr.Processes.Default.ReturnCode = 0 diff --git a/tests/gold_tests/pluginTest/xdebug/x_remap/x_remap.test.py b/tests/gold_tests/pluginTest/xdebug/x_remap/x_remap.test.py index f5ee5df0eea..a4dcee01622 100644 --- a/tests/gold_tests/pluginTest/xdebug/x_remap/x_remap.test.py +++ b/tests/gold_tests/pluginTest/xdebug/x_remap/x_remap.test.py @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys + Test.Summary = ''' Test xdebug plugin X-Remap, Probe and fwd headers ''' @@ -59,10 +61,8 @@ def sendMsg(msgFile): tr = Test.AddTestRun() tr.Processes.Default.Command = ( - "( python3 {}/tcp_client.py 127.0.0.1 {} {}/{}.in".format( - Test.RunDirectory, ts.Variables.port, Test.TestDirectory, msgFile) + - " ; echo '======' ) | sed 's/:{}/:SERVER_PORT/' >> {}/out.log 2>&1 ".format( - server.Variables.Port, Test.RunDirectory) + f"( {sys.executable} {Test.RunDirectory}/tcp_client.py 127.0.0.1 {ts.Variables.port} {Test.TestDirectory}/{msgFile}.in" + f" ; echo '======' ) | sed 's/:{server.Variables.Port}/:SERVER_PORT/' >> {Test.RunDirectory}/out.log 2>&1 " ) tr.Processes.Default.ReturnCode = 0 diff --git a/tests/gold_tests/redirect/redirect.test.py b/tests/gold_tests/redirect/redirect.test.py index bd586898d08..01777dc3738 100644 --- a/tests/gold_tests/redirect/redirect.test.py +++ b/tests/gold_tests/redirect/redirect.test.py @@ -18,6 +18,8 @@ # limitations under the License. import os +import sys + Test.Summary = ''' Test redirection ''' @@ -71,10 +73,10 @@ # Here and below: spaces are deliberately omitted from the test run names because autest creates directories using these names. tr = Test.AddTestRun("FollowsRedirectWithAbsoluteLocationURI") # Here and below: because autest's Copy does not behave like standard cp, it's easiest to write all of our files out and copy last. -with open(os.path.join(data_path, tr.Name), 'w') as f: +command_path = os.path.join(data_path, tr.Name) +with open(command_path, 'w') as f: f.write('GET /redirect HTTP/1.1\r\nHost: iwillredirect.test:{port}\r\n\r\n'.format(port=redirect_serv.Variables.Port)) -tr.Processes.Default.Command = "python3 tcp_client.py 127.0.0.1 {0} {1} | egrep -v '^(Date: |Server: ATS/)'".format( - ts.Variables.port, os.path.join(data_dirname, tr.Name)) +tr.Processes.Default.Command = f"{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} {command_path} | egrep -v '^(Date: |Server: ATS/)'" tr.Processes.Default.StartBefore(ts) tr.Processes.Default.StartBefore(redirect_serv) tr.Processes.Default.StartBefore(dest_serv) @@ -92,11 +94,11 @@ redirect_serv.addResponse("sessionfile.log", redirect_request_header, redirect_response_header) tr = Test.AddTestRun("FollowsRedirectWithRelativeLocationURI") -with open(os.path.join(data_path, tr.Name), 'w') as f: +command_path = os.path.join(data_path, tr.Name) +with open(command_path, 'w') as f: f.write( 'GET /redirect-relative-path HTTP/1.1\r\nHost: iwillredirect.test:{port}\r\n\r\n'.format(port=redirect_serv.Variables.Port)) -tr.Processes.Default.Command = "python3 tcp_client.py 127.0.0.1 {0} {1} | egrep -v '^(Date: |Server: ATS/)'".format( - ts.Variables.port, os.path.join(data_dirname, tr.Name)) +tr.Processes.Default.Command = f"{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} {command_path} | egrep -v '^(Date: |Server: ATS/)'" tr.StillRunningAfter = ts tr.StillRunningAfter = redirect_serv tr.StillRunningAfter = dest_serv @@ -111,11 +113,11 @@ redirect_serv.addResponse("sessionfile.log", redirect_request_header, redirect_response_header) tr = Test.AddTestRun("FollowsRedirectWithRelativeLocationURIMissingLeadingSlash") -with open(os.path.join(data_path, tr.Name), 'w') as f: +command_path = os.path.join(data_path, tr.Name) +with open(command_path, 'w') as f: f.write( 'GET /redirect-relative-path-no-leading-slash HTTP/1.1\r\nHost: iwillredirect.test:{port}\r\n\r\n'.format(port=redirect_serv.Variables.Port)) -tr.Processes.Default.Command = "python3 tcp_client.py 127.0.0.1 {0} {1} | egrep -v '^(Date: |Server: ATS/)'".format( - ts.Variables.port, os.path.join(data_dirname, tr.Name)) +tr.Processes.Default.Command = f"{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} {command_path} | egrep -v '^(Date: |Server: ATS/)'" tr.StillRunningAfter = ts tr.StillRunningAfter = redirect_serv tr.StillRunningAfter = dest_serv @@ -149,12 +151,12 @@ redirect_serv.addResponse("sessionfile.log", redirect_request_header, redirect_response_header) tr = Test.AddTestRun("FollowsRedirect{0}".format(status)) - with open(os.path.join(data_path, tr.Name), 'w') as f: + command_path = os.path.join(data_path, tr.Name) + with open(command_path, 'w') as f: f.write(('GET /redirect{0} HTTP/1.1\r\n' 'Host: iwillredirect.test:{1}\r\n\r\n'). format(status, redirect_serv.Variables.Port)) - tr.Processes.Default.Command = "python3 tcp_client.py 127.0.0.1 {0} {1} | egrep -v '^(Date: |Server: ATS/)'".\ - format(ts.Variables.port, os.path.join(data_dirname, tr.Name)) + tr.Processes.Default.Command = f"{sys.executable} tcp_client.py 127.0.0.1 {ts.Variables.port} {command_path} | egrep -v '^(Date: |Server: ATS/)'" tr.StillRunningAfter = ts tr.StillRunningAfter = redirect_serv tr.StillRunningAfter = dest_serv diff --git a/tests/gold_tests/redirect/redirect_actions.test.py b/tests/gold_tests/redirect/redirect_actions.test.py index 5c1f49e481f..486b39af581 100644 --- a/tests/gold_tests/redirect/redirect_actions.test.py +++ b/tests/gold_tests/redirect/redirect_actions.test.py @@ -21,6 +21,8 @@ import re import os import socket +import sys + Test.Summary = ''' Test redirection behavior to invalid addresses ''' @@ -149,13 +151,17 @@ def makeTestCase(redirectTarget, expectedAction, scenario): origin.addResponse('sessionfile.log', request_header, response_header) # Generate the request data file. - with open(os.path.join(data_path, tr.Name), 'w') as f: + command_path = os.path.join(data_path, tr.Name) + with open(command_path, 'w') as f: f.write(('GET /redirect?config={0}&target={1} HTTP/1.1\r\n' 'Host: iwillredirect.test:{2}\r\n\r\n'). format(normConfig, normRedirectTarget, origin.Variables.Port)) # Set the command with the appropriate URL. - tr.Processes.Default.Command = "bash -o pipefail -c 'python3 tcp_client.py 127.0.0.1 {0} {1} | head -n 1'".\ - format(trafficservers[config].Variables.port, os.path.join(data_dirname, tr.Name)) + port = trafficservers[config].Variables.port + dir_path = os.path.join(data_dirname, tr.Name) + tr.Processes.Default.Command = \ + (f"bash -o pipefail -c '{sys.executable} tcp_client.py 127.0.0.1 {port} " + f"{dir_path} | head -n 1'") tr.Processes.Default.ReturnCode = 0 # Generate and set the 'gold file' to check stdout goldFilePath = os.path.join(data_path, '{0}.gold'.format(tr.Name)) diff --git a/tests/gold_tests/slow_post/slow_post.test.py b/tests/gold_tests/slow_post/slow_post.test.py index 35bcbec644d..1de7ddbfeab 100644 --- a/tests/gold_tests/slow_post/slow_post.test.py +++ b/tests/gold_tests/slow_post/slow_post.test.py @@ -16,6 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys Test.SkipUnless( Condition.PluginExists('request_buffer.so') @@ -60,8 +61,8 @@ def setupTS(self): def run(self): tr = Test.AddTestRun() - tr.Processes.Default.Command = 'python3 {0} -p {1} -c {2}'.format( - self._slow_post_client, self._ts.Variables.port, self._origin_max_connections) + tr.Processes.Default.Command = \ + f'{sys.executable} {self._slow_post_client} -p {self._ts.Variables.port} -c {self._origin_max_connections}' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(self._server) tr.Processes.Default.StartBefore(Test.Processes.ts) diff --git a/tests/gold_tests/thread_config/thread_config.test.py b/tests/gold_tests/thread_config/thread_config.test.py index a1e6324251a..0ef86a1599b 100644 --- a/tests/gold_tests/thread_config/thread_config.test.py +++ b/tests/gold_tests/thread_config/thread_config.test.py @@ -16,6 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys Test.Summary = 'Test that Trafficserver starts with different thread configurations.' Test.ContinueOnFail = True @@ -33,7 +34,8 @@ ts.Setup.CopyAs('check_threads.py', Test.RunDirectory) tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 check_threads.py -p {0} -e {1} -a {2} -t {3} -c {4}'.format(ts.Env['TS_ROOT'], 1, 0, 1, 1) +TS_ROOT = ts.Env['TS_ROOT'] +tr.Processes.Default.Command = f'{sys.executable} check_threads.py -p {TS_ROOT} -e 1 -a 0 -t 1 -c 1' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(ts) @@ -49,7 +51,8 @@ 'proxy.config.diags.debug.tags': 'iocore_thread_start|iocore_net_accept_start'}) tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 check_threads.py -p {0} -e {1} -a {2} -t {3} -c {4}'.format(ts.Env['TS_ROOT'], 1, 1, 2, 8) +TS_ROOT = ts.Env['TS_ROOT'] +tr.Processes.Default.Command = f'{sys.executable} check_threads.py -p {TS_ROOT} -e 1 -a 1 -t 2 -c 8' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(ts) @@ -65,8 +68,8 @@ 'proxy.config.diags.debug.tags': 'iocore_thread_start|iocore_net_accept_start'}) tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 check_threads.py -p {0} -e {1} -a {2} -t {3} -c {4}'.format( - ts.Env['TS_ROOT'], 1, 10, 10, 32) +TS_ROOT = ts.Env['TS_ROOT'] +tr.Processes.Default.Command = f'{sys.executable} check_threads.py -p {TS_ROOT} -e 1 -a 10 -t 10 -c 32' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(ts) @@ -82,7 +85,8 @@ 'proxy.config.diags.debug.tags': 'iocore_thread_start|iocore_net_accept_start'}) tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 check_threads.py -p {0} -e {1} -a {2} -t {3} -c {4}'.format(ts.Env['TS_ROOT'], 2, 0, 1, 1) +TS_ROOT = ts.Env['TS_ROOT'] +tr.Processes.Default.Command = f'{sys.executable} check_threads.py -p {TS_ROOT} -e 2 -a 0 -t 1 -c 1' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(ts) @@ -98,7 +102,8 @@ 'proxy.config.diags.debug.tags': 'iocore_thread_start|iocore_net_accept_start'}) tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 check_threads.py -p {0} -e {1} -a {2} -t {3} -c {4}'.format(ts.Env['TS_ROOT'], 2, 1, 2, 8) +TS_ROOT = ts.Env['TS_ROOT'] +tr.Processes.Default.Command = f'{sys.executable} check_threads.py -p {TS_ROOT} -e 2 -a 1 -t 2 -c 8' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(ts) @@ -114,8 +119,8 @@ 'proxy.config.diags.debug.tags': 'iocore_thread_start|iocore_net_accept_start'}) tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 check_threads.py -p {0} -e {1} -a {2} -t {3} -c {4}'.format( - ts.Env['TS_ROOT'], 2, 10, 10, 32) +TS_ROOT = ts.Env['TS_ROOT'] +tr.Processes.Default.Command = f'{sys.executable} check_threads.py -p {TS_ROOT} -e 2 -a 10 -t 10 -c 32' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(ts) @@ -131,7 +136,8 @@ 'proxy.config.diags.debug.tags': 'iocore_thread_start|iocore_net_accept_start'}) tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 check_threads.py -p {0} -e {1} -a {2} -t {3} -c {4}'.format(ts.Env['TS_ROOT'], 32, 0, 1, 1) +TS_ROOT = ts.Env['TS_ROOT'] +tr.Processes.Default.Command = f'{sys.executable} check_threads.py -p {TS_ROOT} -e 32 -a 0 -t 1 -c 1' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(ts) @@ -147,7 +153,8 @@ 'proxy.config.diags.debug.tags': 'iocore_thread_start|iocore_net_accept_start'}) tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 check_threads.py -p {0} -e {1} -a {2} -t {3} -c {4}'.format(ts.Env['TS_ROOT'], 32, 1, 2, 8) +TS_ROOT = ts.Env['TS_ROOT'] +tr.Processes.Default.Command = f'{sys.executable} check_threads.py -p {TS_ROOT} -e 32 -a 1 -t 2 -c 8' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(ts) @@ -163,8 +170,8 @@ 'proxy.config.diags.debug.tags': 'iocore_thread_start|iocore_net_accept_start'}) tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 check_threads.py -p {0} -e {1} -a {2} -t {3} -c {4}'.format( - ts.Env['TS_ROOT'], 32, 10, 10, 32) +TS_ROOT = ts.Env['TS_ROOT'] +tr.Processes.Default.Command = f'{sys.executable} check_threads.py -p {TS_ROOT} -e 32 -a 10 -t 10 -c 32' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(ts) @@ -180,7 +187,8 @@ 'proxy.config.diags.debug.tags': 'iocore_thread_start|iocore_net_accept_start'}) tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 check_threads.py -p {0} -e {1} -a {2} -t {3} -c {4}'.format(ts.Env['TS_ROOT'], 100, 0, 1, 1) +TS_ROOT = ts.Env['TS_ROOT'] +tr.Processes.Default.Command = f'{sys.executable} check_threads.py -p {TS_ROOT} -e 100 -a 0 -t 1 -c 1' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(ts) @@ -196,7 +204,8 @@ 'proxy.config.diags.debug.tags': 'iocore_thread_start|iocore_net_accept_start'}) tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 check_threads.py -p {0} -e {1} -a {2} -t {3} -c {4}'.format(ts.Env['TS_ROOT'], 100, 1, 2, 8) +TS_ROOT = ts.Env['TS_ROOT'] +tr.Processes.Default.Command = f'{sys.executable} check_threads.py -p {TS_ROOT} -e 100 -a 1 -t 2 -c 8' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(ts) @@ -212,7 +221,7 @@ 'proxy.config.diags.debug.tags': 'iocore_thread_start|iocore_net_accept_start'}) tr = Test.AddTestRun() -tr.Processes.Default.Command = 'python3 check_threads.py -p {0} -e {1} -a {2} -t {3} -c {4}'.format( - ts.Env['TS_ROOT'], 100, 10, 10, 32) +TS_ROOT = ts.Env['TS_ROOT'] +tr.Processes.Default.Command = f'{sys.executable} check_threads.py -p {TS_ROOT} -e 100 -a 10 -t 10 -c 32' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.StartBefore(ts) diff --git a/tests/gold_tests/tls/tls_0rtt_server.test.py b/tests/gold_tests/tls/tls_0rtt_server.test.py index 2c69ec087f2..a86e9795f4b 100644 --- a/tests/gold_tests/tls/tls_0rtt_server.test.py +++ b/tests/gold_tests/tls/tls_0rtt_server.test.py @@ -16,6 +16,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys + Test.Summary = ''' Test ATS TLSv1.3 0-RTT support ''' @@ -143,8 +145,7 @@ tr.StillRunningAfter += ts tr = Test.AddTestRun('TLSv1.3 0-RTT Support (HTTP/1.1 GET)') -tr.Processes.Default.Command = 'python3 test-0rtt-s_client.py {0} {1} {2} {3}'.format( - ts.Variables.ssl_port, 'h1', 'get', Test.RunDirectory) +tr.Processes.Default.Command = f'{sys.executable} test-0rtt-s_client.py {ts.Variables.ssl_port} h1 get {Test.RunDirectory}' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.Streams.All = Testers.ContainsExpression('early data accepted', '') tr.Processes.Default.Streams.All += Testers.ExcludesExpression('curl test', '') @@ -152,8 +153,7 @@ tr.StillRunningAfter += ts tr = Test.AddTestRun('TLSv1.3 0-RTT Support (HTTP/1.1 POST)') -tr.Processes.Default.Command = 'python3 test-0rtt-s_client.py {0} {1} {2} {3}'.format( - ts.Variables.ssl_port, 'h1', 'post', Test.RunDirectory) +tr.Processes.Default.Command = f'{sys.executable} test-0rtt-s_client.py {ts.Variables.ssl_port} h1 post {Test.RunDirectory}' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.Streams.All = Testers.ContainsExpression('HTTP/1.1 425 Too Early', '') tr.Processes.Default.Streams.All += Testers.ExcludesExpression('curl test', '') @@ -162,8 +162,7 @@ tr.StillRunningAfter += ts tr = Test.AddTestRun('TLSv1.3 0-RTT Support (HTTP/2 GET)') -tr.Processes.Default.Command = 'python3 test-0rtt-s_client.py {0} {1} {2} {3}'.format( - ts.Variables.ssl_port, 'h2', 'get', Test.RunDirectory) +tr.Processes.Default.Command = f'{sys.executable} test-0rtt-s_client.py {ts.Variables.ssl_port} h2 get {Test.RunDirectory}' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.Streams.All = Testers.ContainsExpression('early data accepted', '') tr.Processes.Default.Streams.All += Testers.ExcludesExpression('curl test', '') @@ -171,8 +170,7 @@ tr.StillRunningAfter += ts tr = Test.AddTestRun('TLSv1.3 0-RTT Support (HTTP/2 POST)') -tr.Processes.Default.Command = 'python3 test-0rtt-s_client.py {0} {1} {2} {3}'.format( - ts.Variables.ssl_port, 'h2', 'post', Test.RunDirectory) +tr.Processes.Default.Command = f'{sys.executable} test-0rtt-s_client.py {ts.Variables.ssl_port} h2 post {Test.RunDirectory}' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.Streams.All = Testers.ContainsExpression(':status 425', 'Only safe methods are allowed') tr.Processes.Default.Streams.All += Testers.ExcludesExpression('curl test', '') @@ -181,8 +179,7 @@ tr.StillRunningAfter += ts tr = Test.AddTestRun('TLSv1.3 0-RTT Support (HTTP/2 Multiplex)') -tr.Processes.Default.Command = 'python3 test-0rtt-s_client.py {0} {1} {2} {3}'.format( - ts.Variables.ssl_port, 'h2', 'multi1', Test.RunDirectory) +tr.Processes.Default.Command = f'{sys.executable} test-0rtt-s_client.py {ts.Variables.ssl_port} h2 multi1 {Test.RunDirectory}' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.Streams.All = Testers.ContainsExpression('early data accepted multi_1', '') tr.Processes.Default.Streams.All += Testers.ContainsExpression('early data accepted multi_2', '') @@ -192,8 +189,7 @@ tr.StillRunningAfter += ts tr = Test.AddTestRun('TLSv1.3 0-RTT Support (HTTP/2 Multiplex with POST)') -tr.Processes.Default.Command = 'python3 test-0rtt-s_client.py {0} {1} {2} {3}'.format( - ts.Variables.ssl_port, 'h2', 'multi2', Test.RunDirectory) +tr.Processes.Default.Command = f'{sys.executable} test-0rtt-s_client.py {ts.Variables.ssl_port} h2 multi2 {Test.RunDirectory}' tr.Processes.Default.ReturnCode = 0 tr.Processes.Default.Streams.All = Testers.ContainsExpression('early data accepted multi_1', '') tr.Processes.Default.Streams.All += Testers.ContainsExpression(':status 425', 'Only safe methods are allowed')