Skip to content

Commit

Permalink
Change v3 extended_status to v2.1
Browse files Browse the repository at this point in the history
This patch changes v3 extended_status API to v2.1 and makes v2
unit tests share between v2 and v2.1.
Revert v3 changes back to v2.
os-extended-status:* -> OS-EXT-STS:*
The differences between v2 and v3 are descibed on the wiki page
https://wiki.openstack.org/wiki/NovaAPIv2tov3.
Partially implements blueprint v2-on-v3-api

Change-Id: Ieefca1d0e8da831830f43cc83eb50bc7e7f4a10c
  • Loading branch information
Eli Qiao committed Aug 26, 2014
1 parent dab9a09 commit f9930a8
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 168 deletions.
8 changes: 4 additions & 4 deletions doc/v3/api_samples/all_extensions/server-get-resp.json
Expand Up @@ -53,10 +53,10 @@
"OS-EXT-SRV-ATTR:host": "b8b357f7100d4391828f2177c922ef93",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
"os-extended-status:locked_by": null,
"os-extended-status:power_state": 1,
"os-extended-status:task_state": null,
"os-extended-status:vm_state": "active",
"OS-EXT-STS:locked_by": null,
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"os-extended-volumes:volumes_attached": [],
"os-pci:pci_devices": [
{
Expand Down
8 changes: 4 additions & 4 deletions doc/v3/api_samples/all_extensions/servers-details-resp.json
Expand Up @@ -54,10 +54,10 @@
"OS-EXT-SRV-ATTR:host": "c3f14e9812ad496baf92ccfb3c61e15f",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
"os-extended-status:locked_by": null,
"os-extended-status:power_state": 1,
"os-extended-status:task_state": null,
"os-extended-status:vm_state": "active",
"OS-EXT-STS:locked_by": null,
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"os-extended-volumes:volumes_attached": [],
"os-pci:pci_devices": [
{
Expand Down
8 changes: 4 additions & 4 deletions doc/v3/api_samples/os-extended-status/server-get-resp.json
Expand Up @@ -46,10 +46,10 @@
"My Server Name": "Apache1"
},
"name": "new-server-test",
"os-extended-status:locked_by": null,
"os-extended-status:power_state": 1,
"os-extended-status:task_state": null,
"os-extended-status:vm_state": "active",
"OS-EXT-STS:locked_by": null,
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"progress": 0,
"status": "ACTIVE",
"tenant_id": "openstack",
Expand Down
Expand Up @@ -47,10 +47,10 @@
"My Server Name": "Apache1"
},
"name": "new-server-test",
"os-extended-status:locked_by": null,
"os-extended-status:power_state": 1,
"os-extended-status:task_state": null,
"os-extended-status:vm_state": "active",
"OS-EXT-STS:locked_by": null,
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"progress": 0,
"status": "ACTIVE",
"tenant_id": "openstack",
Expand Down
2 changes: 1 addition & 1 deletion nova/api/openstack/compute/plugins/v3/extended_status.py
Expand Up @@ -29,7 +29,7 @@ def __init__(self, *args, **kwargs):

def _extend_server(self, server, instance):
for state in ['task_state', 'vm_state', 'power_state', 'locked_by']:
key = "%s:%s" % (ExtendedStatus.alias, state)
key = "%s:%s" % ('OS-EXT-STS', state)
server[key] = instance[state]

@wsgi.extends
Expand Down
51 changes: 35 additions & 16 deletions nova/tests/api/openstack/compute/contrib/test_extended_status.py
Expand Up @@ -52,28 +52,31 @@ def fake_compute_get_all(*args, **kwargs):
db_list, fields)


class ExtendedStatusTest(test.TestCase):
class ExtendedStatusTestV21(test.TestCase):
content_type = 'application/json'
prefix = 'OS-EXT-STS:'
fake_url = '/v3'

def _set_flags(self):
pass

def _make_request(self, url):
req = webob.Request.blank(url)
req.headers['Accept'] = self.content_type
res = req.get_response(fakes.wsgi_app_v3(
init_only=('servers',
'os-extended-status')))
return res

def setUp(self):
super(ExtendedStatusTest, self).setUp()
super(ExtendedStatusTestV21, self).setUp()
fakes.stub_out_nw_api(self.stubs)
self.stubs.Set(compute.api.API, 'get', fake_compute_get)
self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
self.flags(
osapi_compute_extension=[
'nova.api.openstack.compute.contrib.select_extensions'],
osapi_compute_ext_list=['Extended_status'])
self._set_flags()
return_server = fakes.fake_instance_get()
self.stubs.Set(db, 'instance_get_by_uuid', return_server)

def _make_request(self, url):
req = webob.Request.blank(url)
req.headers['Accept'] = self.content_type
res = req.get_response(fakes.wsgi_app(init_only=('servers',)))
return res

def _get_server(self, body):
return jsonutils.loads(body).get('server')

Expand All @@ -87,7 +90,7 @@ def assertServerStates(self, server, vm_state, power_state, task_state):
self.assertEqual(server.get('%stask_state' % self.prefix), task_state)

def test_show(self):
url = '/v2/fake/servers/%s' % UUID3
url = self.fake_url + '/servers/%s' % UUID3
res = self._make_request(url)

self.assertEqual(res.status_int, 200)
Expand All @@ -97,7 +100,7 @@ def test_show(self):
task_state='kayaking')

