Use correct session in update_allocation_pools

This fixes the IP driver update_allocation_pools to use
the session on the subnet rather than generating a new one.
Generating a new one was causing the allocation pool
creation to be uncommitted since nothing was ever starting
a transaction on the session before it added allocation pool
objects to the session. This resulted in them never being
committed to the database so the subnet would become unusable
after an update.

This also adds a very simple unit test to ensure the
subnet still works after an update.

Closes-Bug: #1573443
Change-Id: I1c80a01f475760b9cd405fc89ee2df3a4a1c26c4
(cherry picked from 4d6fe0c38b)
This commit is contained in:
Kevin Benton 2016-04-21 19:40:07 -07:00
parent ddaab57c58
commit 8825166f5b
2 changed files with 11 additions and 1 deletions

View File

@ -374,7 +374,7 @@ class NeutronDbSubnet(ipam_base.Subnet):
# Pools have already been validated in the subnet request object which
# was sent to the subnet pool driver. Further validation should not be
# required.
session = db_api.get_session()
session = self._context.session
self.subnet_manager.delete_allocation_pools(session)
self.create_allocation_pools(self.subnet_manager, session, pools, cidr)
self._pools = pools

View File

@ -4155,6 +4155,16 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
res = self.deserialize(self.fmt, req.get_response(self.api))
self.assertIsNone(data['subnet']['gateway_ip'])
def test_subnet_usable_after_update(self):
with self.subnet() as subnet:
data = {'subnet': {'name': 'newname'}}
req = self.new_update_request('subnets', data,
subnet['subnet']['id'])
res = self.deserialize(self.fmt, req.get_response(self.api))
self.assertEqual(data['subnet']['name'], res['subnet']['name'])
with self.port(subnet=subnet):
pass
def test_update_subnet(self):
with self.subnet() as subnet:
data = {'subnet': {'gateway_ip': '10.0.0.1'}}