]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Fix security groups (need to be accessed as attributes)
authorAngus Salkeld <asalkeld@redhat.com>
Wed, 13 Mar 2013 06:16:20 +0000 (17:16 +1100)
committerAngus Salkeld <asalkeld@redhat.com>
Wed, 13 Mar 2013 06:16:20 +0000 (17:16 +1100)
bug 1134193
Thanks Lukas Barton for the patch in the bug.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
Change-Id: I448ba76fcf47d4e02775ff8eca38897eb399a3cc

heat/engine/resources/security_group.py
heat/tests/test_security_group.py

index 0c55e7a9001d991dd277eee228d80b8a2a6dc268..c62dffadd0a1c35d93ba763dbcbe45dea94359ed 100644 (file)
@@ -38,7 +38,7 @@ class SecurityGroup(resource.Resource):
 
         groups = self.nova().security_groups.list()
         for group in groups:
-            if group['name'] == self.physical_resource_name():
+            if group.name == self.physical_resource_name():
                 sec = group
                 break
 
@@ -47,12 +47,12 @@ class SecurityGroup(resource.Resource):
                 self.physical_resource_name(),
                 self.properties['GroupDescription'])
 
-        self.resource_id_set(sec['id'])
+        self.resource_id_set(sec.id)
         if self.properties['SecurityGroupIngress']:
             rules_client = self.nova().security_group_rules
             for i in self.properties['SecurityGroupIngress']:
                 try:
-                    rule = rules_client.create(sec['id'],
+                    rule = rules_client.create(sec.id,
                                                i['IpProtocol'],
                                                i['FromPort'],
                                                i['ToPort'],
@@ -75,7 +75,7 @@ class SecurityGroup(resource.Resource):
             except clients.novaclient.exceptions.NotFound:
                 pass
             else:
-                for rule in sec['rules']:
+                for rule in sec.rules:
                     try:
                         self.nova().security_group_rules.delete(rule['id'])
                     except clients.novaclient.exceptions.NotFound:
index 0364e8c9d2bf886ec4cb378cd5efe1562a42fb10..bfa30dd4ac8aa84975d340db632c3cb42c8acbb3 100644 (file)
@@ -12,7 +12,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-
+import collections
 import unittest
 import mox
 
@@ -29,6 +29,15 @@ from novaclient.v1_1 import security_groups as nova_sg
 from novaclient.v1_1 import security_group_rules as nova_sgr
 
 
+NovaSG = collections.namedtuple('NovaSG',
+                                ' '.join([
+                                    'name',
+                                    'id',
+                                    'rules',
+                                    'description',
+                                ]))
+
+
 @attr(tag=['unit', 'resource'])
 @attr(speed='fast')
 class SecurityGroupTest(unittest.TestCase):
@@ -93,19 +102,20 @@ Resources:
     def test_security_group_nova(self):
         #create script
         clients.OpenStackClients.nova('compute').AndReturn(self.fc)
-        nova_sg.SecurityGroupManager.list().AndReturn([{
-            'id': 1,
-            'name': 'test',
-            'description': 'FAKE_SECURITY_GROUP'
-        }])
+        nova_sg.SecurityGroupManager.list().AndReturn([NovaSG(
+            id=1,
+            name='test',
+            description='FAKE_SECURITY_GROUP',
+            rules=[],
+        )])
         clients.OpenStackClients.nova('compute').AndReturn(self.fc)
         nova_sg.SecurityGroupManager.create(
             'test_stack.the_sg',
-            'HTTP and SSH access').AndReturn({
-                'id': 2,
-                'name': 'test_stack.the_sg',
-                'description': 'HTTP and SSH access'
-            })
+            'HTTP and SSH access').AndReturn(NovaSG(
+                id=2,
+                name='test_stack.the_sg',
+                description='HTTP and SSH access',
+                rules=[]))
 
         clients.OpenStackClients.nova('compute').AndReturn(self.fc)
         nova_sgr.SecurityGroupRuleManager.create(
@@ -115,11 +125,11 @@ Resources:
 
         # delete script
         clients.OpenStackClients.nova('compute').AndReturn(self.fc)
-        nova_sg.SecurityGroupManager.get(2).AndReturn({
-            'id': 2,
-            'name': 'test_stack.the_sg',
-            'description': 'HTTP and SSH access',
-            "rules": [{
+        nova_sg.SecurityGroupManager.get(2).AndReturn(NovaSG(
+            id=2,
+            name='test_stack.the_sg',
+            description='HTTP and SSH access',
+            rules=[{
                 "from_port": 22,
                 "group": {},
                 "ip_protocol": "tcp",
@@ -140,7 +150,7 @@ Resources:
                 },
                 "id": 131
             }]
-        })
+        ))
         clients.OpenStackClients.nova('compute').AndReturn(self.fc)
         nova_sgr.SecurityGroupRuleManager.delete(130).AndReturn(None)
         clients.OpenStackClients.nova('compute').AndReturn(self.fc)
@@ -162,11 +172,12 @@ Resources:
     def test_security_group_nova_exception(self):
         #create script
         clients.OpenStackClients.nova('compute').AndReturn(self.fc)
-        nova_sg.SecurityGroupManager.list().AndReturn([{
-            'id': 2,
-            'name': 'test_stack.the_sg',
-            'description': 'HTTP and SSH access'
-        }])
+        nova_sg.SecurityGroupManager.list().AndReturn([NovaSG(
+            id=2,
+            name='test_stack.the_sg',
+            description='HTTP and SSH access',
+            rules=[],
+        )])
 
         clients.OpenStackClients.nova('compute').AndReturn(self.fc)
         nova_sgr.SecurityGroupRuleManager.create(
@@ -180,11 +191,11 @@ Resources:
 
         # delete script
         clients.OpenStackClients.nova('compute').AndReturn(self.fc)
-        nova_sg.SecurityGroupManager.get(2).AndReturn({
-            'id': 2,
-            'name': 'test_stack.the_sg',
-            'description': 'HTTP and SSH access',
-            "rules": [{
+        nova_sg.SecurityGroupManager.get(2).AndReturn(NovaSG(
+            id=2,
+            name='test_stack.the_sg',
+            description='HTTP and SSH access',
+            rules=[{
                 "from_port": 22,
                 "group": {},
                 "ip_protocol": "tcp",
@@ -205,7 +216,7 @@ Resources:
                 },
                 "id": 131
             }]
-        })
+        ))
         clients.OpenStackClients.nova('compute').AndReturn(self.fc)
         nova_sgr.SecurityGroupRuleManager.delete(130).AndRaise(
             clients.novaclient.exceptions.NotFound('goneburger'))