def test_convert_list_nested_list(self): expr = ["{{ _.a }}", [ "<% $.a %>", ]] result = ExpressionConverter.convert_list(expr) self.assertEqual(result, ["{{ ctx().a }}", [ "<% ctx().a %>", ]])
def test_convert_list_nested_dict(self): expr = [{ "nested_jinja": "{{ _.a }}", "nested_yaql": "<% $.a %>", }] result = ExpressionConverter.convert_list(expr) self.assertEqual(result, [{ "nested_jinja": "{{ ctx().a }}", "nested_yaql": "<% ctx().a %>", }])
def test_convert_list(self): expr = [ "{{ _.test_jinja }}", "<% $.test_yaql %>", ] result = ExpressionConverter.convert_list(expr) self.assertEqual(result, [ "{{ ctx().test_jinja }}", "<% ctx().test_yaql %>", ])
def convert(self, mistral_wf, expr_type=None, force=False): variables_used_in_output = set() expr_converter = self.expr_type_converter(expr_type) orquesta_wf = ruamel.yaml.comments.CommentedMap() orquesta_wf['version'] = '1.0' if force: for attr in WORKFLOW_UNSUPPORTED_ATTRIBUTES: val = mistral_wf.get(attr) if val: orquesta_wf[attr] = val else: for attr in WORKFLOW_UNSUPPORTED_ATTRIBUTES: if attr in mistral_wf: raise NotImplementedError(("Workflow contains an attribute '{}' that is not" " supported in orquesta.").format(attr)) if mistral_wf.get('description'): orquesta_wf['description'] = mistral_wf['description'] if mistral_wf.get('type'): if mistral_wf['type'] not in WORKFLOW_TYPES: raise NotImplementedError(("Workflows of type '{}' are NOT supported." " Only 'direct' workflows can be converted"). format(mistral_wf['type'])) if mistral_wf.get('input'): orquesta_wf['input'] = ExpressionConverter.convert_list(mistral_wf['input']) if mistral_wf.get('vars'): expression_vars = ExpressionConverter.convert_dict(mistral_wf['vars']) orquesta_wf['vars'] = self.dict_to_list(expression_vars) if mistral_wf.get('output'): output = ExpressionConverter.convert_dict(mistral_wf['output']) orquesta_wf['output'] = self.dict_to_list(output) variables_used_in_output = self.extract_context_variables(output) if mistral_wf.get('tasks'): o_tasks = self.convert_tasks( mistral_wf['tasks'], expr_converter, variables_used_in_output, force=force) if o_tasks: orquesta_wf['tasks'] = o_tasks return orquesta_wf