Add negative UT cases for subnet/GW create/update

When force_gateway_on_subnet is configured, ensure
that a GW with IP same as subnet, and BCAST GW IP
are rejected during subnet create. For subnet update,
ensure GW outside of subnet is rejected.

bug 1178675

Change-Id: Ice58f7e1be7966b247c165e52807405401e5a4ea
This commit is contained in:
Paul Michali 2013-05-10 06:17:24 -07:00
parent 391108a014
commit c2a672fe21
2 changed files with 45 additions and 3 deletions

View File

@ -300,9 +300,20 @@ class TestMidonetSubnetsV2(test_plugin.TestSubnetsV2,
self._setup_subnet_mocks() self._setup_subnet_mocks()
super(TestMidonetSubnetsV2, self).test_create_subnet_gw_values() super(TestMidonetSubnetsV2, self).test_create_subnet_gw_values()
def test_create_force_subnet_gw_values(self): def test_create_subnet_gw_outside_cidr_force_on_returns_400(self):
self._setup_subnet_mocks() self._setup_subnet_mocks()
super(TestMidonetSubnetsV2, self).test_create_force_subnet_gw_values() super(TestMidonetSubnetsV2,
self).test_create_subnet_gw_outside_cidr_force_on_returns_400()
def test_create_subnet_gw_of_network_force_on_returns_400(self):
self._setup_subnet_mocks()
super(TestMidonetSubnetsV2,
self).test_create_subnet_gw_of_network_force_on_returns_400()
def test_create_subnet_gw_bcast_force_on_returns_400(self):
self._setup_subnet_mocks()
super(TestMidonetSubnetsV2,
self).test_create_subnet_gw_bcast_force_on_returns_400()
def test_create_subnet_with_allocation_pool(self): def test_create_subnet_with_allocation_pool(self):
self._setup_subnet_mocks() self._setup_subnet_mocks()
@ -398,6 +409,9 @@ class TestMidonetSubnetsV2(test_plugin.TestSubnetsV2,
super(TestMidonetSubnetsV2, super(TestMidonetSubnetsV2,
self).test_update_subnet_shared_returns_400() self).test_update_subnet_shared_returns_400()
def test_update_subnet_gw_outside_cidr_force_on_returns_400(self):
pass
def test_update_subnet_inconsistent_ipv4_gatewayv6(self): def test_update_subnet_inconsistent_ipv4_gatewayv6(self):
pass pass

View File

@ -2695,7 +2695,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
self._test_create_subnet(expected=expected, self._test_create_subnet(expected=expected,
gateway_ip=gateway) gateway_ip=gateway)
def test_create_force_subnet_gw_values(self): def test_create_subnet_gw_outside_cidr_force_on_returns_400(self):
cfg.CONF.set_override('force_gateway_on_subnet', True) cfg.CONF.set_override('force_gateway_on_subnet', True)
with self.network() as network: with self.network() as network:
self._create_subnet(self.fmt, self._create_subnet(self.fmt,
@ -2704,6 +2704,24 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
400, 400,
gateway_ip='100.0.0.1') gateway_ip='100.0.0.1')
def test_create_subnet_gw_of_network_force_on_returns_400(self):
cfg.CONF.set_override('force_gateway_on_subnet', True)
with self.network() as network:
self._create_subnet(self.fmt,
network['network']['id'],
'10.0.0.0/24',
400,
gateway_ip='10.0.0.0')
def test_create_subnet_gw_bcast_force_on_returns_400(self):
cfg.CONF.set_override('force_gateway_on_subnet', True)
with self.network() as network:
self._create_subnet(self.fmt,
network['network']['id'],
'10.0.0.0/24',
400,
gateway_ip='10.0.0.255')
def test_create_subnet_with_allocation_pool(self): def test_create_subnet_with_allocation_pool(self):
gateway_ip = '10.0.0.1' gateway_ip = '10.0.0.1'
cidr = '10.0.0.0/24' cidr = '10.0.0.0/24'
@ -2968,6 +2986,16 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
res = req.get_response(self.api) res = req.get_response(self.api)
self.assertEqual(res.status_int, 400) self.assertEqual(res.status_int, 400)
def test_update_subnet_gw_outside_cidr_force_on_returns_400(self):
cfg.CONF.set_override('force_gateway_on_subnet', True)
with self.network() as network:
with self.subnet(network=network) as subnet:
data = {'subnet': {'gateway_ip': '100.0.0.1'}}
req = self.new_update_request('subnets', data,
subnet['subnet']['id'])
res = req.get_response(self.api)
self.assertEqual(res.status_int, 400)
def test_update_subnet_inconsistent_ipv4_gatewayv6(self): def test_update_subnet_inconsistent_ipv4_gatewayv6(self):
with self.network() as network: with self.network() as network:
with self.subnet(network=network) as subnet: with self.subnet(network=network) as subnet: