Adds API Sample tests for FlavorAccess extension.

Partially implements blueprint nova-api-samples
Fixes bug 1091741

Change-Id: I65bb9e508996417bdcdc9ec87997df5373c06bad
This commit is contained in:
Giampaolo Lauria 2013-02-07 22:22:47 -05:00
parent dbdd6945d7
commit de56abd4b1
37 changed files with 561 additions and 1 deletions

View File

@ -0,0 +1,5 @@
{
"addTenantAccess": {
"tenant": "fake_tenant"
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<addTenantAccess>
<tenant>fake_tenant</tenant>
</addTenantAccess>

View File

@ -0,0 +1,8 @@
{
"flavor_access": [
{
"flavor_id": "10",
"tenant_id": "fake_tenant"
}
]
}

View File

@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavor_access>
<access tenant_id="fake_tenant" flavor_id="10"/>
</flavor_access>

View File

@ -0,0 +1,10 @@
{
"flavor": {
"name": "test_flavor",
"ram": 1024,
"vcpus": 2,
"disk": 10,
"id": "10",
"os-flavor-access:is_public": false
}
}

View File

@ -0,0 +1,10 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavor xmlns="http://docs.openstack.org/compute/api/v1.1"
xmlns:os-flavor-access="http://docs.openstack.org/compute/ext/flavor_access/api/v1.1"
name="test_flavor"
ram="1024"
vcpus="2"
disk="10"
id="10"
os-flavor-access:is_public="False"
/>

View File

@ -0,0 +1,20 @@
{
"flavor": {
"disk": 10,
"id": "10",
"links": [
{
"href": "http://openstack.example.com/v2/openstack/flavors/10",
"rel": "self"
},
{
"href": "http://openstack.example.com/openstack/flavors/10",
"rel": "bookmark"
}
],
"name": "test_flavor",
"os-flavor-access:is_public": false,
"ram": 1024,
"vcpus": 2
}
}

View File

@ -0,0 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavor xmlns:os-flavor-access="http://docs.openstack.org/compute/ext/flavor_access/api/v2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" disk="10" vcpus="2" ram="1024" name="test_flavor" id="10" os-flavor-access:is_public="False">
<atom:link href="http://openstack.example.com/v2/openstack/flavors/10" rel="self"/>
<atom:link href="http://openstack.example.com/openstack/flavors/10" rel="bookmark"/>
</flavor>

View File

@ -0,0 +1,94 @@
{
"flavors": [
{
"disk": 0,
"id": "1",
"links": [
{
"href": "http://openstack.example.com/v2/openstack/flavors/1",
"rel": "self"
},
{
"href": "http://openstack.example.com/openstack/flavors/1",
"rel": "bookmark"
}
],
"name": "m1.tiny",
"os-flavor-access:is_public": true,
"ram": 512,
"vcpus": 1
},
{
"disk": 20,
"id": "2",
"links": [
{
"href": "http://openstack.example.com/v2/openstack/flavors/2",
"rel": "self"
},
{
"href": "http://openstack.example.com/openstack/flavors/2",
"rel": "bookmark"
}
],
"name": "m1.small",
"os-flavor-access:is_public": true,
"ram": 2048,
"vcpus": 1
},
{
"disk": 40,
"id": "3",
"links": [
{
"href": "http://openstack.example.com/v2/openstack/flavors/3",
"rel": "self"
},
{
"href": "http://openstack.example.com/openstack/flavors/3",
"rel": "bookmark"
}
],
"name": "m1.medium",
"os-flavor-access:is_public": true,
"ram": 4096,
"vcpus": 2
},
{
"disk": 80,
"id": "4",
"links": [
{
"href": "http://openstack.example.com/v2/openstack/flavors/4",
"rel": "self"
},
{
"href": "http://openstack.example.com/openstack/flavors/4",
"rel": "bookmark"
}
],
"name": "m1.large",
"os-flavor-access:is_public": true,
"ram": 8192,
"vcpus": 4
},
{
"disk": 160,
"id": "5",
"links": [
{
"href": "http://openstack.example.com/v2/openstack/flavors/5",
"rel": "self"
},
{
"href": "http://openstack.example.com/openstack/flavors/5",
"rel": "bookmark"
}
],
"name": "m1.xlarge",
"os-flavor-access:is_public": true,
"ram": 16384,
"vcpus": 8
}
]
}

View File

@ -0,0 +1,23 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavors xmlns:os-flavor-access="http://docs.openstack.org/compute/ext/flavor_access/api/v2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1">
<flavor disk="0" vcpus="1" ram="512" name="m1.tiny" id="1" os-flavor-access:is_public="True">
<atom:link href="http://openstack.example.com/v2/openstack/flavors/1" rel="self"/>
<atom:link href="http://openstack.example.com/openstack/flavors/1" rel="bookmark"/>
</flavor>
<flavor disk="20" vcpus="1" ram="2048" name="m1.small" id="2" os-flavor-access:is_public="True">
<atom:link href="http://openstack.example.com/v2/openstack/flavors/2" rel="self"/>
<atom:link href="http://openstack.example.com/openstack/flavors/2" rel="bookmark"/>
</flavor>
<flavor disk="40" vcpus="2" ram="4096" name="m1.medium" id="3" os-flavor-access:is_public="True">
<atom:link href="http://openstack.example.com/v2/openstack/flavors/3" rel="self"/>
<atom:link href="http://openstack.example.com/openstack/flavors/3" rel="bookmark"/>
</flavor>
<flavor disk="80" vcpus="4" ram="8192" name="m1.large" id="4" os-flavor-access:is_public="True">
<atom:link href="http://openstack.example.com/v2/openstack/flavors/4" rel="self"/>
<atom:link href="http://openstack.example.com/openstack/flavors/4" rel="bookmark"/>
</flavor>
<flavor disk="160" vcpus="8" ram="16384" name="m1.xlarge" id="5" os-flavor-access:is_public="True">
<atom:link href="http://openstack.example.com/v2/openstack/flavors/5" rel="self"/>
<atom:link href="http://openstack.example.com/openstack/flavors/5" rel="bookmark"/>
</flavor>
</flavors>

View File

@ -0,0 +1,8 @@
{
"flavor_access": [
{
"flavor_id": "10",
"tenant_id": "fake_tenant"
}
]
}

View File

@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavor_access>
<access tenant_id="fake_tenant" flavor_id="10"/>
</flavor_access>

View File

@ -0,0 +1,5 @@
{
"removeTenantAccess": {
"tenant": "fake_tenant"
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<removeTenantAccess>
<tenant>fake_tenant</tenant>
</removeTenantAccess>

View File

@ -0,0 +1,3 @@
{
"flavor_access": []
}

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavor_access/>

View File

@ -0,0 +1,20 @@
{
"flavor": {
"disk": 0,
"id": "1",
"links": [
{
"href": "http://openstack.example.com/v2/openstack/flavors/1",
"rel": "self"
},
{
"href": "http://openstack.example.com/openstack/flavors/1",
"rel": "bookmark"
}
],
"name": "m1.tiny",
"os-flavor-access:is_public": true,
"ram": 512,
"vcpus": 1
}
}

View File

@ -0,0 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavor xmlns:os-flavor-access="http://docs.openstack.org/compute/ext/flavor_access/api/v2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" disk="0" vcpus="1" ram="512" name="m1.tiny" id="1" os-flavor-access:is_public="True">
<atom:link href="http://openstack.example.com/v2/openstack/flavors/1" rel="self"/>
<atom:link href="http://openstack.example.com/openstack/flavors/1" rel="bookmark"/>
</flavor>

View File

@ -0,0 +1,5 @@
{
"addTenantAccess": {
"tenant": "%(tenant_id)s"
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<addTenantAccess>
<tenant>%(tenant_id)s</tenant>
</addTenantAccess>

View File

@ -0,0 +1,8 @@
{
"flavor_access": [
{
"flavor_id": "%(flavor_id)s",
"tenant_id": "%(tenant_id)s"
}
]
}

View File

@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavor_access>
<access tenant_id="%(tenant_id)s" flavor_id="%(flavor_id)s"/>
</flavor_access>

View File

@ -0,0 +1,10 @@
{
"flavor": {
"name": "%(flavor_name)s",
"ram": 1024,
"vcpus": 2,
"disk": 10,
"id": "%(flavor_id)s",
"os-flavor-access:is_public": false
}
}

View File

@ -0,0 +1,10 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavor xmlns="http://docs.openstack.org/compute/api/v1.1"
xmlns:os-flavor-access="http://docs.openstack.org/compute/ext/flavor_access/api/v1.1"
name="%(flavor_name)s"
ram="1024"
vcpus="2"
disk="10"
id="%(flavor_id)s"
os-flavor-access:is_public="False"
/>

View File

@ -0,0 +1,20 @@
{
"flavor": {
"disk": 10,
"id": "%(flavor_id)s",
"links": [
{
"href": "%(host)s/v2/openstack/flavors/%(flavor_id)s",
"rel": "self"
},
{
"href": "%(host)s/openstack/flavors/%(flavor_id)s",
"rel": "bookmark"
}
],
"name": "%(flavor_name)s",
"os-flavor-access:is_public": false,
"ram": 1024,
"vcpus": 2
}
}

View File

@ -0,0 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavor xmlns:os-flavor-access="http://docs.openstack.org/compute/ext/flavor_access/api/v2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" disk="10" vcpus="2" ram="1024" name="%(flavor_name)s" id="%(flavor_id)s" os-flavor-access:is_public="False">
<atom:link href="%(host)s/v2/openstack/flavors/%(flavor_id)s" rel="self"/>
<atom:link href="%(host)s/openstack/flavors/%(flavor_id)s" rel="bookmark"/>
</flavor>

View File

@ -0,0 +1,94 @@
{
"flavors": [
{
"disk": 0,
"id": "1",
"links": [
{
"href": "%(host)s/v2/openstack/flavors/1",
"rel": "self"
},
{
"href": "%(host)s/openstack/flavors/1",
"rel": "bookmark"
}
],
"name": "m1.tiny",
"os-flavor-access:is_public": true,
"ram": 512,
"vcpus": 1
},
{
"disk": 20,
"id": "2",
"links": [
{
"href": "%(host)s/v2/openstack/flavors/2",
"rel": "self"
},
{
"href": "%(host)s/openstack/flavors/2",
"rel": "bookmark"
}
],
"name": "m1.small",
"os-flavor-access:is_public": true,
"ram": 2048,
"vcpus": 1
},
{
"disk": 40,
"id": "3",
"links": [
{
"href": "%(host)s/v2/openstack/flavors/3",
"rel": "self"
},
{
"href": "%(host)s/openstack/flavors/3",
"rel": "bookmark"
}
],
"name": "m1.medium",
"os-flavor-access:is_public": true,
"ram": 4096,
"vcpus": 2
},
{
"disk": 80,
"id": "4",
"links": [
{
"href": "%(host)s/v2/openstack/flavors/4",
"rel": "self"
},
{
"href": "%(host)s/openstack/flavors/4",
"rel": "bookmark"
}
],
"name": "m1.large",
"os-flavor-access:is_public": true,
"ram": 8192,
"vcpus": 4
},
{
"disk": 160,
"id": "5",
"links": [
{
"href": "%(host)s/v2/openstack/flavors/5",
"rel": "self"
},
{
"href": "%(host)s/openstack/flavors/5",
"rel": "bookmark"
}
],
"name": "m1.xlarge",
"os-flavor-access:is_public": true,
"ram": 16384,
"vcpus": 8
}
]
}

View File

@ -0,0 +1,23 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavors xmlns:os-flavor-access="http://docs.openstack.org/compute/ext/flavor_access/api/v2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1">
<flavor disk="0" vcpus="1" ram="512" name="m1.tiny" id="1" os-flavor-access:is_public="True">
<atom:link href="%(host)s/v2/openstack/flavors/1" rel="self"/>
<atom:link href="%(host)s/openstack/flavors/1" rel="bookmark"/>
</flavor>
<flavor disk="20" vcpus="1" ram="2048" name="m1.small" id="2" os-flavor-access:is_public="True">
<atom:link href="%(host)s/v2/openstack/flavors/2" rel="self"/>
<atom:link href="%(host)s/openstack/flavors/2" rel="bookmark"/>
</flavor>
<flavor disk="40" vcpus="2" ram="4096" name="m1.medium" id="3" os-flavor-access:is_public="True">
<atom:link href="%(host)s/v2/openstack/flavors/3" rel="self"/>
<atom:link href="%(host)s/openstack/flavors/3" rel="bookmark"/>
</flavor>
<flavor disk="80" vcpus="4" ram="8192" name="m1.large" id="4" os-flavor-access:is_public="True">
<atom:link href="%(host)s/v2/openstack/flavors/4" rel="self"/>
<atom:link href="%(host)s/openstack/flavors/4" rel="bookmark"/>
</flavor>
<flavor disk="160" vcpus="8" ram="16384" name="m1.xlarge" id="5" os-flavor-access:is_public="True">
<atom:link href="%(host)s/v2/openstack/flavors/5" rel="self"/>
<atom:link href="%(host)s/openstack/flavors/5" rel="bookmark"/>
</flavor>
</flavors>

View File

@ -0,0 +1,8 @@
{
"flavor_access": [
{
"flavor_id": "%(flavor_id)s",
"tenant_id": "fake_tenant"
}
]
}

View File

@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavor_access>
<access tenant_id="%(tenant_id)s" flavor_id="%(flavor_id)s"/>
</flavor_access>

View File

@ -0,0 +1,5 @@
{
"removeTenantAccess": {
"tenant": "%(tenant_id)s"
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<removeTenantAccess>
<tenant>%(tenant_id)s</tenant>
</removeTenantAccess>

View File

@ -0,0 +1,3 @@
{
"flavor_access": []
}

View File

@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavor_access/>

View File

@ -0,0 +1,20 @@
{
"flavor": {
"disk": 0,
"id": "%(flavor_id)s",
"links": [
{
"href": "%(host)s/v2/openstack/flavors/%(flavor_id)s",
"rel": "self"
},
{
"href": "%(host)s/openstack/flavors/%(flavor_id)s",
"rel": "bookmark"
}
],
"name": "m1.tiny",
"os-flavor-access:is_public": true,
"ram": 512,
"vcpus": 1
}
}

View File

@ -0,0 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<flavor xmlns:os-flavor-access="http://docs.openstack.org/compute/ext/flavor_access/api/v2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" disk="0" vcpus="1" ram="512" name="m1.tiny" id="%(flavor_id)s" os-flavor-access:is_public="True">
<atom:link href="%(host)s/v2/openstack/flavors/%(flavor_id)s" rel="self"/>
<atom:link href="%(host)s/openstack/flavors/%(flavor_id)s" rel="bookmark"/>
</flavor>

View File

@ -383,7 +383,6 @@ class ApiSamplesTrap(ApiSampleTestBase):
do_not_approve_additions = []
do_not_approve_additions.append('os-config-drive')
do_not_approve_additions.append('os-create-server-ext')
do_not_approve_additions.append('os-flavor-access')
do_not_approve_additions.append('os-hypervisors')
do_not_approve_additions.append('os-volumes')
@ -3173,3 +3172,96 @@ class InstanceActionsSampleJsonTest(ApiSampleTestBase):
class InstanceActionsSampleXmlTest(InstanceActionsSampleJsonTest):
ctype = 'xml'
class FlavorAccessSampleJsonTests(ApiSampleTestBase):
extension_name = ("nova.api.openstack.compute.contrib.flavor_access."
"Flavor_access")
def _get_flags(self):
f = super(FlavorAccessSampleJsonTests, self)._get_flags()
f['osapi_compute_extension'] = CONF.osapi_compute_extension[:]
# FlavorAccess extension also needs Flavormanage to be loaded.
f['osapi_compute_extension'].append(
'nova.api.openstack.compute.contrib.flavormanage.Flavormanage')
return f
def _add_tenant(self):
subs = {
'tenant_id': 'fake_tenant',
'flavor_id': 10
}
response = self._do_post('flavors/10/action',
'flavor-access-add-tenant-req',
subs)
self.assertEqual(response.status, 200)
return self._verify_response('flavor-access-add-tenant-resp',
subs, response)
def _create_flavor(self):
subs = {
'flavor_id': 10,
'flavor_name': 'test_flavor'
}
response = self._do_post("flavors",
"flavor-access-create-req",
subs)
self.assertEqual(response.status, 200)
subs.update(self._get_regexes())
return self._verify_response("flavor-access-create-resp",
subs, response)
def test_flavor_access_create(self):
self._create_flavor()
def test_flavor_access_detail(self):
response = self._do_get('flavors/detail')
self.assertEqual(response.status, 200)
subs = self._get_regexes()
return self._verify_response('flavor-access-detail-resp',
subs, response)
def test_flavor_access_list(self):
self._create_flavor()
self._add_tenant()
flavor_id = 10
response = self._do_get('flavors/%s/os-flavor-access' % flavor_id)
self.assertEqual(response.status, 200)
subs = {
'flavor_id': flavor_id,
'tenant_id': 'fake_tenant',
}
return self._verify_response('flavor-access-list-resp',
subs, response)
def test_flavor_access_show(self):
flavor_id = 1
response = self._do_get('flavors/%s' % flavor_id)
self.assertEqual(response.status, 200)
subs = {
'flavor_id': flavor_id
}
subs.update(self._get_regexes())
return self._verify_response('flavor-access-show-resp',
subs, response)
def test_flavor_access_add_tenant(self):
self._create_flavor()
response = self._add_tenant()
def test_flavor_access_remove_tenant(self):
self._create_flavor()
self._add_tenant()
subs = {
'tenant_id': 'fake_tenant',
}
response = self._do_post('flavors/10/action',
"flavor-access-remove-tenant-req",
subs)
self.assertEqual(response.status, 200)
return self._verify_response('flavor-access-remove-tenant-resp',
{}, response)
class FlavorAccessSampleXmlTests(FlavorAccessSampleJsonTests):
ctype = "xml"