def test_detail(self):
url = '/v2/fake/servers/detail'
url = self.fake_url + '/servers/detail'
res = self._make_request(url)

self.assertEqual(res.status_int, 200)
Expand All @@ -113,13 +116,29 @@ def fake_compute_get(*args, **kwargs):
raise exception.InstanceNotFound(instance_id='fake')

self.stubs.Set(compute.api.API, 'get', fake_compute_get)
url = '/v2/fake/servers/70f6db34-de8d-4fbd-aafb-4065bdfa6115'
url = self.fake_url + '/servers/70f6db34-de8d-4fbd-aafb-4065bdfa6115'
res = self._make_request(url)

self.assertEqual(res.status_int, 404)


class ExtendedStatusXmlTest(ExtendedStatusTest):
class ExtendedStatusTestV2(ExtendedStatusTestV21):
fake_url = '/v2/fake'

def _set_flags(self):
self.flags(
osapi_compute_extension=[
'nova.api.openstack.compute.contrib.select_extensions'],
osapi_compute_ext_list=['Extended_status'])

def _make_request(self, url):
req = webob.Request.blank(url)
req.headers['Accept'] = self.content_type
res = req.get_response(fakes.wsgi_app(init_only=('servers',)))
return res


class ExtendedStatusXmlTest(ExtendedStatusTestV2):
content_type = 'application/xml'
prefix = '{%s}' % extended_status.Extended_status.namespace

Expand Down
119 changes: 0 additions & 119 deletions nova/tests/api/openstack/compute/plugins/v3/test_extended_status.py

This file was deleted.

Expand Up @@ -53,10 +53,10 @@
"OS-EXT-SRV-ATTR:host": "%(compute_host)s",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "%(hypervisor_hostname)s",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
"os-extended-status:locked_by": null,
"os-extended-status:power_state": 1,
"os-extended-status:task_state": null,
"os-extended-status:vm_state": "active",
"OS-EXT-STS:locked_by": null,
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"os-extended-volumes:volumes_attached": [],
"os-pci:pci_devices": [{"id": 1}],
"os-server-usage:launched_at": "%(strtime)s",
Expand Down
Expand Up @@ -54,10 +54,10 @@
"OS-EXT-SRV-ATTR:host": "%(compute_host)s",
"OS-EXT-SRV-ATTR:hypervisor_hostname": "%(hypervisor_hostname)s",
"OS-EXT-SRV-ATTR:instance_name": "instance-00000001",
"os-extended-status:locked_by": null,
"os-extended-status:power_state": 1,
"os-extended-status:task_state": null,
"os-extended-status:vm_state": "active",
"OS-EXT-STS:locked_by": null,
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"os-extended-volumes:volumes_attached": [],
"os-pci:pci_devices": [{"id": 1}],
"os-server-usage:launched_at": "%(strtime)s",
Expand Down
@@ -1,9 +1,9 @@
{
"server": {
"os-extended-status:task_state": null,
"os-extended-status:vm_state": "active",
"os-extended-status:power_state": 1,
"os-extended-status:locked_by": null,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:locked_by": null,
"updated": "%(isotime)s",
"created": "%(isotime)s",
"addresses": {
Expand Down
@@ -1,10 +1,10 @@
{
"servers": [
{
"os-extended-status:task_state": null,
"os-extended-status:vm_state": "active",
"os-extended-status:power_state": 1,
"os-extended-status:locked_by": null,
"OS-EXT-STS:task_state": null,
"OS-EXT-STS:vm_state": "active",
"OS-EXT-STS:power_state": 1,
"OS-EXT-STS:locked_by": null,
"updated": "%(isotime)s",
"created": "%(isotime)s",
"addresses": {
Expand Down

0 comments on commit f9930a8

Please sign in to comment.