Skip to content

Commit

Permalink
Add SecurityGroups API sample tests
Browse files Browse the repository at this point in the history
Add sample tests for adding and removing security groups
Fixes bug 1157222

Change-Id: Ib8450fcd6334b720a2199d52e07ae00f78aa6df0
  • Loading branch information
Giampaolo Lauria committed Apr 5, 2013
1 parent aa81b75 commit 4274902
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 10 deletions.
@@ -0,0 +1,5 @@
{
"addSecurityGroup" : {
"name" : "test"
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<addSecurityGroup>
<name>test</name>
</addSecurityGroup>
@@ -1,6 +1,6 @@
{
"security_group": {
"name": "json-test",
"name": "test",
"description": "description"
}
}
@@ -1,4 +1,4 @@
<security_group name="xml-test">
<security_group name="test">
<description>
description
</description>
Expand Down
@@ -0,0 +1,5 @@
{
"removeSecurityGroup" : {
"name" : "test"
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<removeSecurityGroup>
<name>test</name>
</removeSecurityGroup>
Expand Up @@ -2,7 +2,7 @@
"security_group": {
"description": "description",
"id": 2,
"name": "json-test",
"name": "test",
"rules": [],
"tenant_id": "openstack"
}
Expand Down
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<security_group xmlns="http://docs.openstack.org/compute/api/v1.1" tenant_id="openstack" id="2" name="xml-test">
<security_group xmlns="http://docs.openstack.org/compute/api/v1.1" tenant_id="openstack" id="2" name="test">
<description>
description
</description>
Expand Down
@@ -0,0 +1,5 @@
{
"addSecurityGroup" : {
"name" : "%(group_name)s"
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<addSecurityGroup>
<name>%(group_name)s</name>
</addSecurityGroup>
@@ -0,0 +1,5 @@
{
"removeSecurityGroup" : {
"name" : "%(group_name)s"
}
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<removeSecurityGroup>
<name>%(group_name)s</name>
</removeSecurityGroup>
44 changes: 38 additions & 6 deletions nova/tests/integrated/test_api_samples.py
Expand Up @@ -1090,14 +1090,27 @@ class SecurityGroupsSampleJsonTest(ServersSampleBase):
extension_name = "nova.api.openstack.compute.contrib" + \
".security_groups.Security_groups"

def test_security_group_create(self):
name = self.ctype + '-test'
subs = {
'group_name': name,
def _get_create_subs(self):
return {
'group_name': 'test',
"description": "description",
}
response = self._do_post('os-security-groups',
'security-group-post-req', subs)

def _create_security_group(self):
subs = self._get_create_subs()
return self._do_post('os-security-groups',
'security-group-post-req', subs)

def _add_group(self, uuid):
subs = {
'group_name': 'test'
}
return self._do_post('servers/%s/action' % uuid,
'security-group-add-post-req', subs)

def test_security_group_create(self):
response = self._create_security_group()
subs = self._get_create_subs()
self._verify_response('security-groups-create-resp', subs,
response, 200)

Expand All @@ -1124,6 +1137,25 @@ def test_security_groups_list_server(self):
return self._verify_response('server-security-groups-list-resp',
subs, response, 200)

def test_security_groups_add(self):
self._create_security_group()
uuid = self._post_server()
response = self._add_group(uuid)
self.assertEqual(response.status, 202)
self.assertEqual(response.read(), '')

def test_security_groups_remove(self):
self._create_security_group()
uuid = self._post_server()
self._add_group(uuid)
subs = {
'group_name': 'test'
}
response = self._do_post('servers/%s/action' % uuid,
'security-group-remove-post-req', subs)
self.assertEqual(response.status, 202)
self.assertEqual(response.read(), '')


class SecurityGroupsSampleXmlTest(SecurityGroupsSampleJsonTest):
ctype = 'xml'
Expand Down

0 comments on commit 4274902

Please sign in to comment.