Add JSON schema for "associate_host" API

This patch adds JSON schema for V2.1 "associate_host" API
and unit tests for same.

Partially implements blueprint v2-on-v3-api

Change-Id: I43843dd9d2c7b607b32210c446294b628e1cf871
This commit is contained in:
ghanshyam 2015-01-29 16:39:20 +09:00
parent f88b1484a8
commit 2d53cb76cd
3 changed files with 55 additions and 1 deletions

View File

@ -12,8 +12,10 @@
from webob import exc
from nova.api.openstack.compute.schemas.v3 import networks_associate
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api import validation
from nova import exception
from nova.i18n import _
from nova import network
@ -64,6 +66,7 @@ class NetworkAssociateActionController(wsgi.Controller):
@wsgi.action("associate_host")
@wsgi.response(202)
@extensions.expected_errors((404, 501))
@validation.schema(networks_associate.associate_host)
def _associate_host(self, req, id, body):
context = req.environ['nova.context']
authorize(context)

View File

@ -0,0 +1,24 @@
# Copyright 2015 NEC 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
associate_host = {
'type': 'object',
'properties': {
'associate_host': parameter_types.hostname
},
'required': ['associate_host'],
'additionalProperties': False
}

View File

@ -551,7 +551,7 @@ class NetworksAssociateTestV21(test.NoDBTestCase):
uuid = FAKE_NETWORKS[1]['uuid']
req = fakes.HTTPRequest.blank('/v2/1234//os-networks/%s/action' % uuid)
res = self.associate_controller._associate_host(
req, uuid, {'associate_host': "TestHost"})
req, uuid, body={'associate_host': "TestHost"})
self._check_status(res, self.associate_controller._associate_host, 202)
req = fakes.HTTPRequest.blank('/v2/1234/os-networks/%s' % uuid)
req.environ["nova.context"].is_admin = True
@ -568,6 +568,30 @@ class NetworksAssociateTestV21(test.NoDBTestCase):
assoc_ctrl._associate_host,
req, uuid, {'associate_host': "TestHost"})
def _test_network_neutron_associate_host_validation_failed(self, body):
uuid = FAKE_NETWORKS[1]['uuid']
req = fakes.HTTPRequest.blank('')
self.assertRaises(exception.ValidationError,
self.associate_controller._associate_host,
req, uuid, body=body)
def test_network_neutron_associate_host_non_string(self):
self._test_network_neutron_associate_host_validation_failed(
{'associate_host': 123})
def test_network_neutron_associate_host_empty_body(self):
self._test_network_neutron_associate_host_validation_failed({})
def test_network_neutron_associate_bad_associate_host_key(self):
self._test_network_neutron_associate_host_validation_failed(
{'badassociate_host': "TestHost"})
def test_network_neutron_associate_host_extra_arg(self):
self._test_network_neutron_associate_host_validation_failed(
{'associate_host': "TestHost",
'extra_arg': "extra_arg"})
def test_network_neutron_disassociate_project_not_implemented(self):
uuid = FAKE_NETWORKS[1]['uuid']
self.flags(network_api_class='nova.network.neutronv2.api.API')
@ -601,3 +625,6 @@ class NetworksAssociateTestV2(NetworksAssociateTestV21):
def _check_status(self, res, method, code):
self.assertEqual(res.status_int, 202)
def _test_network_neutron_associate_host_validation_failed(self, body):
pass