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
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'],
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:
# License for the specific language governing permissions and limitations
# under the License.
-
+import collections
import unittest
import mox
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):
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(
# 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",
},
"id": 131
}]
- })
+ ))
clients.OpenStackClients.nova('compute').AndReturn(self.fc)
nova_sgr.SecurityGroupRuleManager.delete(130).AndReturn(None)
clients.OpenStackClients.nova('compute').AndReturn(self.fc)
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(
# 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",
},
"id": 131
}]
- })
+ ))
clients.OpenStackClients.nova('compute').AndReturn(self.fc)
nova_sgr.SecurityGroupRuleManager.delete(130).AndRaise(
clients.novaclient.exceptions.NotFound('goneburger'))