ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject [3/4] incubator-ariatosca git commit: ARIA-56 Implement ip property on node instance model
Date Sun, 08 Jan 2017 09:45:45 GMT
ARIA-56 Implement ip property on node instance model


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/3caf1771
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/3caf1771
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/3caf1771

Branch: refs/heads/ARIA-52-Support-order-management-in-relationships
Commit: 3caf17717a70041d878ad11b4e4234d362a7f000
Parents: fa221f7
Author: Dan Kilman <dank@gigaspaces.com>
Authored: Thu Jan 5 15:01:16 2017 +0200
Committer: Dan Kilman <dank@gigaspaces.com>
Committed: Thu Jan 5 16:51:25 2017 +0200

----------------------------------------------------------------------
 aria/.pylintrc               |  2 +-
 aria/storage/base_model.py   | 12 ++++++
 tests/storage/test_models.py | 80 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3caf1771/aria/.pylintrc
----------------------------------------------------------------------
diff --git a/aria/.pylintrc b/aria/.pylintrc
index 13a84fc..ee4d0ef 100644
--- a/aria/.pylintrc
+++ b/aria/.pylintrc
@@ -162,7 +162,7 @@ logging-modules=logging
 [BASIC]
 
 # Good variable names which should always be accepted, separated by a comma
-good-names=i,j,k,v,f,ex,e,_,id
+good-names=i,j,k,v,f,ex,e,_,id,ip
 
 # Bad variable names which should always be refused, separated by a comma
 bad-names=foo,bar,baz,toto,tutu,tata

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3caf1771/aria/storage/base_model.py
----------------------------------------------------------------------
diff --git a/aria/storage/base_model.py b/aria/storage/base_model.py
index 97c541c..418d3b6 100644
--- a/aria/storage/base_model.py
+++ b/aria/storage/base_model.py
@@ -495,6 +495,18 @@ class NodeInstanceBase(ModelMixin):
     def node_name(cls):
         return association_proxy('node', cls.name_column_name())
 
+    @property
+    def ip(self):
+        if not self.host_fk:
+            return None
+        host_node_instance = self.host
+        if 'ip' in host_node_instance.runtime_properties:  # pylint: disable=no-member
+            return host_node_instance.runtime_properties['ip']  # pylint: disable=no-member
+        host_node = host_node_instance.node  # pylint: disable=no-member
+        if 'ip' in host_node.properties:
+            return host_node.properties['ip']
+        return None
+
 
 class RelationshipInstanceBase(ModelMixin):
     """

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3caf1771/tests/storage/test_models.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_models.py b/tests/storage/test_models.py
index df81f95..2088676 100644
--- a/tests/storage/test_models.py
+++ b/tests/storage/test_models.py
@@ -664,6 +664,86 @@ class TestNodeInstance(object):
             assert node_instance.deployment == node_storage.deployment.list()[0]
 
 
+class TestNodeInstanceIP(object):
+
+    ip = '1.1.1.1'
+
+    def test_ip_on_none_hosted_node_instance(self, deployment_storage):
+        node = self._node(deployment_storage, ip='not considered')
+        node_instance = self._node_instance(deployment_storage, node,
+                                            is_host=False,
+                                            ip='not considered')
+        assert node_instance.ip is None
+
+    def test_property_ip_on_host_node_instance(self, deployment_storage):
+        node = self._node(deployment_storage, ip=self.ip)
+        node_instance = self._node_instance(deployment_storage, node,
+                                            is_host=True,
+                                            ip=None)
+        assert node_instance.ip == self.ip
+
+    def test_runtime_property_ip_on_host_node_instance(self, deployment_storage):
+        node = self._node(deployment_storage, ip='not considered')
+        node_instance = self._node_instance(deployment_storage, node,
+                                            is_host=True,
+                                            ip=self.ip)
+        assert node_instance.ip == self.ip
+
+    def test_no_ip_configured_on_host_node_instance(self, deployment_storage):
+        node = self._node(deployment_storage, ip=None)
+        node_instance = self._node_instance(deployment_storage, node,
+                                            is_host=True,
+                                            ip=None)
+        assert node_instance.ip is None
+
+    def test_runtime_property_on_hosted_node_instance(self, deployment_storage):
+        host_node = self._node(deployment_storage, ip=None)
+        host_node_instance = self._node_instance(deployment_storage, host_node,
+                                                 is_host=True,
+                                                 ip=self.ip)
+        node = self._node(deployment_storage, ip=None)
+        node_instance = self._node_instance(deployment_storage, node,
+                                            is_host=False,
+                                            ip=None,
+                                            host_fk=host_node_instance.id)
+        assert node_instance.ip == self.ip
+
+    def _node(self, storage, ip):
+        kwargs = dict(
+            name='node',
+            deploy_number_of_instances=1,
+            max_number_of_instances=1,
+            min_number_of_instances=1,
+            number_of_instances=1,
+            planned_number_of_instances=1,
+            properties={},
+            type='',
+            deployment=storage.deployment.list()[0]
+        )
+        if ip:
+            kwargs['properties']['ip'] = ip
+        node = Node(**kwargs)
+        storage.node.put(node)
+        return node
+
+    def _node_instance(self, storage, node, is_host, ip, host_fk=None):
+        kwargs = dict(
+            name='node_instance',
+            node=node,
+            runtime_properties={},
+            state=''
+        )
+        if ip:
+            kwargs['runtime_properties']['ip'] = ip
+        if is_host:
+            kwargs['host_fk'] = 1
+        elif host_fk:
+            kwargs['host_fk'] = host_fk
+        node_instance = NodeInstance(**kwargs)
+        storage.node_instance.put(node_instance)
+        return node_instance
+
+
 class TestRelationshipInstance(object):
     def test_relatiship_instance_model_creation(self, node_instances_storage):
         relationship = mock.models.get_relationship(


Mime
View raw message