Fix OVS and LB plugins' VLAN allocation table synchronization
In both the openvswitch and linuxbridge plugins, if previous entries for a physical network have been completely removed from the network_vlan_ranges configuration variable, allocation table records for unallocated VLANs on that physical network are now removed from the DB at startup. The test_ovs_db and test_lb_db unit tests have also been extended to cover this case. Fixes bug 1052289. Test assertions that were added to the test_ovs_db unit test in https://review.openstack.org/#/c/11388 have been added to the test_lb_db unit test. Fixes bug 1045596. Change-Id: I04e924603eaf0df717414c2aaa83fd203b791308
This commit is contained in:
parent
e5f9c71224
commit
64fee8f3e8
@ -40,23 +40,28 @@ def initialize():
|
|||||||
def sync_network_states(network_vlan_ranges):
|
def sync_network_states(network_vlan_ranges):
|
||||||
"""Synchronize network_states table with current configured VLAN ranges."""
|
"""Synchronize network_states table with current configured VLAN ranges."""
|
||||||
|
|
||||||
# process vlan ranges for each physical network separately
|
session = db.get_session()
|
||||||
for physical_network, vlan_ranges in network_vlan_ranges.iteritems():
|
with session.begin():
|
||||||
|
# get existing allocations for all physical networks
|
||||||
|
allocations = dict()
|
||||||
|
states = (session.query(l2network_models_v2.NetworkState).
|
||||||
|
all())
|
||||||
|
for state in states:
|
||||||
|
if state.physical_network not in allocations:
|
||||||
|
allocations[state.physical_network] = set()
|
||||||
|
allocations[state.physical_network].add(state)
|
||||||
|
|
||||||
# determine current configured allocatable vlans for this
|
# process vlan ranges for each configured physical network
|
||||||
# physical network
|
for physical_network, vlan_ranges in network_vlan_ranges.iteritems():
|
||||||
vlan_ids = set()
|
# determine current configured allocatable vlans for this
|
||||||
for vlan_range in vlan_ranges:
|
# physical network
|
||||||
vlan_ids |= set(xrange(vlan_range[0], vlan_range[1] + 1))
|
vlan_ids = set()
|
||||||
|
for vlan_range in vlan_ranges:
|
||||||
|
vlan_ids |= set(xrange(vlan_range[0], vlan_range[1] + 1))
|
||||||
|
|
||||||
session = db.get_session()
|
|
||||||
with session.begin():
|
|
||||||
# remove from table unallocated vlans not currently allocatable
|
# remove from table unallocated vlans not currently allocatable
|
||||||
try:
|
if physical_network in allocations:
|
||||||
states = (session.query(l2network_models_v2.NetworkState).
|
for state in allocations[physical_network]:
|
||||||
filter_by(physical_network=physical_network).
|
|
||||||
all())
|
|
||||||
for state in states:
|
|
||||||
try:
|
try:
|
||||||
# see if vlan is allocatable
|
# see if vlan is allocatable
|
||||||
vlan_ids.remove(state.vlan_id)
|
vlan_ids.remove(state.vlan_id)
|
||||||
@ -68,8 +73,7 @@ def sync_network_states(network_vlan_ranges):
|
|||||||
"%s from pool" %
|
"%s from pool" %
|
||||||
(state.vlan_id, physical_network))
|
(state.vlan_id, physical_network))
|
||||||
session.delete(state)
|
session.delete(state)
|
||||||
except exc.NoResultFound:
|
del allocations[physical_network]
|
||||||
pass
|
|
||||||
|
|
||||||
# add missing allocatable vlans to table
|
# add missing allocatable vlans to table
|
||||||
for vlan_id in sorted(vlan_ids):
|
for vlan_id in sorted(vlan_ids):
|
||||||
@ -77,6 +81,16 @@ def sync_network_states(network_vlan_ranges):
|
|||||||
vlan_id)
|
vlan_id)
|
||||||
session.add(state)
|
session.add(state)
|
||||||
|
|
||||||
|
# remove from table unallocated vlans for any unconfigured physical
|
||||||
|
# networks
|
||||||
|
for states in allocations.itervalues():
|
||||||
|
for state in states:
|
||||||
|
if not state.allocated:
|
||||||
|
LOG.debug("removing vlan %s on physical network %s"
|
||||||
|
" from pool" %
|
||||||
|
(state.vlan_id, physical_network))
|
||||||
|
session.delete(state)
|
||||||
|
|
||||||
|
|
||||||
def get_network_state(physical_network, vlan_id):
|
def get_network_state(physical_network, vlan_id):
|
||||||
"""Get state of specified network"""
|
"""Get state of specified network"""
|
||||||
|
@ -64,9 +64,17 @@ def sync_vlan_allocations(network_vlan_ranges):
|
|||||||
|
|
||||||
session = db.get_session()
|
session = db.get_session()
|
||||||
with session.begin():
|
with session.begin():
|
||||||
# process vlan ranges for each physical network separately
|
# get existing allocations for all physical networks
|
||||||
for physical_network, vlan_ranges in network_vlan_ranges.iteritems():
|
allocations = dict()
|
||||||
|
allocs = (session.query(ovs_models_v2.VlanAllocation).
|
||||||
|
all())
|
||||||
|
for alloc in allocs:
|
||||||
|
if alloc.physical_network not in allocations:
|
||||||
|
allocations[alloc.physical_network] = set()
|
||||||
|
allocations[alloc.physical_network].add(alloc)
|
||||||
|
|
||||||
|
# process vlan ranges for each configured physical network
|
||||||
|
for physical_network, vlan_ranges in network_vlan_ranges.iteritems():
|
||||||
# determine current configured allocatable vlans for this
|
# determine current configured allocatable vlans for this
|
||||||
# physical network
|
# physical network
|
||||||
vlan_ids = set()
|
vlan_ids = set()
|
||||||
@ -74,11 +82,8 @@ def sync_vlan_allocations(network_vlan_ranges):
|
|||||||
vlan_ids |= set(xrange(vlan_range[0], vlan_range[1] + 1))
|
vlan_ids |= set(xrange(vlan_range[0], vlan_range[1] + 1))
|
||||||
|
|
||||||
# remove from table unallocated vlans not currently allocatable
|
# remove from table unallocated vlans not currently allocatable
|
||||||
try:
|
if physical_network in allocations:
|
||||||
allocs = (session.query(ovs_models_v2.VlanAllocation).
|
for alloc in allocations[physical_network]:
|
||||||
filter_by(physical_network=physical_network).
|
|
||||||
all())
|
|
||||||
for alloc in allocs:
|
|
||||||
try:
|
try:
|
||||||
# see if vlan is allocatable
|
# see if vlan is allocatable
|
||||||
vlan_ids.remove(alloc.vlan_id)
|
vlan_ids.remove(alloc.vlan_id)
|
||||||
@ -90,14 +95,23 @@ def sync_vlan_allocations(network_vlan_ranges):
|
|||||||
"%s from pool" %
|
"%s from pool" %
|
||||||
(alloc.vlan_id, physical_network))
|
(alloc.vlan_id, physical_network))
|
||||||
session.delete(alloc)
|
session.delete(alloc)
|
||||||
except exc.NoResultFound:
|
del allocations[physical_network]
|
||||||
pass
|
|
||||||
|
|
||||||
# add missing allocatable vlans to table
|
# add missing allocatable vlans to table
|
||||||
for vlan_id in sorted(vlan_ids):
|
for vlan_id in sorted(vlan_ids):
|
||||||
alloc = ovs_models_v2.VlanAllocation(physical_network, vlan_id)
|
alloc = ovs_models_v2.VlanAllocation(physical_network, vlan_id)
|
||||||
session.add(alloc)
|
session.add(alloc)
|
||||||
|
|
||||||
|
# remove from table unallocated vlans for any unconfigured physical
|
||||||
|
# networks
|
||||||
|
for allocs in allocations.itervalues():
|
||||||
|
for alloc in allocs:
|
||||||
|
if not alloc.allocated:
|
||||||
|
LOG.debug("removing vlan %s on physical network %s"
|
||||||
|
" from pool" %
|
||||||
|
(alloc.vlan_id, physical_network))
|
||||||
|
session.delete(alloc)
|
||||||
|
|
||||||
|
|
||||||
def get_vlan_allocation(physical_network, vlan_id):
|
def get_vlan_allocation(physical_network, vlan_id):
|
||||||
session = db.get_session()
|
session = db.get_session()
|
||||||
@ -188,22 +202,19 @@ def sync_tunnel_allocations(tunnel_id_ranges):
|
|||||||
session = db.get_session()
|
session = db.get_session()
|
||||||
with session.begin():
|
with session.begin():
|
||||||
# remove from table unallocated tunnels not currently allocatable
|
# remove from table unallocated tunnels not currently allocatable
|
||||||
try:
|
allocs = (session.query(ovs_models_v2.TunnelAllocation).
|
||||||
allocs = (session.query(ovs_models_v2.TunnelAllocation).
|
all())
|
||||||
all())
|
for alloc in allocs:
|
||||||
for alloc in allocs:
|
try:
|
||||||
try:
|
# see if tunnel is allocatable
|
||||||
# see if tunnel is allocatable
|
tunnel_ids.remove(alloc.tunnel_id)
|
||||||
tunnel_ids.remove(alloc.tunnel_id)
|
except KeyError:
|
||||||
except KeyError:
|
# it's not allocatable, so check if its allocated
|
||||||
# it's not allocatable, so check if its allocated
|
if not alloc.allocated:
|
||||||
if not alloc.allocated:
|
# it's not, so remove it from table
|
||||||
# it's not, so remove it from table
|
LOG.debug("removing tunnel %s from pool" %
|
||||||
LOG.debug("removing tunnel %s from pool" %
|
alloc.tunnel_id)
|
||||||
alloc.tunnel_id)
|
session.delete(alloc)
|
||||||
session.delete(alloc)
|
|
||||||
except exc.NoResultFound:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# add missing allocatable tunnels to table
|
# add missing allocatable tunnels to table
|
||||||
for tunnel_id in sorted(tunnel_ids):
|
for tunnel_id in sorted(tunnel_ids):
|
||||||
|
@ -20,10 +20,12 @@ from quantum.db import api as db
|
|||||||
from quantum.plugins.linuxbridge.db import l2network_db_v2 as lb_db
|
from quantum.plugins.linuxbridge.db import l2network_db_v2 as lb_db
|
||||||
|
|
||||||
PHYS_NET = 'physnet1'
|
PHYS_NET = 'physnet1'
|
||||||
|
PHYS_NET_2 = 'physnet2'
|
||||||
VLAN_MIN = 10
|
VLAN_MIN = 10
|
||||||
VLAN_MAX = 19
|
VLAN_MAX = 19
|
||||||
VLAN_RANGES = {PHYS_NET: [(VLAN_MIN, VLAN_MAX)]}
|
VLAN_RANGES = {PHYS_NET: [(VLAN_MIN, VLAN_MAX)]}
|
||||||
UPDATED_VLAN_RANGES = {PHYS_NET: [(VLAN_MIN + 5, VLAN_MAX + 5)]}
|
UPDATED_VLAN_RANGES = {PHYS_NET: [(VLAN_MIN + 5, VLAN_MAX + 5)],
|
||||||
|
PHYS_NET_2: [(VLAN_MIN + 20, VLAN_MAX + 20)]}
|
||||||
TEST_NETWORK_ID = 'abcdefghijklmnopqrstuvwxyz'
|
TEST_NETWORK_ID = 'abcdefghijklmnopqrstuvwxyz'
|
||||||
|
|
||||||
|
|
||||||
@ -43,6 +45,8 @@ class NetworkStatesTest(unittest2.TestCase):
|
|||||||
VLAN_MIN).allocated)
|
VLAN_MIN).allocated)
|
||||||
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
||||||
VLAN_MIN + 1).allocated)
|
VLAN_MIN + 1).allocated)
|
||||||
|
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
||||||
|
VLAN_MAX - 1).allocated)
|
||||||
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
||||||
VLAN_MAX).allocated)
|
VLAN_MAX).allocated)
|
||||||
self.assertIsNone(lb_db.get_network_state(PHYS_NET,
|
self.assertIsNone(lb_db.get_network_state(PHYS_NET,
|
||||||
@ -56,11 +60,46 @@ class NetworkStatesTest(unittest2.TestCase):
|
|||||||
VLAN_MIN + 5).allocated)
|
VLAN_MIN + 5).allocated)
|
||||||
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
||||||
VLAN_MIN + 5 + 1).allocated)
|
VLAN_MIN + 5 + 1).allocated)
|
||||||
|
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
||||||
|
VLAN_MAX + 5 - 1).allocated)
|
||||||
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
||||||
VLAN_MAX + 5).allocated)
|
VLAN_MAX + 5).allocated)
|
||||||
self.assertIsNone(lb_db.get_network_state(PHYS_NET,
|
self.assertIsNone(lb_db.get_network_state(PHYS_NET,
|
||||||
VLAN_MAX + 5 + 1))
|
VLAN_MAX + 5 + 1))
|
||||||
|
|
||||||
|
self.assertIsNone(lb_db.get_network_state(PHYS_NET_2,
|
||||||
|
VLAN_MIN + 20 - 1))
|
||||||
|
self.assertFalse(lb_db.get_network_state(PHYS_NET_2,
|
||||||
|
VLAN_MIN + 20).allocated)
|
||||||
|
self.assertFalse(lb_db.get_network_state(PHYS_NET_2,
|
||||||
|
VLAN_MIN + 20 + 1).allocated)
|
||||||
|
self.assertFalse(lb_db.get_network_state(PHYS_NET_2,
|
||||||
|
VLAN_MAX + 20 - 1).allocated)
|
||||||
|
self.assertFalse(lb_db.get_network_state(PHYS_NET_2,
|
||||||
|
VLAN_MAX + 20).allocated)
|
||||||
|
self.assertIsNone(lb_db.get_network_state(PHYS_NET_2,
|
||||||
|
VLAN_MAX + 20 + 1))
|
||||||
|
|
||||||
|
lb_db.sync_network_states(VLAN_RANGES)
|
||||||
|
|
||||||
|
self.assertIsNone(lb_db.get_network_state(PHYS_NET,
|
||||||
|
VLAN_MIN - 1))
|
||||||
|
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
||||||
|
VLAN_MIN).allocated)
|
||||||
|
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
||||||
|
VLAN_MIN + 1).allocated)
|
||||||
|
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
||||||
|
VLAN_MAX - 1).allocated)
|
||||||
|
self.assertFalse(lb_db.get_network_state(PHYS_NET,
|
||||||
|
VLAN_MAX).allocated)
|
||||||
|
self.assertIsNone(lb_db.get_network_state(PHYS_NET,
|
||||||
|
VLAN_MAX + 1))
|
||||||
|
|
||||||
|
self.assertIsNone(lb_db.get_network_state(PHYS_NET_2,
|
||||||
|
VLAN_MIN + 20))
|
||||||
|
self.assertIsNone(lb_db.get_network_state(PHYS_NET_2,
|
||||||
|
VLAN_MAX + 20))
|
||||||
|
|
||||||
def test_network_pool(self):
|
def test_network_pool(self):
|
||||||
vlan_ids = set()
|
vlan_ids = set()
|
||||||
for x in xrange(VLAN_MIN, VLAN_MAX + 1):
|
for x in xrange(VLAN_MIN, VLAN_MAX + 1):
|
||||||
|
@ -20,10 +20,12 @@ from quantum.db import api as db
|
|||||||
from quantum.plugins.openvswitch import ovs_db_v2
|
from quantum.plugins.openvswitch import ovs_db_v2
|
||||||
|
|
||||||
PHYS_NET = 'physnet1'
|
PHYS_NET = 'physnet1'
|
||||||
|
PHYS_NET_2 = 'physnet2'
|
||||||
VLAN_MIN = 10
|
VLAN_MIN = 10
|
||||||
VLAN_MAX = 19
|
VLAN_MAX = 19
|
||||||
VLAN_RANGES = {PHYS_NET: [(VLAN_MIN, VLAN_MAX)]}
|
VLAN_RANGES = {PHYS_NET: [(VLAN_MIN, VLAN_MAX)]}
|
||||||
UPDATED_VLAN_RANGES = {PHYS_NET: [(VLAN_MIN + 5, VLAN_MAX + 5)]}
|
UPDATED_VLAN_RANGES = {PHYS_NET: [(VLAN_MIN + 5, VLAN_MAX + 5)],
|
||||||
|
PHYS_NET_2: [(VLAN_MIN + 20, VLAN_MAX + 20)]}
|
||||||
TUN_MIN = 100
|
TUN_MIN = 100
|
||||||
TUN_MAX = 109
|
TUN_MAX = 109
|
||||||
TUNNEL_RANGES = [(TUN_MIN, TUN_MAX)]
|
TUNNEL_RANGES = [(TUN_MIN, TUN_MAX)]
|
||||||
@ -47,6 +49,8 @@ class VlanAllocationsTest(unittest2.TestCase):
|
|||||||
VLAN_MIN).allocated)
|
VLAN_MIN).allocated)
|
||||||
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
||||||
VLAN_MIN + 1).allocated)
|
VLAN_MIN + 1).allocated)
|
||||||
|
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
||||||
|
VLAN_MAX - 1).allocated)
|
||||||
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
||||||
VLAN_MAX).allocated)
|
VLAN_MAX).allocated)
|
||||||
self.assertIsNone(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
self.assertIsNone(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
||||||
@ -71,6 +75,43 @@ class VlanAllocationsTest(unittest2.TestCase):
|
|||||||
self.assertIsNone(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
self.assertIsNone(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
||||||
VLAN_MAX + 5 + 1))
|
VLAN_MAX + 5 + 1))
|
||||||
|
|
||||||
|
self.assertIsNone(ovs_db_v2.get_vlan_allocation(PHYS_NET_2,
|
||||||
|
VLAN_MIN + 20 - 1))
|
||||||
|
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET_2,
|
||||||
|
VLAN_MIN + 20).
|
||||||
|
allocated)
|
||||||
|
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET_2,
|
||||||
|
VLAN_MIN + 20 + 1).
|
||||||
|
allocated)
|
||||||
|
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET_2,
|
||||||
|
VLAN_MAX + 20 - 1).
|
||||||
|
allocated)
|
||||||
|
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET_2,
|
||||||
|
VLAN_MAX + 20).
|
||||||
|
allocated)
|
||||||
|
self.assertIsNone(ovs_db_v2.get_vlan_allocation(PHYS_NET_2,
|
||||||
|
VLAN_MAX + 20 + 1))
|
||||||
|
|
||||||
|
ovs_db_v2.sync_vlan_allocations(VLAN_RANGES)
|
||||||
|
|
||||||
|
self.assertIsNone(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
||||||
|
VLAN_MIN - 1))
|
||||||
|
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
||||||
|
VLAN_MIN).allocated)
|
||||||
|
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
||||||
|
VLAN_MIN + 1).allocated)
|
||||||
|
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
||||||
|
VLAN_MAX - 1).allocated)
|
||||||
|
self.assertFalse(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
||||||
|
VLAN_MAX).allocated)
|
||||||
|
self.assertIsNone(ovs_db_v2.get_vlan_allocation(PHYS_NET,
|
||||||
|
VLAN_MAX + 1))
|
||||||
|
|
||||||
|
self.assertIsNone(ovs_db_v2.get_vlan_allocation(PHYS_NET_2,
|
||||||
|
VLAN_MIN + 20))
|
||||||
|
self.assertIsNone(ovs_db_v2.get_vlan_allocation(PHYS_NET_2,
|
||||||
|
VLAN_MAX + 20))
|
||||||
|
|
||||||
def test_vlan_pool(self):
|
def test_vlan_pool(self):
|
||||||
vlan_ids = set()
|
vlan_ids = set()
|
||||||
for x in xrange(VLAN_MIN, VLAN_MAX + 1):
|
for x in xrange(VLAN_MIN, VLAN_MAX + 1):
|
||||||
@ -138,6 +179,8 @@ class TunnelAllocationsTest(unittest2.TestCase):
|
|||||||
self.assertFalse(ovs_db_v2.get_tunnel_allocation(TUN_MIN).allocated)
|
self.assertFalse(ovs_db_v2.get_tunnel_allocation(TUN_MIN).allocated)
|
||||||
self.assertFalse(ovs_db_v2.get_tunnel_allocation(TUN_MIN + 1).
|
self.assertFalse(ovs_db_v2.get_tunnel_allocation(TUN_MIN + 1).
|
||||||
allocated)
|
allocated)
|
||||||
|
self.assertFalse(ovs_db_v2.get_tunnel_allocation(TUN_MAX - 1).
|
||||||
|
allocated)
|
||||||
self.assertFalse(ovs_db_v2.get_tunnel_allocation(TUN_MAX).allocated)
|
self.assertFalse(ovs_db_v2.get_tunnel_allocation(TUN_MAX).allocated)
|
||||||
self.assertIsNone(ovs_db_v2.get_tunnel_allocation(TUN_MAX + 1))
|
self.assertIsNone(ovs_db_v2.get_tunnel_allocation(TUN_MAX + 1))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user