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) agents = deployment.deploy(scenario['deployment'], base_dir=os.path.dirname(cfg.CONF.scenario)) agents = _extend_agents(agents) output['agents'] = agents LOG.debug('Deployed agents: %s', agents) if not agents: LOG.warning('No agents deployed.') else: message_queue = messaging.MessageQueue(cfg.CONF.server_endpoint) heartbeat = multiprocessing.Process( target=agent_process.work, kwargs=dict(agent_id='heartbeat', endpoint=cfg.CONF.server_endpoint, polling_interval=cfg.CONF.polling_interval)) heartbeat.daemon = True heartbeat.start() quorum = quorum_pkg.Quorum(message_queue, cfg.CONF.polling_interval, cfg.CONF.agent_loss_timeout, cfg.CONF.agent_join_timeout) quorum.join(set(agents.keys())) execution_result = execute(quorum, scenario['execution'], agents) for record in execution_result: record['scenario'] = (scenario.get('title') or scenario.get('file_name')) output['records'] = execution_result except BaseException as e: if isinstance(e, KeyboardInterrupt): LOG.info('Caught SIGINT. Terminating') else: error_msg = 'Error while executing scenario: %s' % e LOG.error(error_msg) LOG.exception(e) output['scenario']['error'] = error_msg finally: if deployment: deployment.cleanup() return output
def __init__(self, server_endpoint, agent_ids, polling_interval=1, agent_loss_timeout=60, agent_join_timeout=600): message_queue = messaging.MessageQueue(server_endpoint) self.quorum = quorum.Quorum(message_queue, polling_interval, agent_loss_timeout, agent_join_timeout) self.quorum.join(agent_ids)
def make_quorum(agent_ids, server_endpoint, polling_interval, agent_loss_timeout, agent_join_timeout): message_queue = messaging.MessageQueue(server_endpoint) heartbeat = multiprocessing.Process( target=agent_process.work, kwargs=dict(agent_id=HEARTBEAT_AGENT, endpoint=server_endpoint, polling_interval=polling_interval, ignore_sigint=True)) heartbeat.daemon = True heartbeat.start() quorum = Quorum(message_queue, polling_interval, agent_loss_timeout, agent_join_timeout) result = quorum.join(set(agent_ids)) failed = dict((agent_id, rec['status']) for agent_id, rec in result.items() if rec['status'] != 'ok') if failed: raise Exception('Agents failed to join: %s' % failed) return quorum
def act(): outputs = [] message_queue = None if 'server_endpoint' in cfg.CONF: message_queue = messaging.MessageQueue(cfg.CONF.server_endpoint) artifacts_dir = cfg.CONF.artifacts_dir if artifacts_dir: utils.mkdir_tree(artifacts_dir) for scenario_name in cfg.CONF.scenario: LOG.info('Play scenario: %s', scenario_name) scenario = read_scenario(scenario_name) play_output = play_scenario(message_queue, scenario) outputs.append(copy.deepcopy(play_output)) # if requested make separate reports if artifacts_dir: prefix = utils.strict(scenario_name) report_name_fn = functools.partial(utils.join_folder_prefix_ext, artifacts_dir, prefix) utils.write_file(json.dumps(play_output, indent=2), report_name_fn('json')) report.generate_report(play_output, cfg.CONF.report_template, report_name_fn('html'), report_name_fn('subunit'), report_name_fn()) LOG.info('Generating aggregated report') aggregated = utils.merge_dicts(outputs) utils.write_file(json.dumps(aggregated, indent=2), cfg.CONF.output) LOG.info('Raw output is stored to: %s', cfg.CONF.output) report.generate_report(aggregated, cfg.CONF.report_template, cfg.CONF.report, cfg.CONF.subunit, cfg.CONF.book)