def read_scenario(scenario_name): alias_base = scenario_name if alias_base[:11] == 'networking/': # backward compatibility LOG.warning('Scenarios from networking/ are moved to openstack/') alias_base = 'openstack/' + alias_base[11:] alias = '%s%s.yaml' % (config.SCENARIOS, alias_base) packaged = utils.resolve_relative_path(alias) # use packaged scenario or fallback to full path scenario_file_name = packaged or scenario_name LOG.debug('Scenario %s is resolved to %s', scenario_name, scenario_file_name) scenario = utils.read_yaml_file(scenario_file_name) schema = utils.read_yaml_file( utils.resolve_relative_path('%s%s.yaml' % (config.SCHEMAS, 'scenario'))) utils.validate_yaml(scenario, schema) scenario['title'] = scenario.get('title') or scenario_file_name scenario['file_name'] = scenario_file_name return scenario
def test_scenario_schema_conformance(self): scenario_schema_file = 'shaker/resources/schemas/scenario.yaml' for file_name in self._iterate_files('shaker/scenarios/'): source_data = utils.read_yaml_file(file_name) schema_data = utils.read_yaml_file(scenario_schema_file) try: utils.validate_yaml(source_data, schema_data) except Exception as e: self.fail('Scenario %s does not conform to schema: %s' % (file_name, e))
def test_scenario_schema_conformance(self): scenario_schema_file = 'shaker/resources/schemas/scenario.yaml' for file_name in self._iterate_files('shaker/scenarios/'): source_data = utils.read_yaml_file(file_name) schema_data = utils.read_yaml_file(scenario_schema_file) try: utils.validate_yaml(source_data, schema_data) except Exception as e: self.fail('Scenario %s does not conform to schema: %s' % (file_name, e))
def act(): output = dict(records={}, agents={}, scenarios={}, tests={}) for scenario_param in [cfg.CONF.scenario]: LOG.debug('Processing scenario: %s', scenario_param) alias_base = scenario_param if alias_base[:11] == 'networking/': # backward compatibility LOG.warning('Scenarios from networking/ are moved to openstack/') alias_base = 'openstack/' + alias_base[11:] alias = '%s%s.yaml' % (config.SCENARIOS, alias_base) packaged = utils.resolve_relative_path(alias) # use packaged scenario or fallback to full path scenario_file_name = packaged or scenario_param LOG.info('Play scenario: %s', scenario_file_name) scenario = utils.read_yaml_file(scenario_file_name) schema = utils.read_yaml_file(utils.resolve_relative_path( '%s%s.yaml' % (config.SCHEMAS, 'scenario'))) utils.validate_yaml(scenario, schema) scenario['title'] = scenario.get('title') or scenario_file_name scenario['file_name'] = scenario_file_name play_output = play_scenario(scenario) output['scenarios'][scenario['title']] = play_output['scenario'] output['records'].update(play_output['records']) output['agents'].update(play_output['agents']) output['tests'].update(play_output['tests']) output_path = "" if cfg.CONF.output: output_path = cfg.CONF.output else: tmp_dir = tempfile.gettempdir() tmp_report = "shaker_%s.json" % str( datetime.datetime.now()).replace(' ', '_') output_path = os.path.join(tmp_dir, tmp_report) utils.write_file(json.dumps(output, indent=2), output_path) if cfg.CONF.no_report_on_error and 'error' in output: LOG.info('Skipped report generation due to errors and ' 'no_report_on_error=True') else: report.generate_report(output, cfg.CONF.report_template, cfg.CONF.report, cfg.CONF.subunit, cfg.CONF.book)
def main(): utils.init_config_and_logging( config.COMMON_OPTS + config.OPENSTACK_OPTS + config.SERVER_OPTS + config.REPORT_OPTS ) output = dict(records=[], agents={}, scenarios={}, tests={}) for scenario_file_name in [cfg.CONF.scenario]: scenario = utils.read_yaml_file(scenario_file_name) scenario['title'] = scenario.get('title') or scenario_file_name scenario['file_name'] = cfg.CONF.scenario play_output = play_scenario(scenario) output['scenarios'][scenario['title']] = play_output['scenario'] output['records'] += play_output['records'] output['agents'].update(play_output['agents']) output['tests'].update(play_output['tests']) if cfg.CONF.output: utils.write_file(json.dumps(output, indent=2), cfg.CONF.output) if cfg.CONF.no_report_on_error and 'error' in output: LOG.info('Skipped report generation due to errors and ' 'no_report_on_error=True') else: report.generate_report(output, cfg.CONF.report_template, cfg.CONF.report, cfg.CONF.subunit)
def act(): output = dict(records={}, agents={}, scenarios={}, tests={}) for scenario_param in [cfg.CONF.scenario]: LOG.debug('Processing scenario: %s', scenario_param) alias = '%s%s.yaml' % (config.SCENARIOS, scenario_param) packaged = utils.resolve_relative_path(alias) # use packaged scenario or fallback to full path scenario_file_name = packaged or scenario_param LOG.info('Play scenario: %s', scenario_file_name) scenario = utils.read_yaml_file(scenario_file_name) scenario['title'] = scenario.get('title') or scenario_file_name scenario['file_name'] = scenario_file_name play_output = play_scenario(scenario) output['scenarios'][scenario['title']] = play_output['scenario'] output['records'].update(play_output['records']) output['agents'].update(play_output['agents']) output['tests'].update(play_output['tests']) if cfg.CONF.output: utils.write_file(json.dumps(output, indent=2), cfg.CONF.output) if cfg.CONF.no_report_on_error and 'error' in output: LOG.info('Skipped report generation due to errors and ' 'no_report_on_error=True') else: report.generate_report(output, cfg.CONF.report_template, cfg.CONF.report, cfg.CONF.subunit, cfg.CONF.book)
def main(): utils.init_config_and_logging(config.COMMON_OPTS + config.OPENSTACK_OPTS + config.SERVER_OPTS + config.REPORT_OPTS) output = dict(records={}, agents={}, scenarios={}, tests={}) for scenario_param in [cfg.CONF.scenario]: LOG.debug('Processing scenario: %s', scenario_param) alias = '%s%s.yaml' % (config.SCENARIOS, scenario_param) packaged = utils.resolve_relative_path(alias) # use packaged scenario or fallback to full path scenario_file_name = packaged or scenario_param LOG.info('Play scenario: %s', scenario_file_name) scenario = utils.read_yaml_file(scenario_file_name) scenario['title'] = scenario.get('title') or scenario_file_name scenario['file_name'] = scenario_file_name play_output = play_scenario(scenario) output['scenarios'][scenario['title']] = play_output['scenario'] output['records'].update(play_output['records']) output['agents'].update(play_output['agents']) output['tests'].update(play_output['tests']) if cfg.CONF.output: utils.write_file(json.dumps(output, indent=2), cfg.CONF.output) if cfg.CONF.no_report_on_error and 'error' in output: LOG.info('Skipped report generation due to errors and ' 'no_report_on_error=True') else: report.generate_report(output, cfg.CONF.report_template, cfg.CONF.report, cfg.CONF.subunit)
def main(): utils.init_config_and_logging(config.COMMON_OPTS + config.OPENSTACK_OPTS + config.SERVER_OPTS + config.REPORT_OPTS) output = dict(records=[], agents={}, scenarios={}, tests={}) for scenario_file_name in [cfg.CONF.scenario]: scenario = utils.read_yaml_file(scenario_file_name) scenario['title'] = scenario.get('title') or scenario_file_name scenario['file_name'] = cfg.CONF.scenario play_output = play_scenario(scenario) output['scenarios'][scenario['title']] = play_output['scenario'] output['records'] += play_output['records'] output['agents'].update(play_output['agents']) output['tests'].update(play_output['tests']) if cfg.CONF.output: utils.write_file(json.dumps(output, indent=2), cfg.CONF.output) if cfg.CONF.no_report_on_error and 'error' in output: LOG.info('Skipped report generation due to errors and ' 'no_report_on_error=True') else: report.generate_report(output, cfg.CONF.report_template, cfg.CONF.report, cfg.CONF.subunit)
def test_deploy_from_hot_with_env_file(self, nova_nodes_mock, openstack_mock, create_stack_mock, stack_output_mock): test_file = 'shaker/scenarios/test/sample_with_env.yaml' absolute_path = utils.resolve_relative_path(test_file) scenario = utils.read_yaml_file(absolute_path) stack_name = 'shaker_abcdefg' server_endpoint = "127.0.0.01" base_dir = os.path.dirname(absolute_path) deployment = deploy.Deployment() deployment.stack_name = stack_name deployment.external_net = 'test-external_net' deployment.image_name = 'test-image' deployment.flavor_name = 'test-flavor' deployment.dns_nameservers = '8.8.8.8' deployment.openstack_client = openstack_mock # read the env file to determine what cidr is set to # minus the last digit env_file = utils.read_file(scenario['deployment']['env_file'], base_dir) cidr = re.findall(r'[0-9]+(?:\.[0-9]+){2}', env_file)[0] nova_nodes_mock.return_value = [{'host': 'host-1', 'zone': 'nova'}] create_stack_mock.return_value = uuid.uuid4() heat_outputs = { stack_name + '_master_0_instance_name': 'instance-0000052f', stack_name + '_master_0_ip': '192.0.0.3', stack_name + '_slave_0_ip': '192.0.0.4', stack_name + '_slave_0_instance_name': 'instance-0000052c'} stack_output_mock.return_value = heat_outputs expected = { 'shaker_abcdefg_master_0': {'availability_zone': 'nova:host-1', 'id': 'shaker_abcdefg_master_0', 'ip': cidr + '.3', 'mode': 'master', 'node': 'host-1', 'slave_id': 'shaker_abcdefg_slave_0', 'zone': 'nova'}, 'shaker_abcdefg_slave_0': {'availability_zone': 'nova:host-1', 'id': 'shaker_abcdefg_slave_0', 'ip': cidr + '.4', 'master_id': 'shaker_abcdefg_master_0', 'mode': 'slave', 'node': 'host-1', 'zone': 'nova'}} agents = deployment._deploy_from_hot(scenario['deployment'], server_endpoint, base_dir=base_dir) self.assertEqual(expected, agents)
def act(): output = dict(records={}, agents={}, scenarios={}, tests={}) for scenario_param in [cfg.CONF.scenario]: LOG.debug('Processing scenario: %s', scenario_param) alias_base = scenario_param if alias_base[:11] == 'networking/': # backward compatibility LOG.warning('Scenarios from networking/ are moved to openstack/') alias_base = 'openstack/' + alias_base[11:] alias = '%s%s.yaml' % (config.SCENARIOS, alias_base) packaged = utils.resolve_relative_path(alias) # use packaged scenario or fallback to full path scenario_file_name = packaged or scenario_param LOG.info('Play scenario: %s', scenario_file_name) scenario = utils.read_yaml_file(scenario_file_name) schema = utils.read_yaml_file( utils.resolve_relative_path('%s%s.yaml' % (config.SCHEMAS, 'scenario'))) utils.validate_yaml(scenario, schema) scenario['title'] = scenario.get('title') or scenario_file_name scenario['file_name'] = scenario_file_name play_output = play_scenario(scenario) output['scenarios'][scenario['title']] = play_output['scenario'] output['records'].update(play_output['records']) output['agents'].update(play_output['agents']) output['tests'].update(play_output['tests']) if cfg.CONF.output: utils.write_file(json.dumps(output, indent=2), cfg.CONF.output) if cfg.CONF.no_report_on_error and 'error' in output: LOG.info('Skipped report generation due to errors and ' 'no_report_on_error=True') else: report.generate_report(output, cfg.CONF.report_template, cfg.CONF.report, cfg.CONF.subunit, cfg.CONF.book)
def test_deploy_from_hot_with_support_stacks(self, nova_nodes_mock, openstack_mock, create_stack_mock, stack_output_mock): test_file = 'shaker/scenarios/test/sample_with_support_stacks.yaml' absolute_path = utils.resolve_relative_path(test_file) scenario = utils.read_yaml_file(absolute_path) stack_name = 'shaker_abcdefg' server_endpoint = "127.0.0.01" base_dir = os.path.dirname(absolute_path) deployment = deploy.Deployment() deployment.stack_name = stack_name deployment.external_net = 'test-external_net' deployment.image_name = 'test-image' deployment.flavor_name = 'test-flavor' deployment.dns_nameservers = '8.8.8.8' deployment.openstack_client = openstack_mock nova_nodes_mock.return_value = [{'host': 'host-1', 'zone': 'nova'}] create_stack_mock.return_value = uuid.uuid4() heat_outputs = { stack_name + '_master_0_instance_name': 'instance-0000052f', stack_name + '_master_0_ip': '10.0.0.3', stack_name + '_slave_0_ip': '10.0.0.4', stack_name + '_slave_0_instance_name': 'instance-0000052c'} stack_output_mock.return_value = heat_outputs expected = { 'shaker_abcdefg_master_0': {'availability_zone': 'nova:host-1', 'id': 'shaker_abcdefg_master_0', 'ip': '10.0.0.3', 'mode': 'master', 'node': 'host-1', 'slave_id': 'shaker_abcdefg_slave_0', 'zone': 'nova'}, 'shaker_abcdefg_slave_0': {'availability_zone': 'nova:host-1', 'id': 'shaker_abcdefg_slave_0', 'ip': '10.0.0.4', 'master_id': 'shaker_abcdefg_master_0', 'mode': 'slave', 'node': 'host-1', 'zone': 'nova'}} agents = deployment._deploy_from_hot(scenario['deployment'], server_endpoint, base_dir=base_dir) self.assertEqual(create_stack_mock.call_count, 3) self.assertEqual(expected, agents)
def test_deploy_support_stacks(self, openstack_mock, create_stack_mock): test_file = 'shaker/scenarios/test/sample_with_support_stacks.yaml' absolute_path = utils.resolve_relative_path(test_file) scenario = utils.read_yaml_file(absolute_path) support_stacks = scenario['deployment']['support_templates'] base_dir = os.path.dirname(absolute_path) deployment = deploy.Deployment() deployment.stack_name = 'shaker_abcdefg' deployment.openstack_client = openstack_mock support_stack_1 = uuid.uuid4() support_stack_2 = uuid.uuid4() create_stack_mock.side_effect = (support_stack_1, support_stack_2) deployment._deploy_support_stacks(support_stacks, base_dir) self.assertEqual(support_stack_1, deployment.support_stacks[0].id) self.assertEqual(support_stack_2, deployment.support_stacks[1].id)