Fix security groups (need to be accessed as attributes)
bug 1134193 Thanks Lukas Barton for the patch in the bug. Signed-off-by: Angus Salkeld <asalkeld@redhat.com> Change-Id: I448ba76fcf47d4e02775ff8eca38897eb399a3ccchanges/88/24288/2
parent
724a6fed27
commit
7149a817b0
|
@ -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:
|
||||
|
|
|
@ -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'))
|
||||
|
|
Loading…
Reference in New Issue