Merge "Fix the wrong address ref when the fixed_ip is invalid"

This commit is contained in:
Jenkins 2015-08-01 20:06:14 +00:00 committed by Gerrit Code Review
commit 7346e646a2
3 changed files with 30 additions and 1 deletions

View File

@ -327,7 +327,8 @@ class Controller(wsgi.Controller):
try:
request.address = network.get('fixed_ip', None)
except ValueError:
msg = _("Invalid fixed IP address (%s)") % request.address
msg = (_("Invalid fixed IP address (%s)") %
network.get('fixed_ip'))
raise exc.HTTPBadRequest(explanation=msg)
# duplicate networks are allowed only for neutron v2.0

View File

@ -2908,6 +2908,18 @@ class ServersControllerCreateTestWithMock(test.TestCase):
self._test_create_extra, params)
self.assertEqual(1, len(create_mock.call_args_list))
@mock.patch.object(compute_api.API, 'create')
def test_create_instance_with_neutronv2_invalid_fixed_ip(self,
create_mock):
self.flags(network_api_class='nova.network.neutronv2.api.API')
network = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
address = '999.0.2.3'
requested_networks = [{'uuid': network, 'fixed_ip': address}]
params = {'networks': requested_networks}
self.assertRaises(exception.ValidationError,
self._test_create_extra, params)
self.assertFalse(create_mock.called)
@mock.patch.object(compute_api.API, 'create',
side_effect=exception.InvalidVolume(reason='error'))
def test_create_instance_with_invalid_volume_error(self, create_mock):

View File

@ -2917,6 +2917,22 @@ class ServersControllerCreateTestWithMock(test.TestCase):
self._test_create_extra, params)
self.assertEqual(1, len(create_mock.call_args_list))
@mock.patch.object(compute_api.API, 'create')
def test_create_instance_with_neutronv2_invalid_fixed_ip(self,
create_mock):
self.flags(network_api_class='nova.network.neutronv2.api.API')
network = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
address = '999.0.2.3'
requested_networks = [{'uuid': network, 'fixed_ip': address}]
params = {'networks': requested_networks}
try:
self._test_create_extra(params)
self.fail()
except webob.exc.HTTPBadRequest as ex:
self.assertEqual(ex.explanation,
'Invalid fixed IP address (%s)' % address)
self.assertFalse(create_mock.called)
@mock.patch.object(compute_api.API, 'create',
side_effect=exception.InvalidVolume(reason='error'))
def test_create_instance_with_invalid_volume_error(self, create_mock):