Merge "ml2: gre, vxlan type driver can leak segment_id"

This commit is contained in:
Jenkins 2013-12-18 17:04:29 +00:00 committed by Gerrit Code Review
commit 5be0aa3e88
4 changed files with 71 additions and 8 deletions

View File

@ -119,10 +119,10 @@ class GreTypeDriver(type_tunnel.TunnelTypeDriver):
LOG.debug(_("Releasing gre tunnel %s to pool"), LOG.debug(_("Releasing gre tunnel %s to pool"),
gre_id) gre_id)
break break
else: else:
session.delete(alloc) session.delete(alloc)
LOG.debug(_("Releasing gre tunnel %s outside pool"), LOG.debug(_("Releasing gre tunnel %s outside pool"),
gre_id) gre_id)
except sa_exc.NoResultFound: except sa_exc.NoResultFound:
LOG.warning(_("gre_id %s not found"), gre_id) LOG.warning(_("gre_id %s not found"), gre_id)

View File

@ -128,10 +128,10 @@ class VxlanTypeDriver(type_tunnel.TunnelTypeDriver):
LOG.debug(_("Releasing vxlan tunnel %s to pool"), LOG.debug(_("Releasing vxlan tunnel %s to pool"),
vxlan_vni) vxlan_vni)
break break
else: else:
session.delete(alloc) session.delete(alloc)
LOG.debug(_("Releasing vxlan tunnel %s outside pool"), LOG.debug(_("Releasing vxlan tunnel %s outside pool"),
vxlan_vni) vxlan_vni)
except sa_exc.NoResultFound: except sa_exc.NoResultFound:
LOG.warning(_("vxlan_vni %s not found"), vxlan_vni) LOG.warning(_("vxlan_vni %s not found"), vxlan_vni)

View File

@ -174,3 +174,34 @@ class GreTypeTest(base.BaseTestCase):
for endpoint in endpoints: for endpoint in endpoints:
self.assertIn(endpoint['ip_address'], self.assertIn(endpoint['ip_address'],
[TUNNEL_IP_ONE, TUNNEL_IP_TWO]) [TUNNEL_IP_ONE, TUNNEL_IP_TWO])
class GreTypeMultiRangeTest(base.BaseTestCase):
TUN_MIN0 = 100
TUN_MAX0 = 101
TUN_MIN1 = 200
TUN_MAX1 = 201
TUNNEL_MULTI_RANGES = [(TUN_MIN0, TUN_MAX0), (TUN_MIN1, TUN_MAX1)]
def setUp(self):
super(GreTypeMultiRangeTest, self).setUp()
ml2_db.initialize()
self.driver = type_gre.GreTypeDriver()
self.driver.gre_id_ranges = self.TUNNEL_MULTI_RANGES
self.driver._sync_gre_allocations()
self.session = db.get_session()
self.addCleanup(db.clear_db)
def test_release_segment(self):
segments = [self.driver.allocate_tenant_segment(self.session)
for i in range(4)]
# Release them in random order. No special meaning.
for i in (0, 2, 1, 3):
self.driver.release_segment(self.session, segments[i])
for key in (self.TUN_MIN0, self.TUN_MAX0,
self.TUN_MIN1, self.TUN_MAX1):
alloc = self.driver.get_gre_allocation(self.session, key)
self.assertFalse(alloc.allocated)

View File

@ -195,3 +195,35 @@ class VxlanTypeTest(base.BaseTestCase):
self.assertEqual(VXLAN_UDP_PORT_ONE, endpoint['udp_port']) self.assertEqual(VXLAN_UDP_PORT_ONE, endpoint['udp_port'])
elif endpoint['ip_address'] == TUNNEL_IP_TWO: elif endpoint['ip_address'] == TUNNEL_IP_TWO:
self.assertEqual(VXLAN_UDP_PORT_TWO, endpoint['udp_port']) self.assertEqual(VXLAN_UDP_PORT_TWO, endpoint['udp_port'])
class VxlanTypeMultiRangeTest(base.BaseTestCase):
TUN_MIN0 = 100
TUN_MAX0 = 101
TUN_MIN1 = 200
TUN_MAX1 = 201
TUNNEL_MULTI_RANGES = [(TUN_MIN0, TUN_MAX0), (TUN_MIN1, TUN_MAX1)]
def setUp(self):
super(VxlanTypeMultiRangeTest, self).setUp()
ml2_db.initialize()
self.driver = type_vxlan.VxlanTypeDriver()
self.driver.vxlan_vni_ranges = self.TUNNEL_MULTI_RANGES
self.driver._sync_vxlan_allocations()
self.session = db.get_session()
self.addCleanup(cfg.CONF.reset)
self.addCleanup(db.clear_db)
def test_release_segment(self):
segments = [self.driver.allocate_tenant_segment(self.session)
for i in range(4)]
# Release them in random order. No special meaning.
for i in (0, 2, 1, 3):
self.driver.release_segment(self.session, segments[i])
for key in (self.TUN_MIN0, self.TUN_MAX0,
self.TUN_MIN1, self.TUN_MAX1):
alloc = self.driver.get_vxlan_allocation(self.session, key)
self.assertFalse(alloc.allocated)