예제 #1
0
파일: server.py 프로젝트: esboych/shaker
def play_scenario(scenario):
    deployment = None
    output = dict(scenario=scenario, records={}, agents={})
    output['tests'] = dict((_make_test_title(test), test)
                           for test in scenario['execution']['tests'])

    try:
        deployment = deploy.Deployment(cfg.CONF.server_endpoint)

        if (cfg.CONF.os_username and cfg.CONF.os_password
                and cfg.CONF.os_tenant_name and cfg.CONF.os_auth_url):
            deployment.connect_to_openstack(
                cfg.CONF.os_username, cfg.CONF.os_password,
                cfg.CONF.os_tenant_name, cfg.CONF.os_auth_url,
                cfg.CONF.os_region_name, cfg.CONF.external_net,
                cfg.CONF.flavor_name, cfg.CONF.image_name, cfg.CONF.os_cacert)

        base_dir = os.path.dirname(scenario['file_name'])
        agents = deployment.deploy(scenario['deployment'], base_dir=base_dir)

        agents = _extend_agents(agents)
        output['agents'] = agents
        LOG.debug('Deployed agents: %s', agents)

        if not agents:
            raise Exception('No agents deployed.')

        quorum = quorum_pkg.make_quorum(agents.keys(),
                                        cfg.CONF.server_endpoint,
                                        cfg.CONF.polling_interval,
                                        cfg.CONF.agent_loss_timeout,
                                        cfg.CONF.agent_join_timeout)

        output['records'] = execute(quorum, scenario['execution'], agents)

    except BaseException as e:
        if isinstance(e, KeyboardInterrupt):
            LOG.info('Caught SIGINT. Terminating')
            record = dict(id=utils.make_record_id(), status='interrupted')
        else:
            error_msg = 'Error while executing scenario: %s' % e
            LOG.error(error_msg)
            LOG.exception(e)
            record = dict(id=utils.make_record_id(),
                          status='error',
                          stderr=error_msg)
        output['records'][record['id']] = record
    finally:
        if deployment:
            deployment.cleanup()

    # extend every record with reference to scenario
    for record in output['records'].values():
        record['scenario'] = scenario['title']
    return output
예제 #2
0
파일: server.py 프로젝트: esboych/shaker
def play_scenario(scenario):
    deployment = None
    output = dict(scenario=scenario, records={}, agents={})
    output['tests'] = dict((_make_test_title(test), test)
                           for test in scenario['execution']['tests'])

    try:
        deployment = deploy.Deployment(cfg.CONF.server_endpoint)

        if (cfg.CONF.os_username and cfg.CONF.os_password and
                cfg.CONF.os_tenant_name and cfg.CONF.os_auth_url):
            deployment.connect_to_openstack(
                cfg.CONF.os_username, cfg.CONF.os_password,
                cfg.CONF.os_tenant_name, cfg.CONF.os_auth_url,
                cfg.CONF.os_region_name, cfg.CONF.external_net,
                cfg.CONF.flavor_name, cfg.CONF.image_name,
                cfg.CONF.os_cacert)

        base_dir = os.path.dirname(scenario['file_name'])
        agents = deployment.deploy(scenario['deployment'], base_dir=base_dir)

        agents = _extend_agents(agents)
        output['agents'] = agents
        LOG.debug('Deployed agents: %s', agents)

        if not agents:
            raise Exception('No agents deployed.')

        quorum = quorum_pkg.make_quorum(
            agents.keys(), cfg.CONF.server_endpoint,
            cfg.CONF.polling_interval, cfg.CONF.agent_loss_timeout,
            cfg.CONF.agent_join_timeout)

        output['records'] = execute(quorum, scenario['execution'], agents)

    except BaseException as e:
        if isinstance(e, KeyboardInterrupt):
            LOG.info('Caught SIGINT. Terminating')
            record = dict(id=utils.make_record_id(), status='interrupted')
        else:
            error_msg = 'Error while executing scenario: %s' % e
            LOG.error(error_msg)
            LOG.exception(e)
            record = dict(id=utils.make_record_id(), status='error',
                          stderr=error_msg)
        output['records'][record['id']] = record
    finally:
        if deployment:
            deployment.cleanup()

    # extend every record with reference to scenario
    for record in output['records'].values():
        record['scenario'] = scenario['title']
    return output
예제 #3
0
def run_test(records, quorum, test, agents, progression):

    LOG.debug('Running test %s on all agents', test)
    test_title = test['title']

    for selected_agents in _pick_agents(agents, progression):
        executors = dict((a['id'], executors_classes.get_executor(test, a))
                         for a in selected_agents)

        execution_result = quorum.execute(executors)

        has_interrupted = False
        for agent_id, record in execution_result.items():
            record_id = utils.make_record_id()
            node = agents[agent_id].get('node')
            if node == 'localhost':
                node = test.get('host')

            record.update(dict(
                id=record_id,
                agent=agent_id,
                node=node,
                concurrency=len(selected_agents),
                test=test_title,
                executor=test.get('class'),
                type='agent',
            ))
            records[record_id] = record
            has_interrupted |= record['status'] == 'interrupted'

        if has_interrupted:
            LOG.info('Execution is interrupted')
            return False

    return True
예제 #4
0
def run_test(records, quorum, test, agents, progression):

    LOG.debug('Running test %s on all agents', test)
    test_title = test['title']

    for selected_agents in _pick_agents(agents, progression):
        executors = dict((a['id'], executors_classes.get_executor(test, a))
                         for a in selected_agents)

        execution_result = quorum.execute(executors)

        has_interrupted = False
        for agent_id, record in execution_result.items():
            record_id = utils.make_record_id()
            node = agents[agent_id].get('node')
            if node == 'localhost':
                node = test.get('host')

            record.update(dict(
                id=record_id,
                agent=agent_id,
                node=node,
                concurrency=len(selected_agents),
                test=test_title,
                executor=test.get('class'),
                type='agent',
            ))
            records[record_id] = record
            has_interrupted |= record['status'] == 'interrupted'

        if has_interrupted:
            LOG.info('Execution is interrupted')
            return False

    return True
예제 #5
0
파일: server.py 프로젝트: smalleni/shaker
def execute(quorum, execution, agents):
    records = {}

    for test in execution['tests']:
        LOG.debug('Running test %s on all agents', test)
        test_title = _make_test_title(test)
        progression = execution.get('progression', execution.get('size'))

        for selected_agents in _pick_agents(agents, progression):
            executors = dict((a['id'], executors_classes.get_executor(test, a))
                             for a in selected_agents)

            execution_result = quorum.execute(executors)

            has_interrupted = False
            for agent_id, record in execution_result.items():
                record_id = utils.make_record_id()
                record.update(dict(
                    id=record_id,
                    agent=agent_id,
                    node=agents[agent_id].get('node'),
                    concurrency=len(selected_agents),
                    test=test_title,
                    executor=test.get('class'),
                    type='agent',
                ))
                records[record_id] = record
                has_interrupted |= record['status'] == 'interrupted'

            if has_interrupted:
                LOG.info('Execution is interrupted')
                return records

    LOG.info('Execution is done')
    return records
예제 #6
0
파일: report.py 프로젝트: voron3x/shaker
def calculate_stats(records, tests):
    # scenario -> test -> concurrency -> [record]
    rec_map = collections.defaultdict(
        functools.partial(collections.defaultdict,
                          functools.partial(collections.defaultdict, list)))

    for record in records.values():
        if 'test' not in record:
            continue

        aggregator = aggregators.get_aggregator(tests[record['test']])
        aggregator.record_summary(record)

        rec_map[record['scenario']][record['test']][
            record['concurrency']].append(record)

    for scenario, per_scenario in rec_map.items():
        for test, per_test in per_scenario.items():
            aggregator = aggregators.get_aggregator(tests[test])

            concurrency_aggregates = []
            for concurrency, per_concurrency in per_test.items():
                summary = aggregator.concurrency_summary(per_concurrency)
                if summary:
                    record_id = utils.make_record_id()
                    summary.update(
                        dict(id=record_id,
                             scenario=scenario,
                             test=test,
                             concurrency=concurrency,
                             type='concurrency'))
                    records[record_id] = summary
                    concurrency_aggregates.append(summary)

            per_test_summary = aggregator.test_summary(concurrency_aggregates)
            if per_test_summary:
                record_id = utils.make_record_id()
                per_test_summary.update(
                    dict(id=record_id,
                         scenario=scenario,
                         test=test,
                         type='test'))
                records[record_id] = per_test_summary
예제 #7
0
def calculate_stats(records, tests):
    # scenario -> test -> concurrency -> [record]
    rec_map = collections.defaultdict(
        functools.partial(collections.defaultdict,
                          functools.partial(collections.defaultdict, list)))

    for record in records.values():
        if 'test' not in record:
            continue

        aggregator = aggregators.get_aggregator(tests[record['test']])
        aggregator.record_summary(record)

        rec_map[record['scenario']][record['test']][
            record['concurrency']].append(record)

    for scenario, per_scenario in rec_map.items():
        for test, per_test in per_scenario.items():
            aggregator = aggregators.get_aggregator(tests[test])

            concurrency_aggregates = []
            for concurrency, per_concurrency in per_test.items():
                summary = aggregator.concurrency_summary(per_concurrency)
                if summary:
                    record_id = utils.make_record_id()
                    summary.update(dict(id=record_id,
                                        scenario=scenario, test=test,
                                        concurrency=concurrency,
                                        type='concurrency'))
                    records[record_id] = summary
                    concurrency_aggregates.append(summary)

            per_test_summary = aggregator.test_summary(concurrency_aggregates)
            if per_test_summary:
                record_id = utils.make_record_id()
                per_test_summary.update(dict(id=record_id,
                                             scenario=scenario, test=test,
                                             type='test'))
                records[record_id] = per_test_summary
예제 #8
0
파일: server.py 프로젝트: esboych/shaker
def execute(quorum, execution, agents):
    records = {}

    for test in execution['tests']:
        LOG.debug('Running test %s on all agents', test)
        test_title = _make_test_title(test)
        progression = execution.get('progression', execution.get('size'))

        for selected_agents in _pick_agents(agents, progression):
            executors = dict((a['id'], executors_classes.get_executor(test, a))
                             for a in selected_agents)

            execution_result = quorum.execute(executors)

            has_interrupted = False
            for agent_id, record in execution_result.items():
                record_id = utils.make_record_id()
                record.update(
                    dict(
                        id=record_id,
                        agent=agent_id,
                        node=agents[agent_id].get('node'),
                        concurrency=len(selected_agents),
                        test=test_title,
                        executor=test.get('class'),
                        type='agent',
                    ))
                records[record_id] = record
                has_interrupted |= record['status'] == 'interrupted'

            if has_interrupted:
                LOG.info('Execution is interrupted')
                return records

    LOG.info('Execution is done')
    return records
예제 #9
0
def play_scenario(message_queue, scenario):
    deployment = None
    output = dict(scenarios={}, records={}, agents={}, tests={})
    output['scenarios'][scenario['title']] = scenario

    try:
        deployment = deploy.Deployment()

        if _under_openstack():
            openstack_params = utils.pack_openstack_params(cfg.CONF)
            try:
                deployment.connect_to_openstack(openstack_params,
                                                cfg.CONF.flavor_name,
                                                cfg.CONF.image_name,
                                                cfg.CONF.external_net,
                                                cfg.CONF.dns_nameservers)
            except openstack_clients.OpenStackClientException:
                raise
            except Exception as e:
                LOG.warning(
                    'Failed to connect to OpenStack: %s. Please '
                    'verify parameters: %s', e, openstack_params)
                # try to proceed even if OpenStack connection fails
                # (in case scenario does not need it)

        base_dir = os.path.dirname(scenario['file_name'])
        scenario_deployment = scenario.get('deployment', {})
        server_endpoint = (cfg.CONF.server_endpoint
                           if 'server_endpoint' in cfg.CONF else None)

        agents = deployment.deploy(scenario_deployment,
                                   base_dir=base_dir,
                                   server_endpoint=server_endpoint)

        agents = _extend_agents(agents)
        output['agents'] = agents
        LOG.debug('Deployed agents: %s', agents)

        if not agents:
            raise Exception('No agents deployed.')

        if scenario_deployment:
            quorum = quorum_pkg.make_quorum(agents.keys(), message_queue,
                                            cfg.CONF.polling_interval,
                                            cfg.CONF.agent_loss_timeout,
                                            cfg.CONF.agent_join_timeout)
        else:
            # local
            quorum = quorum_pkg.make_local_quorum()

        matrix = cfg.CONF.matrix if 'matrix' in cfg.CONF else None
        if matrix:
            scenario['matrix'] = matrix

        execute(output, quorum, scenario['execution'], agents, matrix)

    except BaseException as e:
        if isinstance(e, KeyboardInterrupt):
            LOG.info('Caught SIGINT. Terminating')
            record = dict(id=utils.make_record_id(), status='interrupted')
        else:
            error_msg = 'Error while executing scenario: %s' % e
            LOG.exception(e)
            record = dict(id=utils.make_record_id(),
                          status='error',
                          stderr=error_msg)
        output['records'][record['id']] = record
    finally:
        if deployment:
            try:
                deployment.cleanup()
            except Exception as e:
                LOG.error('Failed to cleanup the deployment: %s',
                          e,
                          exc_info=True)

    # extend every record with reference to scenario
    for record in output['records'].values():
        record['scenario'] = scenario['title']
    return output
