Add SecurityGroups API sample tests

Add sample tests for adding and removing security groups
Fixes bug 1157222

Change-Id: Ib8450fcd6334b720a2199d52e07ae00f78aa6df0
This commit is contained in:
Giampaolo Lauria 2013-03-20 15:53:24 -04:00
parent aa81b75528
commit 42749024b6
13 changed files with 78 additions and 10 deletions

View File

@ -0,0 +1,5 @@
{
"addSecurityGroup" : {
"name" : "test"
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<addSecurityGroup>
<name>test</name>
</addSecurityGroup>

View File

@ -1,6 +1,6 @@
{
"security_group": {
"name": "json-test",
"name": "test",
"description": "description"
}
}

View File

@ -1,4 +1,4 @@
<security_group name="xml-test">
<security_group name="test">
<description>
description
</description>

View File

@ -0,0 +1,5 @@
{
"removeSecurityGroup" : {
"name" : "test"
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<removeSecurityGroup>
<name>test</name>
</removeSecurityGroup>

View File

@ -2,7 +2,7 @@
"security_group": {
"description": "description",
"id": 2,
"name": "json-test",
"name": "test",
"rules": [],
"tenant_id": "openstack"
}

View File

@ -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>

View File

@ -0,0 +1,5 @@
{
"addSecurityGroup" : {
"name" : "%(group_name)s"
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<addSecurityGroup>
<name>%(group_name)s</name>
</addSecurityGroup>

View File

@ -0,0 +1,5 @@
{
"removeSecurityGroup" : {
"name" : "%(group_name)s"
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<removeSecurityGroup>
<name>%(group_name)s</name>
</removeSecurityGroup>

View File

@ -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)
@ -1124,6 +1137,25 @@ class SecurityGroupsSampleJsonTest(ServersSampleBase):
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'