Exemple #1
0
def test_graph_to_tasks_exit_status_2():
    graph = {
        "tasks": [{
            "requires": ["a"],
            "taskId": "b",
            "task": {
                "payload": {
                    'onExitStatus': {
                        'retry': [2, 3, 45]
                    }
                },
                "provisionerId": "aws-provisioner-v1"
            }
        }]
    }
    expected = OrderedDict([('b', {
        'dependencies': ['a'],
        'payload': {
            'onExitStatus': {
                'retry': [2, 3, 45]
            }
        },
        'provisionerId': 'aws-provisioner-v1'
    })])
    assert graph_to_tasks(graph) == expected
Exemple #2
0
def test_graph_to_tasks_no_requires():
    graph = {
        "tasks": [{
            "taskId": "b",
            "task": {
                "payload": {},
                "provisionerId": "m"
            }
        }]
    }
    expected = OrderedDict([('b', {'payload': {}, 'provisionerId': 'm'})])
    assert graph_to_tasks(graph) == expected
Exemple #3
0
def test_graph_to_tasks():
    graph = {
        "tasks": [{
            "requires": ["a"],
            "taskId": "b",
            "task": {
                "payload": {},
                "provisionerId": "m"
            }
        }]
    }
    expected = OrderedDict([('b', {
        'dependencies': ['a'],
        'payload': {},
        'provisionerId': 'm'
    })])
    assert graph_to_tasks(graph) == expected
Exemple #4
0
def make_tasks(public_key,
               signing_pvt_key,
               product,
               root_home_dir,
               root_template="release_graph.yml.tmpl",
               template_dir=DEFAULT_TEMPLATE_DIR,
               **template_kwargs):
    graph = make_task_graph(public_key, signing_pvt_key, product,
                            root_home_dir, root_template, template_dir,
                            **template_kwargs)
    tasks = graph_to_tasks(graph)
    with open(signing_pvt_key) as f:
        pvt_key = f.read()
    toplevel_task_id = slug_id()
    env = Environment(loader=FileSystemLoader([
        path.join(template_dir, root_home_dir),
        path.join(template_dir, 'notification'),
        path.join(template_dir, 'shared'),
    ]),
                      undefined=StrictUndefined,
                      extensions=['jinja2.ext.do'])
    template = env.get_template("atomic_task.yml.tmpl")
    template_vars = {
        "product": product,
        "now": arrow.now(),
        "never": arrow.now().replace(years=1000),
        "sorted": sorted,
        "stableSlugId": stable_slug_id(),
        "sign_task": partial(sign_task, pvt_key=pvt_key),
    }
    template_vars.update(template_kwargs)
    toplevel_task = yaml.safe_load(template.render(**template_vars))

    dummy_task_template = env.get_template("dummy_task.yml.tmpl")
    dummy_task = yaml.safe_load(dummy_task_template.render(**template_vars))
    tasks = inject_dummy_tasks(tasks, dummy_task)
    tasks = add_atomic_task(tasks, (toplevel_task_id, toplevel_task))
    taskGroupId = toplevel_task_id
    tasks = inject_taskGroupId(tasks, taskGroupId)
    # TODO: Only return taskGroupId and sorted task, as taskGroupId and
    # toplevel_task_id are now the same ID.
    return taskGroupId, toplevel_task_id, sort_tasks(tasks)
Exemple #5
0
def test_graph_to_tasks_multiple():
    graph = {
        "tasks": [
            {
                "requires": ["b"],
                "taskId": "a",
                "task": {
                    "payload": {},
                    "provisionerId": "m"
                }
            },
            {
                "requires": ["c"],
                "taskId": "b",
                "task": {
                    "payload": {},
                    "provisionerId": "m"
                }
            },
            {
                "taskId": "c",
                "task": {
                    "payload": {},
                    "provisionerId": "m"
                }
            },
        ]
    }
    expected = OrderedDict([('a', {
        'dependencies': ['b'],
        'payload': {},
        'provisionerId': 'm'
    }), ('b', {
        'dependencies': ['c'],
        'payload': {},
        'provisionerId': 'm'
    }), ('c', {
        'payload': {},
        'provisionerId': 'm'
    })])
    assert graph_to_tasks(graph) == expected