Skip to content

Commit

Permalink
Check fixed-cidr is within fixed-range-v4
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thang-pham committed Oct 21, 2014
1 parent 9fd059b commit 445e4e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nova/network/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,11 @@ def create_networks(self, context,
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)

Expand Down
7 changes: 7 additions & 0 deletions nova/tests/network/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2518,6 +2518,13 @@ def test_fixed_ip_cleanup_rollback(self, fake_trig,
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):
Expand Down

0 comments on commit 445e4e2

Please sign in to comment.