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)