Change format of returning message

* When no free IP addresses are available in public network, Nailgun should
  return error message in a way which is acceptable by Fuel UI.
* Update corresponding unit test.

Change-Id: I9a2689c134bb4157d81f0749db495ec66d399118
Partial-bug: #1513774
This commit is contained in:
Ivan Kliuk 2015-11-17 23:53:08 +02:00
parent 7a8294cdad
commit ec5879ca6d
3 changed files with 17 additions and 3 deletions

View File

@ -138,7 +138,12 @@ class ProviderHandler(BaseHandler):
try:
network_config = self.serializer.serialize_for_cluster(cluster)
except errors.OutOfIPs as exc:
raise self.http(400, six.text_type(exc))
network_id = getattr(exc, 'network_id', None)
raise self.http(
400,
six.text_type(exc),
err_list=[{"errors": ["ip_ranges"], "ids": [network_id]}]
)
if admin_nets != nm.get_admin_networks():
try:

View File

@ -538,8 +538,13 @@ class NetworkManager(object):
ips_in_use = ips_in_use or set()
ip_ranges = [IPRange(r.first, r.last)
for r in network_group.ip_ranges]
return cls.get_free_ips_from_ranges(
network_group.name, ip_ranges, ips_in_use, num)
try:
return cls.get_free_ips_from_ranges(
network_group.name, ip_ranges, ips_in_use, num)
except errors.OutOfIPs as exc:
exc.network_id = network_group.id
raise
@classmethod
def _get_ips_except_admin(cls, node_id=None,

View File

@ -610,6 +610,10 @@ class TestNeutronNetworkConfigurationHandler(BaseIntegrationTest):
"Not enough free IP addresses in ranges [172.16.0.19-172.16.0.19] "
"of 'public' network",
resp.json_body['message'])
self.assertEqual(
[{'errors': ["ip_ranges"], 'ids': [public['id']]}],
resp.json_body['errors']
)
def test_assign_vip_in_correct_node_group(self):
# prepare two nodes that are in different node groups