예제 #1
0
def generate_workflow_job_template_nodes(workflow_job_template, persisted,
                                         **kwargs):

    workflow_job_template_nodes = kwargs.get('workflow_job_template_nodes', [])
    if len(workflow_job_template_nodes) > 0 and not persisted:
        raise RuntimeError(
            'workflow job template nodes cannot be used when persisted=False')

    new_nodes = []

    for i, node in enumerate(workflow_job_template_nodes):
        new_node = WorkflowJobTemplateNode(
            workflow_job_template=workflow_job_template,
            unified_job_template=node['unified_job_template'],
            id=i)
        if persisted:
            new_node.save()
        new_nodes.append(new_node)

    node_types = ['success_nodes', 'failure_nodes', 'always_nodes']
    for node_type in node_types:
        for i, new_node in enumerate(new_nodes):
            if node_type not in workflow_job_template_nodes[i]:
                continue
            for related_index in workflow_job_template_nodes[i][node_type]:
                getattr(new_node, node_type).add(new_nodes[related_index])
예제 #2
0
 def WFJT_serializer(self):
     serializer = WorkflowJobTemplateNodeSerializer()
     node = WorkflowJobTemplateNode(pk=1)
     node.char_prompts = {'limit': 'webservers'}
     serializer.instance = node
     view = FakeView(node)
     view.request = FakeRequest()
     view.request.method = "PATCH"
     serializer.context = {'view': view}
     return serializer
예제 #3
0
def mk_workflow_job_template_node(
    workflow_job_template=None, unified_job_template=None, success_nodes=None, failure_nodes=None, always_nodes=None, persisted=True
):
    workflow_node = WorkflowJobTemplateNode(
        workflow_job_template=workflow_job_template,
        unified_job_template=unified_job_template,
        success_nodes=success_nodes,
        failure_nodes=failure_nodes,
        always_nodes=always_nodes,
    )
    if persisted:
        workflow_node.save()
    return workflow_node
예제 #4
0
 def test_use_db_answer(self, jt, mocker):
     serializer = WorkflowJobTemplateNodeSerializer()
     wfjt = WorkflowJobTemplate(name='fake-wfjt')
     serializer.instance = WorkflowJobTemplateNode(workflow_job_template=wfjt, unified_job_template=jt, extra_data={'var1': '$encrypted$foooooo'})
     with mocker.patch('awx.main.models.mixins.decrypt_value', return_value='foo'):
         attrs = serializer.validate({'unified_job_template': jt, 'workflow_job_template': wfjt, 'extra_data': {'var1': '$encrypted$'}})
     assert 'survey_passwords' in attrs
     assert 'var1' in attrs['survey_passwords']
     assert attrs['extra_data']['var1'] == '$encrypted$foooooo'
예제 #5
0
 def test_set_survey_passwords_modify(self, jt):
     serializer = WorkflowJobTemplateNodeSerializer()
     wfjt = WorkflowJobTemplate(name='fake-wfjt')
     serializer.instance = WorkflowJobTemplateNode(workflow_job_template=wfjt, unified_job_template=jt)
     attrs = serializer.validate({'unified_job_template': jt, 'workflow_job_template': wfjt, 'extra_data': {'var1': 'secret_answer'}})
     assert 'survey_passwords' in attrs
     assert 'var1' in attrs['survey_passwords']
     assert attrs['extra_data']['var1'].startswith('$encrypted$')
     assert len(attrs['extra_data']['var1']) > len('$encrypted$')
 def workflow_job_template_node(self):
     return WorkflowJobTemplateNode(pk=1)
 def workflow_job_template_node_related(self, job_template):
     return WorkflowJobTemplateNode(pk=1, unified_job_template=job_template)