Limit amount of fixed ips per port

Fixes bug 1100476

The patch also updates the quantum configuration file to
contain the following:
 - max number of host routes
 - max number of dns servers

Change-Id: Ic5d90034b0231687dfbde8fc65780ab52222c0fd
This commit is contained in:
Gary Kotton 2013-02-24 13:20:14 +00:00
parent 9f6adb4b26
commit 785cbcca4f
5 changed files with 57 additions and 0 deletions

View File

@ -189,6 +189,15 @@ notification_topics = notifications
# of number of items.
# pagination_max_limit = -1
# Maximum number of DNS nameservers per subnet
# max_dns_nameservers = 5
# Maximum number of host routes per subnet
# max_subnet_host_routes = 20
# Maximum number of fixed ips per port
# max_fixed_ips_per_port = 5
[QUOTAS]
# resource name(s) that are supported in quota features
# quota_items = network,subnet,port

View File

@ -69,6 +69,8 @@ core_opts = [
help=_("Maximum number of DNS nameservers")),
cfg.IntOpt('max_subnet_host_routes', default=20,
help=_("Maximum number of host routes per subnet")),
cfg.IntOpt('max_fixed_ips_per_port', default=5,
help=_("Maximum number of fixed ips per port")),
cfg.IntOpt('dhcp_lease_duration', default=120,
help=_("DHCP lease duration")),
cfg.BoolOpt('dhcp_agent_notification', default=True,

View File

@ -609,6 +609,9 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
'ip_address': fixed['ip_address']})
else:
fixed_ip_set.append({'subnet_id': subnet_id})
if len(fixed_ip_set) > cfg.CONF.max_fixed_ips_per_port:
msg = _('Exceeded maximim amount of fixed ips per port')
raise q_exc.InvalidInput(error_message=msg)
return fixed_ip_set
def _allocate_fixed_ips(self, context, network, fixed_ips):
@ -636,6 +639,11 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
"""Add or remove IPs from the port."""
ips = []
# the new_ips contain all of the fixed_ips that are to be updated
if len(new_ips) > cfg.CONF.max_fixed_ips_per_port:
msg = _('Exceeded maximim amount of fixed ips per port')
raise q_exc.InvalidInput(error_message=msg)
# Remove all of the intersecting elements
for original_ip in original_ips[:]:
for new_ip in new_ips[:]:

View File

@ -750,3 +750,9 @@ class TestMidonetPortsV2(test_plugin.TestPortsV2,
def test_list_ports_with_sort_emulated(self):
pass
def test_max_fixed_ips_exceeded(self):
pass
def test_update_max_fixed_ips_exceeded(self):
pass

View File

@ -1745,6 +1745,38 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
self.assertEqual(update_context._recycled_networks,
set([subnet['subnet']['network_id']]))
def test_max_fixed_ips_exceeded(self):
with self.subnet(gateway_ip='10.0.0.3',
cidr='10.0.0.0/24') as subnet:
kwargs = {"fixed_ips":
[{'subnet_id': subnet['subnet']['id']},
{'subnet_id': subnet['subnet']['id']},
{'subnet_id': subnet['subnet']['id']},
{'subnet_id': subnet['subnet']['id']},
{'subnet_id': subnet['subnet']['id']},
{'subnet_id': subnet['subnet']['id']}]}
net_id = subnet['subnet']['network_id']
res = self._create_port(self.fmt, net_id=net_id, **kwargs)
self.assertEqual(res.status_int, 400)
def test_update_max_fixed_ips_exceeded(self):
with self.subnet(gateway_ip='10.0.0.3',
cidr='10.0.0.0/24') as subnet:
with self.port(subnet) as port:
data = {'port': {'fixed_ips':
[{'subnet_id': subnet['subnet']['id'],
'ip_address': '10.0.0.2'},
{'subnet_id': subnet['subnet']['id'],
'ip_address': '10.0.0.4'},
{'subnet_id': subnet['subnet']['id']},
{'subnet_id': subnet['subnet']['id']},
{'subnet_id': subnet['subnet']['id']},
{'subnet_id': subnet['subnet']['id']}]}}
req = self.new_update_request('ports', data,
port['port']['id'])
res = req.get_response(self.api)
self.assertEqual(res.status_int, 400)
class TestNetworksV2(QuantumDbPluginV2TestCase):
# NOTE(cerberus): successful network update and delete are