コード例 #1
0
ファイル: test_bench_config.py プロジェクト: movermeyer/wight
    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
            """)
コード例 #2
0
    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
''')
コード例 #3
0
    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
''')
コード例 #4
0
ファイル: test_bench_config.py プロジェクト: heynemann/wight
    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
            """)
コード例 #5
0
ファイル: test_bench_config.py プロジェクト: movermeyer/wight
    def test_can_create_bench_config(self):
        tst = BenchConfiguration(test_name="test_name",
                                 title="test title",
                                 description="test description",
                                 startup_delay=0.01,
                                 cycle_time=1,
                                 sleep_time=0.01,
                                 sleep_time_min=0,
                                 sleep_time_max=0.5)

        expect(tst).not_to_be_null()

        expect(tst.test_name).to_equal("test_name")
        expect(tst.title).to_equal("test title")
        expect(tst.description).to_equal("test description")

        expect(tst.startup_delay).to_equal(0.01)
        expect(tst.cycle_time).to_equal(1)
        expect(tst.sleep_time).to_equal(0.01)
        expect(tst.sleep_time_min).to_equal(0)
        expect(tst.sleep_time_max).to_equal(0.5)
コード例 #6
0
ファイル: runners.py プロジェクト: heynemann/wight
    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,
            )
コード例 #7
0
ファイル: runners.py プロジェクト: movermeyer/wight
    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)