diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-10-22 07:35:36 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-10-22 07:35:36 +0000 |
commit | 660588bf569c3cad234b26e9250e75be10761e77 (patch) | |
tree | 25b4f7fb64b105bcf6796fb1d2e2d9b53b803d05 /nova | |
parent | e96d4d29bcf6f37bbad0d18464f62b5a63b0c5ec (diff) | |
parent | 72859d6fbf172c50dd7d9ed3f90d6f4fb43c0382 (diff) | |
download | nova-660588bf569c3cad234b26e9250e75be10761e77.tar.gz |
Merge "Port update method of cloudpipe_update to v2.1(v3)"
Diffstat (limited to 'nova')
5 files changed, 110 insertions, 10 deletions
diff --git a/nova/api/openstack/compute/plugins/v3/cloudpipe.py b/nova/api/openstack/compute/plugins/v3/cloudpipe.py index 5c4dd8c6fb..6d57d15c72 100644 --- a/nova/api/openstack/compute/plugins/v3/cloudpipe.py +++ b/nova/api/openstack/compute/plugins/v3/cloudpipe.py @@ -18,8 +18,10 @@ from oslo.config import cfg from oslo.utils import timeutils from webob import exc +from nova.api.openstack.compute.schemas.v3 import cloudpipe from nova.api.openstack import extensions from nova.api.openstack import wsgi +from nova.api import validation from nova.cloudpipe import pipelib from nova import compute from nova.compute import utils as compute_utils @@ -27,6 +29,7 @@ from nova.compute import vm_states from nova import exception from nova.i18n import _ from nova import network +from nova import objects from nova.openstack.common import fileutils from nova import utils @@ -143,6 +146,30 @@ class CloudpipeController(wsgi.Controller): for x in self._get_all_cloudpipes(context)] return {'cloudpipes': vpns} + @wsgi.response(202) + @extensions.expected_errors(400) + @validation.schema(cloudpipe.update) + def update(self, req, id, body): + """Configure cloudpipe parameters for the project.""" + + context = req.environ['nova.context'] + authorize(context) + + if id != "configure-project": + msg = _("Unknown action %s") % id + raise exc.HTTPBadRequest(explanation=msg) + + project_id = context.project_id + networks = objects.NetworkList.get_by_project(context, project_id) + + params = body['configure_project'] + vpn_ip = params['vpn_ip'] + vpn_port = params['vpn_port'] + for nw in networks: + nw.vpn_public_address = vpn_ip + nw.vpn_public_port = vpn_port + nw.save() + class Cloudpipe(extensions.V3APIExtensionBase): """Adds actions to create cloudpipe instances. diff --git a/nova/api/openstack/compute/schemas/v3/cloudpipe.py b/nova/api/openstack/compute/schemas/v3/cloudpipe.py new file mode 100644 index 0000000000..d4e0183772 --- /dev/null +++ b/nova/api/openstack/compute/schemas/v3/cloudpipe.py @@ -0,0 +1,39 @@ +# Copyright 2014 IBM Corporation. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from nova.api.validation import parameter_types + + +update = { + 'type': 'object', + 'properties': { + 'configure_project': { + 'type': 'object', + 'properties': { + 'vpn_ip': { + 'type': 'string', + 'oneOf': [ + {'format': 'ipv4'}, + {'format': 'ipv6'} + ], + }, + 'vpn_port': parameter_types.tcp_udp_port, + }, + 'required': ['vpn_ip', 'vpn_port'], + 'additionalProperties': False, + }, + }, + 'required': ['configure_project'], + 'additionalProperties': False, +} diff --git a/nova/tests/api/openstack/compute/contrib/test_cloudpipe_update.py b/nova/tests/api/openstack/compute/contrib/test_cloudpipe_update.py index b17722902d..5caccf14b5 100644 --- a/nova/tests/api/openstack/compute/contrib/test_cloudpipe_update.py +++ b/nova/tests/api/openstack/compute/contrib/test_cloudpipe_update.py @@ -14,8 +14,10 @@ import webob -from nova.api.openstack.compute.contrib import cloudpipe_update +from nova.api.openstack.compute.contrib import cloudpipe_update as clup_v2 +from nova.api.openstack.compute.plugins.v3 import cloudpipe as clup_v21 from nova import db +from nova import exception from nova import test from nova.tests.api.openstack import fakes from nova.tests import fake_network @@ -36,13 +38,20 @@ def fake_network_update(context, network_id, values): network[key] = values[key] -class CloudpipeUpdateTest(test.NoDBTestCase): +class CloudpipeUpdateTestV21(test.NoDBTestCase): + bad_request = exception.ValidationError def setUp(self): - super(CloudpipeUpdateTest, self).setUp() - self.controller = cloudpipe_update.CloudpipeUpdateController() + super(CloudpipeUpdateTestV21, self).setUp() self.stubs.Set(db, "project_get_networks", fake_project_get_networks) self.stubs.Set(db, "network_update", fake_network_update) + self._setup() + + def _setup(self): + self.controller = clup_v21.CloudpipeController() + + def _check_status(self, expected_status, res, controller_methord): + self.assertEqual(expected_status, controller_methord.wsgi_code) def test_cloudpipe_configure_project(self): req = fakes.HTTPRequest.blank( @@ -50,7 +59,7 @@ class CloudpipeUpdateTest(test.NoDBTestCase): body = {"configure_project": {"vpn_ip": "1.2.3.4", "vpn_port": 222}} result = self.controller.update(req, 'configure-project', body=body) - self.assertEqual('202 Accepted', result.status) + self._check_status(202, result, self.controller.update) self.assertEqual(fake_networks[0]['vpn_public_address'], "1.2.3.4") self.assertEqual(fake_networks[0]['vpn_public_port'], 222) @@ -60,21 +69,31 @@ class CloudpipeUpdateTest(test.NoDBTestCase): body = {"configure_project": {"vpn_ip": "1.2.3.4", "vpn_port": 222}} self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update, req, - 'configure-projectx', body) + 'configure-projectx', body=body) def test_cloudpipe_configure_project_bad_data(self): req = fakes.HTTPRequest.blank( '/v2/fake/os-cloudpipe/configure-project') body = {"configure_project": {"vpn_ipxx": "1.2.3.4", "vpn_port": 222}} - self.assertRaises(webob.exc.HTTPBadRequest, + self.assertRaises(self.bad_request, self.controller.update, req, - 'configure-project', body) + 'configure-project', body=body) def test_cloudpipe_configure_project_bad_vpn_port(self): req = fakes.HTTPRequest.blank( '/v2/fake/os-cloudpipe/configure-project') body = {"configure_project": {"vpn_ipxx": "1.2.3.4", "vpn_port": "foo"}} - self.assertRaises(webob.exc.HTTPBadRequest, + self.assertRaises(self.bad_request, self.controller.update, req, - 'configure-project', body) + 'configure-project', body=body) + + +class CloudpipeUpdateTestV2(CloudpipeUpdateTestV21): + bad_request = webob.exc.HTTPBadRequest + + def _setup(self): + self.controller = clup_v2.CloudpipeUpdateController() + + def _check_status(self, expected_status, res, controller_methord): + self.assertEqual(expected_status, res.status_int) diff --git a/nova/tests/integrated/v3/api_samples/os-cloudpipe/cloud-pipe-update-req.json.tpl b/nova/tests/integrated/v3/api_samples/os-cloudpipe/cloud-pipe-update-req.json.tpl new file mode 100644 index 0000000000..0ab9141aea --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-cloudpipe/cloud-pipe-update-req.json.tpl @@ -0,0 +1,6 @@ +{ + "configure_project": { + "vpn_ip": "%(vpn_ip)s", + "vpn_port": "%(vpn_port)s" + } +} diff --git a/nova/tests/integrated/v3/test_cloudpipe.py b/nova/tests/integrated/v3/test_cloudpipe.py index 435f875795..a3042eb736 100644 --- a/nova/tests/integrated/v3/test_cloudpipe.py +++ b/nova/tests/integrated/v3/test_cloudpipe.py @@ -69,3 +69,12 @@ class CloudPipeSampleTest(api_sample_base.ApiSampleTestBaseV3): subs.update(project) subs['image_id'] = CONF.vpn_image_id self._verify_response('cloud-pipe-get-resp', subs, response, 200) + + def test_cloud_pipe_update(self): + subs = {'vpn_ip': '192.168.1.1', + 'vpn_port': 2000} + response = self._do_put('os-cloudpipe/configure-project', + 'cloud-pipe-update-req', + subs) + self.assertEqual(response.status_code, 202) + self.assertEqual(response.content, "") |