Skip to content

Commit

Permalink
Add ramping test.
Browse files Browse the repository at this point in the history
Split TxnBox AuTest extensions to support multiple runs per test.
  • Loading branch information
SolidWallOfCode committed Jun 4, 2020
1 parent e3d2c1f commit 6938183
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 72 deletions.
42 changes: 25 additions & 17 deletions plugin/src/Machinery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Do_ua_req_url_host : public Directive {
};

const std::string Do_ua_req_url_host::KEY {"ua-req-url-host" };
const HookMask Do_ua_req_url_host::HOOKS {MaskFor({Hook::PREQ, Hook::PRE_REMAP, Hook::POST_REMAP}) };
const HookMask Do_ua_req_url_host::HOOKS {MaskFor({ Hook::PREQ, Hook::PRE_REMAP, Hook::REMAP, Hook::POST_REMAP}) };

Do_ua_req_url_host::Do_ua_req_url_host(Expr && expr) : _expr(std::move(expr)) {}

Expand Down Expand Up @@ -106,7 +106,7 @@ class Do_proxy_req_url_host : public Directive {
};

const std::string Do_proxy_req_url_host::KEY {"proxy-req-url-host" };
const HookMask Do_proxy_req_url_host::HOOKS {MaskFor({Hook::PREQ, Hook::PRE_REMAP, Hook::POST_REMAP}) };
const HookMask Do_proxy_req_url_host::HOOKS {MaskFor({ Hook::PREQ }) };

Do_proxy_req_url_host::Do_proxy_req_url_host(Expr && expr) : _expr(std::move(expr)) {}

Expand Down Expand Up @@ -136,6 +136,7 @@ swoc::Rv<Directive::Handle> Do_proxy_req_url_host::load(Config& cfg, YAML::Node

// ---

#if 0
class Do_remap_req_url_host : public Directive {
using super_type = Directive;
using self_type = Do_remap_req_url_host;
Expand Down Expand Up @@ -181,6 +182,7 @@ swoc::Rv<Directive::Handle> Do_remap_req_url_host::load(Config& cfg, YAML::Node
}
return Handle(new self_type{std::move(expr)});
}
#endif
/* ------------------------------------------------------------------------------------ */
/** Set the host for the request.
* This updates both the URL and the "Host" field, if appropriate.
Expand Down Expand Up @@ -222,7 +224,7 @@ class Do_ua_req_host : public Directive {
};

const std::string Do_ua_req_host::KEY {"ua-req-host" };
const HookMask Do_ua_req_host::HOOKS {MaskFor({Hook::CREQ, Hook::PRE_REMAP, Hook::POST_REMAP}) };
const HookMask Do_ua_req_host::HOOKS {MaskFor({Hook::CREQ, Hook::PRE_REMAP, Hook::REMAP, Hook::POST_REMAP}) };

Do_ua_req_host::Do_ua_req_host(Expr &&expr) : _expr(std::move(expr)) {}

Expand Down Expand Up @@ -288,7 +290,7 @@ class Do_proxy_req_host : public Directive {
};

const std::string Do_proxy_req_host::KEY {"proxy-req-host" };
const HookMask Do_proxy_req_host::HOOKS {MaskFor({Hook::PREQ, Hook::PRE_REMAP, Hook::POST_REMAP}) };
const HookMask Do_proxy_req_host::HOOKS {MaskFor({ Hook::PREQ }) };

Do_proxy_req_host::Do_proxy_req_host(Expr &&fmt) : _fmt(std::move(fmt)) {}

Expand All @@ -312,6 +314,7 @@ swoc::Rv<Directive::Handle> Do_proxy_req_host::load(Config& cfg, YAML::Node drtv
return Handle(new self_type(std::move(expr)));
}
/* ------------------------------------------------------------------------------------ */
#if 0
/** Set the host for remap.
* This updates both the URL and the "Host" field, if appropriate.
*/
Expand Down Expand Up @@ -379,6 +382,7 @@ swoc::Rv<Directive::Handle> Do_remap_host::load(Config& cfg, YAML::Node drtv_nod
}
return Handle(new self_type(std::move(expr)));
}
#endif
/* ------------------------------------------------------------------------------------ */
/** Set the scheme for the inbound request.
*/
Expand Down Expand Up @@ -419,7 +423,7 @@ class Do_ua_req_scheme : public Directive {
};

