PASSWORD = os.environ["PASSWORD"]
USER = os.environ["USERNAME"]
STD_OPTIONS = "-U%s%%%s %s" % (USER, PASSWORD, SERVER)
-SUMMARY = os.path.join(DATA_DIR, "traffic-sample-very-short.txt")
EXPECTED_NAME = os.path.join(DATA_DIR, "traffic_replay.expected")
"""
options = ("--generate-users-only --number-of-users 20 "
"--number-of-groups 5 --average-groups-per-user 2")
- command = "%s %s %s %s %s" % (
- SCRIPT, SUMMARY, options, FIXED, STD_OPTIONS)
+ command = "%s %s %s %s" % (
+ SCRIPT, options, FIXED, STD_OPTIONS)
self.check_run(command)
- def test_summary_generation(self):
- """Ensure a summary file is generated and the contents are correct"""
-
- with temp_file(self.tempdir) as output:
- options = "--traffic-summary %s " % (output)
- command = "%s %s %s %s %s" % (
- SCRIPT, SUMMARY, options, FIXED, STD_OPTIONS)
- self.check_run(command)
- expected = (open(EXPECTED_NAME).readlines())
- actual = open(output).readlines()
- self.assertEquals(expected, actual)
-
- def test_summary_replay(self):
- """Ensure a summary file can be replayed against a DC
- """
-
- command = "%s %s %s %s" % (SCRIPT, SUMMARY, FIXED, STD_OPTIONS)
- self.check_run(command)
-
- def test_summary_replay_no_fixed(self):
- """Ensure a summary file with no fixed password fails
- """
-
- command = "%s %s %s" % (SCRIPT, SUMMARY, STD_OPTIONS)
- self.check_exit_code(command, 1)
-
def test_model_replay(self):
"""Ensure a model can be replayed against a DC
"""
"""
options = ("--generate-users-only --number-of-users 20 "
"--number-of-groups 5 --average-groups-per-user 2")
- summary = "testdata/traffic-sample-very-short.txt"
- command = "%s %s %s %s" % (SCRIPT, summary, options, STD_OPTIONS)
+ command = "%s %s %s" % (SCRIPT, options, STD_OPTIONS)
self.check_exit_code(command, 1)
def main():
- desc = ("Generates network traffic 'conversations' based on <summary-file>"
- " (which should be the output file produced by either traffic_learner"
- " or traffic_summary.pl). This traffic is sent to <dns-hostname>,"
+ desc = ("Generates network traffic 'conversations' based on a model generated"
+ " by script/traffic_learner. This traffic is sent to <dns-hostname>,"
" which is the full DNS hostname of the DC being tested.")
parser = optparse.OptionParser(
- "%prog [--help|options] <summary-file> <dns-hostname>",
+ "%prog [--help|options] <model-file> <dns-hostname>",
description=desc)
parser.add_option('--dns-rate', type='float', default=0,
model_group = optparse.OptionGroup(parser, 'Traffic Model Options',
'These options alter the traffic '
- 'generated when the summary-file is a '
- 'traffic-model (produced by '
- 'traffic_learner)')
+ 'generated by the model')
model_group.add_option('-S', '--scale-traffic', type='float', default=1.0,
help='Increase the number of conversations by '
'this factor')
# First ensure we have reasonable arguments
if len(args) == 1:
- summary = None
+ model_file = None
host = args[0]
elif len(args) == 2:
- summary, host = args
+ model_file, host = args
else:
parser.print_usage()
return
traffic.clean_up_accounts(ldb, opts.instance_id)
exit(0)
- if summary:
- if not os.path.exists(summary):
- logger.error("Summary file %s doesn't exist" % summary)
+ if model_file:
+ if not os.path.exists(model_file):
+ logger.error("Model file %s doesn't exist" % model_file)
sys.exit(1)
- # the summary-file can be ommitted for --generate-users-only and
+ # the model-file can be ommitted for --generate-users-only and
# --cleanup-up, but it should be specified in all other cases
elif not opts.generate_users_only:
- logger.error("No summary-file specified to replay traffic from")
+ logger.error("No model file specified to replay traffic from")
sys.exit(1)
if not opts.fixed_password:
if duration is None:
duration = 60.0
- # ingest the model or traffic summary
- if summary:
+ # ingest the model
+ if model_file:
try:
- conversations, interval, duration, dns_counts = \
- traffic.ingest_summaries([summary])
-
- logger.info(("Using conversations from the traffic summary "
- "file specified"))
-
- # honour the specified duration if it's different to the
- # capture duration
- if opts.duration is not None:
- duration = opts.duration
-
- except ValueError as e:
- if not str(e).startswith('need more than'):
- raise
-
model = traffic.TrafficModel()
try:
- model.load(summary)
+ model.load(model_file)
except ValueError:
- logger.error(("Could not parse %s. The summary file "
- "should be the output from either the "
- "traffic_summary.pl or "
- "traffic_learner scripts.") % summary)
+ logger.error(("Could not parse %s. The model file "
+ "should be generated by the "
+ "traffic_learner script.") % model_file)
sys.exit()
logger.info(("Using the specified model file to "
conversations = model.generate_conversations(opts.scale_traffic,
duration,
opts.replay_rate)
+ except ValueError:
+ logger.error(("Could not parse %s, which does not seem to be "
+ "a model generated by script/traffic_learner."
+ % model_file))
+ sys.exit(1)
else:
conversations = []