Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dnslib = "*"
requests = "*"
gunicorn = "*"
httpbin = "*"
psutil = "*"

# Keep init.cli.ext updated with this required microserver version.
microserver = ">=1.0.6"
Expand Down
11 changes: 8 additions & 3 deletions tests/gold_tests/basic/deny0.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# limitations under the License.

import os
import sys

Test.Summary = '''
Test that Trafficserver rejects requests for host 0
'''
Expand Down Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions tests/gold_tests/h2/http2.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# limitations under the License.

import os
import sys

Test.Summary = '''
Test a basic remap of a http/2 connection
'''
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/gold_tests/h2/httpbin.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.

import os
import sys

# ----
# Setup Test
Expand Down Expand Up @@ -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=(',', ': ')))"
'''

# ----
Expand Down
31 changes: 13 additions & 18 deletions tests/gold_tests/headers/domain-blacklist-30x.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# limitations under the License.

import os
import sys

Test.Summary = '''
Tests 30x responses are returned for matching domains
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# limitations under the License.

import os
import sys

Test.Summary = '''
Test response when connection to origin fails
Expand All @@ -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'
5 changes: 3 additions & 2 deletions tests/gold_tests/headers/http408.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# limitations under the License.

import os
import sys

Test.Summary = '''
Check 408 response header for protocol stack data.
Expand Down Expand Up @@ -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"
19 changes: 11 additions & 8 deletions tests/gold_tests/logging/all_headers.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.

import os
import sys

Test.Summary = '''
Test new "all headers" log fields
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion tests/gold_tests/logging/log_pipe.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.

import os
import sys

Test.Summary = '''
Test custom log file format
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions tests/gold_tests/logging/new_log_flds.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.

import os
import sys

Test.Summary = '''
Test new log fields
Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions tests/gold_tests/logging/sigusr2.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# limitations under the License.

import os
import sys


TRAFFIC_MANAGER_PID_SCRIPT = 'ts_process_handler.py'
Expand Down Expand Up @@ -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 = '''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.

import os
import sys

Test.Summary = '''
Test combo_handler plugin
Expand All @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading