Merge "Add API schema for v2.1 'removeFloatingIp'"

This commit is contained in:
Jenkins 2015-02-02 19:31:08 +00:00 committed by Gerrit Code Review
commit c46bfcfaeb
3 changed files with 29 additions and 19 deletions

View File

@ -247,19 +247,13 @@ class FloatingIPActionController(wsgi.Controller):
@extensions.expected_errors((400, 403, 404, 409))
@wsgi.action('removeFloatingIp')
@validation.schema(floating_ips.remove_floating_ip)
def _remove_floating_ip(self, req, id, body):
"""Dissociate floating_ip from an instance."""
context = req.environ['nova.context']
authorize(context)
try:
address = body['removeFloatingIp']['address']
except TypeError:
msg = _("Missing parameter dict")
raise webob.exc.HTTPBadRequest(explanation=msg)
except KeyError:
msg = _("Address not specified")
raise webob.exc.HTTPBadRequest(explanation=msg)
address = body['removeFloatingIp']['address']
# get the floating ip object
try:

View File

@ -32,3 +32,19 @@ add_floating_ip = {
'required': ['addFloatingIp'],
'additionalProperties': False
}
remove_floating_ip = {
'type': 'object',
'properties': {
'removeFloatingIp': {
'type': 'object',
'properties': {
'address': parameter_types.ip_address
},
'required': ['address'],
'additionalProperties': False
}
},
'required': ['removeFloatingIp'],
'additionalProperties': False
}

View File

@ -553,7 +553,7 @@ class FloatingIpTestV21(test.TestCase):
body = dict(removeFloatingIp=dict(address='10.10.10.10'))
rsp = self.manager._remove_floating_ip(self.fake_req, 'test_inst',
body)
body=body)
self.assertEqual(202, rsp.status_int)
def test_floating_ip_disassociate_missing(self):
@ -561,7 +561,7 @@ class FloatingIpTestV21(test.TestCase):
self.assertRaises(webob.exc.HTTPConflict,
self.manager._remove_floating_ip,
self.fake_req, 'test_inst', body)
self.fake_req, 'test_inst', body=body)
def test_floating_ip_associate_non_existent_ip(self):
def fake_network_api_associate(self, context, instance,
@ -594,7 +594,7 @@ class FloatingIpTestV21(test.TestCase):
body = dict(removeFloatingIp=dict(address='1.1.1.1'))
self.assertRaises(webob.exc.HTTPNotFound,
self.manager._remove_floating_ip,
self.fake_req, 'test_inst', body)
self.fake_req, 'test_inst', body=body)
def test_floating_ip_disassociate_wrong_instance_uuid(self):
def get_instance_by_floating_ip_addr(self, context, address):
@ -609,7 +609,7 @@ class FloatingIpTestV21(test.TestCase):
self.assertRaises(webob.exc.HTTPConflict,
self.manager._remove_floating_ip,
self.fake_req, wrong_uuid, body)
self.fake_req, wrong_uuid, body=body)
def test_floating_ip_disassociate_wrong_instance_id(self):
def get_instance_by_floating_ip_addr(self, context, address):
@ -623,7 +623,7 @@ class FloatingIpTestV21(test.TestCase):
self.assertRaises(webob.exc.HTTPConflict,
self.manager._remove_floating_ip,
self.fake_req, 'test_inst', body)
self.fake_req, 'test_inst', body=body)
def test_floating_ip_disassociate_auto_assigned(self):
def fake_get_floating_ip_addr_auto_assigned(self, context, address):
@ -647,7 +647,7 @@ class FloatingIpTestV21(test.TestCase):
body = dict(removeFloatingIp=dict(address='10.10.10.10'))
self.assertRaises(webob.exc.HTTPForbidden,
self.manager._remove_floating_ip,
self.fake_req, 'test_inst', body)
self.fake_req, 'test_inst', body=body)
def test_floating_ip_disassociate_map_authorization_exc(self):
def fake_get_floating_ip_addr_auto_assigned(self, context, address):
@ -670,23 +670,23 @@ class FloatingIpTestV21(test.TestCase):
body = dict(removeFloatingIp=dict(address='10.10.10.10'))
self.assertRaises(webob.exc.HTTPForbidden,
self.manager._remove_floating_ip,
self.fake_req, 'test_inst', body)
self.fake_req, 'test_inst', body=body)
# these are a few bad param tests
def test_bad_address_param_in_remove_floating_ip(self):
body = dict(removeFloatingIp=dict(badparam='11.0.0.1'))
self.assertRaises(webob.exc.HTTPBadRequest,
self.assertRaises(self.validation_error,
self.manager._remove_floating_ip, self.fake_req,
'test_inst', body)
'test_inst', body=body)
def test_missing_dict_param_in_remove_floating_ip(self):
body = dict(removeFloatingIp='11.0.0.1')
self.assertRaises(webob.exc.HTTPBadRequest,
self.assertRaises(self.validation_error,
self.manager._remove_floating_ip, self.fake_req,
'test_inst', body)
'test_inst', body=body)
def test_missing_dict_param_in_add_floating_ip(self):
body = dict(addFloatingIp='11.0.0.1')