Example #1
0
 def __init__(self,
              server_endpoint,
              agent_ids=None,
              polling_interval=1,
              agent_loss_timeout=60,
              agent_join_timeout=600):
     self.quorum = quorum.make_quorum(agent_ids or [], server_endpoint,
                                      polling_interval, agent_loss_timeout,
                                      agent_join_timeout)
Example #2
0
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
Example #3
0
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
Example #4
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
Example #5
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
Example #6
0
 def __init__(self, server_endpoint, agent_ids=None, polling_interval=1,
              agent_loss_timeout=60, agent_join_timeout=600):
     self.quorum = quorum.make_quorum(
         agent_ids or [], server_endpoint, polling_interval,
         agent_loss_timeout, agent_join_timeout)
Example #7
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