const std::string Do_ua_req_scheme::KEY {"ua-req-scheme" };
const HookMask Do_ua_req_scheme::HOOKS {MaskFor({Hook::CREQ, Hook::PRE_REMAP, Hook::POST_REMAP}) };
const HookMask Do_ua_req_scheme::HOOKS {MaskFor({ Hook::CREQ, Hook::PRE_REMAP, Hook::REMAP, Hook::POST_REMAP}) };

Do_ua_req_scheme::Do_ua_req_scheme(Expr &&fmt) : _fmt(std::move(fmt)) {}

Expand Down Expand Up @@ -482,7 +486,7 @@ class Do_proxy_req_scheme : public Directive {
};

const std::string Do_proxy_req_scheme::KEY {"proxy-req-scheme" };
const HookMask Do_proxy_req_scheme::HOOKS {MaskFor({Hook::PRE_REMAP, Hook::POST_REMAP, Hook::PREQ}) };
const HookMask Do_proxy_req_scheme::HOOKS {MaskFor({ Hook::PREQ}) };

Do_proxy_req_scheme::Do_proxy_req_scheme(Expr &&fmt) : _fmt(std::move(fmt)) {}

Expand All @@ -506,6 +510,7 @@ swoc::Rv<Directive::Handle> Do_proxy_req_scheme::load(Config& cfg, YAML::Node dr
return Handle(new self_type(std::move(expr)));
}
/* ------------------------------------------------------------------------------------ */
#if 0
/** Set the scheme for the outbound request.
*/
class Do_remap_scheme : public Directive {
Expand Down Expand Up @@ -570,6 +575,7 @@ swoc::Rv<Directive::Handle> Do_remap_scheme::load(Config& cfg, YAML::Node drtv_n
}
return Handle(new self_type(std::move(expr)));
}
#endif
/* ------------------------------------------------------------------------------------ */
/** Do the remap.
*/
Expand Down Expand Up @@ -642,7 +648,6 @@ Errata Do_apply_remap_rule::invoke(Context &ctx) {
request_url.path_set(TextView{url_w.view()}.ltrim('/'));
};

// TSUrlCopy(ctx._remap_info->requestBufp, ctx._remap_info->requestUrl, ctx._remap_info->requestBufp, ctx._remap_info->mapToUrl);
return {};
}

Expand Down Expand Up @@ -689,7 +694,7 @@ class Do_ua_req_path : public Directive {
};

const std::string Do_ua_req_path::KEY {"ua-req-path" };
const HookMask Do_ua_req_path::HOOKS {MaskFor({Hook::CREQ, Hook::PRE_REMAP, Hook::POST_REMAP}) };
const HookMask Do_ua_req_path::HOOKS {MaskFor({ Hook::CREQ, Hook::PRE_REMAP, Hook::REMAP, Hook::POST_REMAP}) };

Do_ua_req_path::Do_ua_req_path(Expr &&fmt) : _fmt(std::move(fmt)) {}

Expand Down Expand Up @@ -752,7 +757,7 @@ class Do_proxy_req_path : public Directive {
};

const std::string Do_proxy_req_path::KEY {"proxy-req-path" };
const HookMask Do_proxy_req_path::HOOKS {MaskFor({Hook::CREQ, Hook::PRE_REMAP, Hook::POST_REMAP}) };
const HookMask Do_proxy_req_path::HOOKS {MaskFor({ Hook::PREQ }) };

Do_proxy_req_path::Do_proxy_req_path(Expr &&fmt) : _fmt(std::move(fmt)) {}

