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
35 changes: 3 additions & 32 deletions doc/appendices/command-line/traffic_ctl_jsonrpc.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -570,38 +570,9 @@ Configure Traffic Server to insert ``Via`` header in the response to the client
Autest
======

If you want to interact with |TS| under a unit test, then a few things need to be considered.

- Runroot needs to be configured in order to let `traffic_ctl` knows where to find the socket.

There are currently two ways to do this:

1. Using `run-root` param.

1. Let `Test.MakeATSProcess` to create the runroot file under the |TS| config directory. This can be done by passing `dump_runroot=True` to the above function:

.. code-block:: python

ts = Test.MakeATSProcess(..., dump_runroot=True)


`dump_runroot` will write out some of the keys inside the runroot file, in this case the `runtimedir`.

1. Then you should specify the :option:`traffic_ctl --run-root` when invoking the command:

.. code-block:: python

tr.Processes.Default.Command = f'traffic_ctl config reload --run-root {ts.Disk.runroot_yaml.Name}'

2. Setting up the `TS_RUNROOT` environment variable.
This is very similar to `1` but, instead of passing the `--run-root` param to `traffic_ctl`, you just need to specify the
`TS_RUNROOT` environment variable. To do that, just do as 1.1 shows and then:

.. code-block:: python

ts.SetRunRootEnv()

The above call will set the variable, please be aware that this variable will also be read by TS.
Runroot needs to be configured in order to let `traffic_ctl` know where to find the socket. This is done by default
and there is no change you have to do to interact with it, but make sure that you are not overriding the `dump_runroot=False`
when creating the ATS Process, otherwise the `runroot.yaml` will not be set.

See also
========
Expand Down
20 changes: 12 additions & 8 deletions tests/gold_tests/autest-site/trafficserver.test.ext
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ default_log_data = {

def MakeATSProcess(obj, name, command='traffic_server', select_ports=True,
enable_tls=False, enable_cache=True, enable_quic=False,
block_for_debug=False, log_data=default_log_data, dump_runroot=False):
block_for_debug=False, log_data=default_log_data, dump_runroot=True):
#####################################
# common locations

Expand Down Expand Up @@ -307,14 +307,18 @@ def MakeATSProcess(obj, name, command='traffic_server', select_ports=True,
tmpname = os.path.join(config_dir, fname)
p.Disk.File(tmpname, id=make_id(fname), typename="ats:config")

# Expect the instruction to set the variables inside the runroot. This is not mandatory
# Fill in the runroot file and set the config var, this will be used traffic_server
# and traffic_ctl
if dump_runroot:
p.Disk.runroot_yaml.AddLine(f'runtimedir: {runtime_dir}')

def SetRunRootEnv(self):
self.Env['TS_RUNROOT'] = os.path.join(config_dir, "runroot.yaml")

AddMethodToInstance(p, SetRunRootEnv)
p.Disk.runroot_yaml.AddLines([f'runtimedir: {runtime_dir}',
f'cachedir: {cache_dir}',
f'localstatedir: {runtime_dir}',
f'bindir: {bin_dir}',
f'prefix: {ts_dir}',
f'logdir: {log_dir}',
f'sysconfdir: {config_dir}'])
# Add more if needed
p.Env['TS_RUNROOT'] = os.path.join(config_dir, "runroot.yaml")

##########################################################
# set up default ports
Expand Down
4 changes: 2 additions & 2 deletions tests/gold_tests/cache/cache-generation-clear.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'''
Test.ContinueOnFail = True
# Define default ATS
ts = Test.MakeATSProcess("ts", command="traffic_server", select_ports=True, dump_runroot=True)
ts = Test.MakeATSProcess("ts", command="traffic_server", select_ports=True)

# setup some config file for this server
ts.Disk.records_config.update({
Expand Down Expand Up @@ -63,7 +63,7 @@

# Call traffic_ctrl to set new generation
tr = Test.AddTestRun()
tr.Processes.Default.Command = f'traffic_ctl --debug config set proxy.config.http.cache.generation 77 --run-root {ts.Disk.runroot_yaml.Name}'
tr.Processes.Default.Command = f'traffic_ctl --debug config set proxy.config.http.cache.generation 77'
tr.Processes.Default.ForceUseShell = False
tr.Processes.Default.ReturnCode = 0
tr.Processes.Default.Env = ts.Env # set the environment for traffic_control to run in
Expand Down
5 changes: 1 addition & 4 deletions tests/gold_tests/continuations/double.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@

Test.ContinueOnFail = True
# Define default ATS. Disable the cache to simplify the test.
ts = Test.MakeATSProcess("ts", select_ports=True, command="traffic_server", enable_cache=False, dump_runroot=True)
ts = Test.MakeATSProcess("ts", select_ports=True, command="traffic_server", enable_cache=False)
server = Test.MakeOriginServer("server")

# Set TS_RUNROOT, traffic_ctl needs it to find the socket.
ts.SetRunRootEnv()

Test.testName = ""
request_header = {"headers": "GET / HTTP/1.1\r\nHost: double_h2.test\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
# expected response from the origin server
Expand Down
5 changes: 1 addition & 4 deletions tests/gold_tests/continuations/double_h2.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@
)
Test.ContinueOnFail = True
# Define default ATS. Disable the cache to simplify the test.
ts = Test.MakeATSProcess("ts", select_ports=True, enable_tls=True, command="traffic_server", enable_cache=False, dump_runroot=True)
ts = Test.MakeATSProcess("ts", select_ports=True, enable_tls=True, command="traffic_server", enable_cache=False)
server = Test.MakeOriginServer("server")
server2 = Test.MakeOriginServer("server2")


# Set TS_RUNROOT, traffic_ctl needs it to find the socket.
ts.SetRunRootEnv()

Test.testName = ""
request_header = {"headers": "GET / HTTP/1.1\r\nHost: double_h2.test\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
# expected response from the origin server
Expand Down
4 changes: 1 addition & 3 deletions tests/gold_tests/continuations/openclose.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'''

# Define default ATS. Disable the cache to simplify the test.
ts = Test.MakeATSProcess("ts", command="traffic_server", enable_cache=False, dump_runroot=True)
ts = Test.MakeATSProcess("ts", command="traffic_server", enable_cache=False)

server = Test.MakeOriginServer("server")
server2 = Test.MakeOriginServer("server2")
Expand Down Expand Up @@ -72,8 +72,6 @@
tr.StillRunningAfter = ts


# Set TS_RUNROOT, traffic_ctl needs it to find the socket.
ts.SetRunRootEnv()
# Signal that all the curl processes have completed
tr = Test.AddTestRun("Curl Done")
tr.DelayStart = 2 # Delaying a couple seconds to make sure the global continuation's lock contention resolves.
Expand Down
5 changes: 1 addition & 4 deletions tests/gold_tests/continuations/openclose_h2.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)

