From: Douglas Bagnall Date: Fri, 19 Oct 2018 03:18:39 +0000 (+1300) Subject: traffic_replay: drop summary replay X-Git-Tag: tdb-1.3.17~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79e8459817246a80918dca73b109549475e128fc;p=thirdparty%2Fsamba.git traffic_replay: drop summary replay The traffic_replay script has been able to replay a replay log as well as a model, which was not used in practice and complicated the script. If we want that feature, we can make a new script for it. Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/blackbox/traffic_replay.py b/python/samba/tests/blackbox/traffic_replay.py index cea9be057b9..015db2ed39b 100644 --- a/python/samba/tests/blackbox/traffic_replay.py +++ b/python/samba/tests/blackbox/traffic_replay.py @@ -30,7 +30,6 @@ SERVER = os.environ["SERVER"] 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") @@ -58,36 +57,10 @@ class TrafficLearnerTests(BlackboxTestCase): """ 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 """ @@ -101,6 +74,5 @@ class TrafficLearnerTests(BlackboxTestCase): """ 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) diff --git a/script/traffic_replay b/script/traffic_replay index 5adeec101de..d3f1c14d4f4 100755 --- a/script/traffic_replay +++ b/script/traffic_replay @@ -40,13 +40,12 @@ def print_err(*args, **kwargs): def main(): - desc = ("Generates network traffic 'conversations' based on " - " (which should be the output file produced by either traffic_learner" - " or traffic_summary.pl). This traffic is sent to ," + desc = ("Generates network traffic 'conversations' based on a model generated" + " by script/traffic_learner. This traffic is sent to ," " which is the full DNS hostname of the DC being tested.") parser = optparse.OptionParser( - "%prog [--help|options] ", + "%prog [--help|options] ", description=desc) parser.add_option('--dns-rate', type='float', default=0, @@ -76,9 +75,7 @@ def main(): 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') @@ -131,10 +128,10 @@ def main(): # 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 @@ -158,14 +155,14 @@ def main(): 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: @@ -241,33 +238,17 @@ def main(): 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 " @@ -276,6 +257,11 @@ def main(): 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 = []