Fix for failing network operations in Cisco plugin

Bug #1050545

This fixes the exceptions occurring in the virtual switch mode of the
Cisco plugin for create/delete/update network operations. The exceptions
were occurring on account of the recent changes in the OVS module to the
get_vlan and get_vlans methods, which were still being invoked here.
Test configuration has been changed to increase the code coverage to
catch such issues in the future. All changes are limited to the Cisco
plugin and related tests.

Change-Id: Id18473f7a9a2a22217a59b4f8b1541b4918e07e7
This commit is contained in:
Sumit Naiksatam 2012-09-14 17:50:54 -07:00
parent 59fe9efa6c
commit 8786e547f9
5 changed files with 30 additions and 36 deletions

View File

@ -1,6 +1,7 @@
[PLUGINS]
#ucs_plugin=quantum.plugins.cisco.ucs.cisco_ucs_plugin_v2.UCSVICPlugin
#nexus_plugin=quantum.plugins.cisco.nexus.cisco_nexus_plugin_v2.NexusPlugin
vswitch_plugin=quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2
[INVENTORY]
#ucs_plugin=quantum.plugins.cisco.ucs.cisco_ucs_inventory_v2.UCSInventory

View File

@ -13,8 +13,8 @@ max_port_profiles=65568
max_networks=65568
[MODEL]
#model_class=quantum.plugins.cisco.models.l2network_multi_blade.L2NetworkMultiBlade
model_class=quantum.plugins.cisco.models.network_multi_blade_v2.NetworkMultiBladeV2
#model_class=quantum.plugins.cisco.models.network_multi_blade_v2.NetworkMultiBladeV2
model_class=quantum.plugins.cisco.models.virt_phy_sw_v2.VirtualPhysicalSwitchModelV2
[SEGMENTATION]
manager_class=quantum.plugins.cisco.segmentation.l2network_vlan_mgr_v2.L2NetworkVLANMgr

View File

