Пример #1
0
    def test_convert_tasks_unsupported_attributes(self):
        converter = WorkflowConverter()
        expr_converter = YaqlExpressionConverter()

        with self.assertRaises(NotImplementedError):
            mistral_tasks = self._create_task(('keep-result', True))
            converter.convert_tasks(mistral_tasks, expr_converter, set())

        with self.assertRaises(NotImplementedError):
            mistral_tasks = self._create_task(('pause-before', True))
            converter.convert_tasks(mistral_tasks, expr_converter, set())

        with self.assertRaises(NotImplementedError):
            mistral_tasks = self._create_task(('safe-rerun', True))
            converter.convert_tasks(mistral_tasks, expr_converter, set())

        with self.assertRaises(NotImplementedError):
            mistral_tasks = self._create_task(('target', 'some-node'))
            converter.convert_tasks(mistral_tasks, expr_converter, set())

        with self.assertRaises(NotImplementedError):
            mistral_tasks = self._create_task(('timeout', 60))
            converter.convert_tasks(mistral_tasks, expr_converter, set())

        with self.assertRaises(NotImplementedError):
            mistral_tasks = self._create_task(('wait-after', 60))
            converter.convert_tasks(mistral_tasks, expr_converter, set())

        with self.assertRaises(NotImplementedError):
            mistral_tasks = self._create_task(('wait-before', 60))
            converter.convert_tasks(mistral_tasks, expr_converter, set())

        with self.assertRaises(NotImplementedError):
            mistral_tasks = self._create_task(('workflow', 'someworkflowname'))
            converter.convert_tasks(mistral_tasks, expr_converter, set())
Пример #2
0
 def test_convert_tasks_yaql(self):
     converter = WorkflowConverter()
     expr_converter = YaqlExpressionConverter()
     mistral_tasks = OrderedMap([('jinja_task',
                                  OrderedMap([
                                      ('action', 'mypack.actionname'),
                                      ('input',
                                       OrderedMap([
                                           ('cmd', '<% $.test %>'),
                                       ])),
                                      ('on-success', ['next_task']),
                                  ]))])
     result = converter.convert_tasks(mistral_tasks, expr_converter, set())
     self.assertEqual(
         result,
         OrderedMap([('jinja_task',
                      OrderedMap([
                          ('action', 'mypack.actionname'),
                          ('input',
                           OrderedMap([
                               ('cmd', '<% ctx().test %>'),
                           ])),
                          ('next', [
                              OrderedMap([('when', '<% succeeded() %>'),
                                          ('do', [
                                              'next_task',
                                          ])]),
                          ]),
                      ]))]))
Пример #3
0
 def test_convert_tasks_join(self):
     converter = WorkflowConverter()
     expr_converter = YaqlExpressionConverter()
     mistral_tasks = OrderedMap([('jinja_task',
                                  OrderedMap([
                                      ('action', 'mypack.actionname'),
                                      ('join', 'all'),
                                  ]))])
     result = converter.convert_tasks(mistral_tasks, expr_converter, set())
     self.assertEqual(
         result,
         OrderedMap([('jinja_task',
                      OrderedMap([
                          ('action', 'mypack.actionname'),
                          ('join', 'all'),
                      ]))]))
Пример #4
0
 def expr_type_converter(self, expr_type):
     if expr_type is None:
         expr_converter = JinjaExpressionConverter()
     elif isinstance(expr_type, six.string_types):
         expr_type = expr_type.lower()
         if expr_type == 'jinja':
             expr_converter = JinjaExpressionConverter()
         elif expr_type == 'yaql':
             expr_converter = YaqlExpressionConverter()
         else:
             raise TypeError("Unknown expression type: {}".format(expr_type))
     elif isinstance(expr_type, BaseExpressionConverter):
         expr_converter = expr_type
     else:
         raise TypeError("Unknown expression class type: {}".format(type(expr_type)))
     return expr_converter
Пример #5
0
    def test_convert_task_transition_simple_yaql(self):
        converter = WorkflowConverter()
        transitions = ['a', 'b', 'c']
        publish = OrderedMap([('key_plain', 'data'),
                              ('key_expr', '{{ _.test }}')])
        orquesta_expr = 'succeeded()'
        expr_converter = YaqlExpressionConverter()

        result = converter.convert_task_transition_simple(
            transitions, publish, orquesta_expr, expr_converter)

        # note: only the orquesta_expr is converted using YAQL, the expressions
        #       in the rest are converted independently because they may each
        #       be a different type
        expected = OrderedMap([
            ('when', '<% succeeded() %>'),
            ('publish', [{
                'key_plain': 'data'
            }, {
                'key_expr': '{{ ctx().test }}'
            }]),
            ('do', ['a', 'b', 'c']),
        ])
        self.assertEqual(result, expected)
