Merge "NSX|V3: check if subnet overlaps with shared address space"
This commit is contained in:
commit
dd376dead4
@ -1004,7 +1004,20 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
LOG.error(_LE("Unable to delete DHCP server mapping for "
|
||||
"network %s"), network_id)
|
||||
|
||||
def _validate_address_space(self, subnet):
|
||||
cidr = subnet.get('cidr')
|
||||
if (not validators.is_attr_set(cidr) or
|
||||
netaddr.IPNetwork(cidr).version != 4):
|
||||
return
|
||||
# Check if subnet overlaps with shared address space.
|
||||
# This is checked on the backend when attaching subnet to a router.
|
||||
if netaddr.IPSet([cidr]) & netaddr.IPSet(['100.64.0.0/10']):
|
||||
msg = _("Subnet overlaps with shared address space 100.64.0.0/10")
|
||||
raise n_exc.InvalidInput(error_message=msg)
|
||||
|
||||
def create_subnet(self, context, subnet):
|
||||
self._validate_address_space(subnet['subnet'])
|
||||
|
||||
# TODO(berlin): public external subnet announcement
|
||||
if (cfg.CONF.nsx_v3.native_dhcp_metadata and
|
||||
subnet['subnet'].get('enable_dhcp', False)):
|
||||
|
@ -215,6 +215,17 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin):
|
||||
self.assertListEqual(az_hints, zone)
|
||||
|
||||
|
||||
class TestSubnetsV2(test_plugin.TestSubnetsV2, NsxV3PluginTestCaseMixin):
|
||||
|
||||
def test_create_subnet_with_shared_address_space(self):
|
||||
with self.network() as network:
|
||||
data = {'subnet': {'network_id': network['network']['id'],
|
||||
'cidr': '100.64.0.0/16'}}
|
||||
self.assertRaises(n_exc.InvalidInput,
|
||||
self.plugin.create_subnet,
|
||||
context.get_admin_context(), data)
|
||||
|
||||
|
||||
class TestPortsV2(test_plugin.TestPortsV2, NsxV3PluginTestCaseMixin,
|
||||
test_bindings.PortBindingsTestCase,
|
||||
test_bindings.PortBindingsHostTestCaseMixin,
|
||||
|
Loading…
Reference in New Issue
Block a user