X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=azure%2Faria%2Faria-extension-cloudify%2Fsrc%2Faria%2Ftests%2Fmock%2Fcontext.py;fp=azure%2Faria%2Faria-extension-cloudify%2Fsrc%2Faria%2Ftests%2Fmock%2Fcontext.py;h=ac0a8a73b9b4b94486b30cf9254a4395ed216469;hb=7409dfb144cf2a06210400134d822a1393462b1f;hp=0000000000000000000000000000000000000000;hpb=9e65649dfff8f00dc0a0ef6b10d020ae0e2255ba;p=multicloud%2Fazure.git diff --git a/azure/aria/aria-extension-cloudify/src/aria/tests/mock/context.py b/azure/aria/aria-extension-cloudify/src/aria/tests/mock/context.py new file mode 100644 index 0000000..ac0a8a7 --- /dev/null +++ b/azure/aria/aria-extension-cloudify/src/aria/tests/mock/context.py @@ -0,0 +1,57 @@ +# 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. + +import os + +import aria +from aria.orchestrator import context +from aria.storage import ( + sql_mapi, + filesystem_rapi, +) + +from . import models +from ..storage import init_inmemory_model_storage +from .topology import create_simple_topology_two_nodes + + +def simple(tmpdir, inmemory=False, context_kwargs=None, topology=None): + initiator = init_inmemory_model_storage if inmemory else None + initiator_kwargs = {} if inmemory else dict(base_dir=tmpdir) + topology = topology or create_simple_topology_two_nodes + + model_storage = aria.application_model_storage( + sql_mapi.SQLAlchemyModelAPI, initiator=initiator, initiator_kwargs=initiator_kwargs) + resource_storage = aria.application_resource_storage( + filesystem_rapi.FileSystemResourceAPI, + api_kwargs=dict(directory=os.path.join(tmpdir, 'resources')) + ) + + service_id = topology(model_storage) + execution = models.create_execution(model_storage.service.get(service_id)) + model_storage.execution.put(execution) + + final_kwargs = dict( + name='simple_context', + model_storage=model_storage, + resource_storage=resource_storage, + service_id=service_id, + workflow_name=models.WORKFLOW_NAME, + execution_id=execution.id, + task_max_attempts=models.TASK_MAX_ATTEMPTS, + task_retry_interval=models.TASK_RETRY_INTERVAL + ) + final_kwargs.update(context_kwargs or {}) + return context.workflow.WorkflowContext(**final_kwargs)