Expand All @@ -776,6 +781,7 @@ swoc::Rv<Directive::Handle> Do_proxy_req_path::load(Config& cfg, YAML::Node drtv
return Handle(new self_type(std::move(expr)));
}
/* ------------------------------------------------------------------------------------ */
#if 0
/** Set the path for remap.
*/
class Do_remap_path : public Directive {
Expand Down Expand Up @@ -837,6 +843,7 @@ swoc::Rv<Directive::Handle> Do_remap_path::load(Config& cfg, YAML::Node drtv_nod
}
return Handle(new self_type(std::move(expr)));
}
#endif
/* ------------------------------------------------------------------------------------ */
class FieldDirective : public Directive {
using self_type = FieldDirective; ///< Self reference type.
Expand Down Expand Up @@ -1009,9 +1016,10 @@ class Do_ua_req_field : public FieldDirective {
};

const std::string Do_ua_req_field::KEY {"ua-req-field" };
const HookMask Do_ua_req_field::HOOKS {MaskFor({Hook::CREQ, Hook::PRE_REMAP, Hook::REMAP }) };
const HookMask Do_ua_req_field::HOOKS {MaskFor({ Hook::CREQ, Hook::PRE_REMAP, Hook::REMAP, Hook::POST_REMAP }) };

Errata Do_ua_req_field::invoke(Context &ctx) {
ctx._remap_status = TSREMAP_DID_REMAP;
return this->super_type::invoke(ctx, ctx.creq_hdr());
}

Expand All @@ -1036,7 +1044,7 @@ class Do_proxy_req_field : public FieldDirective {
};

const std::string Do_proxy_req_field::KEY {"proxy-req-field" };
const HookMask Do_proxy_req_field::HOOKS {MaskFor({Hook::PREQ, Hook::PRE_REMAP, Hook::POST_REMAP}) };
const HookMask Do_proxy_req_field::HOOKS {MaskFor({ Hook::PREQ }) };

Errata Do_proxy_req_field::invoke(Context &ctx) {
return this->super_type::invoke(ctx, ctx.preq_hdr());
Expand Down Expand Up @@ -1824,6 +1832,7 @@ Rv<Directive::Handle> Do_set_creq_query::load(Config &cfg, YAML::Node drtv_node
return Handle(new self_type(cfg.localize(arg), std::move(expr)));
}

#if 0
class Do_remap_query : public Directive, QueryDirective {
using self_type = Do_remap_query;
using super_type = Directive;
Expand Down Expand Up @@ -1861,8 +1870,7 @@ Errata Do_remap_query::invoke(Context &ctx) {
// ctx._remap_status = TSREMAP_DID_REMAP;
return this->QueryDirective::invoke(ctx, _expr, ts::URL(ctx._remap_info->requestBufp, ctx._remap_info->requestUrl), _arg);
}
/* ------------------------------------------------------------------------------------ */

#endif
/* ------------------------------------------------------------------------------------ */
/// Set the cache key.
class Do_cache_key : public Directive {
Expand Down Expand Up @@ -2299,10 +2307,10 @@ namespace {
Config::define<Do_proxy_req_path>();
Config::define<Do_proxy_req_scheme>();

Config::define(Do_remap_host::KEY, Do_remap_host::HOOKS, Do_remap_host::load);
Config::define(Do_remap_path::KEY, Do_remap_path::HOOKS, Do_remap_path::load);
Config::define<Do_remap_scheme>();
Config::define(Do_remap_query::KEY, Do_remap_query::HOOKS, Do_remap_query::load);
// Config::define(Do_remap_host::KEY, Do_remap_host::HOOKS, Do_remap_host::load);
// Config::define(Do_remap_path::KEY, Do_remap_path::HOOKS, Do_remap_path::load);
// Config::define<Do_remap_scheme>();
// Config::define(Do_remap_query::KEY, Do_remap_query::HOOKS, Do_remap_query::load);
Config::define(Do_apply_remap_rule::KEY, Do_apply_remap_rule::HOOKS, Do_apply_remap_rule::load);

Config::define(Do_upstream_rsp_field::KEY, Do_upstream_rsp_field::HOOKS, Do_upstream_rsp_field::load);
Expand Down
111 changes: 68 additions & 43 deletions test/autest/gold_tests/autest-site/txn_box.test.ext
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,24 @@ Implement txn_box extensions for Traffic Server.
import os.path
import types

def TxnBoxTestRun(self, text, replay_path, config_key="meta.txn_box",
config_path=None, remap=None):
def TxnBoxTest(self, replay_path, config_path=None, config_key="meta.txn_box", remap=None):
"""
Set up a standard test run for TxnBox
Create a base test object specialized for TxnBox testing.

Args:
text: (str) Description for test run.
replay_path: (str) Path to the replay file.
config_path: (str) Path to the global configuration file for txn_box.so. If omitted only
remap configuration is done. If it's 'Auto' then the replay path is used.
config_key: (str) The --key parameter to pass into txn_box.so in the
plugin.config file.
config_path: (str) The --config parameter to pass into txn_box.so in the
plugin.config file.
remap: [(from, to, [pparams])] Allows the specification of a
set of remap config lines. If pparams is provided, then
@plugin=txn_box.so is set and the set of pparams are placed in.
if to is missing, it is set equal to from yielding an identity remap.
Keywords
replay_path: (str) The replay file.
"""

run = self.AddTestRun(text)

ts = self.MakeATSProcess("ts")
run.Variables.TS = ts
pv_client = run.AddVerifierClientProcess(
"pv-client", ts, replay_path,
http_ports=[ts.Variables.port])
run.Variables.CLIENT = pv_client

pv_server = run.AddVerifierServerProcess("pv-server", replay_path)
run.Variables.SERVER = pv_server
self.Variables.TXNBOX_TS = ts
self.Variables.TXNBOX_REPLAY_PATH = replay_path

# Put the txn_box.so into the sandbox.
plugin_dir = ts.Env['PROXY_CONFIG_PLUGIN_PLUGIN_DIR']
Expand All @@ -49,64 +36,102 @@ def TxnBoxTestRun(self, text, replay_path, config_key="meta.txn_box",
txn_box_lib = os.path.join(git_root, "lib", "txn_box.so")
ts.Setup.Copy(txn_box_lib, plugin_dir, CopyLogic.SoftFiles)

# Configure txn_box in Traffic Server.
txn_box_command = 'txn_box.so'
# Configure txn_box in Traffic Server if there's a config. Otherwise assume it's remap only.
if config_path == 'Auto':
config_path = replay_path

if config_key:
txn_box_command += ' --key {}'.format(config_key)
if config_path:
txn_box_command = 'txn_box.so'

if config_path is None:
config_path = replay_path
if config_key:
txn_box_command += ' --key {}'.format(config_key)

ts.Setup.Copy(config_path, ts.Variables.CONFIGDIR)
txn_box_command += ' {}'.format(os.path.basename(config_path))
ts.Setup.Copy(config_path, ts.Variables.CONFIGDIR)
txn_box_command += ' {}'.format(os.path.basename(config_path))

ts.Disk.plugin_config.AddLine(txn_box_command)
ts.Disk.plugin_config.AddLine(txn_box_command)

# Configure Traffic Server to use the DNS process.
dns = self.MakeDNServer("dns", ip='127.0.0.1', default=['127.0.0.1'])
self.Variables.TXNBOX_DNS = self.MakeDNServer("dns", ip='127.0.0.1', default=['127.0.0.1'])

self.Variables.TXNBOX_SERVER = self.MakeVerifierServerProcess("pv-server", replay_path)

ts.Disk.records_config.update({
'proxy.config.dns.nameservers': '127.0.0.1:{0}'.format(dns.Variables.Port),
'proxy.config.dns.nameservers': '127.0.0.1:{0}'.format(self.Variables.TXNBOX_DNS.Variables.Port),
'proxy.config.dns.resolv_conf': 'NULL',
# The following is needed for ATS 9 and later.
# 'proxy.config.plugin.dynamic_reload': 0
})

if remap:
for remap_config in remap:
pparams = None
map_from = remap_config[0]
if len(remap_config) == 1:
map_to = map_from
map_to = map_from
elif len(remap_config) == 2:
if isinstance(remap_config[1], str):
map_to = remap_config[1]
else:
pparams = remap_config[1]
if isinstance(remap_config[1], str):
map_to = remap_config[1]
else:
pparams = remap_config[1]
elif len(remap_config) == 3:
map_to = remap_config[1]
pparams = remap_config[2]
map_to = remap_config[1]
pparams = remap_config[2]
else:
raise ValueError("remap entries must be either "
"(from, to) or (from, to, [pparams])")
raise ValueError("remap entries must be either "
"(from, to) or (from, to, [pparams])")

line = 'map {map_from} {map_to}:{server_port} '.format(
map_from=map_from, map_to=map_to, server_port=pv_server.Variables.http_port)
map_from=map_from, map_to=map_to, server_port=self.Variables.TXNBOX_SERVER.Variables.http_port)
if pparams:
line += '@plugin=txn_box.so '
for pparam in pparams:
line += '@pparam={} '.format(pparam)
ts.Disk.remap_config.AddLine(line)

# Always add this as a catch all at the end
ts.Disk.remap_config.AddLine('map / http://127.0.0.1:{0}'.format(pv_server.Variables.http_port))
ts.Disk.remap_config.AddLine('map / http://127.0.0.1:{0}'.format(self.Variables.TXNBOX_SERVER.Variables.http_port))

return self


def TxnBoxRun(self, text, replay_path=None):
"""
Set up a standard test run for TxnBox

Args:
text: (str) Description for test run.
replay_path: (str) Path to the replay file. Defaults to the path used for TxnBoxTest.
Keywords
replay_path: (str) The replay file.
"""

if replay_path == None:
replay_path = self.Variables.TXNBOX_REPLAY_PATH

run = self.AddTestRun(text)
ts = run.Variables.TS = self.Variables.TXNBOX_TS

pv_client = run.AddVerifierClientProcess(
"pv-client", ts, replay_path,
http_ports=[ts.Variables.port])
run.Variables.CLIENT = pv_client

pv_server = self.Variables.TXNBOX_SERVER
run.Variables.SERVER = pv_server

pv_client.StartBefore(pv_server)
run.Processes.Default.StartBefore(pv_server)
run.Processes.Default.StartBefore(self.Variables.TXNBOX_DNS)
run.Processes.Default.StartBefore(ts, ready=When.PortOpen(ts.Variables.port))
run.Processes.Default.StartBefore(dns)
run.Processes.Default.StartBefore(self.Variables.TXNBOX_DNS)

return run

def TxnBoxTestAndRun(self, name, replay_path, config_path=None, config_key="meta.txn_box", remap=None):
self.TxnBoxTest(replay_path, config_path, config_key, remap)
return self.TxnBoxRun(name)

ExtendTest(TxnBoxTestRun, name="TxnBoxTestRun")
ExtendTest(TxnBoxTest, name="TxnBoxTest")
ExtendTest(TxnBoxRun, name="TxnBoxRun")
ExtendTest(TxnBoxTestAndRun, name="TxnBoxTestAndRun")
7 changes: 4 additions & 3 deletions test/autest/gold_tests/ct_header/ct_header.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
Test.Summary = '''
Verify txn_box can filter fields as expected.
'''
r = Test.TxnBoxTestRun("Test HTTP field manipulation", "ct_header.replay.yaml"
, config_key="meta.txn_box"
, remap=[ [ "http://example.one/" ]
r = Test.TxnBoxTestAndRun("Test HTTP field manipulation", "ct_header.replay.yaml"
, config_path='Auto'
, config_key="meta.txn_box"
, remap=[ [ "http://example.one/" ]
, [ "http://s.protected.com" ]
])
Loading

0 comments on commit 6938183

Please sign in to comment.