-
Notifications
You must be signed in to change notification settings - Fork 840
Hrw autest refactor #12371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Hrw autest refactor #12371
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
''' | ||
Shared library code for ATS autest tests. Add and update this file as needed. | ||
''' | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import glob | ||
import os | ||
import time | ||
|
||
|
||
class ATSTestManager: | ||
""" | ||
A comprehensive test management class for Apache Traffic Server tests. | ||
""" | ||
host_example = "Host: www.example.com" | ||
conn_keepalive = "Connection: keep-alive" | ||
|
||
def __init__(self, Test, When, test_name="ts"): | ||
""" | ||
Initialize the ATSTestManager with ATS and origin server processes. | ||
""" | ||
self.Test = Test | ||
self.When = When | ||
self.ts = self.Test.MakeATSProcess(test_name) | ||
self.server = self.Test.MakeOriginServer("server") | ||
|
||
self.ats_port = self.ts.Variables.port | ||
self.origin_port = self.server.Variables.Port | ||
self.run_dir = self.Test.RunDirectory | ||
self.localhost = f"127.0.0.1:{self.ats_port}" | ||
|
||
self.started = False | ||
|
||
# Default response header template | ||
self.default_response_header = { | ||
"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", | ||
"timestamp": "1469733493.993", | ||
"body": "" | ||
} | ||
|
||
def enable_diagnostics(self, tags="http_hdrs"): | ||
""" | ||
Configure debug logging for the ATS process. | ||
""" | ||
self.ts.Disk.records_config.update( | ||
{ | ||
'proxy.config.diags.debug.enabled': 1, | ||
'proxy.config.diags.show_location': 0, | ||
'proxy.config.diags.debug.tags': tags, | ||
}) | ||
|
||
def add_server_responses(self, responses, log_file="sessionfile.log"): | ||
""" | ||
Add responses to the origin server for the given request/response pairs. | ||
""" | ||
for req, resp in responses: | ||
if resp is None: | ||
resp = self.default_response_header | ||
self.server.addResponse(log_file, req, resp) | ||
|
||
def add_remap_rules(self, remap_rules, disable_tls=True): | ||
""" | ||
Add remap rules to the ATS configuration. | ||
This method processes a list of remap rule dictionaries and adds them to the | ||
remap.config file. Each rule can have associated plugins with parameters. | ||
""" | ||
for rule in remap_rules: | ||
plugin_args = self._build_plugin_args(rule["plugins"]) | ||
|
||
self.ts.Disk.remap_config.AddLine(f'map http://{rule["from"]} http://{rule["to"]} {plugin_args}') | ||
if not disable_tls: | ||
self.ts.Disk.remap_config.AddLine(f'map https://{rule["from"]} http://{rule["to"]} {plugin_args}') | ||
|
||
def _build_plugin_args(self, plugins): | ||
""" | ||
Build plugin arguments string from plugins list. | ||
""" | ||
if not plugins: | ||
return "" | ||
|
||
return " ".join(f'@plugin={plugin}.so ' + " ".join(f'@pparam={p}' for p in params) for plugin, params in plugins) | ||
|
||
def execute_tests(self, test_runs): | ||
""" | ||
Execute all configured test runs. | ||
""" | ||
for test in test_runs: | ||
if not 'desc' in test: | ||
raise ValueError("Test run must include 'desc' key") | ||
tr = self.Test.AddTestRun(test["desc"]) | ||
|
||
# Start processes before the first test | ||
if not self.started: | ||
tr.Processes.Default.StartBefore(self.server, ready=self.When.PortOpen(self.origin_port)) | ||
tr.Processes.Default.StartBefore(self.ts) | ||
self.started = True | ||
|
||
if curl := test.get("curl"): | ||
tr.MakeCurlCommand(curl, ts=self.ts) | ||
elif multi := test.get("multi_curl"): | ||
tr.MakeCurlCommandMulti(multi, ts=self.ts) | ||
|
||
if gold := test.get("gold"): | ||
tr.Processes.Default.Streams.stderr = gold | ||
|
||
tr.StillRunningAfter = self.server | ||
|
||
def set_traffic_out_content(self, content_file): | ||
""" | ||
Set the traffic.out content file for debugging. | ||
Args: | ||
content_file (str): Path to the content file | ||
""" | ||
self.ts.Disk.traffic_out.Content = content_file | ||
|
||
def copy_files(self, source, pattern, destination_dir=None): | ||
""" | ||
Copy files using either glob pattern matching or explicit file list. | ||
This method supports two modes: | ||
1. Pattern matching: When source is a string directory path, it finds all files | ||
matching the glob pattern and copies them to the destination. | ||
2. Explicit file list: When source is a list of file paths, it copies each | ||
file directly (pattern parameter is ignored in this case). | ||
""" | ||
if destination_dir is None: | ||
destination_dir = self.run_dir | ||
|
||
if isinstance(source, list): | ||
for file_path in source: | ||
self.ts.Setup.CopyAs(file_path, destination_dir) | ||
elif pattern is not None: | ||
for file_path in glob.glob(os.path.join(self.Test.TestDirectory, source, pattern)): | ||
relative_path = os.path.relpath(file_path, self.Test.TestDirectory) | ||
self.ts.Setup.CopyAs(relative_path, destination_dir) | ||
else: | ||
raise ValueError("Either 'source' must be a list of files or 'pattern' must be provided with a source directory.") |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 6 additions & 20 deletions
26
...write/gold/header_rewrite_cond_cache.gold → ...nTest/header_rewrite/gold/cond_cache.gold
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/gold_tests/pluginTest/header_rewrite/gold/cond_cache_first.gold
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
`` | ||
> GET /from_5/ HTTP/1.1 | ||
> Host: www.example.com | ||
> User-Agent: curl/`` | ||
> Accept: */* | ||
`` | ||
< HTTP/1.1 200 OK | ||
< Cache-Control: max-age=5,public | ||
< Content-Length: 6 | ||
< Date: `` | ||
< Age: `` | ||
< Connection: keep-alive | ||
< Server: ATS/{} | ||
< Cache-Result: miss | ||
`` |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
tests/gold_tests/pluginTest/header_rewrite/gold/header_rewrite-502.gold
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
tests/gold_tests/pluginTest/header_rewrite/gold/implicit_hook_fie.gold
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
`` | ||
> GET `` | ||
> Host: www.example.com`` | ||
> User-Agent: curl/`` | ||
> Accept: */* | ||
> Proxy-Connection: Keep-Alive | ||
> X-Fie: Fie | ||
`` | ||
< HTTP/1.1 200 OK | ||
< Date: `` | ||
< Age: `` | ||
< Transfer-Encoding: chunked | ||
< Proxy-Connection: keep-alive | ||
< Server: ATS/`` | ||
< X-Response-Foo: Yes | ||
`` |
15 changes: 15 additions & 0 deletions
15
tests/gold_tests/pluginTest/header_rewrite/gold/implicit_hook_no_fie.gold
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
`` | ||
> GET `` | ||
> Host: www.example.com`` | ||
> User-Agent: curl/`` | ||
> Accept: */* | ||
> Proxy-Connection: Keep-Alive | ||
`` | ||
< HTTP/1.1 200 OK | ||
< Date: `` | ||
< Age: `` | ||
< Transfer-Encoding: chunked | ||
< Proxy-Connection: keep-alive | ||
< Server: ATS/`` | ||
< X-Response-Foo: No | ||
`` |
16 changes: 16 additions & 0 deletions
16
tests/gold_tests/pluginTest/header_rewrite/gold/implicit_hook_prefix.gold
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
`` | ||
> GET `` | ||
> Host: www.example.com`` | ||
> User-Agent: curl/`` | ||
> Accept: */* | ||
> Proxy-Connection: Keep-Alive | ||
> X-Client-Foo: fOoBar | ||
`` | ||
< HTTP/1.1 200 OK | ||
< Date: `` | ||
< Age: `` | ||
< Transfer-Encoding: chunked | ||
< Proxy-Connection: keep-alive | ||
< Server: ATS/`` | ||
< X-Response-Foo: Prefix | ||
`` |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unique URL is helpful, but let's not use sequential numbers or letters. Inserting tests would be painful.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would that be painful? I guess I don't really care what we name them, but they have to be named something :). I'd imagined that if you are adding a new test to an existing autest, you append to the current list of remap rules if you need a new one. Sequential numbering. There'd never be a reason to add a rule in the middle of remap rules I don't think. If there is, at some point, just name it /from_x_y ? E.g. /from_4_1.
We could automate the numbering, but when I looked at that, it makes making the subsequent tests more difficult (you need some sort of identifier).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, note that it's not the request that's unique, it's the remap rule. One remap rule can handle multiple requests (test cases).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think similar test cases should be close each other. We could do "4_1", but that doesn't completely resolve the issue. Let's say we have "4_1", "4_2", and "4_3". If I wanted to insert a test between "4_1" and "4_2", I'd have to make "4_1_1" or renumber "4_2" and "4_3".
Also even for the case that I append tests, somebody else could be appending another tests on the same file. Then the number would conflicts. Either of those have to update the test number.
I don't think whether tests or remap rules matters in this discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the order doesn't matter. It's just an identifier, which I thought was easier to make numbered, but we can call them bob and alice if you want ...