From: Edgar Magana Date: Thu, 25 Aug 2011 19:34:03 +0000 (-0700) Subject: Fixed the Unit Test for Nexus Driver X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=51ddffa2641d0cf0725f7a5147ad0b90551e36a0;p=openstack-build%2Fneutron-build.git Fixed the Unit Test for Nexus Driver --- diff --git a/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py b/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py index fce17dfb1..717be135f 100644 --- a/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py +++ b/quantum/plugins/cisco/nexus/cisco_nexus_network_driver.py @@ -143,4 +143,6 @@ class CiscoNEXUSDriver(): vlans = '' for vlanid in assigned_vlan: vlans = str(vlanid["vlan_id"]) + ',' + vlans + if vlans == '': + vlans = 'none' return vlans.strip(',') diff --git a/quantum/plugins/cisco/tests/unit/test_nexus_plugin.py b/quantum/plugins/cisco/tests/unit/test_nexus_plugin.py index e9f95f1fc..bfb7b851b 100644 --- a/quantum/plugins/cisco/tests/unit/test_nexus_plugin.py +++ b/quantum/plugins/cisco/tests/unit/test_nexus_plugin.py @@ -20,6 +20,7 @@ from quantum.common import exceptions as exc from quantum.plugins.cisco.common import cisco_constants as const from quantum.plugins.cisco.nexus import cisco_nexus_plugin from quantum.plugins.cisco.db import l2network_db as cdb +from quantum.plugins.cisco.db import api as db LOG = logging.getLogger('quantum.tests.test_nexus') @@ -34,8 +35,8 @@ class TestNexusPlugin(unittest.TestCase): self.vlan_name = "q-" + str(self.net_id) + "vlan" self.vlan_id = 267 self.port_id = "9" - self._cisco_nexus_plugin = cisco_nexus_plugin.NexusPlugin() cdb.initialize() + self._cisco_nexus_plugin = cisco_nexus_plugin.NexusPlugin() def test_create_network(self, net_tenant_id=None, network_name=None, network_id=None, net_vlan_name=None, @@ -66,6 +67,8 @@ class TestNexusPlugin(unittest.TestCase): else: vlan_id = self.vlan_id + network_created = self.create_network(tenant_id, net_id) + cdb.add_vlan_binding(vlan_id, vlan_name, network_created["net-id"]) new_net_dict = self._cisco_nexus_plugin.create_network( tenant_id, net_name, net_id, vlan_name, vlan_id) self.assertEqual(new_net_dict[const.NET_ID], self.net_id) @@ -260,6 +263,19 @@ class TestNexusPlugin(unittest.TestCase): self.tearDownNetwork(tenant_id, new_net_dict[const.NET_ID]) LOG.debug("test_get_vlan_id_for_network - END") + def create_network(self, tenant_id, net_name): + """Create a network""" + net_dict = {} + try: + res = db.network_create(tenant_id, net_name) + LOG.debug("Created network: %s" % res.uuid) + net_dict["tenant-id"] = res.tenant_id + net_dict["net-id"] = str(res.uuid) + net_dict["net-name"] = res.name + return net_dict + except Exception, exc: + LOG.error("Failed to create network: %s" % str(exc)) + def tearDownNetwork(self, tenant_id, network_dict_id): """ Clean up functions after the tests