@ -28,6 +28,7 @@ from quantum.plugins.cisco.db import network_models_v2
from quantum.plugins.cisco.db import nexus_models_v2
from quantum.plugins.cisco.db import ucs_models_v2
from quantum.plugins.cisco import l2network_plugin_configuration as conf
from quantum.plugins.openvswitch import ovs_models_v2
def initialize():
@ -525,3 +526,14 @@ def update_credential(tenant_id, credential_id,
except exc.NoResultFound:
raise c_exc.CredentialNotFound(credential_id=credential_id,
tenant_id=tenant_id)
def get_ovs_vlans():
session = db.get_session()
try:
bindings = (session.query(ovs_models_v2.VlanAllocation).
filter_by(allocated=True).
all())
except exc.NoResultFound:
return []
return [binding.vlan_id for binding in bindings]

View File

@ -163,6 +163,10 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
else:
return func(*args)
def _get_segmentation_id(self, network_id):
binding_seg_id = odb.get_network_binding(None, network_id)
return binding_seg_id.segmentation_id
def create_network(self, context, network):
"""
Perform this operation in the context of the configured device
@ -174,12 +178,12 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
ovs_output = self._invoke_plugin_per_device(const.VSWITCH_PLUGIN,
self._func_name(),
args)
vlan_id = odb.get_vlan(ovs_output[0]['id'])
vlan_id = self._get_segmentation_id(ovs_output[0]['id'])
vlan_name = conf.VLAN_NAME_PREFIX + str(vlan_id)
vlan_ids = odb.get_vlans()
vlan_ids = cdb.get_ovs_vlans()
vlanids = ''
for v_id in vlan_ids:
vlanids = str(v_id[0]) + ',' + vlanids
vlanids = str(v_id) + ',' + vlanids
vlanids = vlanids.strip(',')
args = [ovs_output[0]['tenant_id'], ovs_output[0]['name'],
ovs_output[0]['id'], vlan_name, vlan_id,
@ -202,7 +206,7 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
args = [context, networks]
ovs_output = self._plugins[
const.VSWITCH_PLUGIN].create_network_bulk(context, networks)
vlan_ids = odb.get_vlans()
vlan_ids = cdb.get_ovs_vlans()
vlanids = ''
for v_id in vlan_ids:
vlanids = str(v_id[0]) + ',' + vlanids
@ -210,7 +214,7 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
LOG.debug("ovs_output: %s\n " % ovs_output)
ovs_networks = ovs_output
for ovs_network in ovs_networks:
vlan_id = odb.get_vlan(ovs_network['id'])
vlan_id = self._get_segmentation_id(ovs_network['id'])
vlan_name = conf.VLAN_NAME_PREFIX + str(vlan_id)
args = [ovs_network['tenant_id'], ovs_network['name'],
ovs_network['id'], vlan_name, vlan_id,
@ -232,8 +236,8 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
ovs_output = self._invoke_plugin_per_device(const.VSWITCH_PLUGIN,
self._func_name(),
args)
vlan_id = odb.get_vlan(ovs_output[0]['id'])
vlan_ids = ','.join(str(vlan[0]) for vlan in odb.get_vlans())
vlan_id = self._get_segmentation_id(ovs_output[0]['id'])
vlan_ids = ','.join(str(vlan[0]) for vlan in cdb.get_ovs_vlans())
args = [ovs_output[0]['tenant_id'], id, {'vlan_id': vlan_id},
{'net_admin_state': ovs_output[0]['admin_state_up']},
{'vlan_ids': vlan_ids}]
@ -251,7 +255,7 @@ class VirtualPhysicalSwitchModelV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
base_plugin_ref = QuantumManager.get_plugin()
n = base_plugin_ref.get_network(context, id)
tenant_id = n['tenant_id']
vlan_id = odb.get_vlan(id)
vlan_id = self._get_segmentation_id(id)
output = []
args = [tenant_id, id, {const.VLANID:vlan_id},
{const.CONTEXT:context},

View File

@ -22,11 +22,13 @@ from quantum.common import config
from quantum.common.test_lib import test_config
from quantum import context
from quantum.db import api as db
from quantum.db import l3_db
from quantum.extensions import _quotav2_model as quotav2_model
from quantum.manager import QuantumManager
from quantum.plugins.cisco.common import cisco_constants as const
from quantum.plugins.cisco.db import network_db_v2
from quantum.plugins.cisco.db import network_models_v2
from quantum.plugins.openvswitch import ovs_models_v2
from quantum.openstack.common import cfg
from quantum.tests.unit import test_db_plugin
from quantum.wsgi import JSONDeserializer
@ -39,38 +41,13 @@ class CiscoNetworkPluginV2TestCase(test_db_plugin.QuantumDbPluginV2TestCase):
_plugin_name = 'quantum.plugins.cisco.network_plugin.PluginV2'
def setUp(self):
super(CiscoNetworkPluginV2TestCase, self).setUp()
db._ENGINE = None
db._MAKER = None
QuantumManager._instance = None
# Update the plugin
cfg.CONF.set_override('core_plugin', self._plugin_name)
def new_init():
db.configure_db({'sql_connection': 'sqlite://',
'base': network_models_v2.model_base.BASEV2})
with mock.patch.object(network_db_v2,
'initialize', new=new_init):
self.api = APIRouter()
def _is_native_bulk_supported():
plugin_obj = QuantumManager.get_plugin()
native_bulk_attr_name = ("_%s__native_bulk_support"
% plugin_obj.__class__.__name__)
return getattr(plugin_obj, native_bulk_attr_name, False)
self._skip_native_bulk = not _is_native_bulk_supported()
LOG.debug("%s.%s.%s done" % (__name__, self.__class__.__name__,
inspect.stack()[0][3]))
def tearDown(self):
db.clear_db(network_models_v2.model_base.BASEV2)
db._ENGINE = None
db._MAKER = None
cfg.CONF.reset()
super(CiscoNetworkPluginV2TestCase, self).setUp(self._plugin_name)
def _get_plugin_ref(self):
plugin_obj = QuantumManager.get_plugin()