Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 36636200BBF for ; Mon, 14 Nov 2016 15:57:02 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 350CC160B06; Mon, 14 Nov 2016 14:57:02 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 31ADE160B05 for ; Mon, 14 Nov 2016 15:57:01 +0100 (CET) Received: (qmail 2631 invoked by uid 500); 14 Nov 2016 14:57:00 -0000 Mailing-List: contact dev-help@ariatosca.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ariatosca.incubator.apache.org Delivered-To: mailing list dev@ariatosca.incubator.apache.org Received: (qmail 2620 invoked by uid 99); 14 Nov 2016 14:57:00 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Nov 2016 14:57:00 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 99EC3180617 for ; Mon, 14 Nov 2016 14:56:59 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -5.22 X-Spam-Level: X-Spam-Status: No, score=-5.22 tagged_above=-999 required=6.31 tests=[HK_RANDOM_FROM=0.999, KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id ZN3WwG2i4Ss3 for ; Mon, 14 Nov 2016 14:56:57 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 46B285FC88 for ; Mon, 14 Nov 2016 14:56:56 +0000 (UTC) Received: (qmail 2319 invoked by uid 99); 14 Nov 2016 14:56:41 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Nov 2016 14:56:41 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D5909E09B6; Mon, 14 Nov 2016 14:56:40 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mxmrlv@apache.org To: dev@ariatosca.incubator.apache.org Date: Mon, 14 Nov 2016 14:56:41 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/3] incubator-ariatosca git commit: ARIATOSCA-9-API-for-operation-context archived-at: Mon, 14 Nov 2016 14:57:02 -0000 http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/bd22e8eb/tests/workflows/core/test_task.py ---------------------------------------------------------------------- diff --git a/tests/workflows/core/test_task.py b/tests/workflows/core/test_task.py new file mode 100644 index 0000000..d0b329a --- /dev/null +++ b/tests/workflows/core/test_task.py @@ -0,0 +1,113 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from datetime import ( + datetime, + timedelta +) + +import pytest + +from aria.context import workflow as workflow_context +from aria.workflows import ( + api, + core, + exceptions, +) + +from ... import mock + + +@pytest.fixture +def ctx(): + simple_context = mock.context.simple() + + blueprint = mock.models.get_blueprint() + deployment = mock.models.get_deployment() + node = mock.models.get_dependency_node() + node_instance = mock.models.get_dependency_node_instance(node) + execution = mock.models.get_execution() + + simple_context.model.blueprint.store(blueprint) + simple_context.model.deployment.store(deployment) + simple_context.model.node.store(node) + simple_context.model.node_instance.store(node_instance) + simple_context.model.execution.store(execution) + + return simple_context + + +class TestOperationTask(object): + + def _create_operation_task(self, ctx, node_instance): + with workflow_context.current.push(ctx): + api_task = api.task.NodeOperationTask( + actor=node_instance, + name='aria.interfaces.lifecycle.create', + ) + + core_task = core.task.OperationTask(api_task=api_task) + + return api_task, core_task + + def test_operation_task_creation(self, ctx): + node_instance = ctx.model.node_instance.get(mock.models.DEPENDENCY_NODE_INSTANCE_ID) + api_task, core_task = self._create_operation_task(ctx, node_instance) + storage_task = ctx.model.task.get(core_task.id) + + assert core_task.model_context == storage_task + assert core_task.name == api_task.name + assert core_task.operation_mapping == api_task.operation_mapping + assert core_task.actor == api_task.actor == node_instance + assert core_task.inputs == api_task.inputs == storage_task.inputs + + def test_operation_task_edit_locked_attribute(self, ctx): + node_instance = ctx.model.node_instance.get(mock.models.DEPENDENCY_NODE_INSTANCE_ID) + + _, core_task = self._create_operation_task(ctx, node_instance) + now = datetime.utcnow() + with pytest.raises(exceptions.TaskException): + core_task.status = core_task.STARTED + with pytest.raises(exceptions.TaskException): + core_task.started_at = now + with pytest.raises(exceptions.TaskException): + core_task.ended_at = now + with pytest.raises(exceptions.TaskException): + core_task.retry_count = 2 + with pytest.raises(exceptions.TaskException): + core_task.due_at = now + + def test_operation_task_edit_attributes(self, ctx): + node_instance = ctx.model.node_instance.get(mock.models.DEPENDENCY_NODE_INSTANCE_ID) + + _, core_task = self._create_operation_task(ctx, node_instance) + future_time = datetime.utcnow() + timedelta(seconds=3) + + with core_task.update(): + core_task.status = core_task.STARTED + core_task.started_at = future_time + core_task.ended_at = future_time + core_task.retry_count = 2 + core_task.eta = future_time + assert core_task.status != core_task.STARTED + assert core_task.started_at != future_time + assert core_task.ended_at != future_time + assert core_task.retry_count != 2 + assert core_task.due_at != future_time + + assert core_task.status == core_task.STARTED + assert core_task.started_at == future_time + assert core_task.ended_at == future_time + assert core_task.retry_count == 2 + assert core_task.eta == future_time http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/bd22e8eb/tests/workflows/core/test_task_graph_into_exececution_graph.py ---------------------------------------------------------------------- diff --git a/tests/workflows/core/test_task_graph_into_exececution_graph.py b/tests/workflows/core/test_task_graph_into_exececution_graph.py index 75e825f..e48fc9a 100644 --- a/tests/workflows/core/test_task_graph_into_exececution_graph.py +++ b/tests/workflows/core/test_task_graph_into_exececution_graph.py @@ -22,22 +22,27 @@ from ... import mock def test_task_graph_into_execution_graph(): + operation_name = 'aria.interfaces.lifecycle.create' task_context = mock.context.simple() node = mock.models.get_dependency_node() node_instance = mock.models.get_dependency_node_instance() + deployment = mock.models.get_deployment() + execution = mock.models.get_execution() task_context.model.node.store(node) task_context.model.node_instance.store(node_instance) + task_context.model.deployment.store(deployment) + task_context.model.execution.store(execution) def sub_workflow(name, **_): return api.task_graph.TaskGraph(name) with context.workflow.current.push(task_context): test_task_graph = api.task.WorkflowTask(sub_workflow, name='test_task_graph') - simple_before_task = api.task.OperationTask('test_simple_before_task', {}, node_instance) - simple_after_task = api.task.OperationTask('test_simple_after_task', {}, node_instance) + simple_before_task = api.task.NodeOperationTask(node_instance, operation_name) + simple_after_task = api.task.NodeOperationTask(node_instance, operation_name) inner_task_graph = api.task.WorkflowTask(sub_workflow, name='test_inner_task_graph') - inner_task = api.task.OperationTask('test_inner_task', {}, node_instance) + inner_task = api.task.NodeOperationTask(node_instance, operation_name) inner_task_graph.add_tasks(inner_task) test_task_graph.add_tasks(simple_before_task) @@ -88,8 +93,8 @@ def test_task_graph_into_execution_graph(): def _assert_execution_is_api_task(execution_task, api_task): assert execution_task.id == api_task.id assert execution_task.name == api_task.name - assert execution_task.operation_details == api_task.operation_details - assert execution_task.node_instance == api_task.node_instance + assert execution_task.operation_mapping == api_task.operation_mapping + assert execution_task.actor == api_task.actor assert execution_task.inputs == api_task.inputs http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/bd22e8eb/tests/workflows/executor/test_executor.py ---------------------------------------------------------------------- diff --git a/tests/workflows/executor/test_executor.py b/tests/workflows/executor/test_executor.py index 0faa753..6c7551c 100644 --- a/tests/workflows/executor/test_executor.py +++ b/tests/workflows/executor/test_executor.py @@ -81,15 +81,15 @@ class TestExecutor(object): self.executor.close() -def mock_successful_task(): +def mock_successful_task(**_): pass -def mock_failing_task(): +def mock_failing_task(**_): raise MockException -def mock_task_with_input(input): +def mock_task_with_input(input, **_): raise MockException(input) if app: @@ -106,16 +106,17 @@ class MockTask(object): INFINITE_RETRIES = models.Task.INFINITE_RETRIES - def __init__(self, func, inputs=None): + def __init__(self, func, inputs=None, ctx=None): self.states = [] self.exception = None self.id = str(uuid.uuid4()) name = func.__name__ operation = 'tests.workflows.executor.test_executor.{name}'.format(name=name) - self.operation_details = {'operation': operation} + self.operation_mapping = operation self.logger = logging.getLogger() self.name = name self.inputs = inputs or {} + self.context = ctx or None self.retry_count = 0 self.max_attempts = 1