def _update_subnet_allocation_pools(self, context, subnet_id, s):
context.session.query(models_v2.IPAllocationPool).filter_by(
subnet_id=subnet_id).delete()
- pools = ((netaddr.IPAddress(p.first, p.version).format(),
+ pools = [(netaddr.IPAddress(p.first, p.version).format(),
netaddr.IPAddress(p.last, p.version).format())
- for p in s['allocation_pools'])
+ for p in s['allocation_pools']]
new_pools = [models_v2.IPAllocationPool(first_ip=p[0],
last_ip=p[1],
subnet_id=subnet_id)
self.assertEqual(res.status_int,
webob.exc.HTTPClientError.code)
+ def _verify_updated_subnet_allocation_pools(self, res, with_gateway_ip):
+ res = self.deserialize(self.fmt, res)
+ self.assertEqual(len(res['subnet']['allocation_pools']), 2)
+ res_vals = (
+ list(res['subnet']['allocation_pools'][0].values()) +
+ list(res['subnet']['allocation_pools'][1].values())
+ )
+ for pool_val in ['10', '20', '30', '40']:
+ self.assertTrue('192.168.0.%s' % (pool_val) in res_vals)
+ if with_gateway_ip:
+ self.assertEqual((res['subnet']['gateway_ip']),
+ '192.168.0.9')
+
def _test_update_subnet_allocation_pools(self, with_gateway_ip=False):
"""Test that we can successfully update with sane params.
data['subnet']['gateway_ip'] = '192.168.0.9'
req = self.new_update_request('subnets', data,
subnet['subnet']['id'])
- #check res code but then do GET on subnet for verification
+ #check res code and contents
res = req.get_response(self.api)
self.assertEqual(res.status_code, 200)
+ self._verify_updated_subnet_allocation_pools(res,
+ with_gateway_ip)
+ #GET subnet to verify DB updated correctly
req = self.new_show_request('subnets', subnet['subnet']['id'],
self.fmt)
- res = self.deserialize(self.fmt, req.get_response(self.api))
- self.assertEqual(len(res['subnet']['allocation_pools']), 2)
- res_vals = (
- list(res['subnet']['allocation_pools'][0].values()) +
- list(res['subnet']['allocation_pools'][1].values())
- )
- for pool_val in ['10', '20', '30', '40']:
- self.assertTrue('192.168.0.%s' % (pool_val) in res_vals)
- if with_gateway_ip:
- self.assertEqual((res['subnet']['gateway_ip']),
- '192.168.0.9')
+ res = req.get_response(self.api)
+ self._verify_updated_subnet_allocation_pools(res,
+ with_gateway_ip)
def test_update_subnet_allocation_pools(self):
self._test_update_subnet_allocation_pools()