def test_can_write_to_file(self): tst = BenchConfiguration(test_name="test_name", title="test title", description="test description", duration=30, startup_delay=0.01, cycle_time=1, sleep_time=0.01, sleep_time_min=0, sleep_time_max=0.5) temp_path = mkdtemp() conf_path = join(temp_path, 'test.conf') tst.save(conf_path) with open(conf_path) as conf_file: config = conf_file.read() expect(config).to_be_like(""" [main] title=test title description=test description [bench] duration = 30 startup_delay = 0.01 cycle_time = 1 sleep_time = 0.01 sleep_time_min = 0.00 sleep_time_max = 0.50 [test_name] description=test description """)
def test_generate_conf_with_workers_key(self, executable_mock): bench = BenchConfiguration('test', 'test', 'test', workers=[ { "host": "ma-amazing-host", "user": "******", "ssh_key": "/path/my.pem", }, ]) with NamedTemporaryFile() as temp_file: bench.save(temp_file.name) expect(temp_file.read()).to_be_like(''' [main] title=test description=test [bench] duration=10 startup_delay = 0.01 cycle_time = 1 sleep_time = 0.01 sleep_time_min = 0.00 sleep_time_max = 0.50 [test] description=test [distribute] channel_timeout = 300 log_path = python_bin = /bin/python funkload_location=https://github.com/nuxeo/FunkLoad/archive/master.zip [workers] hosts = worker_0 [worker_0] host = ma-amazing-host username = user ssh_key = /path/my.pem ''')
def test_can_write_to_file(self): tst = BenchConfiguration( test_name="test_name", title="test title", description="test description", duration=30, startup_delay=0.01, cycle_time=1, sleep_time=0.01, sleep_time_min=0, sleep_time_max=0.5 ) temp_path = mkdtemp() conf_path = join(temp_path, 'test.conf') tst.save(conf_path) with open(conf_path) as conf_file: config = conf_file.read() expect(config).to_be_like(""" [main] title=test title description=test description [bench] duration = 30 startup_delay = 0.01 cycle_time = 1 sleep_time = 0.01 sleep_time_min = 0.00 sleep_time_max = 0.50 [test_name] description=test description """)
def run(cls, root_path, test, base_url, workers=[], cycles=DEFAULT_CYCLES, duration=10): logging.debug("run bench") assert isinstance(test, TestConfig), "The test argument must be of type wight.worker.config.TestConfig" # fl-run-bench --distribute --distribute-workers=localhost -u http://www.something.com -c 10:20:30:40:50 -D 30 --simple-fetch geo.py GeoTests.test_geo arguments = [test.module, "%s.%s" % (test.class_name, test.test_name)] keyword_arguments = dict( # keyword arguments u=base_url, simple_fetch=True, c=":".join([str(cycle) for cycle in cycles[test.pressure]]), feedback_endpoint=join(root_path, "%s_%s" % (test.class_name, test.test_name)), # sh.py options _env={ "PYTHONPATH": "$PYTHONPATH:%s:%s" % (join(root_path.rstrip("/")), join(root_path.rstrip("/"), "bench")) }, _cwd=join(root_path, "bench"), _tty_in=True, _tty_out=True, ) logging.debug("creating arguments: %s" % str(keyword_arguments)) if workers: keyword_arguments["distribute"] = True if test.deps: keyword_arguments["distributed-packages"] = " ".join(['"%s"' % package for package in test.deps]) logging.debug("save config") cfg = BenchConfiguration( test_name=test.test_name, title=test.title, description=test.description, duration=duration, log_path=root_path, workers=workers, ) cfg.calculate_timeout(len(cycles[test.pressure])) cfg.save(join(root_path, "bench", "%s.conf" % test.class_name)) logging.debug("config saved") try: logging.debug("running bench") result = fl_run_bench(*arguments, **keyword_arguments) logging.debug("bench run") except ErrorReturnCode: err = sys.exc_info()[1] logging.error("run bench error: %s" % err) return FunkLoadTestRunResult(1, err.stderr + err.stdout, log=err.stderr, result=None, config=None) try: with open(join(root_path, "bench", "funkload.log")) as fl_log: logging.debug("readind log") log = fl_log.read() xml_path = join(root_path, "bench", "funkload.xml") if workers: logging.debug("merge resulting") MergeResultFiles( [join(root_path, "worker_%s-funkload.xml" % index) for index in range(len(workers))], xml_path ) parser = FunkLoadXmlParser(1.5) logging.debug("parse xml") parser.parse(xml_path) return FunkLoadTestRunResult( result.exit_code, result.stdout + result.stderr, log=log, result=parser.stats, config=parser.config ) except Exception: err = sys.exc_info()[1] logging.error("Parse error: %s" % err) return FunkLoadTestRunResult( 1, "Result STDOUT: %s\nResult STDERR: %s\nResult Parsing Error: %s" % (result.stdout, result.stderr, str(err)), log=None, result=None, config=None, )
def run(cls, root_path, test, base_url, workers=[], cycles=DEFAULT_CYCLES, duration=10): logging.debug("run bench") assert isinstance( test, TestConfig ), "The test argument must be of type wight.worker.config.TestConfig" #fl-run-bench --distribute --distribute-workers=localhost -u http://www.something.com -c 10:20:30:40:50 -D 30 --simple-fetch geo.py GeoTests.test_geo arguments = [test.module, "%s.%s" % (test.class_name, test.test_name)] keyword_arguments = dict( # keyword arguments u=base_url, simple_fetch=True, c=":".join([str(cycle) for cycle in cycles[test.pressure]]), feedback_endpoint=join(root_path, "%s_%s" % (test.class_name, test.test_name)), # sh.py options _env={ "PYTHONPATH": '$PYTHONPATH:%s:%s' % (join(root_path.rstrip('/')), join(root_path.rstrip('/'), "bench")) }, _cwd=join(root_path, 'bench'), _tty_in=True, _tty_out=True) logging.debug("creating arguments: %s" % str(keyword_arguments)) if workers: keyword_arguments["distribute"] = True if test.deps: keyword_arguments["distributed-packages"] = ' '.join( ['"%s"' % package for package in test.deps]) logging.debug("save config") cfg = BenchConfiguration(test_name=test.test_name, title=test.title, description=test.description, duration=duration, log_path=root_path, workers=workers) cfg.calculate_timeout(len(cycles[test.pressure])) cfg.save(join(root_path, 'bench', '%s.conf' % test.class_name)) logging.debug("config saved") try: logging.debug("running bench") result = fl_run_bench(*arguments, **keyword_arguments) logging.debug("bench run") except ErrorReturnCode: err = sys.exc_info()[1] logging.error("run bench error: %s" % err) return FunkLoadTestRunResult(1, err.stderr + err.stdout, log=err.stderr, result=None, config=None) try: with open(join(root_path, 'bench', 'funkload.log')) as fl_log: logging.debug("readind log") log = fl_log.read() xml_path = join(root_path, 'bench', 'funkload.xml') if workers: logging.debug("merge resulting") MergeResultFiles([ join(root_path, 'worker_%s-funkload.xml' % index) for index in range(len(workers)) ], xml_path) parser = FunkLoadXmlParser(1.5) logging.debug("parse xml") parser.parse(xml_path) return FunkLoadTestRunResult(result.exit_code, result.stdout + result.stderr, log=log, result=parser.stats, config=parser.config) except Exception: err = sys.exc_info()[1] logging.error("Parse error: %s" % err) return FunkLoadTestRunResult( 1, "Result STDOUT: %s\nResult STDERR: %s\nResult Parsing Error: %s" % (result.stdout, result.stderr, str(err)), log=None, result=None, config=None)