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 87927200BD0 for ; Wed, 30 Nov 2016 14:58:35 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 861A3160B13; Wed, 30 Nov 2016 13:58:35 +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 B2CBD160B08 for ; Wed, 30 Nov 2016 14:58:33 +0100 (CET) Received: (qmail 49122 invoked by uid 500); 30 Nov 2016 13:58:33 -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 49111 invoked by uid 99); 30 Nov 2016 13:58:32 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Nov 2016 13:58:32 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 70EA1C13E4 for ; Wed, 30 Nov 2016 13:58:32 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -5.219 X-Spam-Level: X-Spam-Status: No, score=-5.219 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, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id n4emfubf6rUO for ; Wed, 30 Nov 2016 13:58:23 +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 08B7C5FC61 for ; Wed, 30 Nov 2016 13:58:21 +0000 (UTC) Received: (qmail 47534 invoked by uid 99); 30 Nov 2016 13:57:46 -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; Wed, 30 Nov 2016 13:57:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9B234DFCF8; Wed, 30 Nov 2016 13:57:46 +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: Wed, 30 Nov 2016 13:57:47 -0000 Message-Id: <4d3fbcb160f34cef83e269489a877ae7@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/3] incubator-ariatosca git commit: lynting archived-at: Wed, 30 Nov 2016 13:58:35 -0000 http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/aria/storage/models.py ---------------------------------------------------------------------- diff --git a/aria/storage/models.py b/aria/storage/models.py index 035e4e9..5a8d017 100644 --- a/aria/storage/models.py +++ b/aria/storage/models.py @@ -40,9 +40,19 @@ from datetime import datetime from uuid import uuid4 from aria.storage import structures +from .structures import ( + schema, + Integer, + Text, + DateTime, + Boolean, + Enum, + String, + PickleType, + Float, +) __all__ = ( - 'Model', 'Blueprint', 'Snapshot', 'Deployment', @@ -72,19 +82,25 @@ def uuid_generator(): class Blueprint(structures.SQLModelBase): + """ + Blueprint model representation. + """ __tablename__ = 'blueprints' - storage_id = structures.db.Column(structures.db.Integer, primary_key=True, autoincrement=True) - id = structures.db.Column(structures.db.Text, index=True) + storage_id = schema.Column(Integer, primary_key=True, autoincrement=True) + id = schema.Column(Text, index=True) - created_at = structures.db.Column(structures.db.DateTime, nullable=False, index=True) - main_file_name = structures.db.Column(structures.db.Text, nullable=False) - plan = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict), nullable=False) - updated_at = structures.db.Column(structures.db.DateTime) - description = structures.db.Column(structures.db.Text) + created_at = schema.Column(DateTime, nullable=False, index=True) + main_file_name = schema.Column(Text, nullable=False) + plan = schema.Column(structures.MutableDict.as_mutable(structures.Dict), nullable=False) + updated_at = schema.Column(DateTime) + description = schema.Column(Text) class Snapshot(structures.SQLModelBase): + """ + Snapshot model representation. + """ __tablename__ = 'snapshots' CREATED = 'created' @@ -95,15 +111,18 @@ class Snapshot(structures.SQLModelBase): STATES = [CREATED, FAILED, CREATING, UPLOADED] END_STATES = [CREATED, FAILED, UPLOADED] - storage_id = structures.db.Column(structures.db.Integer, primary_key=True, autoincrement=True) - id = structures.db.Column(structures.db.Text, index=True) + storage_id = schema.Column(Integer, primary_key=True, autoincrement=True) + id = schema.Column(Text, index=True) - created_at = structures.db.Column(structures.db.DateTime, nullable=False, index=True) - status = structures.db.Column(structures.db.Enum(*STATES, name='snapshot_status')) - error = structures.db.Column(structures.db.Text) + created_at = schema.Column(DateTime, nullable=False, index=True) + status = schema.Column(Enum(*STATES, name='snapshot_status')) + error = schema.Column(Text) class Deployment(structures.SQLModelBase): + """ + Deployment model representation. + """ __tablename__ = 'deployments' # See base class for an explanation on these properties @@ -118,20 +137,20 @@ class Deployment(structures.SQLModelBase): _private_fields = ['blueprint_storage_id'] - storage_id = structures.db.Column(structures.db.Integer, primary_key=True, autoincrement=True) - id = structures.db.Column(structures.db.Text, index=True) - - created_at = structures.db.Column(structures.db.DateTime, nullable=False, index=True) - description = structures.db.Column(structures.db.Text) - inputs = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - groups = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - permalink = structures.db.Column(structures.db.Text) - policy_triggers = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - policy_types = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - outputs = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - scaling_groups = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - updated_at = structures.db.Column(structures.db.DateTime) - workflows = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) + storage_id = schema.Column(Integer, primary_key=True, autoincrement=True) + id = schema.Column(Text, index=True) + + created_at = schema.Column(DateTime, nullable=False, index=True) + description = schema.Column(Text) + inputs = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + groups = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + permalink = schema.Column(Text) + policy_triggers = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + policy_types = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + outputs = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + scaling_groups = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + updated_at = schema.Column(DateTime) + workflows = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) blueprint_storage_id = structures.foreign_key(Blueprint) blueprint = structures.one_to_many_relationship( @@ -143,10 +162,17 @@ class Deployment(structures.SQLModelBase): @property def blueprint_id(self): + """ + Returns the blueprint is + :return: + """ return self.blueprint.id class Execution(structures.SQLModelBase): + """ + Execution model representation. + """ __tablename__ = 'executions' TERMINATED = 'terminated' @@ -177,17 +203,17 @@ class Execution(structures.SQLModelBase): _private_fields = ['deployment_storage_id'] - storage_id = structures.db.Column(structures.db.Integer, primary_key=True, autoincrement=True) - id = structures.db.Column(structures.db.Text, index=True) + storage_id = schema.Column(Integer, primary_key=True, autoincrement=True) + id = schema.Column(Text, index=True) - created_at = structures.db.Column(structures.db.DateTime, index=True) - started_at = structures.db.Column(structures.db.DateTime, nullable=True, index=True) - ended_at = structures.db.Column(structures.db.DateTime, nullable=True, index=True) - error = structures.db.Column(structures.db.Text, nullable=True) - is_system_workflow = structures.db.Column(structures.db.Boolean, nullable=False, default=False) - parameters = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - status = structures.db.Column(structures.db.Enum(*STATES, name='execution_status')) - workflow_id = structures.db.Column(structures.db.Text, nullable=False) + created_at = schema.Column(DateTime, index=True) + started_at = schema.Column(DateTime, nullable=True, index=True) + ended_at = schema.Column(DateTime, nullable=True, index=True) + error = schema.Column(Text, nullable=True) + is_system_workflow = schema.Column(Boolean, nullable=False, default=False) + parameters = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + status = schema.Column(Enum(*STATES, name='execution_status')) + workflow_id = schema.Column(Text, nullable=False) deployment_storage_id = structures.foreign_key(Deployment, nullable=True) deployment = structures.one_to_many_relationship( @@ -199,10 +225,18 @@ class Execution(structures.SQLModelBase): @property def deployment_id(self): + """ + Returns the deployment id + :return: + """ return self.deployment.id if self.deployment else None @property def blueprint_id(self): + """ + Returns the blueprint id + :return: + """ return self.deployment.blueprint_id if self.deployment else None def __str__(self): @@ -216,6 +250,9 @@ class Execution(structures.SQLModelBase): class DeploymentUpdate(structures.SQLModelBase): + """ + Deployment update model representation. + """ __tablename__ = 'deployment_updates' # See base class for an explanation on these properties @@ -233,16 +270,17 @@ class DeploymentUpdate(structures.SQLModelBase): _private_fields = ['execution_storage_id'] - storage_id = structures.db.Column(structures.db.Integer, primary_key=True, autoincrement=True) - id = structures.db.Column(structures.db.Text, index=True) + storage_id = schema.Column(Integer, primary_key=True, autoincrement=True) + id = schema.Column(Text, index=True) - created_at = structures.db.Column(structures.db.DateTime, nullable=False, index=True) - deployment_plan = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - deployment_update_node_instances = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - deployment_update_deployment = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - deployment_update_nodes = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - modified_entity_ids = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - state = structures.db.Column(structures.db.Text) + created_at = schema.Column(DateTime, nullable=False, index=True) + deployment_plan = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + deployment_update_node_instances = schema.Column(structures.MutableDict.as_mutable( + structures.Dict)) + deployment_update_deployment = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + deployment_update_nodes = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + modified_entity_ids = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + state = schema.Column(Text) execution_storage_id = structures.foreign_key(Execution, nullable=True) execution = structures.one_to_many_relationship( @@ -262,10 +300,18 @@ class DeploymentUpdate(structures.SQLModelBase): @property def execution_id(self): + """ + Returns the execution id + :return: + """ return self.execution.id if self.execution else None @property def deployment_id(self): + """ + Rerturns the deployment id + :return: + """ return self.deployment.id def to_dict(self, suppress_error=False): @@ -276,6 +322,9 @@ class DeploymentUpdate(structures.SQLModelBase): class DeploymentUpdateStep(structures.SQLModelBase): + """ + Deployment update step model representation. + """ __tablename__ = 'deployment_update_steps' # See base class for an explanation on these properties @@ -289,11 +338,11 @@ class DeploymentUpdateStep(structures.SQLModelBase): _private_fields = ['deployment_update_storage_id'] - id = structures.db.Column(structures.db.Integer, primary_key=True, autoincrement=True) + id = schema.Column(Integer, primary_key=True, autoincrement=True) - action = structures.db.Column(structures.db.Enum(*ACTION_TYPES, name='action_type')) - entity_id = structures.db.Column(structures.db.Text, nullable=False) - entity_type = structures.db.Column(structures.db.Enum(*ENTITY_TYPES, name='entity_type')) + action = schema.Column(Enum(*ACTION_TYPES, name='action_type')) + entity_id = schema.Column(Text, nullable=False) + entity_type = schema.Column(Enum(*ENTITY_TYPES, name='entity_type')) deployment_update_storage_id = structures.foreign_key(DeploymentUpdate) deployment_update = structures.one_to_many_relationship( @@ -305,10 +354,17 @@ class DeploymentUpdateStep(structures.SQLModelBase): @property def deployment_update_id(self): + """ + Returns the deployment update id + :return: + """ return self.deployment_update.id class DeploymentModification(structures.SQLModelBase): + """ + Deployment modification model representation. + """ __tablename__ = 'deployment_modifications' STARTED = 'started' @@ -329,16 +385,16 @@ class DeploymentModification(structures.SQLModelBase): _private_fields = ['deployment_storage_id'] - storage_id = structures.db.Column(structures.db.Integer, primary_key=True, autoincrement=True) - id = structures.db.Column(structures.db.Text, index=True) + storage_id = schema.Column(Integer, primary_key=True, autoincrement=True) + id = schema.Column(Text, index=True) - context = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - created_at = structures.db.Column(structures.db.DateTime, nullable=False, index=True) - ended_at = structures.db.Column(structures.db.DateTime, index=True) - modified_nodes = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - node_instances = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - status = structures.db.Column( - structures.db.Enum(*STATES, name='deployment_modification_status')) + context = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + created_at = schema.Column(DateTime, nullable=False, index=True) + ended_at = schema.Column(DateTime, index=True) + modified_nodes = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + node_instances = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + status = schema.Column( + Enum(*STATES, name='deployment_modification_status')) deployment_storage_id = structures.foreign_key(Deployment) deployment = structures.one_to_many_relationship( @@ -350,10 +406,17 @@ class DeploymentModification(structures.SQLModelBase): @property def deployment_id(self): + """ + Returns the deployment id + :return: + """ return self.deployment.id class Node(structures.SQLModelBase): + """ + Node model representation. + """ __tablename__ = 'nodes' # See base class for an explanation on these properties @@ -372,23 +435,23 @@ class Node(structures.SQLModelBase): _private_fields = ['deployment_storage_id'] - storage_id = structures.db.Column(structures.db.Integer, primary_key=True, autoincrement=True) - id = structures.db.Column(structures.db.Text, index=True) + storage_id = schema.Column(Integer, primary_key=True, autoincrement=True) + id = schema.Column(Text, index=True) - deploy_number_of_instances = structures.db.Column(structures.db.Integer, nullable=False) + deploy_number_of_instances = schema.Column(Integer, nullable=False) # TODO: This probably should be a foreign key, but there's no guarantee # in the code, currently, that the host will be created beforehand - host_id = structures.db.Column(structures.db.Text) - max_number_of_instances = structures.db.Column(structures.db.Integer, nullable=False) - min_number_of_instances = structures.db.Column(structures.db.Integer, nullable=False) - number_of_instances = structures.db.Column(structures.db.Integer, nullable=False) - planned_number_of_instances = structures.db.Column(structures.db.Integer, nullable=False) - plugins = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - plugins_to_install = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - properties = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - operations = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - type = structures.db.Column(structures.db.Text, nullable=False, index=True) - type_hierarchy = structures.db.Column(structures.db.PickleType) + host_id = schema.Column(Text) + max_number_of_instances = schema.Column(Integer, nullable=False) + min_number_of_instances = schema.Column(Integer, nullable=False) + number_of_instances = schema.Column(Integer, nullable=False) + planned_number_of_instances = schema.Column(Integer, nullable=False) + plugins = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + plugins_to_install = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + properties = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + operations = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + type = schema.Column(Text, nullable=False, index=True) + type_hierarchy = schema.Column(PickleType) deployment_storage_id = structures.foreign_key(Deployment) deployment = structures.one_to_many_relationship( @@ -400,14 +463,25 @@ class Node(structures.SQLModelBase): @property def deployment_id(self): + """ + Returns the deployment id + :return: + """ return self.deployment.id @property def blueprint_id(self): + """ + Returns the blueprint id + :return: + """ return self.deployment.blueprint_id class Relationship(structures.SQLModelBase): + """ + Relationship model representation. + """ __tablename__ = 'relationships' join_properties = { @@ -424,16 +498,16 @@ class Relationship(structures.SQLModelBase): _private_fields = ['relationship_storage_source_node_id', 'relationship_storage_target_node_id'] - storage_id = structures.db.Column(structures.db.Integer, primary_key=True, autoincrement=True) - id = structures.db.Column(structures.db.Text, index=True) + storage_id = schema.Column(Integer, primary_key=True, autoincrement=True) + id = schema.Column(Text, index=True) - source_interfaces = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - source_operations = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - target_interfaces = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - target_operations = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - type = structures.db.Column(structures.db.String) - type_hierarchy = structures.db.Column(structures.db.PickleType) # TODO: this should be list - properties = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) + source_interfaces = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + source_operations = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + target_interfaces = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + target_operations = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + type = schema.Column(String) + type_hierarchy = schema.Column(PickleType) # TODO: this should be list + properties = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) source_node_storage_id = structures.foreign_key(Node) target_node_storage_id = structures.foreign_key(Node) @@ -453,6 +527,9 @@ class Relationship(structures.SQLModelBase): class NodeInstance(structures.SQLModelBase): + """ + Node instance model representation. + """ __tablename__ = 'node_instances' # See base class for an explanation on these properties @@ -470,16 +547,16 @@ class NodeInstance(structures.SQLModelBase): _private_fields = ['node_storage_id', 'deployment_storage_id'] - storage_id = structures.db.Column(structures.db.Integer, primary_key=True, autoincrement=True) - id = structures.db.Column(structures.db.Text, index=True) + storage_id = schema.Column(Integer, primary_key=True, autoincrement=True) + id = schema.Column(Text, index=True) # TODO: This probably should be a foreign key, but there's no guarantee # in the code, currently, that the host will be created beforehand - host_id = structures.db.Column(structures.db.Text) - runtime_properties = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - scaling_groups = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - state = structures.db.Column(structures.db.Text, nullable=False) - version = structures.db.Column(structures.db.Integer, default=1) + host_id = schema.Column(Text) + runtime_properties = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + scaling_groups = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + state = schema.Column(Text, nullable=False) + version = schema.Column(Integer, default=1) node_storage_id = structures.foreign_key(Node) node = structures.one_to_many_relationship( @@ -491,6 +568,10 @@ class NodeInstance(structures.SQLModelBase): @property def node_id(self): + """ + Returns the node id + :return: + """ return self.node.id deployment_storage_id = structures.foreign_key(Deployment) @@ -503,6 +584,9 @@ class NodeInstance(structures.SQLModelBase): class RelationshipInstance(structures.SQLModelBase): + """ + Relationship instance model representation. + """ __tablename__ = 'relationship_instances' join_properties = { @@ -521,10 +605,10 @@ class RelationshipInstance(structures.SQLModelBase): 'source_node_instance_id', 'target_node_instance_id'] - storage_id = structures.db.Column(structures.db.Integer, primary_key=True, autoincrement=True) - id = structures.db.Column(structures.db.Text, index=True) + storage_id = schema.Column(Integer, primary_key=True, autoincrement=True) + id = schema.Column(Text, index=True) - type = structures.db.Column(structures.db.String) + type = schema.Column(String) source_node_instance_storage_id = structures.foreign_key(NodeInstance) source_node_instance = structures.one_to_many_relationship( @@ -550,31 +634,37 @@ class RelationshipInstance(structures.SQLModelBase): class ProviderContext(structures.SQLModelBase): + """ + Provider context model representation. + """ __tablename__ = 'provider_context' - id = structures.db.Column(structures.db.Text, primary_key=True) - name = structures.db.Column(structures.db.Text, nullable=False) - context = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict), nullable=False) + id = schema.Column(Text, primary_key=True) + name = schema.Column(Text, nullable=False) + context = schema.Column(structures.MutableDict.as_mutable(structures.Dict), nullable=False) class Plugin(structures.SQLModelBase): + """ + Plugin model representation. + """ __tablename__ = 'plugins' - storage_id = structures.db.Column(structures.db.Integer, primary_key=True, autoincrement=True) - id = structures.db.Column(structures.db.Text, index=True) + storage_id = schema.Column(Integer, primary_key=True, autoincrement=True) + id = schema.Column(Text, index=True) - archive_name = structures.db.Column(structures.db.Text, nullable=False, index=True) - distribution = structures.db.Column(structures.db.Text) - distribution_release = structures.db.Column(structures.db.Text) - distribution_version = structures.db.Column(structures.db.Text) - excluded_wheels = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - package_name = structures.db.Column(structures.db.Text, nullable=False, index=True) - package_source = structures.db.Column(structures.db.Text) - package_version = structures.db.Column(structures.db.Text) - supported_platform = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - supported_py_versions = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) - uploaded_at = structures.db.Column(structures.db.DateTime, nullable=False, index=True) - wheels = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict), nullable=False) + archive_name = schema.Column(Text, nullable=False, index=True) + distribution = schema.Column(Text) + distribution_release = schema.Column(Text) + distribution_version = schema.Column(Text) + excluded_wheels = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + package_name = schema.Column(Text, nullable=False, index=True) + package_source = schema.Column(Text) + package_version = schema.Column(Text) + supported_platform = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + supported_py_versions = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) + uploaded_at = schema.Column(DateTime, nullable=False, index=True) + wheels = schema.Column(structures.MutableDict.as_mutable(structures.Dict), nullable=False) class Task(structures.SQLModelBase): @@ -584,9 +674,7 @@ class Task(structures.SQLModelBase): __tablename__ = 'task' - _private_fields = ['node_instance_storage_id', - 'relationship_instance_storage_id'] - + _private_fields = ['node_instance_storage_id', 'relationship_instance_storage_id'] PENDING = 'pending' RETRYING = 'retrying' @@ -617,24 +705,23 @@ class Task(structures.SQLModelBase): INFINITE_RETRIES = -1 - id = structures.db.Column(structures.db.String, primary_key=True, default=uuid_generator) - status = structures.db.Column(structures.db.Enum(*STATES), - name='status', - default=PENDING) + id = schema.Column(String, primary_key=True, default=uuid_generator) + status = schema.Column(Enum(*STATES), name='status', default=PENDING) - execution_id = structures.db.Column(structures.db.String) - due_at = structures.db.Column(structures.db.DateTime, default=datetime.utcnow, nullable=True) - started_at = structures.db.Column(structures.db.DateTime, default=None, nullable=True) - ended_at = structures.db.Column(structures.db.DateTime, default=None, nullable=True) - max_attempts = structures.db.Column(structures.db.Integer, default=1) # , validation_func=_Validation.validate_max_attempts) - retry_count = structures.db.Column(structures.db.Integer, default=0) - retry_interval = structures.db.Column(structures.db.Float, default=0) - ignore_failure = structures.db.Column(structures.db.Boolean, default=False) + execution_id = schema.Column(String) + due_at = schema.Column(DateTime, default=datetime.utcnow, nullable=True) + started_at = schema.Column(DateTime, default=None, nullable=True) + ended_at = schema.Column(DateTime, default=None, nullable=True) + # , validation_func=_Validation.validate_max_attempts) + max_attempts = schema.Column(Integer, default=1) + retry_count = schema.Column(Integer, default=0) + retry_interval = schema.Column(Float, default=0) + ignore_failure = schema.Column(Boolean, default=False) # Operation specific fields - name = structures.db.Column(structures.db.String) - operation_mapping = structures.db.Column(structures.db.String) - inputs = structures.db.Column(structures.MutableDict.as_mutable(structures.Dict)) + name = schema.Column(String) + operation_mapping = schema.Column(String) + inputs = schema.Column(structures.MutableDict.as_mutable(structures.Dict)) node_instance_storage_id = structures.foreign_key(NodeInstance, nullable=True) relationship_instance_storage_id = structures.foreign_key(RelationshipInstance, nullable=True) @@ -655,10 +742,18 @@ class Task(structures.SQLModelBase): @property def actor_storage_id(self): + """ + Return the actor storage id of the task + :return: + """ return self.node_instance_storage_id or self.relationship_instance_storage_id @property def actor(self): + """ + Return the actor of the task + :return: + """ return self.node_instance or self.relationship_instance def __init__(self, actor, **kwargs): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/aria/storage/rapi/__init__.py ---------------------------------------------------------------------- diff --git a/aria/storage/rapi/__init__.py b/aria/storage/rapi/__init__.py new file mode 100644 index 0000000..2217281 --- /dev/null +++ b/aria/storage/rapi/__init__.py @@ -0,0 +1,18 @@ +# 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. +""" +A collection of RAPIs +""" +from .filesystem import FileSystemResourceAPI http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/aria/storage/rapi/filesystem.py ---------------------------------------------------------------------- diff --git a/aria/storage/rapi/filesystem.py b/aria/storage/rapi/filesystem.py new file mode 100644 index 0000000..7abbe07 --- /dev/null +++ b/aria/storage/rapi/filesystem.py @@ -0,0 +1,115 @@ +# 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. +""" +SQLalchemy based RAPI +""" +import os +import shutil +from distutils import dir_util +from functools import partial + +from aria.storage import StorageError +from aria.storage import api +from aria.storage import filesystem_api + + +class FileSystemResourceAPI(api.ResourceAPI, filesystem_api.FileSystemAPI): + """ + File system resource storage. + """ + + def __init__(self, directory, **kwargs): + """ + File system implementation for storage api. + :param str directory: root dir for storage. + """ + super(FileSystemResourceAPI, self).__init__(**kwargs) + self.directory = directory + self.base_path = os.path.join(self.directory, self.name) + self._join_path = partial(os.path.join, self.base_path) + + def __repr__(self): + return '{cls.__name__}(directory={self.directory})'.format( + cls=self.__class__, self=self) + + def create(self, **kwargs): + """ + Create directory in storage by path. + tries to create the root directory as well. + :param str name: path of file in storage. + """ + try: + os.makedirs(self.directory) + except (OSError, IOError): + pass + os.makedirs(self.base_path) + + def data(self, entry_id, path=None, **_): + """ + Retrieve the content of a file system storage resource. + + :param str entry_type: the type of the entry. + :param str entry_id: the id of the entry. + :param str path: a path to a specific resource. + :return: the content of the file + :rtype: bytes + """ + resource_relative_path = os.path.join(self.name, entry_id, path or '') + resource = os.path.join(self.directory, resource_relative_path) + if not os.path.exists(resource): + raise StorageError("Resource {0} does not exist".format(resource_relative_path)) + if not os.path.isfile(resource): + resources = os.listdir(resource) + if len(resources) != 1: + raise StorageError('No resource in path: {0}'.format(resource)) + resource = os.path.join(resource, resources[0]) + with open(resource, 'rb') as resource_file: + return resource_file.read() + + def download(self, entry_id, destination, path=None, **_): + """ + Download a specific file or dir from the file system resource storage. + + :param str entry_type: the name of the entry. + :param str entry_id: the id of the entry + :param str destination: the destination of the files. + :param str path: a path on the remote machine relative to the root of the entry. + """ + resource_relative_path = os.path.join(self.name, entry_id, path or '') + resource = os.path.join(self.directory, resource_relative_path) + if not os.path.exists(resource): + raise StorageError("Resource {0} does not exist".format(resource_relative_path)) + if os.path.isfile(resource): + shutil.copy2(resource, destination) + else: + dir_util.copy_tree(resource, destination) # pylint: disable=no-member + + def upload(self, entry_id, source, path=None, **_): + """ + Uploads a specific file or dir to the file system resource storage. + + :param str entry_type: the name of the entry. + :param str entry_id: the id of the entry + :param source: the source of the files to upload. + :param path: the destination of the file/s relative to the entry root dir. + """ + resource_directory = os.path.join(self.directory, self.name, entry_id) + if not os.path.exists(resource_directory): + os.makedirs(resource_directory) + destination = os.path.join(resource_directory, path or '') + if os.path.isfile(source): + shutil.copy2(source, destination) + else: + dir_util.copy_tree(source, destination) # pylint: disable=no-member http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/aria/storage/structures.py ---------------------------------------------------------------------- diff --git a/aria/storage/structures.py b/aria/storage/structures.py index f86a3cb..92434d6 100644 --- a/aria/storage/structures.py +++ b/aria/storage/structures.py @@ -31,6 +31,22 @@ import json import jsonpickle from flask_sqlalchemy import SQLAlchemy from sqlalchemy.ext.mutable import Mutable +# pylint: disable=unused-import +from sqlalchemy import ( + schema, + Integer, + Text, + DateTime, + Boolean, + Enum, + String, + PickleType, + Float, + TypeDecorator, + ForeignKey +) + + db = SQLAlchemy() @@ -61,7 +77,7 @@ def foreign_key( parent_table, id_col_name='storage_id', nullable=False, - column_type=db.Integer + column_type=Integer ): """Return a ForeignKey object with the relevant @@ -73,7 +89,7 @@ def foreign_key( """ return db.Column( column_type, - db.ForeignKey( + ForeignKey( '{0}.{1}'.format(parent_table.__tablename__, id_col_name), ondelete='CASCADE' ), @@ -132,7 +148,7 @@ def many_to_many_relationship( ) -# class UTCDateTime(db.TypeDecorator): +# class UTCDateTime(TypeDecorator): # # impl = db.DateTime # @@ -155,7 +171,10 @@ def many_to_many_relationship( # return value -class Dict(db.TypeDecorator): +class Dict(TypeDecorator): + """ + Dict represenation of type. + """ impl = db.VARCHAR @@ -171,6 +190,9 @@ class Dict(db.TypeDecorator): class MutableDict(Mutable, dict): + """ + Enables tracking for dict values. + """ @classmethod def coerce(cls, key, value): "Convert plain dictionaries to MutableDict." @@ -213,9 +235,17 @@ class SQLModelBase(db.Model): @property def to_dict(self): + """ + Convert the model into dict + :return: + """ return {field: getattr(self, field) for field in self.fields} def to_json(self): + """ + Convert the model into json. + :return: + """ return jsonpickle.encode(self.to_dict(), unpicklable=False) @classproperty @@ -226,10 +256,6 @@ class SQLModelBase(db.Model): """ return cls.__table__.columns.keys() - @property - def fields_dict(self): - return dict((field, getattr(self, field)) for field in self.fields) - def _get_unique_id(self): """A method to allow classes to override the default representation """ @@ -248,6 +274,3 @@ class SQLModelBase(db.Model): def __unicode__(self): return str(self) - - # def __eq__(self, other): - # return isinstance(other, self.__class__) and self.fields_dict == other.fields_dict http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/aria/storage/testing.py ---------------------------------------------------------------------- diff --git a/aria/storage/testing.py b/aria/storage/testing.py deleted file mode 100644 index bbe268e..0000000 --- a/aria/storage/testing.py +++ /dev/null @@ -1,19 +0,0 @@ -import flask -from aria.storage import db -from aria import storage - -def create_app(user, password, db_name, host='localhost', port=5432): - app = flask.Flask('app') - app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://' - # app.config['SQLALCHEMY_DATABASE_URI'] = \ - # 'postgresql://{user}:{password}@{host}:{port}/{db_name}'.\ - # format(user=user, password=password, db_name=db_name, host=host, port=port) - db.init_app(app) - db.app=app - with app.app_context(): - db.create_all() - -create_app('user', 'pass', 'tennis') -db.session.add(storage.models.ProviderContext(name='a', context={'a': 1})) -q = db.session.query(storage.models.Blueprint) -pass http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/tests/mock/context.py ---------------------------------------------------------------------- diff --git a/tests/mock/context.py b/tests/mock/context.py index 0a00829..54e877c 100644 --- a/tests/mock/context.py +++ b/tests/mock/context.py @@ -18,7 +18,7 @@ from flask import Flask from aria import application_model_storage from aria.orchestrator import context -from aria.storage.api_driver import SQLAlchemyModelAPI +from aria.storage.mapi import SQLAlchemyModelAPI from tests import storage from . import models @@ -32,7 +32,7 @@ def simple(**kwargs): blueprint = model_storage.blueprint.get(models.BLUEPRINT_ID) deployment = models.get_deployment(blueprint) model_storage.deployment.store(deployment) - + ################################################################################# # Creating a simple deployment with node -> node as a graph http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/tests/orchestrator/context/test_operation.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_operation.py b/tests/orchestrator/context/test_operation.py index 229d48d..4f52577 100644 --- a/tests/orchestrator/context/test_operation.py +++ b/tests/orchestrator/context/test_operation.py @@ -40,9 +40,7 @@ def ctx(): @pytest.fixture def executor(): - from aria.orchestrator.workflows.executor import blocking - result = blocking.CurrentThreadBlockingExecutor() - # result = thread.ThreadExecutor() + result = thread.ThreadExecutor() try: yield result finally: @@ -97,7 +95,8 @@ def test_relationship_operation_task_execution(ctx, executor): 'operation': op_path(my_operation, module_path=__name__) } ctx.model.relationship.update(relationship) - relationship_instance = ctx.model.relationship_instance.get(mock.models.RELATIONSHIP_INSTANCE_ID) + relationship_instance = ctx.model.relationship_instance.get( + mock.models.RELATIONSHIP_INSTANCE_ID) dependency_node = ctx.model.node.get(mock.models.DEPENDENCY_NODE_ID) dependency_node_instance = ctx.model.node_instance.get(mock.models.DEPENDENCY_NODE_INSTANCE_ID) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/tests/orchestrator/context/test_toolbelt.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_toolbelt.py b/tests/orchestrator/context/test_toolbelt.py index 452e236..dc06c4e 100644 --- a/tests/orchestrator/context/test_toolbelt.py +++ b/tests/orchestrator/context/test_toolbelt.py @@ -38,9 +38,7 @@ def workflow_context(): @pytest.fixture def executor(): - from aria.orchestrator.workflows.executor import blocking - result = blocking.CurrentThreadBlockingExecutor() - # result = thread.ThreadExecutor() + result = thread.ThreadExecutor() try: yield result finally: @@ -49,11 +47,14 @@ def executor(): def _get_elements(workflow_context): dependency_node = workflow_context.model.node.get(mock.models.DEPENDENCY_NODE_ID) - dependency_node_instance = workflow_context.model.node_instance.get(mock.models.DEPENDENCY_NODE_INSTANCE_ID) + dependency_node_instance = workflow_context.model.node_instance.get( + mock.models.DEPENDENCY_NODE_INSTANCE_ID) dependent_node = workflow_context.model.node.get(mock.models.DEPENDENT_NODE_ID) - dependent_node_instance = workflow_context.model.node_instance.get(mock.models.DEPENDENT_NODE_INSTANCE_ID) + dependent_node_instance = workflow_context.model.node_instance.get( + mock.models.DEPENDENT_NODE_INSTANCE_ID) relationship = workflow_context.model.relationship.get(mock.models.RELATIONSHIP_ID) - relationship_instance = workflow_context.model.relationship_instance.get(mock.models.RELATIONSHIP_INSTANCE_ID) + relationship_instance = workflow_context.model.relationship_instance.get( + mock.models.RELATIONSHIP_INSTANCE_ID) return dependency_node, dependency_node_instance, dependent_node, dependent_node_instance, \ relationship, relationship_instance @@ -107,8 +108,8 @@ def test_dependent_node_instances(workflow_context, executor): execute(workflow_func=basic_workflow, workflow_context=workflow_context, executor=executor) - assert list(global_test_holder.get('dependent_node_instances', [])) == \ - list([dependent_node_instance]) + assert global_test_holder.get('dependent_node_instances')[0].to_dict == \ + dependent_node_instance.to_dict def test_relationship_tool_belt(workflow_context, executor): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/tests/orchestrator/context/test_workflow.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/context/test_workflow.py b/tests/orchestrator/context/test_workflow.py index 19d83e0..f385b93 100644 --- a/tests/orchestrator/context/test_workflow.py +++ b/tests/orchestrator/context/test_workflow.py @@ -20,7 +20,7 @@ from flask import Flask from aria import application_model_storage from aria.orchestrator import context -from aria.storage.api_driver.sql import SQLAlchemyModelAPI +from aria.storage.mapi.sql import SQLAlchemyModelAPI from tests.mock import models from tests import storage as test_storage http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/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 2171303..4da42c1 100644 --- a/tests/orchestrator/workflows/api/test_task.py +++ b/tests/orchestrator/workflows/api/test_task.py @@ -71,7 +71,8 @@ class TestOperationTask(object): op_details = {'operation': True} relationship = ctx.model.relationship.get(mock.models.RELATIONSHIP_ID) relationship.source_operations[operation_name] = op_details - relationship_instance = ctx.model.relationship_instance.get(mock.models.RELATIONSHIP_INSTANCE_ID) + relationship_instance = ctx.model.relationship_instance.get( + mock.models.RELATIONSHIP_INSTANCE_ID) inputs = {'inputs': True} max_attempts = 10 retry_interval = 10 http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/tests/orchestrator/workflows/core/test_engine.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/core/test_engine.py b/tests/orchestrator/workflows/core/test_engine.py index bca38a0..b58460a 100644 --- a/tests/orchestrator/workflows/core/test_engine.py +++ b/tests/orchestrator/workflows/core/test_engine.py @@ -14,7 +14,8 @@ # limitations under the License. import time -import threading +# TODO: fix together with the test +# import threading from datetime import datetime import pytest @@ -220,6 +221,7 @@ class TestEngine(BaseTest): class TestCancel(BaseTest): + # TODO: what is up with this test? # def test_cancel_started_execution(self, workflow_context, executor): # number_of_tasks = 100 # http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/tests/storage/__init__.py ---------------------------------------------------------------------- diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py index f4d2705..5cbdc6a 100644 --- a/tests/storage/__init__.py +++ b/tests/storage/__init__.py @@ -13,10 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from aria import storage - -from tempfile import mkdtemp from shutil import rmtree +from tempfile import mkdtemp + +from aria import storage class TestFileSystem(object): @@ -30,4 +30,4 @@ class TestFileSystem(object): def drop_tables(): if storage.structures.db.app is not None: - storage.structures.db.drop_all(bind=None) \ No newline at end of file + storage.structures.db.drop_all(bind=None) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/tests/storage/test_model_storage.py ---------------------------------------------------------------------- diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py index 165f638..9723afc 100644 --- a/tests/storage/test_model_storage.py +++ b/tests/storage/test_model_storage.py @@ -25,7 +25,7 @@ from aria.storage import ( ModelStorage, models, exceptions, - api_driver as storage_api, + mapi as storage_api, ) from . import drop_tables @@ -67,10 +67,10 @@ def test_model_storage(api, api_params): pc = models.ProviderContext(context={}, name='context_name', id='id1') storage.provider_context.store(pc) - assert storage.provider_context.get('id1').fields_dict == pc.fields_dict + assert storage.provider_context.get('id1') == pc - assert [pc_from_storage.to_dict for pc_from_storage in storage.provider_context.iter()] == [pc.to_dict] - assert [pc_from_storage.to_dict for pc_from_storage in storage.provider_context] == [pc.to_dict] + assert [pc_from_storage for pc_from_storage in storage.provider_context.iter()] == [pc] + assert [pc_from_storage for pc_from_storage in storage.provider_context] == [pc] new_context = {'update_key': 0} pc.context = new_context @@ -90,9 +90,9 @@ def test_storage_driver(api, api_params): pc = models.ProviderContext(context={}, name='context_name', id='id2') storage.registered['provider_context'].store(entry=pc) - assert storage.registered['provider_context'].get(entry_id='id2').fields_dict == pc.fields_dict + assert storage.registered['provider_context'].get(entry_id='id2') == pc - assert next(i.fields_dict for i in storage.registered['provider_context'].iter()) == pc.fields_dict + assert next(i for i in storage.registered['provider_context'].iter()) == pc assert [i for i in storage.provider_context] == [pc] storage.registered['provider_context'].delete('id2') @@ -115,65 +115,3 @@ def test_application_storage_factory(api, api_params): assert storage.deployment_modification assert storage.execution assert storage.provider_context - -# def test_storage_pointers(): -# class PointedModel(Model): -# id = Field() -# -# class PointingModel(Model): -# id = Field() -# pointing_field = PointerField(type=PointedModel) -# -# storage = ModelStorage(InMemoryModelDriver(), model_classes=[PointingModel]) -# storage.setup() -# -# assert storage.pointed_model -# assert storage.pointing_model -# -# pointed_model = PointedModel(id='pointed_id') -# -# pointing_model = PointingModel(id='pointing_id', pointing_field=pointed_model) -# storage.pointing_model.store(pointing_model) -# -# assert storage.pointed_model.get('pointed_id') == pointed_model -# assert storage.pointing_model.get('pointing_id') == pointing_model -# -# storage.pointing_model.delete('pointing_id') -# -# with pytest.raises(StorageError): -# assert storage.pointed_model.get('pointed_id') -# assert storage.pointing_model.get('pointing_id') - - -# def test_storage_iter_pointers(): -# class PointedIterModel(models.Model): -# id = structures.Field() -# -# class PointingIterModel(models.Model): -# id = models.Field() -# pointing_field = structures.IterPointerField(type=PointedIterModel) -# -# storage = ModelStorage(InMemoryModelDriver(), model_classes=[PointingIterModel]) -# storage.setup() -# -# assert storage.pointed_iter_model -# assert storage.pointing_iter_model -# -# pointed_iter_model1 = PointedIterModel(id='pointed_id1') -# pointed_iter_model2 = PointedIterModel(id='pointed_id2') -# -# pointing_iter_model = PointingIterModel( -# id='pointing_id', -# pointing_field=[pointed_iter_model1, pointed_iter_model2]) -# storage.pointing_iter_model.store(pointing_iter_model) -# -# assert storage.pointed_iter_model.get('pointed_id1') == pointed_iter_model1 -# assert storage.pointed_iter_model.get('pointed_id2') == pointed_iter_model2 -# assert storage.pointing_iter_model.get('pointing_id') == pointing_iter_model -# -# storage.pointing_iter_model.delete('pointing_id') -# -# with pytest.raises(StorageError): -# assert storage.pointed_iter_model.get('pointed_id1') -# assert storage.pointed_iter_model.get('pointed_id2') -# assert storage.pointing_iter_model.get('pointing_id') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8f0fe26/tests/storage/test_resource_storage.py ---------------------------------------------------------------------- diff --git a/tests/storage/test_resource_storage.py b/tests/storage/test_resource_storage.py index 42e69f5..06d0810 100644 --- a/tests/storage/test_resource_storage.py +++ b/tests/storage/test_resource_storage.py @@ -19,7 +19,7 @@ import tempfile import pytest from aria.storage import ( - api_driver, + rapi, exceptions, ResourceStorage ) @@ -44,16 +44,16 @@ class TestResourceStorage(TestFileSystem): storage.blueprint.upload(entry_id=id, source=tmp_dir) def _create_storage(self): - return ResourceStorage(api_driver.FileSystemResourceAPI, + return ResourceStorage(rapi.FileSystemResourceAPI, api_params=dict(directory=self.path)) def test_name(self): - api = api_driver.FileSystemResourceAPI - storage = ResourceStorage(api_driver.FileSystemResourceAPI, + api = rapi.FileSystemResourceAPI + storage = ResourceStorage(rapi.FileSystemResourceAPI, items=['blueprint'], api_params=dict(directory=self.path)) assert repr(storage) == 'ResourceStorage(api={api})'.format(api=api) - assert 'directory={resource_dir}'.format(api=api, resource_dir=self.path) in \ + assert 'directory={resource_dir}'.format(resource_dir=self.path) in \ repr(storage.registered['blueprint']) def test_create(self): @@ -62,7 +62,7 @@ class TestResourceStorage(TestFileSystem): assert os.path.exists(os.path.join(self.path, 'blueprint')) def test_upload_file(self): - storage = ResourceStorage(api_driver.FileSystemResourceAPI, + storage = ResourceStorage(rapi.FileSystemResourceAPI, api_params=dict(directory=self.path)) self._create(storage) tmpfile_path = tempfile.mkstemp(suffix=self.__class__.__name__, dir=self.path)[1]