def storage(): base_storage = ModelStorage( sql_mapi.SQLAlchemyModelAPI, initiator=tests_storage.init_inmemory_model_storage) base_storage.register(tests_modeling.MockModel) yield base_storage tests_storage.release_sqlite_storage(base_storage)
def ctx(tmpdir): context = mock.context.simple( str(tmpdir), context_kwargs=dict(workdir=str(tmpdir.join('workdir'))) ) yield context storage.release_sqlite_storage(context.model)
def ctx(tmpdir): context = mock.context.simple(str(tmpdir)) relationship = context.model.relationship.list()[0] interface = mock.models.create_interface( relationship.source_node.service, RELATIONSHIP_INTERFACE_NAME, RELATIONSHIP_OPERATION_NAME, operation_kwargs=dict(function='test') ) relationship.interfaces[interface.name] = interface context.model.relationship.update(relationship) node = context.model.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME) interface = mock.models.create_interface( node.service, NODE_INTERFACE_NAME, NODE_OPERATION_NAME, operation_kwargs=dict(function='test') ) node.interfaces[interface.name] = interface context.model.node.update(node) yield context storage.release_sqlite_storage(context.model)
def workflow_context(self, tmpdir): result = mock.context.simple( str(tmpdir), context_kwargs=dict(workdir=str(tmpdir.join('workdir'))) ) yield result storage.release_sqlite_storage(result.model)
def workflow_context(self, tmpdir): workflow_context = mock.context.simple( storage.get_sqlite_api_kwargs(str(tmpdir)), resources_dir=str(tmpdir.join('resources'))) workflow_context.states = [] workflow_context.exception = None yield workflow_context storage.release_sqlite_storage(workflow_context.model)
def sql_storage(storage_func): storage = None try: storage = storage_func() yield storage finally: if storage: release_sqlite_storage(storage)
def storage(self): model_storage = application_model_storage( sql_mapi.SQLAlchemyModelAPI, initiator=tests_storage.init_inmemory_model_storage) model_storage.register(MockModel) for value in (1, 2, 3, 4): model_storage.op_mock_model.put(MockModel(value=value)) yield model_storage tests_storage.release_sqlite_storage(model_storage)
def storage(): api_kwargs = test_storage.get_sqlite_api_kwargs() workflow_storage = application_model_storage(SQLAlchemyModelAPI, api_kwargs=api_kwargs) workflow_storage.blueprint.put(models.get_blueprint()) blueprint = workflow_storage.blueprint.get_by_name(models.BLUEPRINT_NAME) workflow_storage.deployment.put(models.get_deployment(blueprint)) yield workflow_storage test_storage.release_sqlite_storage(workflow_storage)
def storage(): workflow_storage = application_model_storage( sql_mapi.SQLAlchemyModelAPI, initiator=test_storage.init_inmemory_model_storage) workflow_storage.service_template.put(models.create_service_template()) service_template = workflow_storage.service_template.get_by_name(models.SERVICE_TEMPLATE_NAME) service = models.create_service(service_template) workflow_storage.service.put(service) workflow_storage.execution.put(models.create_execution(service)) yield workflow_storage test_storage.release_sqlite_storage(workflow_storage)
def ctx(): """ Create the following graph in storage: dependency_node <------ dependent_node :return: """ simple_context = mock.context.simple(storage.get_sqlite_api_kwargs()) simple_context.model.execution.put(mock.models.get_execution(simple_context.deployment)) yield simple_context storage.release_sqlite_storage(simple_context.model)
def ctx(tmpdir): """ Create the following graph in storage: dependency_node <------ dependent_node :return: """ simple_context = mock.context.simple(str(tmpdir), inmemory=False) simple_context.model.execution.put( mock.models.create_execution(simple_context.service)) yield simple_context storage.release_sqlite_storage(simple_context.model)
def test_application_storage_factory(): storage = application_model_storage( sql_mapi.SQLAlchemyModelAPI, initiator=tests_storage.init_inmemory_model_storage) assert storage.service_template assert storage.node_template assert storage.group_template assert storage.policy_template assert storage.substitution_template assert storage.substitution_template_mapping assert storage.requirement_template assert storage.relationship_template assert storage.capability_template assert storage.interface_template assert storage.operation_template assert storage.artifact_template assert storage.service assert storage.node assert storage.group assert storage.policy assert storage.substitution assert storage.substitution_mapping assert storage.relationship assert storage.capability assert storage.interface assert storage.operation assert storage.artifact assert storage.execution assert storage.service_update assert storage.service_update_step assert storage.service_modification assert storage.plugin assert storage.task assert storage.input assert storage.output assert storage.property assert storage.attribute assert storage.type assert storage.metadata tests_storage.release_sqlite_storage(storage)
def test_task_graph_into_execution_graph(): operation_name = 'tosca.interfaces.node.lifecycle.Standard.create' task_context = mock.context.simple(storage.get_sqlite_api_kwargs()) node_instance = \ task_context.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME) 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.node_instance( instance=node_instance, name=operation_name) simple_after_task = api.task.OperationTask.node_instance( instance=node_instance, name=operation_name) inner_task_graph = api.task.WorkflowTask(sub_workflow, name='test_inner_task_graph') inner_task = api.task.OperationTask.node_instance( instance=node_instance, name=operation_name) inner_task_graph.add_tasks(inner_task) test_task_graph.add_tasks(simple_before_task) test_task_graph.add_tasks(simple_after_task) test_task_graph.add_tasks(inner_task_graph) test_task_graph.add_dependency(inner_task_graph, simple_before_task) test_task_graph.add_dependency(simple_after_task, inner_task_graph) # Direct check execution_graph = DiGraph() core.translation.build_execution_graph(task_graph=test_task_graph, execution_graph=execution_graph) execution_tasks = topological_sort(execution_graph) assert len(execution_tasks) == 7 expected_tasks_names = [ '{0}-Start'.format(test_task_graph.id), simple_before_task.id, '{0}-Start'.format(inner_task_graph.id), inner_task.id, '{0}-End'.format(inner_task_graph.id), simple_after_task.id, '{0}-End'.format(test_task_graph.id) ] assert expected_tasks_names == execution_tasks assert isinstance(_get_task_by_name(execution_tasks[0], execution_graph), core.task.StartWorkflowTask) _assert_execution_is_api_task( _get_task_by_name(execution_tasks[1], execution_graph), simple_before_task) assert isinstance(_get_task_by_name(execution_tasks[2], execution_graph), core.task.StartSubWorkflowTask) _assert_execution_is_api_task( _get_task_by_name(execution_tasks[3], execution_graph), inner_task) assert isinstance(_get_task_by_name(execution_tasks[4], execution_graph), core.task.EndSubWorkflowTask) _assert_execution_is_api_task( _get_task_by_name(execution_tasks[5], execution_graph), simple_after_task) assert isinstance(_get_task_by_name(execution_tasks[6], execution_graph), core.task.EndWorkflowTask) storage.release_sqlite_storage(task_context.model)
def ctx(tmpdir): context = mock.context.simple( str(tmpdir), topology=mock.topology.create_simple_topology_three_nodes) yield context storage.release_sqlite_storage(context.model)
def context(tmpdir): result = mock.context.simple(str(tmpdir)) yield result tests_storage.release_sqlite_storage(result.model)
def context(tmpdir): result = mock.context.simple(storage.get_sqlite_api_kwargs(str(tmpdir))) yield result storage.release_sqlite_storage(result.model)
def ctx(tmpdir): context = mock.context.simple(storage.get_sqlite_api_kwargs(str(tmpdir))) yield context storage.release_sqlite_storage(context.model)
def workflow_context(self, tmpdir): workflow_context = mock.context.simple(str(tmpdir)) workflow_context.states = [] workflow_context.exception = None yield workflow_context storage.release_sqlite_storage(workflow_context.model)
def context(tmpdir): result = mock.context.simple(storage.get_sqlite_api_kwargs(str(tmpdir)), resources_dir=str(tmpdir.join('resources')), workdir=str(tmpdir.join('workdir'))) yield result storage.release_sqlite_storage(result.model)
def ctx(tmpdir): context = mock.context.simple(str(tmpdir), inmemory=False) yield context storage.release_sqlite_storage(context.model)
def workflow_ctx(self, tmpdir): context = mock.context.simple(str(tmpdir), inmemory=True) yield context storage.release_sqlite_storage(context.model)
def workflow_context(tmpdir): workflow_context = tests_mock.context.simple(str(tmpdir)) yield workflow_context storage.release_sqlite_storage(workflow_context.model)
def test_task_graph_into_execution_graph(tmpdir): interface_name = 'Standard' operation_name = 'create' task_context = mock.context.simple(str(tmpdir)) node = task_context.model.node.get_by_name( mock.models.DEPENDENCY_NODE_NAME) interface = mock.models.create_interface( node.service, interface_name, operation_name, operation_kwargs=dict(function='test')) node.interfaces[interface.name] = interface task_context.model.node.update(node) 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( node, interface_name=interface_name, operation_name=operation_name) simple_after_task = api.task.OperationTask( node, interface_name=interface_name, operation_name=operation_name) inner_task_graph = api.task.WorkflowTask(sub_workflow, name='test_inner_task_graph') inner_task = api.task.OperationTask(node, interface_name=interface_name, operation_name=operation_name) inner_task_graph.add_tasks(inner_task) test_task_graph.add_tasks(simple_before_task) test_task_graph.add_tasks(simple_after_task) test_task_graph.add_tasks(inner_task_graph) test_task_graph.add_dependency(inner_task_graph, simple_before_task) test_task_graph.add_dependency(simple_after_task, inner_task_graph) # Direct check execution_graph = DiGraph() core.translation.build_execution_graph( task_graph=test_task_graph, execution_graph=execution_graph, default_executor=base.StubTaskExecutor()) execution_tasks = topological_sort(execution_graph) assert len(execution_tasks) == 7 expected_tasks_names = [ '{0}-Start'.format(test_task_graph.id), simple_before_task.id, '{0}-Start'.format(inner_task_graph.id), inner_task.id, '{0}-End'.format(inner_task_graph.id), simple_after_task.id, '{0}-End'.format(test_task_graph.id) ] assert expected_tasks_names == execution_tasks assert isinstance(_get_task_by_name(execution_tasks[0], execution_graph), core.task.StartWorkflowTask) _assert_execution_is_api_task( _get_task_by_name(execution_tasks[1], execution_graph), simple_before_task) assert isinstance(_get_task_by_name(execution_tasks[2], execution_graph), core.task.StartSubWorkflowTask) _assert_execution_is_api_task( _get_task_by_name(execution_tasks[3], execution_graph), inner_task) assert isinstance(_get_task_by_name(execution_tasks[4], execution_graph), core.task.EndSubWorkflowTask) _assert_execution_is_api_task( _get_task_by_name(execution_tasks[5], execution_graph), simple_after_task) assert isinstance(_get_task_by_name(execution_tasks[6], execution_graph), core.task.EndWorkflowTask) storage.release_sqlite_storage(task_context.model)
def memory_model_storage(): result = aria.application_model_storage( SQLAlchemyModelAPI, api_kwargs=storage.get_sqlite_api_kwargs()) yield result storage.release_sqlite_storage(result)
def workflow_context(tmpdir): context = mock.context.simple(str(tmpdir)) yield context storage.release_sqlite_storage(context.model)
def ctx(tmpdir): context = mock.context.simple(storage.get_sqlite_api_kwargs(), resources_dir=str(tmpdir.join('resources'))) yield context storage.release_sqlite_storage(context.model)
def test_task_graph_into_execution_graph(tmpdir): interface_name = 'Standard' op1_name, op2_name, op3_name = 'create', 'configure', 'start' workflow_context = mock.context.simple(str(tmpdir)) node = workflow_context.model.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME) interface = mock.models.create_interface( node.service, interface_name, op1_name, operation_kwargs=dict(function='test') ) interface.operations[op2_name] = mock.models.create_operation(op2_name) # pylint: disable=unsubscriptable-object interface.operations[op3_name] = mock.models.create_operation(op3_name) # pylint: disable=unsubscriptable-object node.interfaces[interface.name] = interface workflow_context.model.node.update(node) def sub_workflow(name, **_): return api.task_graph.TaskGraph(name) with context.workflow.current.push(workflow_context): test_task_graph = api.task.WorkflowTask(sub_workflow, name='test_task_graph') simple_before_task = api.task.OperationTask( node, interface_name=interface_name, operation_name=op1_name) simple_after_task = api.task.OperationTask( node, interface_name=interface_name, operation_name=op1_name) inner_task_graph = api.task.WorkflowTask(sub_workflow, name='test_inner_task_graph') inner_task_1 = api.task.OperationTask( node, interface_name=interface_name, operation_name=op1_name) inner_task_2 = api.task.OperationTask( node, interface_name=interface_name, operation_name=op2_name) inner_task_3 = api.task.OperationTask( node, interface_name=interface_name, operation_name=op3_name) inner_task_graph.add_tasks(inner_task_1) inner_task_graph.add_tasks(inner_task_2) inner_task_graph.add_tasks(inner_task_3) inner_task_graph.add_dependency(inner_task_2, inner_task_1) inner_task_graph.add_dependency(inner_task_3, inner_task_1) inner_task_graph.add_dependency(inner_task_3, inner_task_2) test_task_graph.add_tasks(simple_before_task) test_task_graph.add_tasks(simple_after_task) test_task_graph.add_tasks(inner_task_graph) test_task_graph.add_dependency(inner_task_graph, simple_before_task) test_task_graph.add_dependency(simple_after_task, inner_task_graph) compiler = graph_compiler.GraphCompiler(workflow_context, base.StubTaskExecutor) compiler.compile(test_task_graph) execution_tasks = topological_sort(_graph(workflow_context.execution.tasks)) assert len(execution_tasks) == 9 expected_tasks_names = [ '{0}-Start'.format(test_task_graph.id), simple_before_task.id, '{0}-Start'.format(inner_task_graph.id), inner_task_1.id, inner_task_2.id, inner_task_3.id, '{0}-End'.format(inner_task_graph.id), simple_after_task.id, '{0}-End'.format(test_task_graph.id) ] assert expected_tasks_names == [compiler._model_to_api_id[t.id] for t in execution_tasks] assert all(isinstance(task, models.Task) for task in execution_tasks) execution_tasks = iter(execution_tasks) _assert_tasks( iter(execution_tasks), iter([simple_after_task, inner_task_1, inner_task_2, inner_task_3, simple_after_task]) ) storage.release_sqlite_storage(workflow_context.model)