Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-105-integrate-modeling f6da64acb -> 0f040a2b9
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/aria/orchestrator/workflows/api/task.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflows/api/task.py b/aria/orchestrator/workflows/api/task.py index 744d1b4..e4ebbda 100644 --- a/aria/orchestrator/workflows/api/task.py +++ b/aria/orchestrator/workflows/api/task.py @@ -59,17 +59,19 @@ class OperationTask(BaseTask): Represents an operation task in the task_graph """ - NAME_FORMAT = '{interface}:{operation}@{type}:{id}' + NAME_FORMAT = '{interface}:{operation}@{type}:{name}' def __init__(self, - name, actor, - implementation, + name=None, + actor_type=None, + interface_name=None, + operation_name=None, + implementation=None, max_attempts=None, retry_interval=None, ignore_failure=None, inputs=None, - plugin=None, runs_on=None): """ Creates an operation task using the name, details, node instance and any additional kwargs. @@ -83,21 +85,7 @@ class OperationTask(BaseTask): assert (runs_on is None) or (runs_on in models.Task.RUNS_ON) super(OperationTask, self).__init__() - # Coerce inputs - if inputs is None: - inputs = {} - else: - for k, v in inputs.iteritems(): - if not isinstance(v, models.Parameter): - inputs[k] = models.Parameter(name=k, - type_name=full_type_name(v), - value=v) - - self.name = name self.actor = actor - self.implementation = implementation - self.inputs = inputs - self.plugin = plugin self.max_attempts = (self.workflow_context._task_max_attempts if max_attempts is None else max_attempts) self.retry_interval = (self.workflow_context._task_retry_interval @@ -106,8 +94,51 @@ class OperationTask(BaseTask): if ignore_failure is None else ignore_failure) self.runs_on = runs_on + # Coerce inputs + if inputs: + for k, v in inputs.iteritems(): + if not isinstance(v, models.Parameter): + inputs[k] = models.Parameter(name=k, + type_name=full_type_name(v), + value=v) + + if interface_name or operation_name: + operation = OperationTask._get_operation(actor.interfaces, interface_name, operation_name) + if operation is None: + raise exceptions.TaskException( + 'Could not find operation "{0}" on interface "{1}" for {2} "{3}"' + .format(operation_name, interface_name, actor_type, actor.name)) + + self.plugin = None + if operation.plugin_specification: + self.plugin = OperationTask._find_plugin(operation.plugin_specification) + if self.plugin is None: + raise exceptions.TaskException( + 'Could not find plugin of operation "{0}" on interface "{1}" for {2} "{3}"' + .format(operation_name, interface_name, actor_type, actor.name)) + + self.implementation = operation.implementation + self.inputs = OperationTask._merge_inputs(operation.inputs, inputs) + + self.name = OperationTask.NAME_FORMAT.format(type=actor_type, + name=actor.name, + interface=interface_name, + operation=operation_name) + else: + self.name = name + self.implementation = implementation + self.inputs = inputs or {} + self.plugin = None + @classmethod - def for_node(cls, node, interface_name, operation_name, inputs=None, *args, **kwargs): + def for_node(cls, + node, + interface_name, + operation_name, + max_attempts=None, + retry_interval=None, + ignore_failure=None, + inputs=None): """ Creates an operation on a node. @@ -118,36 +149,27 @@ class OperationTask(BaseTask): """ assert isinstance(node, models.Node) - operation = cls._get_operation(node.interfaces, interface_name, operation_name) - if operation is None: - raise exceptions.TaskException( - 'Could not find operation "{0}" on interface "{1}" for node "{2}"'.format( - operation_name, interface_name, node.name)) - - plugin = None - if operation.plugin_specification: - plugin = cls._find_plugin(operation.plugin_specification, kwargs) - if plugin is None: - raise exceptions.TaskException( - 'Could not find plugin of operation "{0}" on interface "{1}" for node "{2}"' - .format(operation_name, interface_name, node.name)) - return cls( actor=node, - name=cls.NAME_FORMAT.format(type='node', - id=node.name, - interface=interface_name, - operation=operation_name), - plugin=plugin, - implementation=operation.implementation, - inputs=cls._merge_inputs(operation.inputs, inputs), - runs_on=models.Task.RUNS_ON_NODE, - *args, - **kwargs) + actor_type='node', + interface_name=interface_name, + operation_name=operation_name, + max_attempts=max_attempts, + retry_interval=retry_interval, + ignore_failure=ignore_failure, + inputs=inputs, + runs_on=models.Task.RUNS_ON_NODE) @classmethod - def for_relationship(cls, relationship, interface_name, operation_name, inputs=None, - runs_on=models.Task.RUNS_ON_SOURCE, *args, **kwargs): + def for_relationship(cls, + relationship, + interface_name, + operation_name, + max_attempts=None, + retry_interval=None, + ignore_failure=None, + inputs=None, + runs_on=models.Task.RUNS_ON_SOURCE): """ Creates an operation on a relationship edge. @@ -160,49 +182,31 @@ class OperationTask(BaseTask): assert isinstance(relationship, models.Relationship) assert runs_on in models.Task.RUNS_ON - operation = cls._get_operation(relationship.interfaces, interface_name, operation_name) - if operation is None: - raise exceptions.TaskException( - 'Could not find operation "{0}" on interface "{1}" for relationship "{2}"'.format( - operation_name, interface_name, relationship.name)) - - plugin = None - if operation.plugin_specification: - plugin = cls._find_plugin(operation.plugin_specification, kwargs) - if plugin is None: - raise exceptions.TaskException( - 'Could not find plugin of operation "{0}" on interface "{1}" for relationship ' - '"{2}"'.format(operation_name, interface_name, relationship.name)) - return cls( actor=relationship, - name=cls.NAME_FORMAT.format(type='relationship', - id=relationship.name, - interface=interface_name, - operation=operation_name), - plugin=plugin, - implementation=operation.implementation, - inputs=cls._merge_inputs(operation.inputs, inputs), - runs_on=runs_on, - *args, - **kwargs) - - @classmethod - def _get_operation(cls, interfaces, interface_name, operation_name): + actor_type='relationship', + interface_name=interface_name, + operation_name=operation_name, + max_attempts=max_attempts, + retry_interval=retry_interval, + ignore_failure=ignore_failure, + inputs=inputs, + runs_on=runs_on) + + @staticmethod + def _get_operation(interfaces, interface_name, operation_name): interface = interfaces.get(interface_name) if interface is not None: return interface.operations.get(operation_name) return None - @classmethod - def _find_plugin(cls, plugin_specification, kwargs): - workflow_context = kwargs.get('ctx') if kwargs else None - if workflow_context is None: - workflow_context = context.workflow.current.get() + @staticmethod + def _find_plugin(plugin_specification): + workflow_context = context.workflow.current.get() return plugin_specification.find_plugin(workflow_context.model.plugin.list()) - @classmethod - def _merge_inputs(cls, operation_inputs, override_inputs=None): + @staticmethod + def _merge_inputs(operation_inputs, override_inputs=None): final_inputs = OrderedDict(operation_inputs) if override_inputs: final_inputs.update(override_inputs) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py ---------------------------------------------------------------------- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py index a7b2a11..ec5ba3b 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py @@ -86,15 +86,16 @@ def create_service_template_model(context): # pylint: disable=too-many-locals,to if policies: for policy in policies.itervalues(): if model.policy_types.get_descendant(policy.type).role == 'plugin': - model.plugin_specifications.append( - create_plugin_specification_model(context, policy)) + plugin_specification = create_plugin_specification_model(context, policy) + model.plugin_specifications[plugin_specification.name] = plugin_specification # Node templates node_templates = context.presentation.get('service_template', 'topology_template', 'node_templates') if node_templates: for node_template in node_templates.itervalues(): - model.node_templates.append(create_node_template_model(context, model, node_template)) + node_template_model = create_node_template_model(context, model, node_template) + model.node_templates[node_template_model.name] = node_template_model for node_template in node_templates.itervalues(): fix_node_template_model(context, model, node_template) @@ -102,13 +103,15 @@ def create_service_template_model(context): # pylint: disable=too-many-locals,to groups = context.presentation.get('service_template', 'topology_template', 'groups') if groups: for group in groups.itervalues(): - model.group_templates.append(create_group_template_model(context, model, group)) + group_template_model = create_group_template_model(context, model, group) + model.group_templates[group_template_model.name] = group_template_model # Policy templates policies = context.presentation.get('service_template', 'topology_template', 'policies') if policies: for policy in policies.itervalues(): - model.policy_templates.append(create_policy_template_model(context, model, policy)) + policy_template_model = create_policy_template_model(context, model, policy) + model.policy_templates[policy_template_model.name] = policy_template_model # Substitution template substitution_mappings = context.presentation.get('service_template', 'topology_template', @@ -174,7 +177,7 @@ def create_node_template_model(context, service_template, node_template): def fix_node_template_model(context, service_template, node_template): # Requirements have to be created after all node templates have been created, because # requirements might reference another node template - model = service_template.get_node_template(node_template._name) + model = service_template.node_templates[node_template._name] requirements = node_template._get_requirements(context) if requirements: for _, requirement in requirements: @@ -199,7 +202,7 @@ def create_group_template_model(context, service_template, group): members = group.members if members: for member in members: - node_template = service_template.get_node_template(member) + node_template = service_template.node_templates[member] assert node_template model.node_templates.append(node_template) @@ -220,12 +223,12 @@ def create_policy_template_model(context, service_template, policy): node_templates, groups = policy._get_targets(context) if node_templates: for target in node_templates: - node_template = service_template.get_node_template(target._name) + node_template = service_template.node_templates[target._name] assert node_template model.node_templates.append(node_template) if groups: for target in groups: - group_template = service_template.get_group_template(target._name) + group_template = service_template.group_templates[target._name] assert group_template model.group_templates.append(group_template) @@ -241,7 +244,7 @@ def create_requirement_template_model(context, service_template, requirement): node_type = service_template.node_types.get_descendant(node._name) model['target_node_type'] = node_type else: - node_template = service_template.get_node_template(node._name) + node_template = service_template.node_templates[node._name] model['target_node_template'] = node_template capability, capability_variant = requirement._get_capability(context) @@ -402,7 +405,7 @@ def create_substitution_template_model(context, service_template, substitution_m if capabilities: for mapped_capability_name, capability in capabilities.iteritems(): name = 'capability.' + mapped_capability_name - node_template_model = service_template.get_node_template(capability.node_template) + node_template_model = service_template.node_templates[capability.node_template] capability_template_model = \ node_template_model.capability_templates[capability.capability] model.mappings[name] = \ @@ -414,7 +417,7 @@ def create_substitution_template_model(context, service_template, substitution_m if requirements: for mapped_requirement_name, requirement in requirements.iteritems(): name = 'requirement.' + mapped_requirement_name - node_template_model = service_template.get_node_template(requirement.node_template) + node_template_model = service_template.node_templates[requirement.node_template] requirement_template_model = None for a_model in node_template_model.requirement_templates: if a_model.name == requirement.requirement: @@ -435,8 +438,6 @@ def create_plugin_specification_model(context, policy): prop = properties.get(name) return prop.value if prop is not None else None - now = datetime.now() - model = PluginSpecification(name=policy._name, archive_name=get('archive_name') or '', distribution=get('distribution'), @@ -666,11 +667,7 @@ def parse_implementation_string(context, service_template, implementation): if plugin_name == 'execution': plugin_specification = None else: - plugin_specification = None - for a_plugin_specification in service_template.plugin_specifications: - if a_plugin_specification.name == plugin_name: - plugin_specification = a_plugin_specification - break + plugin_specification = service_template.plugin_specifications.get(plugin_name) if plugin_specification is None: raise ValueError('unknown plugin: "{0}"'.format(plugin_name)) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/tests/end2end/test_orchestrator.py ---------------------------------------------------------------------- diff --git a/tests/end2end/test_orchestrator.py b/tests/end2end/test_orchestrator.py index f25134f..7b8dc97 100644 --- a/tests/end2end/test_orchestrator.py +++ b/tests/end2end/test_orchestrator.py @@ -46,12 +46,7 @@ def _workflow(workflow_name): workflow_fn = import_fullname('aria.orchestrator.workflows.builtin.' + workflow_name) inputs = {} else: - workflow = None - for policy in context.modeling.instance.policies: - if policy.name == workflow_name: - workflow = policy - break - + workflow = context.modeling.instance.policies[workflow_name] sys.path.append(workflow.properties['implementation'].value) workflow_fn = import_fullname(workflow.properties['function'].value) inputs = OrderedDict([ http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/tests/mock/models.py ---------------------------------------------------------------------- diff --git a/tests/mock/models.py b/tests/mock/models.py index 483da7d..3ede242 100644 --- a/tests/mock/models.py +++ b/tests/mock/models.py @@ -80,7 +80,7 @@ def create_dependency_node_template(service_template): max_instances=1, service_template=service_template ) - service_template.node_templates.append(node_template) + service_template.node_templates[node_template.name] = node_template return node_template @@ -110,7 +110,7 @@ def create_dependent_node_template(service_template, dependency_node_template): requirement_templates=[requirement_template], service_template=service_template ) - service_template.node_templates.append(node_template) + service_template.node_templates[node_template.name] = node_template return node_template @@ -124,7 +124,7 @@ def create_dependency_node(dependency_node_template, service): state='', scaling_groups=[] ) - service.nodes.append(node) + service.nodes[node.name] = node return node @@ -138,7 +138,7 @@ def create_dependent_node(dependent_node_template, service): state='', scaling_groups=[], ) - service.nodes.append(node) + service.nodes[node.name] = node return node http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/tests/modeling/test_models.py ---------------------------------------------------------------------- diff --git a/tests/modeling/test_models.py b/tests/modeling/test_models.py index c8d36e0..4627bc6 100644 --- a/tests/modeling/test_models.py +++ b/tests/modeling/test_models.py @@ -514,14 +514,14 @@ class TestNodeTemplate(object): 'is_valid, name, default_instances, max_instances, min_instances, plugin_specifications, ' 'properties', [ - (False, m_cls, 1, 1, 1, [], {}), - (False, 'name', m_cls, 1, 1, [], {}), - (False, 'name', 1, m_cls, 1, [], {}), - (False, 'name', 1, 1, m_cls, [], {}), + (False, m_cls, 1, 1, 1, {}, {}), + (False, 'name', m_cls, 1, 1, {}, {}), + (False, 'name', 1, m_cls, 1, {}, {}), + (False, 'name', 1, 1, m_cls, {}, {}), (False, 'name', 1, 1, 1, m_cls, {}), (False, 'name', 1, 1, 1, None, {}), - (True, 'name', 1, 1, 1, [], {}), + (True, 'name', 1, 1, 1, {}, {}), ] ) def test_node_template_model_creation(self, service_storage, is_valid, name, default_instances, http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/tests/orchestrator/context/test_operation.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_operation.py b/tests/orchestrator/context/test_operation.py index 7817a90..e2f2421 100644 --- a/tests/orchestrator/context/test_operation.py +++ b/tests/orchestrator/context/test_operation.py @@ -84,7 +84,7 @@ def test_node_operation_task_execution(ctx, executor): operation_context = global_test_holder[api.task.OperationTask.NAME_FORMAT.format( type='node', - id=node.name, + name=node.name, interface=interface_name, operation=operation_name )] @@ -95,7 +95,7 @@ def test_node_operation_task_execution(ctx, executor): assert operation_context.task.actor == node assert operation_context.task.name == api.task.OperationTask.NAME_FORMAT.format( type='node', - id=node.name, + name=node.name, interface=interface_name, operation=operation_name ) @@ -140,7 +140,7 @@ def test_relationship_operation_task_execution(ctx, executor): operation_context = global_test_holder[api.task.OperationTask.NAME_FORMAT.format( type='relationship', - id=relationship.name, + name=relationship.name, interface=interface_name, operation=operation_name )] @@ -205,7 +205,7 @@ def test_invalid_task_operation_id(ctx, executor): op_node_id = global_test_holder[api.task.OperationTask.NAME_FORMAT.format( type='node', - id=node.name, + name=node.name, interface=interface_name, operation=operation_name )] @@ -230,7 +230,7 @@ def test_plugin_workdir(ctx, executor, tmpdir): plugin_specification=plugin_specification) ) node.interfaces[interface.name] = interface - node.plugin_specifications = [plugin_specification] + node.plugin_specifications[plugin_specification.name] = plugin_specification ctx.model.node.update(node) filename = 'test_file' http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/tests/orchestrator/context/test_serialize.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_serialize.py b/tests/orchestrator/context/test_serialize.py index 2ec999c..eee1743 100644 --- a/tests/orchestrator/context/test_serialize.py +++ b/tests/orchestrator/context/test_serialize.py @@ -54,7 +54,7 @@ def _mock_workflow(ctx, graph): plugin_specification=plugin_specification) ) node.interfaces[interface.name] = interface - node.plugin_specifications = [plugin_specification] + node.plugin_specifications[plugin_specification.name] = plugin_specification task = api.task.OperationTask.for_node(node=node, interface_name='test', operation_name='op') graph.add_tasks(task) return graph http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/tests/orchestrator/context/test_toolbelt.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_toolbelt.py b/tests/orchestrator/context/test_toolbelt.py index 0e35a26..cf82127 100644 --- a/tests/orchestrator/context/test_toolbelt.py +++ b/tests/orchestrator/context/test_toolbelt.py @@ -132,7 +132,7 @@ def test_relationship_tool_belt(workflow_context, executor): assert isinstance(global_test_holder.get(api.task.OperationTask.NAME_FORMAT.format( type='relationship', - id=relationship.name, + name=relationship.name, interface=interface_name, operation=operation_name )), RelationshipToolBelt) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/tests/orchestrator/workflows/api/test_task.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/api/test_task.py b/tests/orchestrator/workflows/api/test_task.py index 139d239..e749b78 100644 --- a/tests/orchestrator/workflows/api/test_task.py +++ b/tests/orchestrator/workflows/api/test_task.py @@ -56,7 +56,7 @@ class TestOperationTask(object): node = ctx.model.node.get_by_name(mock.models.DEPENDENT_NODE_NAME) node.interfaces = {interface.name: interface} - node.plugin_specifications = [plugin_specification] + node.plugin_specifications[plugin_specification.name] = plugin_specification ctx.model.node.update(node) inputs = {'test_input': True} max_attempts = 10 @@ -75,7 +75,7 @@ class TestOperationTask(object): assert api_task.name == api.task.OperationTask.NAME_FORMAT.format( type='node', - id=node.name, + name=node.name, interface=interface_name, operation=operation_name ) @@ -107,7 +107,8 @@ class TestOperationTask(object): relationship = ctx.model.relationship.list()[0] relationship.interfaces[interface.name] = interface - relationship.source_node.plugin_specifications = [plugin_specification] + relationship.source_node.plugin_specifications[plugin_specification.name] = \ + plugin_specification inputs = {'test_input': True} max_attempts = 10 retry_interval = 10 @@ -123,7 +124,7 @@ class TestOperationTask(object): assert api_task.name == api.task.OperationTask.NAME_FORMAT.format( type='relationship', - id=relationship.name, + name=relationship.name, interface=interface_name, operation=operation_name ) @@ -154,7 +155,8 @@ class TestOperationTask(object): relationship = ctx.model.relationship.list()[0] relationship.interfaces[interface.name] = interface - relationship.target_node.plugin_specifications = [plugin_specification] + relationship.target_node.plugin_specifications[plugin_specification.name] = \ + plugin_specification inputs = {'test_input': True} max_attempts = 10 retry_interval = 10 @@ -171,7 +173,7 @@ class TestOperationTask(object): assert api_task.name == api.task.OperationTask.NAME_FORMAT.format( type='relationship', - id=relationship.name, + name=relationship.name, interface=interface_name, operation=operation_name ) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/tests/orchestrator/workflows/builtin/test_execute_operation.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/builtin/test_execute_operation.py b/tests/orchestrator/workflows/builtin/test_execute_operation.py index e2a8ef0..360e17d 100644 --- a/tests/orchestrator/workflows/builtin/test_execute_operation.py +++ b/tests/orchestrator/workflows/builtin/test_execute_operation.py @@ -57,7 +57,7 @@ def test_execute_operation(ctx): assert len(execute_tasks) == 1 assert execute_tasks[0].name == task.OperationTask.NAME_FORMAT.format( type='node', - id=node.name, + name=node.name, interface=interface_name, operation=operation_name ) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/tests/orchestrator/workflows/core/test_task.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/core/test_task.py b/tests/orchestrator/workflows/core/test_task.py index 49f020f..f3ce92f 100644 --- a/tests/orchestrator/workflows/core/test_task.py +++ b/tests/orchestrator/workflows/core/test_task.py @@ -94,7 +94,8 @@ class TestOperationTask(object): ctx.model.plugin_specification.put(storage_plugin_specification) node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME) node_template = node.node_template - node_template.plugin_specifications = [storage_plugin_specification] + node_template.plugin_specifications[storage_plugin_specification.name] = \ + storage_plugin_specification interface = mock.models.create_interface( node.service, NODE_INTERFACE_NAME, http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/tests/orchestrator/workflows/executor/test_process_executor_extension.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/executor/test_process_executor_extension.py b/tests/orchestrator/workflows/executor/test_process_executor_extension.py index 0988fae..1c4cda6 100644 --- a/tests/orchestrator/workflows/executor/test_process_executor_extension.py +++ b/tests/orchestrator/workflows/executor/test_process_executor_extension.py @@ -55,8 +55,8 @@ def test_decorate_extension(context, executor): eng = engine.Engine(executor=executor, workflow_context=context, tasks_graph=graph) eng.execute() out = get_node(context).runtime_properties['out'] - assert out['wrapper_inputs'] == inputs - assert out['function_inputs'] == inputs + assert out['wrapper_inputs'] == dict((k, v.value) for k, v in inputs.iteritems()) + assert out['function_inputs'] == dict((k, v.value) for k, v in inputs.iteritems()) @extension.process_executor http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py b/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py index d84a153..e770b21 100644 --- a/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py +++ b/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py @@ -73,9 +73,9 @@ def test_apply_tracked_changes_during_an_operation(context, executor): inputs=inputs) expected_after_update = expected_initial.copy() - expected_after_update.update(inputs['committed']) + expected_after_update.update(inputs['committed'].value) expected_after_change = expected_after_update.copy() - expected_after_change.update(inputs['changed_but_refreshed']) + expected_after_change.update(inputs['changed_but_refreshed'].value) expected_after_refresh = expected_after_update assert out['initial'] == expected_initial http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0f040a2b/tests/storage/test_resource_storage.py ---------------------------------------------------------------------- diff --git a/tests/storage/test_resource_storage.py b/tests/storage/test_resource_storage.py index 9b5f782..9f0c818 100644 --- a/tests/storage/test_resource_storage.py +++ b/tests/storage/test_resource_storage.py @@ -28,20 +28,20 @@ from . import TestFileSystem class TestResourceStorage(TestFileSystem): def _create(self, storage): - storage.register('blueprint') + storage.register('service_template') def _upload(self, storage, tmp_path, id): with open(tmp_path, 'w') as f: f.write('fake context') - storage.blueprint.upload(entry_id=id, source=tmp_path) + storage.service_template.upload(entry_id=id, source=tmp_path) def _upload_dir(self, storage, tmp_dir, tmp_file_name, id): file_source = os.path.join(tmp_dir, tmp_file_name) with open(file_source, 'w') as f: f.write('fake context') - storage.blueprint.upload(entry_id=id, source=tmp_dir) + storage.service_template.upload(entry_id=id, source=tmp_dir) def _create_storage(self): return ResourceStorage(FileSystemResourceAPI, @@ -50,27 +50,27 @@ class TestResourceStorage(TestFileSystem): def test_name(self): api = FileSystemResourceAPI storage = ResourceStorage(FileSystemResourceAPI, - items=['blueprint'], + items=['service_template'], api_kwargs=dict(directory=self.path)) assert repr(storage) == 'ResourceStorage(api={api})'.format(api=api) assert 'directory={resource_dir}'.format(resource_dir=self.path) in \ - repr(storage.registered['blueprint']) + repr(storage.registered['service_template']) def test_create(self): storage = self._create_storage() self._create(storage) - assert os.path.exists(os.path.join(self.path, 'blueprint')) + assert os.path.exists(os.path.join(self.path, 'service_template')) def test_upload_file(self): storage = ResourceStorage(FileSystemResourceAPI, api_kwargs=dict(directory=self.path)) self._create(storage) tmpfile_path = tempfile.mkstemp(suffix=self.__class__.__name__, dir=self.path)[1] - self._upload(storage, tmpfile_path, id='blueprint_id') + self._upload(storage, tmpfile_path, id='service_template_id') storage_path = os.path.join( self.path, - 'blueprint', - 'blueprint_id', + 'service_template', + 'service_template_id', os.path.basename(tmpfile_path)) assert os.path.exists(storage_path) @@ -82,11 +82,11 @@ class TestResourceStorage(TestFileSystem): self._create(storage) tmpfile_path = tempfile.mkstemp(suffix=self.__class__.__name__, dir=self.path)[1] tmpfile_name = os.path.basename(tmpfile_path) - self._upload(storage, tmpfile_path, 'blueprint_id') + self._upload(storage, tmpfile_path, 'service_template_id') temp_dir = tempfile.mkdtemp(dir=self.path) - storage.blueprint.download( - entry_id='blueprint_id', + storage.service_template.download( + entry_id='service_template_id', destination=temp_dir, path=tmpfile_name) @@ -97,21 +97,21 @@ class TestResourceStorage(TestFileSystem): storage = self._create_storage() self._create(storage) with pytest.raises(exceptions.StorageError): - storage.blueprint.download(entry_id='blueprint_id', destination='', path='fake_path') + storage.service_template.download(entry_id='service_template_id', destination='', path='fake_path') def test_data_non_existing_file(self): storage = self._create_storage() self._create(storage) with pytest.raises(exceptions.StorageError): - storage.blueprint.read(entry_id='blueprint_id', path='fake_path') + storage.service_template.read(entry_id='service_template_id', path='fake_path') def test_data_file(self): storage = self._create_storage() self._create(storage) tmpfile_path = tempfile.mkstemp(suffix=self.__class__.__name__, dir=self.path)[1] - self._upload(storage, tmpfile_path, 'blueprint_id') + self._upload(storage, tmpfile_path, 'service_template_id') - assert storage.blueprint.read(entry_id='blueprint_id') == 'fake context' + assert storage.service_template.read(entry_id='service_template_id') == 'fake context' def test_upload_dir(self): storage = self._create_storage() @@ -119,12 +119,12 @@ class TestResourceStorage(TestFileSystem): tmp_dir = tempfile.mkdtemp(suffix=self.__class__.__name__, dir=self.path) second_level_tmp_dir = tempfile.mkdtemp(dir=tmp_dir) tmp_filename = tempfile.mkstemp(dir=second_level_tmp_dir)[1] - self._upload_dir(storage, tmp_dir, tmp_filename, id='blueprint_id') + self._upload_dir(storage, tmp_dir, tmp_filename, id='service_template_id') destination = os.path.join( self.path, - 'blueprint', - 'blueprint_id', + 'service_template', + 'service_template_id', os.path.basename(second_level_tmp_dir), os.path.basename(tmp_filename)) @@ -136,21 +136,21 @@ class TestResourceStorage(TestFileSystem): tmp_dir = tempfile.mkdtemp(suffix=self.__class__.__name__, dir=self.path) second_level_tmp_dir = tempfile.mkdtemp(dir=tmp_dir) tmp_filename = tempfile.mkstemp(dir=second_level_tmp_dir)[1] - self._upload_dir(storage, tmp_dir, tmp_filename, id='blueprint_id') + self._upload_dir(storage, tmp_dir, tmp_filename, id='service_template_id') second_update_file = tempfile.mkstemp(dir=self.path)[1] with open(second_update_file, 'w') as f: f.write('fake context2') - storage.blueprint.upload( - entry_id='blueprint_id', + storage.service_template.upload( + entry_id='service_template_id', source=second_update_file, path=os.path.basename(second_level_tmp_dir)) assert os.path.isfile(os.path.join( self.path, - 'blueprint', - 'blueprint_id', + 'service_template', + 'service_template_id', os.path.basename(second_level_tmp_dir), os.path.basename(second_update_file))) @@ -160,11 +160,11 @@ class TestResourceStorage(TestFileSystem): tmp_dir = tempfile.mkdtemp(suffix=self.__class__.__name__, dir=self.path) second_level_tmp_dir = tempfile.mkdtemp(dir=tmp_dir) tmp_filename = tempfile.mkstemp(dir=second_level_tmp_dir)[1] - self._upload_dir(storage, tmp_dir, tmp_filename, id='blueprint_id') + self._upload_dir(storage, tmp_dir, tmp_filename, id='service_template_id') temp_destination_dir = tempfile.mkdtemp(dir=self.path) - storage.blueprint.download( - entry_id='blueprint_id', + storage.service_template.download( + entry_id='service_template_id', destination=temp_destination_dir) destination_file_path = os.path.join( @@ -185,7 +185,7 @@ class TestResourceStorage(TestFileSystem): tempfile.mkstemp(dir=tmp_dir) tempfile.mkstemp(dir=tmp_dir) - storage.blueprint.upload(entry_id='blueprint_id', source=tmp_dir) + storage.service_template.upload(entry_id='service_template_id', source=tmp_dir) with pytest.raises(exceptions.StorageError): - storage.blueprint.read(entry_id='blueprint_id') + storage.service_template.read(entry_id='service_template_id')