예제 #10
0
def play_scenario(scenario):
    deployment = None
    output = dict(scenario=scenario, records={}, agents={}, tests={})

    try:
        deployment = deploy.Deployment()

        if _under_openstack():
            deployment.connect_to_openstack(
                cfg.CONF.os_username, cfg.CONF.os_password,
                cfg.CONF.os_tenant_name, cfg.CONF.os_auth_url,
                cfg.CONF.os_region_name, cfg.CONF.external_net,
                cfg.CONF.flavor_name, cfg.CONF.image_name,
                cfg.CONF.os_cacert, cfg.CONF.os_insecure)

        base_dir = os.path.dirname(scenario['file_name'])
        scenario_deployment = scenario.get('deployment', {})
        server_endpoint = (cfg.CONF.server_endpoint
                           if 'server_endpoint' in cfg.CONF else None)

        agents = deployment.deploy(scenario_deployment, base_dir=base_dir,
                                   server_endpoint=server_endpoint)

        agents = _extend_agents(agents)
        output['agents'] = agents
        LOG.debug('Deployed agents: %s', agents)

        if not agents:
            raise Exception('No agents deployed.')

        if scenario_deployment:
            quorum = quorum_pkg.make_quorum(
                agents.keys(), server_endpoint,
                cfg.CONF.polling_interval, cfg.CONF.agent_loss_timeout,
                cfg.CONF.agent_join_timeout)
        else:
            # local
            quorum = quorum_pkg.make_local_quorum()

        matrix = cfg.CONF.matrix if 'matrix' in cfg.CONF else None
        if matrix:
            scenario['matrix'] = matrix

        execute(output, quorum, scenario['execution'], agents, matrix)

    except BaseException as e:
        if isinstance(e, KeyboardInterrupt):
            LOG.info('Caught SIGINT. Terminating')
            record = dict(id=utils.make_record_id(), status='interrupted')
        else:
            error_msg = 'Error while executing scenario: %s' % e
            LOG.error(error_msg)
            LOG.exception(e)
            record = dict(id=utils.make_record_id(), status='error',
                          stderr=error_msg)
        output['records'][record['id']] = record
    finally:
        if deployment:
            try:
                deployment.cleanup()
            except Exception as e:
                LOG.error('Failed to cleanup the deployment: %s', e,
                          exc_info=True)

    # extend every record with reference to scenario
    for record in output['records'].values():
        record['scenario'] = scenario['title']
    return output
예제 #11
0
def play_scenario(scenario):
    deployment = None
    output = dict(scenario=scenario, records={}, agents={}, tests={})

    try:
        deployment = deploy.Deployment()

        if _under_openstack():
            deployment.connect_to_openstack(
                cfg.CONF.os_username, cfg.CONF.os_password,
                cfg.CONF.os_tenant_name, cfg.CONF.os_auth_url,
                cfg.CONF.os_region_name, cfg.CONF.external_net,
                cfg.CONF.flavor_name, cfg.CONF.image_name, cfg.CONF.os_cacert,
                cfg.CONF.os_insecure)

        base_dir = os.path.dirname(scenario['file_name'])
        scenario_deployment = scenario.get('deployment', {})
        server_endpoint = (cfg.CONF.server_endpoint
                           if 'server_endpoint' in cfg.CONF else None)

        agents = deployment.deploy(scenario_deployment,
                                   base_dir=base_dir,
                                   server_endpoint=server_endpoint)

        agents = _extend_agents(agents)
        output['agents'] = agents
        LOG.debug('Deployed agents: %s', agents)

        if not agents:
            raise Exception('No agents deployed.')

        if scenario_deployment:
            quorum = quorum_pkg.make_quorum(agents.keys(), server_endpoint,
                                            cfg.CONF.polling_interval,
                                            cfg.CONF.agent_loss_timeout,
                                            cfg.CONF.agent_join_timeout)
        else:
            # local
            quorum = quorum_pkg.make_local_quorum()

        matrix = cfg.CONF.matrix if 'matrix' in cfg.CONF else None
        if matrix:
            scenario['matrix'] = matrix

        execute(output, quorum, scenario['execution'], agents, matrix)

    except BaseException as e:
        if isinstance(e, KeyboardInterrupt):
            LOG.info('Caught SIGINT. Terminating')
            record = dict(id=utils.make_record_id(), status='interrupted')
        else:
            error_msg = 'Error while executing scenario: %s' % e
            LOG.error(error_msg)
            LOG.exception(e)
            record = dict(id=utils.make_record_id(),
                          status='error',
                          stderr=error_msg)
        output['records'][record['id']] = record
    finally:
        if deployment:
            try:
                deployment.cleanup()
            except Exception as e:
                LOG.error('Failed to cleanup the deployment: %s',
                          e,
                          exc_info=True)

    # extend every record with reference to scenario
    for record in output['records'].values():
        record['scenario'] = scenario['title']
    return output