From 45d1e3c1fa8f7921aeb1b04a2452ae10ccc6aa06 Mon Sep 17 00:00:00 2001 From: ghanshyam Date: Thu, 27 Aug 2015 16:50:44 +0900 Subject: [PATCH] Expose VIF net-id attribute in os-virtual-interfaces Adds a new microversion to show virtual interface 'net-id' in virtual interface list. DocImpact - See nova/api/openstack/rest_api_version_history.rst for details APIImpact Implements blueprint add-vif-net-id-in-vif-list Change-Id: Ic8b26df8d7e69bd71d23dfbc983fa3449c16fa7d --- .../v2.12/vifs-list-resp.json | 9 +++++ .../versions/v21-version-get-resp.json | 2 +- .../versions/versions-get-resp.json | 2 +- nova/api/openstack/api_version_request.py | 3 +- .../openstack/compute/virtual_interfaces.py | 8 +++-- .../openstack/rest_api_version_history.rst | 7 ++++ .../v2.12/vifs-list-resp.json.tpl | 9 +++++ .../versions/v21-version-get-resp.json.tpl | 2 +- .../versions/versions-get-resp.json.tpl | 2 +- .../test_virtual_interfaces.py | 10 +++++- .../api/openstack/compute/test_versions.py | 4 +-- .../compute/test_virtual_interfaces.py | 35 ++++++++++++++----- 12 files changed, 75 insertions(+), 18 deletions(-) create mode 100644 doc/api_samples/os-virtual-interfaces/v2.12/vifs-list-resp.json create mode 100644 nova/tests/functional/api_sample_tests/api_samples/os-virtual-interfaces/v2.12/vifs-list-resp.json.tpl diff --git a/doc/api_samples/os-virtual-interfaces/v2.12/vifs-list-resp.json b/doc/api_samples/os-virtual-interfaces/v2.12/vifs-list-resp.json new file mode 100644 index 000000000000..fe7f28c93393 --- /dev/null +++ b/doc/api_samples/os-virtual-interfaces/v2.12/vifs-list-resp.json @@ -0,0 +1,9 @@ +{ + "virtual_interfaces": [ + { + "id": "cec8b9bb-5d22-4104-b3c8-4c35db3210a6", + "mac_address": "fa:16:3e:3c:ce:6f", + "net_id": "cec8b9bb-5d22-4104-b3c8-4c35db3210a7" + } + ] +} diff --git a/doc/api_samples/versions/v21-version-get-resp.json b/doc/api_samples/versions/v21-version-get-resp.json index e3fb1bfa03a0..8516b3ea6033 100644 --- a/doc/api_samples/versions/v21-version-get-resp.json +++ b/doc/api_samples/versions/v21-version-get-resp.json @@ -19,7 +19,7 @@ } ], "status": "CURRENT", - "version": "2.11", + "version": "2.12", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/doc/api_samples/versions/versions-get-resp.json b/doc/api_samples/versions/versions-get-resp.json index 13123a6117dd..198ea986e6b9 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.11", + "version": "2.12", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/nova/api/openstack/api_version_request.py b/nova/api/openstack/api_version_request.py index 450b2717fd86..2e353b3b13f4 100644 --- a/nova/api/openstack/api_version_request.py +++ b/nova/api/openstack/api_version_request.py @@ -52,6 +52,7 @@ REST_API_VERSION_HISTORY = """REST API Version History: * 2.10 - Allow admins to query, create and delete keypairs owned by any user. * 2.11 - Exposes forced_down attribute for os-services + * 2.12 - Exposes VIF net-id in os-virtual-interfaces """ # The minimum and maximum versions of the API supported @@ -60,7 +61,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.11" +_MAX_API_VERSION = "2.12" DEFAULT_API_VERSION = _MIN_API_VERSION diff --git a/nova/api/openstack/compute/virtual_interfaces.py b/nova/api/openstack/compute/virtual_interfaces.py index ac8015d2f0b9..b8390a4464e9 100644 --- a/nova/api/openstack/compute/virtual_interfaces.py +++ b/nova/api/openstack/compute/virtual_interfaces.py @@ -15,6 +15,7 @@ """The virtual interfaces extension.""" +from nova.api.openstack import api_version_request from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi @@ -26,11 +27,14 @@ ALIAS = 'os-virtual-interfaces' authorize = extensions.os_compute_authorizer(ALIAS) -def _translate_vif_summary_view(_context, vif): +def _translate_vif_summary_view(req, _context, vif): """Maps keys for VIF summary view.""" d = {} d['id'] = vif.uuid d['mac_address'] = vif.address + if (req.api_version_request >= + api_version_request.APIVersionRequest("2.12")): + d['net_id'] = vif.net_uuid return d @@ -51,7 +55,7 @@ class ServerVirtualInterfaceController(wsgi.Controller): vifs = self.network_api.get_vifs_by_instance(context, instance) limited_list = common.limited(vifs, req) - res = [entity_maker(context, vif) for vif in limited_list] + res = [entity_maker(req, context, vif) for vif in limited_list] return {'virtual_interfaces': res} @extensions.expected_errors((404)) diff --git a/nova/api/openstack/rest_api_version_history.rst b/nova/api/openstack/rest_api_version_history.rst index ed0f4c9f42fe..c958c36d4a7e 100644 --- a/nova/api/openstack/rest_api_version_history.rst +++ b/nova/api/openstack/rest_api_version_history.rst @@ -123,3 +123,10 @@ user documentation. Exposed attribute ``forced_down`` for ``os-services``. Added ability to change the ``forced_down`` attribute by calling an update. + +2.12 +---- + + Exposes VIF ``net-id`` attribute in ``os-virtual-interfaces``. + User will be able to get Virtual Interfaces ``net-id`` in Virtual Interfaces + list and can determine in which network a Virtual Interface is plugged into. diff --git a/nova/tests/functional/api_sample_tests/api_samples/os-virtual-interfaces/v2.12/vifs-list-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/os-virtual-interfaces/v2.12/vifs-list-resp.json.tpl new file mode 100644 index 000000000000..86c839f215b1 --- /dev/null +++ b/nova/tests/functional/api_sample_tests/api_samples/os-virtual-interfaces/v2.12/vifs-list-resp.json.tpl @@ -0,0 +1,9 @@ +{ + "virtual_interfaces": [ + { + "id": "%(id)s", + "mac_address": "%(mac_addr)s", + "net_id": "%(id)s" + } + ] +} diff --git a/nova/tests/functional/api_sample_tests/api_samples/versions/v21-version-get-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/versions/v21-version-get-resp.json.tpl index f81ed473f086..ad5183985065 100644 --- a/nova/tests/functional/api_sample_tests/api_samples/versions/v21-version-get-resp.json.tpl +++ b/nova/tests/functional/api_sample_tests/api_samples/versions/v21-version-get-resp.json.tpl @@ -19,7 +19,7 @@ } ], "status": "CURRENT", - "version": "2.11", + "version": "2.12", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/nova/tests/functional/api_sample_tests/api_samples/versions/versions-get-resp.json.tpl b/nova/tests/functional/api_sample_tests/api_samples/versions/versions-get-resp.json.tpl index 13123a6117dd..198ea986e6b9 100644 --- a/nova/tests/functional/api_sample_tests/api_samples/versions/versions-get-resp.json.tpl +++ b/nova/tests/functional/api_sample_tests/api_samples/versions/versions-get-resp.json.tpl @@ -22,7 +22,7 @@ } ], "status": "CURRENT", - "version": "2.11", + "version": "2.12", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z" } diff --git a/nova/tests/functional/api_sample_tests/test_virtual_interfaces.py b/nova/tests/functional/api_sample_tests/test_virtual_interfaces.py index 4ea467128288..0aba0243bdb2 100644 --- a/nova/tests/functional/api_sample_tests/test_virtual_interfaces.py +++ b/nova/tests/functional/api_sample_tests/test_virtual_interfaces.py @@ -44,6 +44,14 @@ class VirtualInterfacesJsonTest(test_servers.ServersSampleBase): subs = self._get_regexes() subs['mac_addr'] = '(?:[a-f0-9]{2}:){5}[a-f0-9]{2}' template = 'vifs-list-resp' - if self._test == 'v2': + if (hasattr(self, '_test') and self._test == 'v2'): template = 'vifs-list-resp-v2' self._verify_response(template, subs, response, 200) + + +class VirtualInterfacesJsonV212Test(VirtualInterfacesJsonTest): + request_api_version = '2.12' + # NOTE(gmann): microversion tests do not need to run for v2 API + # so defining scenarios only for v2.12 which will run the original tests + # by appending '(v2_12)' in test_id. + scenarios = [('v2_12', {})] diff --git a/nova/tests/unit/api/openstack/compute/test_versions.py b/nova/tests/unit/api/openstack/compute/test_versions.py index 7df0715ebca2..53678e44bc54 100644 --- a/nova/tests/unit/api/openstack/compute/test_versions.py +++ b/nova/tests/unit/api/openstack/compute/test_versions.py @@ -66,7 +66,7 @@ EXP_VERSIONS = { "v2.1": { "id": "v2.1", "status": "CURRENT", - "version": "2.11", + "version": "2.12", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z", "links": [ @@ -128,7 +128,7 @@ class VersionsTestV20(test.NoDBTestCase): { "id": "v2.1", "status": "CURRENT", - "version": "2.11", + "version": "2.12", "min_version": "2.1", "updated": "2013-07-23T11:33:21Z", "links": [ diff --git a/nova/tests/unit/api/openstack/compute/test_virtual_interfaces.py b/nova/tests/unit/api/openstack/compute/test_virtual_interfaces.py index a4a30ba05242..0713805da046 100644 --- a/nova/tests/unit/api/openstack/compute/test_virtual_interfaces.py +++ b/nova/tests/unit/api/openstack/compute/test_virtual_interfaces.py @@ -15,6 +15,7 @@ import webob +from nova.api.openstack import api_version_request from nova.api.openstack.compute.legacy_v2.contrib import virtual_interfaces \ as vi20 from nova.api.openstack.compute import virtual_interfaces as vi21 @@ -40,11 +41,13 @@ def _generate_fake_vifs(context): vif = vif_obj.VirtualInterface(context=context) vif.address = '00-00-00-00-00-00' vif.network_id = 123 + vif.net_uuid = '22222222-2222-2222-2222-22222222222222222' vif.uuid = '00000000-0000-0000-0000-00000000000000000' fake_vifs = [vif] vif = vif_obj.VirtualInterface(context=context) vif.address = '11-11-11-11-11-11' vif.network_id = 456 + vif.net_uuid = '33333333-3333-3333-3333-33333333333333333' vif.uuid = '11111111-1111-1111-1111-11111111111111111' fake_vifs.append(vif) return fake_vifs @@ -60,6 +63,13 @@ class FakeRequest(object): class ServerVirtualInterfaceTestV21(test.NoDBTestCase): + wsgi_api_version = None + expected_response = { + 'virtual_interfaces': [ + {'id': '00000000-0000-0000-0000-00000000000000000', + 'mac_address': '00-00-00-00-00-00'}, + {'id': '11111111-1111-1111-1111-11111111111111111', + 'mac_address': '11-11-11-11-11-11'}]} def setUp(self): super(ServerVirtualInterfaceTestV21, self).setUp() @@ -73,20 +83,16 @@ class ServerVirtualInterfaceTestV21(test.NoDBTestCase): self.controller = vi21.ServerVirtualInterfaceController() def test_get_virtual_interfaces_list(self): - req = fakes.HTTPRequest.blank('') + req = fakes.HTTPRequest.blank('', version=self.wsgi_api_version) res_dict = self.controller.index(req, 'fake_uuid') - response = {'virtual_interfaces': [ - {'id': '00000000-0000-0000-0000-00000000000000000', - 'mac_address': '00-00-00-00-00-00'}, - {'id': '11111111-1111-1111-1111-11111111111111111', - 'mac_address': '11-11-11-11-11-11'}]} - self.assertEqual(res_dict, response) + self.assertEqual(res_dict, self.expected_response) def test_vif_instance_not_found(self): self.mox.StubOutWithMock(compute_api.API, 'get') fake_context = context.RequestContext('fake', 'fake') fake_req = FakeRequest(fake_context) - + fake_req.api_version_request = api_version_request.APIVersionRequest( + self.wsgi_api_version) compute_api.API.get(fake_context, 'fake_uuid', expected_attrs=None, want_objects=True).AndRaise( @@ -105,6 +111,19 @@ class ServerVirtualInterfaceTestV20(ServerVirtualInterfaceTestV21): self.controller = vi20.ServerVirtualInterfaceController() +class ServerVirtualInterfaceTestV212(ServerVirtualInterfaceTestV21): + wsgi_api_version = '2.12' + + expected_response = { + 'virtual_interfaces': [ + {'id': '00000000-0000-0000-0000-00000000000000000', + 'mac_address': '00-00-00-00-00-00', + 'net_id': '22222222-2222-2222-2222-22222222222222222'}, + {'id': '11111111-1111-1111-1111-11111111111111111', + 'mac_address': '11-11-11-11-11-11', + 'net_id': '33333333-3333-3333-3333-33333333333333333'}]} + + class ServerVirtualInterfaceEnforcementV21(test.NoDBTestCase): def setUp(self):