Skip to content

Commit 35735bd

Browse files
serrislewSerris Lew
andauthored
Add CurlCommand to autests (#12122)
* Add CurlCommand to autests * MakeCurlCommand, SpawnCurlCommand, quote spaces * separate curl and use rundir for uds path * update new crr/slice autests --------- Co-authored-by: Serris Lew <lserris@apple.com>
1 parent d605c6c commit 35735bd

File tree

216 files changed

+1386
-1248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

216 files changed

+1386
-1248
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ if(ENABLE_DISK_FAILURE_TESTS)
139139
add_compile_definitions("AIO_FAULT_INJECTION")
140140
endif()
141141
option(ENABLE_AUTEST "Setup autest (default OFF)")
142+
option(ENABLE_AUTEST_UDS "Setup autest with curl using UDS (default OFF)")
142143
option(ENABLE_BENCHMARKS "Build benchmarks (default OFF)")
143144
option(EXTERNAL_YAML_CPP "Use external yaml-cpp (default OFF)")
144145
option(EXTERNAL_LIBSWOC "Use external libswoc (default OFF)")

tests/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ set(RUNPIPENV PIPENV_VENV_IN_PROJECT=True ${PipEnv})
5050
configure_file(Pipfile Pipfile COPYONLY)
5151
configure_file(autest.sh.in autest.sh)
5252

53+
set(CURL_UDS_FLAG "")
54+
if(ENABLE_AUTEST_UDS)
55+
set(CURL_UDS_FLAG "--curl-uds")
56+
endif()
57+
5358
add_custom_target(
5459
autest
5560
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target install
@@ -58,7 +63,7 @@ add_custom_target(
5863
${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/gold_tests/remap:$ENV{PYTHONPATH} ${RUNPIPENV} run
5964
env autest --directory ${CMAKE_CURRENT_SOURCE_DIR}/gold_tests --ats-bin=${CMAKE_INSTALL_PREFIX}/bin
6065
--proxy-verifier-bin ${PROXY_VERIFIER_PATH} --build-root ${CMAKE_BINARY_DIR} --sandbox ${AUTEST_SANDBOX}
61-
${AUTEST_OPTIONS}
66+
${CURL_UDS_FLAG} ${AUTEST_OPTIONS}
6267
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
6368
USES_TERMINAL
6469
)
@@ -70,7 +75,7 @@ add_custom_target(
7075
${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/gold_tests/remap:$ENV{PYTHONPATH} ${RUNPIPENV} run
7176
env autest --directory ${CMAKE_CURRENT_SOURCE_DIR}/gold_tests --ats-bin=${CMAKE_INSTALL_PREFIX}/bin
7277
--proxy-verifier-bin ${PROXY_VERIFIER_PATH} --build-root ${CMAKE_BINARY_DIR} --sandbox ${AUTEST_SANDBOX}
73-
${AUTEST_OPTIONS}
78+
${CURL_UDS_FLAG} ${AUTEST_OPTIONS}
7479
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
7580
USES_TERMINAL
7681
)

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ ts=Test.MakeATSProcess("ts")
132132
#first test is a miss for default
133133
tr=Test.AddTestRun()
134134
# get port for command from Variables
135-
tr.Processes.Default.Command='curl "http://127.0.0.1:{0}" --verbose'.format(ts.Variables.port)
135+
tr.MakeCurlCommand('"http://127.0.0.1:{0}" --verbose'.format(ts.Variables.port))
136136

137137
```
138138

tests/autest.sh.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ ${RUNPIPENV} run env autest \
1313
--ats-bin=${CMAKE_INSTALL_PREFIX}/bin \
1414
--proxy-verifier-bin ${PROXY_VERIFIER_PATH} \
1515
--build-root ${CMAKE_BINARY_DIR} \
16-
${AUTEST_OPTIONS} \
16+
${CURL_UDS_FLAG} ${AUTEST_OPTIONS} \
1717
"$@"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
'''
2+
Tools to help with TestRun commands
3+
'''
4+
# Licensed to the Apache Software Foundation (ASF) under one
5+
# or more contributor license agreements. See the NOTICE file
6+
# distributed with this work for additional information
7+
# regarding copyright ownership. The ASF licenses this file
8+
# to you under the Apache License, Version 2.0 (the
9+
# "License"); you may not use this file except in compliance
10+
# with the License. You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
20+
# Adds "curl" prefix to command argument, with possible curl flags
21+
#
22+
# example usage:
23+
# cmd = '-vs -k https:127.0.0.1:{port}'.format(port = ts.Variables.port)
24+
#
25+
# tr = Test.AddTestRun()
26+
# ps = tr.MakeCurlCommand(cmd)
27+
# tr.Processes.Default.StartBefore(ts)
28+
# ts.StartAfter(*ps)
29+
# tr.StillRunningAfter = ts
30+
#
31+
32+
33+
def spawn_curl_commands(self, cmdstr, count, retcode=0, use_default=True):
34+
ret = []
35+
36+
if self.Variables.get("CurlUds", False):
37+
cmdstr = 'curl --unix-socket /tmp/socket ' + cmdstr
38+
else:
39+
cmdstr = 'curl ' + cmdstr
40+
if use_default:
41+
count = int(count) - 1
42+
for cnt in range(0, count):
43+
ret.append(self.Processes.Process(name="cmdline-{num}".format(num=cnt), cmdstr=cmdstr, returncode=retcode))
44+
if use_default:
45+
self.Processes.Default.Command = cmdstr
46+
self.Processes.Default.ReturnCode = retcode
47+
self.Processes.Default.StartBefore(*ret)
48+
return ret
49+
50+
51+
def curl_command(self, cmd, p=None):
52+
if p == None:
53+
p = self.Processes.Default
54+
if self.Variables.get("CurlUds", False):
55+
uds_path = os.path.join(p.RunDirectory, 'uds.socket')
56+
p.Command = f'curl --unix-socket {uds_path} ' + cmd
57+
else:
58+
p.Command = 'curl ' + cmd
59+
return p
60+
61+
62+
def curl_multiple_commands(self, cmd):
63+
p = self.Processes.Default
64+
if self.Variables.get("CurlUds", False):
65+
uds_path = os.path.join(p.RunDirectory, 'uds.socket')
66+
p.Command = cmd.format(curl=f'curl --unix-socket {uds_path}')
67+
else:
68+
p.Command = cmd.format(curl='curl')
69+
return p
70+
71+
72+
ExtendTestRun(spawn_curl_commands, name="SpawnCurlCommands")
73+
ExtendTestRun(curl_command, name="MakeCurlCommand")
74+
ExtendTest(curl_command, name="MakeCurlCommand")
75+
ExtendTestRun(curl_multiple_commands, name="MakeCurlCommandMulti")
76+
ExtendTest(curl_multiple_commands, name="MakeCurlCommandMulti")

tests/gold_tests/autest-site/init.cli.ext

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ Settings.path_argument(["--ats-bin"], required=True, help="A user provided direc
4343
Settings.path_argument(["--build-root"], required=False, help="The location of the build root for out of source builds")
4444

4545
Settings.path_argument(["--proxy-verifier-bin"], required=False, help="A location for system proxy-verifier binaries to test with.")
46+
47+
Settings.add_argument(["--curl-uds"], action="store_true", required=False, help="Run all curl commands with --unix-socket flag")

tests/gold_tests/autest-site/setup.cli.ext

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Variables.BuildRoot = ENV['BUILD_ROOT']
117117
Variables.RepoDir = repo_root
118118
Variables.AtsTestPluginsDir = os.path.join(Variables.BuildRoot, 'tests', 'tools', 'plugins', '.libs')
119119
Variables.AtsBuildGoldTestsDir = os.path.join(Variables.BuildRoot, 'tests', 'gold_tests')
120+
Variables.CurlUds = Arguments.curl_uds
120121

121122
# modify delay times as we always have to kill Trafficserver
122123
# no need to wait

tests/gold_tests/autest-site/trafficserver.test.ext

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def MakeATSProcess(
5252
enable_tls=False,
5353
enable_cache=True,
5454
enable_quic=False,
55+
enable_uds=True,
5556
block_for_debug=False,
5657
log_data=default_log_data,
5758
use_traffic_out=True,
@@ -366,6 +367,10 @@ def MakeATSProcess(
366367
p.Variables.ssl_port = 4443
367368
p.Variables.ssl_portv6 = 4444
368369

370+
# unix domain socket path
371+
uds_path = os.path.join(obj.RunDirectory, 'uds.socket')
372+
p.Variables.uds_path = uds_path
373+
369374
get_port(p, "manager_port")
370375
get_port(p, "admin_port")
371376

@@ -415,6 +420,10 @@ def MakeATSProcess(
415420
port_str += f" {p.Variables.proxy_protocol_port}:pp {p.Variables.proxy_protocol_portv6}:pp:ipv6"
416421
if enable_tls:
417422
port_str += f" {p.Variables.proxy_protocol_ssl_port}:pp:ssl {p.Variables.proxy_protocol_ssl_portv6}:pp:ssl:ipv6"
423+
if enable_uds:
424+
port_str += f" {uds_path}:pp"
425+
elif enable_uds:
426+
port_str += f" {uds_path}"
418427
#p.Env['PROXY_CONFIG_HTTP_SERVER_PORTS'] = port_str
419428
p.Disk.records_config.update({
420429
'proxy.config.http.server_ports': port_str,

tests/gold_tests/basic/basic.test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
t.StillRunningAfter = Test.Processes.ts
2626

2727
p = t.Processes.Default
28-
p.Command = "curl http://127.0.0.1:{0}".format(ts.Variables.port)
28+
t.MakeCurlCommand("http://127.0.0.1:{0}".format(ts.Variables.port))
2929
p.ReturnCode = 0
3030
p.StartBefore(Test.Processes.ts)

tests/gold_tests/basic/config.test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
ts.Ready = When.PortOpen(ts.Variables.port)
2727
t = Test.AddTestRun("Test traffic server started properly")
2828
t.Processes.Default.StartBefore(ts)
29-
t.Command = "curl 127.0.0.1:{port}".format(port=ts.Variables.port)
29+
t.MakeCurlCommand("127.0.0.1:{port}".format(port=ts.Variables.port))
3030
t.ReturnCode = 0
3131
t.StillRunningAfter = ts

0 commit comments

Comments
 (0)