# Define default ATS. Disable the cache to simplify the test.
ts = Test.MakeATSProcess("ts", select_ports=True, enable_tls=True, command="traffic_server", enable_cache=False, dump_runroot=True)
ts = Test.MakeATSProcess("ts", select_ports=True, enable_tls=True, command="traffic_server", enable_cache=False)


server = Test.MakeOriginServer("server")
Expand Down Expand Up @@ -85,9 +85,6 @@
server.StartAfter(*ps)
tr.StillRunningAfter = ts

# Set TS_RUNROOT, traffic_ctl needs it to find the socket.
ts.SetRunRootEnv()

# Signal that all the curl processes have completed
tr = Test.AddTestRun("Curl Done")
tr.DelayStart = 2 # Delaying a couple seconds to make sure the global continuation's lock contention resolves.
Expand Down
4 changes: 1 addition & 3 deletions tests/gold_tests/headers/forwarded.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def TestHttp1_1(host):
TestHttp1_1('www.forwarded-connection-std.com')
TestHttp1_1('www.forwarded-connection-full.com')

ts2 = Test.MakeATSProcess("ts2", command="traffic_server", enable_tls=True, dump_runroot=True)
ts2 = Test.MakeATSProcess("ts2", command="traffic_server", enable_tls=True)

baselineTsSetup(ts2)

Expand All @@ -205,8 +205,6 @@ def TestHttp1_1(host):
'map https://www.no-oride.com http://127.0.0.1:{0}'.format(server.Variables.Port)
)

# Set TS_RUNROOT, traffic_ctl needs it to find the socket.
ts2.SetRunRootEnv()

