Check fixed-cidr is within fixed-range-v4
Creating a network using 'nova network-create' allows the creation of fixed IPs that fall outside the fixed-range-v4, resulting in invalid fixed IPs. The following patch add a check to see if the fixed-cidr subnet is within the fixed-range-v4 and throws an exception if it does not. Change-Id: I00458b54094d3371da63d22e3356660194e2fb95 Closes-Bug: #1367060
This commit is contained in:
parent
9fd059b938
commit
445e4e20b5
|
@ -1188,6 +1188,11 @@ class NetworkManager(manager.Manager):
|
|||
except netaddr.AddrFormatError:
|
||||
raise exception.InvalidCidr(cidr=kwargs["fixed_cidr"])
|
||||
|
||||
# Subnet of fixed IPs must fall within fixed range
|
||||
if kwargs["fixed_cidr"] not in fixnet:
|
||||
raise exception.AddressOutOfRange(
|
||||
address=kwargs["fixed_cidr"].network, cidr=fixnet)
|
||||
|
||||
LOG.debug('Create network: |%s|', kwargs)
|
||||
return self._do_create_networks(context, **kwargs)
|
||||
|
||||
|
|
|
@ -2518,6 +2518,13 @@ class CommonNetworkTestCase(test.TestCase):
|
|||
instance=fake_inst(uuid='ignoreduuid'))
|
||||
rollback.assert_called_once_with(self.context)
|
||||
|
||||
def test_fixed_cidr_out_of_range(self):
|
||||
manager = network_manager.NetworkManager()
|
||||
ctxt = context.get_admin_context()
|
||||
self.assertRaises(exception.AddressOutOfRange,
|
||||
manager.create_networks, ctxt, label="fake",
|
||||
cidr='10.1.0.0/24', fixed_cidr='10.1.1.0/25')
|
||||
|
||||
|
||||
class TestRPCFixedManager(network_manager.RPCAllocateFixedIP,
|
||||
network_manager.NetworkManager):
|
||||
|
|
Loading…
Reference in New Issue