Пример #6
0
 def test_convert_expression_yaql_context_vars_with_underscore(self):
     expr = "<% $.test_.other %>"
     result = YaqlExpressionConverter.convert_string(expr)
     self.assertEqual(result, "<% ctx().test_.other %>")
Пример #7
0
 def test_convert_expression_yaql_context_vars_multiple(self):
     expr = "<% $.test + $.other %>"
     result = YaqlExpressionConverter.convert_string(expr)
     self.assertEqual(result, "<% ctx().test + ctx().other %>")
Пример #8
0
 def test_convert_expression_yaql_complex_function_context_vars(self):
     expr = "<% zip([0, 1, 2], [3, 4, 5], $.all_the_things) %>"
     result = YaqlExpressionConverter.convert_string(expr)
     self.assertEqual(
         result, "<% zip([0, 1, 2], [3, 4, 5], ctx().all_the_things) %>")
Пример #9
0
 def test_convert_expression_yaql_function_context_vars(self):
     expr = "<% list(range(0, $.count)) %>"
     result = YaqlExpressionConverter.convert_string(expr)
     self.assertEqual(result, "<% list(range(0, ctx().count)) %>")
Пример #10
0
 def test_convert_expression_yaql_st2_api_url(self):
     expr = '<% env().st2_action_api_url %>'
     result = YaqlExpressionConverter.convert_string(expr)
     self.assertEqual(result, "<% ctx().st2.api_url %>")
Пример #11
0
 def test_unwrap_expression(self):
     expr = "<% $.test %>"
     result = YaqlExpressionConverter.unwrap_expression(expr)
     self.assertEqual(result, "$.test")
Пример #12
0
 def test_convert_expression_yaql_task_result(self):
     expr = "<% task(abc).result.result %>"
     result = YaqlExpressionConverter.convert_string(expr)
     self.assertEquals(result, "<% result().result %>")
Пример #13
0
 def test_convert_expression_yaql_context_vars(self):
     expr = "<% $.test %>"
     result = YaqlExpressionConverter.convert_string(expr)
     self.assertEquals(result, "<% ctx().test %>")
Пример #14
0
 def test_expr_type_converter_class_yaql(self):
     expr_type = YaqlExpressionConverter()
     converter = WorkflowConverter()
     result = converter.expr_type_converter(expr_type)
     self.assertIs(result, expr_type)
Пример #15
0
 def test_convert_expression_yaql_task_result_single_quote(self):
     expr = "<% task('abc').result.result %>"
     result = YaqlExpressionConverter.convert_string(expr)
     self.assertEqual(result, "<% result().result %>")
Пример #16
0
 def test_convert_expression_yaql_task_result_double_quotes(self):
     expr = '<% task("abc").result.double_quote %>'
     result = YaqlExpressionConverter.convert_string(expr)
     self.assertEqual(result, "<% result().double_quote %>")
Пример #17
0
 def test_unwrap_expression_nested(self):
     expr = "<% $.test <% abc %> %>"
     result = YaqlExpressionConverter.unwrap_expression(expr)
     self.assertEqual(result, "$.test <% abc %>")
Пример #18
0
 def test_convert_expression_yaql_st2kv_user(self):
     expr = '<% st2kv.user.test.kv %>'
     result = YaqlExpressionConverter.convert_string(expr)
     self.assertEqual(result, "<% st2kv('user.test.kv') %>")
Пример #19
0
 def test_convert_expression_yaql_item_vars(self):
     expr = "<% $.test %>"
     result = YaqlExpressionConverter.convert_string(expr,
                                                     item_vars=['test'])
     self.assertEqual(result, "<% item(test) %>")
Пример #20
0
 def test_convert_expression_yaql_context_and_item_vars(self):
     expr = "<% $.test + $.test2 - $.long_var %>"
     result = YaqlExpressionConverter.convert_string(expr,
                                                     item_vars=['test'])
     self.assertEqual(result,
                      "<% item(test) + ctx().test2 - ctx().long_var %>")
Пример #21
0
 def test_convert_expression_yaql_st2_execution_id(self):
     expr = '<% env().st2_execution_id %>'
     result = YaqlExpressionConverter.convert_string(expr)
     self.assertEquals(result, "<% ctx().st2.action_execution_id %>")