def parse_task(self, task_id, task_args=None, task_args_file=None): """parses the task file and return an context and scenario instances""" LOG.info("Parsing task config: %s", self.path) cfg, rendered = self._render_task(task_args, task_args_file) self._check_schema(cfg["schema"], "task") meet_precondition = self._check_precondition(cfg) # TODO: support one or many contexts? Many would simpler and precise # TODO: support hybrid context type if "context" in cfg: context_cfgs = [cfg["context"]] elif "contexts" in cfg: context_cfgs = cfg["contexts"] else: context_cfgs = [{"type": "Dummy"}] contexts = [] for cfg_attrs in context_cfgs: cfg_attrs['task_id'] = task_id # default to Heat context because we are testing OpenStack context_type = cfg_attrs.get("type", "Heat") context = Context.get(context_type) context.init(cfg_attrs) # Update the name in case the context has used the name_suffix cfg_attrs['name'] = context.name contexts.append(context) run_in_parallel = cfg.get("run_in_parallel", False) # add tc and task id for influxdb extended tags for scenario in cfg["scenarios"]: task_name = os.path.splitext(os.path.basename(self.path))[0] scenario["tc"] = task_name scenario["task_id"] = task_id # embed task path into scenario so we can load other files # relative to task path scenario["task_path"] = os.path.dirname(self.path) self._change_node_names(scenario, contexts) # TODO we need something better here, a class that represent the file return { 'scenarios': cfg['scenarios'], 'run_in_parallel': run_in_parallel, 'meet_precondition': meet_precondition, 'contexts': contexts, 'rendered': rendered }
def parse_task(self, task_id, task_args=None, task_args_file=None): """parses the task file and return an context and scenario instances""" print("Parsing task config:", self.path) try: kw = {} if task_args_file: with open(task_args_file) as f: kw.update(parse_task_args("task_args_file", f.read())) kw.update(parse_task_args("task_args", task_args)) except TypeError: raise TypeError() try: with open(self.path) as f: try: input_task = f.read() rendered_task = TaskTemplate.render(input_task, **kw) except Exception as e: print("Failed to render template:\n%(task)s\n%(err)s\n" % { "task": input_task, "err": e }) raise e print("Input task is:\n%s\n" % rendered_task) cfg = yaml_load(rendered_task) except IOError as ioerror: sys.exit(ioerror) self._check_schema(cfg["schema"], "task") meet_precondition = self._check_precondition(cfg) # TODO: support one or many contexts? Many would simpler and precise # TODO: support hybrid context type if "context" in cfg: context_cfgs = [cfg["context"]] elif "contexts" in cfg: context_cfgs = cfg["contexts"] else: context_cfgs = [{"type": "Dummy"}] contexts = [] name_suffix = '-{}'.format(task_id[:8]) for cfg_attrs in context_cfgs: try: cfg_attrs['name'] = '{}{}'.format(cfg_attrs['name'], name_suffix) except KeyError: pass # default to Heat context because we are testing OpenStack context_type = cfg_attrs.get("type", "Heat") context = Context.get(context_type) context.init(cfg_attrs) contexts.append(context) run_in_parallel = cfg.get("run_in_parallel", False) # add tc and task id for influxdb extended tags for scenario in cfg["scenarios"]: task_name = os.path.splitext(os.path.basename(self.path))[0] scenario["tc"] = task_name scenario["task_id"] = task_id # embed task path into scenario so we can load other files # relative to task path scenario["task_path"] = os.path.dirname(self.path) change_server_name(scenario, name_suffix) try: for node in scenario['nodes']: scenario['nodes'][node] += name_suffix except KeyError: pass # TODO we need something better here, a class that represent the file return cfg["scenarios"], run_in_parallel, meet_precondition, contexts
def parse_task(self, task_args=None, task_args_file=None): '''parses the task file and return an context and scenario instances''' print "Parsing task config:", self.path try: kw = {} if task_args_file: with open(task_args_file) as f: kw.update(parse_task_args("task_args_file", f.read())) kw.update(parse_task_args("task_args", task_args)) except TypeError: raise TypeError() try: with open(self.path) as f: try: input_task = f.read() rendered_task = TaskTemplate.render(input_task, **kw) except Exception as e: print(("Failed to render template:\n%(task)s\n%(err)s\n") % {"task": input_task, "err": e}) raise e print(("Input task is:\n%s\n") % rendered_task) cfg = yaml.load(rendered_task) except IOError as ioerror: sys.exit(ioerror) self._check_schema(cfg["schema"], "task") meet_precondition = self._check_precondition(cfg) # TODO: support one or many contexts? Many would simpler and precise # TODO: support hybrid context type if "context" in cfg: context_cfgs = [cfg["context"]] elif "contexts" in cfg: context_cfgs = cfg["contexts"] else: context_cfgs = [{"type": "Dummy"}] for cfg_attrs in context_cfgs: context_type = cfg_attrs.get("type", "Heat") if "Heat" == context_type and "networks" in cfg_attrs: # bugfix: if there are more than one network, # only add "external_network" on first one. # the name of netwrok should follow this rule: # test, test2, test3 ... # sort network with the length of network's name sorted_networks = sorted(cfg_attrs["networks"].keys()) # config external_network based on env var cfg_attrs["networks"][sorted_networks[0]]["external_network"] \ = os.environ.get("EXTERNAL_NETWORK", "net04_ext") context = Context.get(context_type) context.init(cfg_attrs) run_in_parallel = cfg.get("run_in_parallel", False) # add tc and task id for influxdb extended tags task_id = str(uuid.uuid4()) for scenario in cfg["scenarios"]: task_name = os.path.splitext(os.path.basename(self.path))[0] scenario["tc"] = task_name scenario["task_id"] = task_id # TODO we need something better here, a class that represent the file return cfg["scenarios"], run_in_parallel, meet_precondition
def parse_task(self, task_args=None, task_args_file=None): '''parses the task file and return an context and scenario instances''' print "Parsing task config:", self.path try: kw = {} if task_args_file: with open(task_args_file) as f: kw.update(parse_task_args("task_args_file", f.read())) kw.update(parse_task_args("task_args", task_args)) except TypeError: raise TypeError() try: with open(self.path) as f: try: input_task = f.read() rendered_task = TaskTemplate.render(input_task, **kw) except Exception as e: print(("Failed to render template:\n%(task)s\n%(err)s\n") % { "task": input_task, "err": e }) raise e print(("Input task is:\n%s\n") % rendered_task) cfg = yaml.load(rendered_task) except IOError as ioerror: sys.exit(ioerror) self._check_schema(cfg["schema"], "task") meet_precondition = self._check_precondition(cfg) # TODO: support one or many contexts? Many would simpler and precise # TODO: support hybrid context type if "context" in cfg: context_cfgs = [cfg["context"]] elif "contexts" in cfg: context_cfgs = cfg["contexts"] else: context_cfgs = [{"type": "Dummy"}] for cfg_attrs in context_cfgs: context_type = cfg_attrs.get("type", "Heat") if "Heat" == context_type and "networks" in cfg_attrs: # bugfix: if there are more than one network, # only add "external_network" on first one. # the name of netwrok should follow this rule: # test, test2, test3 ... # sort network with the length of network's name sorted_networks = sorted(cfg_attrs["networks"].keys()) # config external_network based on env var cfg_attrs["networks"][sorted_networks[0]]["external_network"] \ = os.environ.get("EXTERNAL_NETWORK", "net04_ext") context = Context.get(context_type) context.init(cfg_attrs) run_in_parallel = cfg.get("run_in_parallel", False) # add tc and task id for influxdb extended tags task_id = str(uuid.uuid4()) for scenario in cfg["scenarios"]: task_name = os.path.splitext(os.path.basename(self.path))[0] scenario["tc"] = task_name scenario["task_id"] = task_id # TODO we need something better here, a class that represent the file return cfg["scenarios"], run_in_parallel, meet_precondition