# Forwarded header with UUID of 2nd ATS.
tr = Test.AddTestRun()
Expand Down
4 changes: 1 addition & 3 deletions tests/gold_tests/jsonrpc/jsonrpc_api_schema.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def add_testrun_for_jsonrpc_request(
return tr


ts = Test.MakeATSProcess('ts', enable_cache=True, dump_runroot=True)
# Set TS_RUNROOT, traffic_ctl needs it to find the socket.
ts.SetRunRootEnv()
ts = Test.MakeATSProcess('ts', enable_cache=True)

Test.testName = 'Basic JSONRPC API test'

Expand Down
5 changes: 1 addition & 4 deletions tests/gold_tests/logging/log_retention.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __create_ts(self, records_config, command="traffic_server"):
"""
ts_name = "ts{counter}".format(counter=TestLogRetention.__ts_counter)
TestLogRetention.__ts_counter += 1
self.ts = Test.MakeATSProcess(ts_name, command=command, dump_runroot=True)
self.ts = Test.MakeATSProcess(ts_name, command=command)

combined_records_config = TestLogRetention.__base_records_config.copy()
combined_records_config.update(records_config)
Expand Down Expand Up @@ -526,9 +526,6 @@ def get_command_to_rotate_thrice(self):
test.tr.StillRunningAfter = test.ts
test.tr.StillRunningAfter = test.server

# Set TS_RUNROOT, traffic_ctl needs it to find the socket.
test.ts.SetRunRootEnv()

tr = Test.AddTestRun("Perform a config reload")
tr.Processes.Default.Command = "traffic_ctl config reload"
tr.Processes.Default.Env = test.ts.Env
Expand Down
5 changes: 1 addition & 4 deletions tests/gold_tests/pluginTest/cert_update/cert_update.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,14 @@
server.addResponse("sessionlog.json", request_header, response_header)

# Set up ATS
ts = Test.MakeATSProcess("ts", command="traffic_server", enable_tls=1, dump_runroot=True)
ts = Test.MakeATSProcess("ts", command="traffic_server", enable_tls=1)

# Set up ssl files
ts.addSSLfile("ssl/server1.pem")
ts.addSSLfile("ssl/server2.pem")
ts.addSSLfile("ssl/client1.pem")
ts.addSSLfile("ssl/client2.pem")

# Set TS_RUNROOT, traffic_ctl needs it to find the socket.
ts.SetRunRootEnv()

# reserve port, attach it to 'ts' so it is released later
ports.get_port(ts, 's_server_port')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
Test.SkipUnless(Condition.PluginExists('client_context_dump.so'))

# Set up ATS
ts = Test.MakeATSProcess("ts", command="traffic_server", select_ports=True, enable_tls=True, dump_runroot=True)
ts = Test.MakeATSProcess("ts", command="traffic_server", select_ports=True, enable_tls=True)

# Set up ssl files
ts.addSSLfile("ssl/one.com.pem")
Expand Down Expand Up @@ -73,6 +73,6 @@
tr = Test.AddTestRun()
tr.Processes.Default.Env = ts.Env
tr.Processes.Default.Command = (
'{0}/traffic_ctl plugin msg client_context_dump.t 1 --run-root {1}'.format(ts.Variables.BINDIR, ts.Disk.runroot_yaml.Name)
'{0}/traffic_ctl plugin msg client_context_dump.t 1'.format(ts.Variables.BINDIR)
)
tr.Processes.Default.ReturnCode = 0
7 changes: 2 additions & 5 deletions tests/gold_tests/pluginTest/lua/lua_states_stats.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

# It is necessary to redirect stderr to a file so it will be available for examination by a test run.
ts = Test.MakeATSProcess(
"ts", command="traffic_server 2> " + Test.RunDirectory + "/ts.stderr.txt", select_ports=True, dump_runroot=True
)
"ts", command="traffic_server 2> " + Test.RunDirectory + "/ts.stderr.txt", select_ports=True)

ts.ReturnCode = 0

Test.testName = "Lua states and stats"
Expand Down Expand Up @@ -64,9 +64,6 @@
'proxy.config.plugin.lua.max_states': 4,
})

# Set TS_RUNROOT, traffic_ctl needs it to find the socket.
ts.SetRunRootEnv()

curl_and_args = 'curl -s -D /dev/stdout -o /dev/stderr -x localhost:{} '.format(ts.Variables.port)

# 0 Test - Check for configured lua states
Expand Down
2 changes: 1 addition & 1 deletion tests/gold_tests/pluginTest/regex_revalidate/metrics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ N=60
while (( N > 0 ))
do
rm -f metrics.out
traffic_ctl metric match regex_revalidate --run-root $1 > metrics.out
traffic_ctl metric match regex_revalidate > metrics.out
sleep 1
if diff metrics.out ${AUTEST_TEST_DIR}/gold/metrics.gold
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ N=60
while (( N > 0 ))
do
rm -f metrics.out
traffic_ctl metric match regex_revalidate --run-root $1 > metrics.out
traffic_ctl metric match regex_revalidate > metrics.out
sleep 1
if diff metrics.out ${AUTEST_TEST_DIR}/gold/metrics_miss.gold
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
server = Test.MakeOriginServer("server")

# Define ATS and configure
ts = Test.MakeATSProcess("ts", command="traffic_server", select_ports=True, dump_runroot=True)
ts = Test.MakeATSProcess("ts", command="traffic_server", select_ports=True)

Test.testName = "regex_revalidate"
Test.Setup.Copy("metrics.sh")
Expand Down Expand Up @@ -279,7 +279,8 @@
# 12 Stats check
tr = Test.AddTestRun("Check stats")
tr.DelayStart = 5
tr.Processes.Default.Command = f"bash -c './metrics.sh {ts.Disk.runroot_yaml.Name}'"
# tr.Processes.Default.Command = f"bash -c './metrics.sh {ts.Disk.runroot_yaml.Name}'"
tr.Processes.Default.Command = f"bash -c './metrics.sh'"
tr.Processes.Default.Env = ts.Env
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
server = Test.MakeOriginServer("server")

# Define ATS and configure
ts = Test.MakeATSProcess("ts", command="traffic_server", dump_runroot=True)
ts = Test.MakeATSProcess("ts", command="traffic_server")

Test.testName = "regex_revalidate_miss"
Test.Setup.Copy("metrics_miss.sh")
Expand Down Expand Up @@ -149,7 +149,7 @@
# 3 Test - Revalidate path1
tr = Test.AddTestRun("Revalidate MISS path1")
ps = tr.Processes.Default
tr.DelayStart = 5
tr.DelayStart = 7
ps.Command = curl_and_args + ' http://ats/path1'
ps.ReturnCode = 0
ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: miss", "expected cache miss response")
Expand Down Expand Up @@ -178,7 +178,7 @@
# 6 Test - Cache stale
tr = Test.AddTestRun("Cache stale path1")
ps = tr.Processes.Default
tr.DelayStart = 5
tr.DelayStart = 7
ps.Command = curl_and_args + ' http://ats/path1'
ps.ReturnCode = 0
ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: hit-stale", "expected cache hit stale response")
Expand All @@ -199,7 +199,7 @@
# 8 Test - Cache stale
tr = Test.AddTestRun("Cache stale path1")
ps = tr.Processes.Default
tr.DelayStart = 5
tr.DelayStart = 7
ps.Command = curl_and_args + ' http://ats/path1'
ps.ReturnCode = 0
ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: miss", "expected cache miss response")
Expand All @@ -220,7 +220,7 @@
# 10 Test - Cache stale
tr = Test.AddTestRun("Cache stale path1")
ps = tr.Processes.Default
tr.DelayStart = 5
tr.DelayStart = 7
ps.Command = curl_and_args + ' http://ats/path1'
ps.ReturnCode = 0
ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: hit-fresh", "expected cache hit response")
Expand All @@ -229,7 +229,7 @@
# 11 Stats check
tr = Test.AddTestRun("Check stats")
tr.DelayStart = 5
tr.Processes.Default.Command = f"bash -c './metrics_miss.sh {ts.Disk.runroot_yaml.Name}'"
tr.Processes.Default.Command = f"bash -c ./metrics_miss.sh"
tr.Processes.Default.Env = ts.Env
tr.Processes.Default.ReturnCode = 0
tr.StillRunningAfter = ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"timestamp": "1469733493.993", "body": ""}
server.addResponse("sessionlog.json", request_header, response_header)

ts = Test.MakeATSProcess("ts", command="traffic_server", select_ports=True, dump_runroot=True)
ts = Test.MakeATSProcess("ts", command="traffic_server", select_ports=True)

ts.Disk.plugin_config.AddLine('remap_stats.so')

Expand Down
7 changes: 2 additions & 5 deletions tests/gold_tests/remap/conf_remap_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
'''
Test.testName = 'Float in conf_remap Config Test'

ts = Test.MakeATSProcess("ts", command="traffic_server", select_ports=True, dump_runroot=True)

# Set TS_RUNROOT, traffic_ctl needs it to find the socket.
ts.SetRunRootEnv()
ts = Test.MakeATSProcess("ts", command="traffic_server", select_ports=True)

# Add dummy remap rule
ts.Disk.remap_config.AddLine(
Expand All @@ -50,6 +47,6 @@
tr.StillRunningAfter = ts

p = tr.Processes.Default
p.Command = f"traffic_ctl config describe proxy.config.http.background_fill_completed_threshold --run-root {ts.Disk.runroot_yaml.Name}"
p.Command = f"traffic_ctl config describe proxy.config.http.background_fill_completed_threshold"
p.ReturnCode = 0
p.StartBefore(Test.Processes.ts, ready=When.FileExists(os.path.join(tr.RunDirectory, 'ts/log/diags.log')))
2 changes: 1 addition & 1 deletion tests/gold_tests/runroot/runroot_manager.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def StopProcess(event, time):
tr.ChownForATSProcess(trafficserver_dir)

p = tr.Processes.Default
p.Command = "$ATS_BIN/traffic_manager --run-root=" + rr_file
p.Command = "$ATS_BIN/traffic_server --run-root=" + rr_file
p.RunningEvent.Connect(Testers.Lambda(lambda ev: StopProcess(ev, 10)))
p.Streams.All = Testers.ContainsExpression("traffic_server: using root directory '" +
runroot_path + "'", "check if the right runroot is passed down")
Loading