From 8886590f30daf736ae30a95b3e4a77cb586d4f02 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 30 Mar 2015 07:32:25 -0700 Subject: [PATCH] Show 'reserved' status in os-fixed-ips Adds a new microversion to show the 'reserved' status on a FixedIP in the os-fixed-ips extension. Closes-Bug: #1249526 Implements blueprint show-reserved-status-in-os-fixed-ips-api Change-Id: Iadaae393fce0c78dbdfd3b02958ddfd6276edb94 --- .../versions/versions-get-resp.json | 2 +- .../os-fixed-ips/v2.4/fixedip-post-req.json | 3 +++ .../os-fixed-ips/v2.4/fixedips-get-resp.json | 9 ++++++++ nova/api/openstack/api_version_request.py | 3 ++- .../openstack/compute/plugins/v3/fixed_ips.py | 13 +++++++++++ .../openstack/rest_api_version_history.rst | 6 +++++ .../versions/versions-get-resp.json.tpl | 2 +- .../v2.4/fixedip-post-req.json.tpl | 3 +++ .../v2.4/fixedips-get-resp.json.tpl | 9 ++++++++ nova/tests/functional/v3/test_fixed_ips.py | 22 ++++++++++++++++--- .../compute/contrib/test_fixed_ips.py | 22 ++++++++++++++++++- .../api/openstack/compute/test_versions.py | 4 ++-- 12 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 doc/v3/api_samples/os-fixed-ips/v2.4/fixedip-post-req.json create mode 100644 doc/v3/api_samples/os-fixed-ips/v2.4/fixedips-get-resp.json create mode 100644 nova/tests/functional/v3/api_samples/os-fixed-ips/v2.4/fixedip-post-req.json.tpl create mode 100644 nova/tests/functional/v3/api_samples/os-fixed-ips/v2.4/fixedips-get-resp.json.tpl diff --git a/doc/api_samples/versions/versions-get-resp.json b/doc/api_samples/versions/versions-get-resp.json index 2b456fd73ab1..97d5f8cf3a2e 100644 --- a/doc/api_samples/versions/versions-get-resp.json +++ b/doc/api_samples/versions/versions-get-resp.json @@ -22,7 +22,7 @@ } ], "status": "CURRENT", - "version": "2.3", + "version": "2.4", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/doc/v3/api_samples/os-fixed-ips/v2.4/fixedip-post-req.json b/doc/v3/api_samples/os-fixed-ips/v2.4/fixedip-post-req.json new file mode 100644 index 000000000000..fd8ee48bf50d --- /dev/null +++ b/doc/v3/api_samples/os-fixed-ips/v2.4/fixedip-post-req.json @@ -0,0 +1,3 @@ +{ + "reserve": null +} \ No newline at end of file diff --git a/doc/v3/api_samples/os-fixed-ips/v2.4/fixedips-get-resp.json b/doc/v3/api_samples/os-fixed-ips/v2.4/fixedips-get-resp.json new file mode 100644 index 000000000000..62fe02c5de51 --- /dev/null +++ b/doc/v3/api_samples/os-fixed-ips/v2.4/fixedips-get-resp.json @@ -0,0 +1,9 @@ +{ + "fixed_ip": { + "address": "192.168.1.1", + "cidr": "192.168.1.0/24", + "host": "host", + "hostname": "openstack", + "reserved": false + } +} \ No newline at end of file diff --git a/nova/api/openstack/api_version_request.py b/nova/api/openstack/api_version_request.py index c167076ef318..8868980bf2a5 100644 --- a/nova/api/openstack/api_version_request.py +++ b/nova/api/openstack/api_version_request.py @@ -42,6 +42,7 @@ REST_API_VERSION_HISTORY = """REST API Version History: Fixes success status code for create/delete a keypair method * 2.3 - Exposes additional os-extended-server-attributes Exposes delete_on_termination for os-extended-volumes + * 2.4 - Exposes reserved field in os-fixed-ips. """ # The minimum and maximum versions of the API supported @@ -50,7 +51,7 @@ REST_API_VERSION_HISTORY = """REST API Version History: # Note(cyeoh): This only applies for the v2.1 API once microversions # support is fully merged. It does not affect the V2 API. _MIN_API_VERSION = "2.1" -_MAX_API_VERSION = "2.3" +_MAX_API_VERSION = "2.4" DEFAULT_API_VERSION = _MIN_API_VERSION diff --git a/nova/api/openstack/compute/plugins/v3/fixed_ips.py b/nova/api/openstack/compute/plugins/v3/fixed_ips.py index 3d710d881524..1938cceef5c3 100644 --- a/nova/api/openstack/compute/plugins/v3/fixed_ips.py +++ b/nova/api/openstack/compute/plugins/v3/fixed_ips.py @@ -28,6 +28,17 @@ authorize = extensions.os_compute_authorizer(ALIAS) class FixedIPController(wsgi.Controller): + + @wsgi.Controller.api_version('2.1', '2.3') + def _fill_reserved_status(self, req, fixed_ip, fixed_ip_info): + # NOTE(mriedem): To be backwards compatible, < 2.4 version does not + # show anything about reserved status. + pass + + @wsgi.Controller.api_version('2.4') # noqa + def _fill_reserved_status(self, req, fixed_ip, fixed_ip_info): + fixed_ip_info['fixed_ip']['reserved'] = fixed_ip.reserved + @extensions.expected_errors((400, 404)) def show(self, req, id): """Return data about the given fixed ip.""" @@ -58,6 +69,8 @@ class FixedIPController(wsgi.Controller): fixed_ip_info['fixed_ip']['hostname'] = None fixed_ip_info['fixed_ip']['host'] = None + self._fill_reserved_status(req, fixed_ip, fixed_ip_info) + return fixed_ip_info @wsgi.response(202) diff --git a/nova/api/openstack/rest_api_version_history.rst b/nova/api/openstack/rest_api_version_history.rst index fc47331672f9..4887534ebea8 100644 --- a/nova/api/openstack/rest_api_version_history.rst +++ b/nova/api/openstack/rest_api_version_history.rst @@ -46,3 +46,9 @@ user documentation. This change is required for the extraction of EC2 API into a standalone service. It exposes necessary properties absent in public nova APIs yet. Add info for Standalone EC2 API to cut access to Nova DB. + +- **2.4** + + Show the 'reserved' status on a FixedIP object in the os-fixed-ips API + extension. The extension allows one to reserve and unreserve a fixed IP + but the show method does not report the current status. diff --git a/nova/tests/functional/api_samples/versions/versions-get-resp.json.tpl b/nova/tests/functional/api_samples/versions/versions-get-resp.json.tpl index 2b456fd73ab1..97d5f8cf3a2e 100644 --- a/nova/tests/functional/api_samples/versions/versions-get-resp.json.tpl +++ b/nova/tests/functional/api_samples/versions/versions-get-resp.json.tpl @@ -22,7 +22,7 @@ } ], "status": "CURRENT", - "version": "2.3", + "version": "2.4", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/nova/tests/functional/v3/api_samples/os-fixed-ips/v2.4/fixedip-post-req.json.tpl b/nova/tests/functional/v3/api_samples/os-fixed-ips/v2.4/fixedip-post-req.json.tpl new file mode 100644 index 000000000000..4a962d98163e --- /dev/null +++ b/nova/tests/functional/v3/api_samples/os-fixed-ips/v2.4/fixedip-post-req.json.tpl @@ -0,0 +1,3 @@ +{ + "reserve": null +} diff --git a/nova/tests/functional/v3/api_samples/os-fixed-ips/v2.4/fixedips-get-resp.json.tpl b/nova/tests/functional/v3/api_samples/os-fixed-ips/v2.4/fixedips-get-resp.json.tpl new file mode 100644 index 000000000000..9bb340acef29 --- /dev/null +++ b/nova/tests/functional/v3/api_samples/os-fixed-ips/v2.4/fixedips-get-resp.json.tpl @@ -0,0 +1,9 @@ +{ + "fixed_ip": { + "cidr": "%(cidr)s", + "hostname": "%(hostname)s", + "host": "%(host)s", + "address": "%(address)s", + "reserved": %(reserved)s + } +} diff --git a/nova/tests/functional/v3/test_fixed_ips.py b/nova/tests/functional/v3/test_fixed_ips.py index 13f48156447c..ddf375504642 100644 --- a/nova/tests/functional/v3/test_fixed_ips.py +++ b/nova/tests/functional/v3/test_fixed_ips.py @@ -32,6 +32,8 @@ class FixedIpTest(test_servers.ServersSampleBase): # itself can be changed to 'v2' _api_version = 'v2' + request_api_version = None + def _get_flags(self): f = super(FixedIpTest, self)._get_flags() f['osapi_compute_extension'] = CONF.osapi_compute_extension[:] @@ -98,15 +100,29 @@ class FixedIpTest(test_servers.ServersSampleBase): def test_fixed_ip_reserve(self): # Reserve a Fixed IP. response = self._do_post('os-fixed-ips/192.168.1.1/action', - 'fixedip-post-req', {}) + 'fixedip-post-req', {}, + api_version=self.request_api_version) self.assertEqual(response.status_code, 202) self.assertEqual(response.content, "") - def test_get_fixed_ip(self): + def _test_get_fixed_ip(self, **kwargs): # Return data about the given fixed ip. - response = self._do_get('os-fixed-ips/192.168.1.1') + response = self._do_get('os-fixed-ips/192.168.1.1', + api_version=self.request_api_version) project = {'cidr': '192.168.1.0/24', 'hostname': 'openstack', 'host': 'host', 'address': '192.168.1.1'} + project.update(**kwargs) self._verify_response('fixedips-get-resp', project, response, 200) + + def test_get_fixed_ip(self): + self._test_get_fixed_ip() + + +class FixedIpV24Test(FixedIpTest): + _api_version = 'v3' + request_api_version = '2.4' + + def test_get_fixed_ip(self): + self._test_get_fixed_ip(reserved=False) diff --git a/nova/tests/unit/api/openstack/compute/contrib/test_fixed_ips.py b/nova/tests/unit/api/openstack/compute/contrib/test_fixed_ips.py index 8a71d7430a5d..f5f8681d389c 100644 --- a/nova/tests/unit/api/openstack/compute/contrib/test_fixed_ips.py +++ b/nova/tests/unit/api/openstack/compute/contrib/test_fixed_ips.py @@ -14,8 +14,10 @@ import webob +from nova.api.openstack import api_version_request from nova.api.openstack.compute.contrib import fixed_ips as fixed_ips_v2 from nova.api.openstack.compute.plugins.v3 import fixed_ips as fixed_ips_v21 +from nova.api.openstack import wsgi as os_wsgi from nova import context from nova import db from nova import exception @@ -119,6 +121,7 @@ class FixedIpTestV21(test.NoDBTestCase): fixed_ips = fixed_ips_v21 url = '/v2/fake/os-fixed-ips' + wsgi_api_version = os_wsgi.DEFAULT_API_VERSION def setUp(self): super(FixedIpTestV21, self).setUp() @@ -139,14 +142,20 @@ class FixedIpTestV21(test.NoDBTestCase): def _get_unreserve_action(self): return self.controller.unreserve + def _get_reserved_status(self, address): + return {} + def test_fixed_ips_get(self): req = fakes.HTTPRequest.blank('%s/192.168.1.1' % self.url) + req.api_version_request = api_version_request.APIVersionRequest( + self.wsgi_api_version) res_dict = self.controller.show(req, '192.168.1.1') response = {'fixed_ip': {'cidr': '192.168.1.0/24', 'hostname': None, 'host': None, 'address': '192.168.1.1'}} - self.assertEqual(response, res_dict) + response['fixed_ip'].update(self._get_reserved_status('192.168.1.1')) + self.assertEqual(response, res_dict, self.wsgi_api_version) def test_fixed_ips_get_bad_ip_fail(self): req = fakes.HTTPRequest.blank('%s/10.0.0.1' % self.url) @@ -242,3 +251,14 @@ class FixedIpTestV2(FixedIpTestV21): def _get_unreserve_action(self): return self.controller.action + + +class FixedIpTestV24(FixedIpTestV21): + + wsgi_api_version = '2.4' + + def _get_reserved_status(self, address): + for fixed_ip in fake_fixed_ips: + if address == fixed_ip['address']: + return {'reserved': fixed_ip['reserved']} + self.fail('Invalid address: %s' % address) diff --git a/nova/tests/unit/api/openstack/compute/test_versions.py b/nova/tests/unit/api/openstack/compute/test_versions.py index 9b235c782a7d..246acbc0384e 100644 --- a/nova/tests/unit/api/openstack/compute/test_versions.py +++ b/nova/tests/unit/api/openstack/compute/test_versions.py @@ -65,7 +65,7 @@ EXP_VERSIONS = { "v2.1": { "id": "v2.1", "status": "CURRENT", - "version": "2.3", + "version": "2.4", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z", "links": [ @@ -114,7 +114,7 @@ class VersionsTestV20(test.NoDBTestCase): { "id": "v2.1", "status": "CURRENT", - "version": "2.3", + "version": "2.4", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z", "links": [