# under the License.
# @author: Rohit Agarwalla, Cisco Systems, Inc.
+"""
+test_database.py is an independent test suite
+that tests the database api method calls
+"""
import logging as LOG
import unittest
-from optparse import OptionParser
from quantum.plugins.cisco.common import cisco_constants as const
import quantum.plugins.cisco.db.api as db
vlan_dict["vlan-name"] = vlan_bind.vlan_name
vlan_dict["net-id"] = str(vlan_bind.network_id)
vlans.append(vlan_dict)
- except Exception, e:
- LOG.error("Failed to get all vlan bindings: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to get all vlan bindings: %s" % str(exc))
return vlans
def get_vlan_binding(self, network_id):
vlan_dict["vlan-name"] = vlan_bind.vlan_name
vlan_dict["net-id"] = str(vlan_bind.network_id)
vlan.append(vlan_dict)
- except Exception, e:
- LOG.error("Failed to get vlan binding: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to get vlan binding: %s" % str(exc))
return vlan
def create_vlan_binding(self, vlan_id, vlan_name, network_id):
vlan_dict["vlan-name"] = res.vlan_name
vlan_dict["net-id"] = str(res.network_id)
return vlan_dict
- except Exception, e:
- LOG.error("Failed to create vlan binding: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to create vlan binding: %s" % str(exc))
def delete_vlan_binding(self, network_id):
"""Delete a vlan binding"""
vlan_dict = {}
vlan_dict["vlan-id"] = str(res.vlan_id)
return vlan_dict
- except Exception, e:
- raise Exception("Failed to delete vlan binding: %s" % str(e))
+ except Exception, exc:
+ raise Exception("Failed to delete vlan binding: %s" % str(exc))
def update_vlan_binding(self, network_id, vlan_id, vlan_name):
"""Update a vlan binding"""
vlan_dict["vlan-name"] = res.vlan_name
vlan_dict["net-id"] = str(res.network_id)
return vlan_dict
- except Exception, e:
- raise Exception("Failed to update vlan binding: %s" % str(e))
+ except Exception, exc:
+ raise Exception("Failed to update vlan binding: %s" % str(exc))
def get_all_portprofiles(self):
"""Get all portprofiles"""
pp_dict["vlan-id"] = str(portprof.vlan_id)
pp_dict["qos"] = portprof.qos
pps.append(pp_dict)
- except Exception, e:
- LOG.error("Failed to get all port profiles: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to get all port profiles: %s" % str(exc))
return pps
def get_portprofile(self, tenant_id, pp_id):
"""Get a portprofile"""
- pp = []
+ pp_list = []
try:
for portprof in l2network_db.get_portprofile(tenant_id, pp_id):
LOG.debug("Getting port profile : %s" % portprof.uuid)
pp_dict["portprofile-name"] = portprof.name
pp_dict["vlan-id"] = str(portprof.vlan_id)
pp_dict["qos"] = portprof.qos
- pp.append(pp_dict)
- except Exception, e:
- LOG.error("Failed to get port profile: %s" % str(e))
+ pp_list.append(pp_dict)
+ except Exception, exc:
+ LOG.error("Failed to get port profile: %s" % str(exc))
return pp
def create_portprofile(self, tenant_id, name, vlan_id, qos):
pp_dict["vlan-id"] = str(res.vlan_id)
pp_dict["qos"] = res.qos
return pp_dict
- except Exception, e:
- LOG.error("Failed to create port profile: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to create port profile: %s" % str(exc))
def delete_portprofile(self, tenant_id, pp_id):
"""Delete a portprofile"""
pp_dict = {}
pp_dict["pp-id"] = str(res.uuid)
return pp_dict
- except Exception, e:
- raise Exception("Failed to delete port profile: %s" % str(e))
+ except Exception, exc:
+ raise Exception("Failed to delete port profile: %s" % str(exc))
def update_portprofile(self, tenant_id, pp_id, name, vlan_id, qos):
"""Update a portprofile"""
pp_dict["vlan-id"] = str(res.vlan_id)
pp_dict["qos"] = res.qos
return pp_dict
- except Exception, e:
- raise Exception("Failed to update port profile: %s" % str(e))
+ except Exception, exc:
+ raise Exception("Failed to update port profile: %s" % str(exc))
def get_all_pp_bindings(self):
"""Get all portprofile bindings"""
ppbinding_dict["tenant-id"] = pp_bind.tenant_id
ppbinding_dict["default"] = pp_bind.default
pp_bindings.append(ppbinding_dict)
- except Exception, e:
- LOG.error("Failed to get all port profiles: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to get all port profiles: %s" % str(exc))
return pp_bindings
def get_pp_binding(self, tenant_id, pp_id):
ppbinding_dict["tenant-id"] = pp_bind.tenant_id
ppbinding_dict["default"] = pp_bind.default
pp_binding.append(ppbinding_dict)
- except Exception, e:
- LOG.error("Failed to get port profile binding: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to get port profile binding: %s" % str(exc))
return pp_binding
def create_pp_binding(self, tenant_id, port_id, pp_id, default):
ppbinding_dict["tenant-id"] = res.tenant_id
ppbinding_dict["default"] = res.default
return ppbinding_dict
- except Exception, e:
- LOG.error("Failed to create port profile binding: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to create port profile binding: %s" % str(exc))
def delete_pp_binding(self, tenant_id, port_id, pp_id):
"""Delete a portprofile binding"""
ppbinding_dict = {}
ppbinding_dict["portprofile-id"] = str(res.portprofile_id)
return ppbinding_dict
- except Exception, e:
- raise Exception("Failed to delete port profile: %s" % str(e))
+ except Exception, exc:
+ raise Exception("Failed to delete port profile: %s" % str(exc))
def update_pp_binding(self, tenant_id, pp_id, newtenant_id, \
port_id, default):
ppbinding_dict["tenant-id"] = res.tenant_id
ppbinding_dict["default"] = res.default
return ppbinding_dict
- except Exception, e:
- raise Exception("Failed to update portprofile binding:%s" % str(e))
+ except Exception, exc:
+ raise Exception("Failed to update portprofile binding:%s" \
+ % str(exc))
class QuantumDB(object):
net_dict["net-id"] = str(net.uuid)
net_dict["net-name"] = net.name
nets.append(net_dict)
- except Exception, e:
- LOG.error("Failed to get all networks: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to get all networks: %s" % str(exc))
return nets
def get_network(self, network_id):
net_dict["net-id"] = str(net.uuid)
net_dict["net-name"] = net.name
net.append(net_dict)
- except Exception, e:
- LOG.error("Failed to get network: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to get network: %s" % str(exc))
return net
def create_network(self, tenant_id, net_name):
net_dict["net-id"] = str(res.uuid)
net_dict["net-name"] = res.name
return net_dict
- except Exception, e:
- LOG.error("Failed to create network: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to create network: %s" % str(exc))
def delete_network(self, net_id):
"""Delete a network"""
net_dict = {}
net_dict["net-id"] = str(net.uuid)
return net_dict
- except Exception, e:
- raise Exception("Failed to delete port: %s" % str(e))
+ except Exception, exc:
+ raise Exception("Failed to delete port: %s" % str(exc))
def rename_network(self, tenant_id, net_id, new_name):
"""Rename a network"""
net_dict["net-id"] = str(net.uuid)
net_dict["net-name"] = net.name
return net_dict
- except Exception, e:
- raise Exception("Failed to rename network: %s" % str(e))
+ except Exception, exc:
+ raise Exception("Failed to rename network: %s" % str(exc))
def get_all_ports(self, net_id):
"""Get all ports"""
port_dict["net"] = port.network
ports.append(port_dict)
return ports
- except Exception, e:
- LOG.error("Failed to get all ports: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to get all ports: %s" % str(exc))
def get_port(self, net_id, port_id):
"""Get a port"""
port_dict["state"] = port.state
port_list.append(port_dict)
return port_list
- except Exception, e:
- LOG.error("Failed to get port: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to get port: %s" % str(exc))
def create_port(self, net_id):
"""Add a port"""
port_dict["int-id"] = port.interface_id
port_dict["state"] = port.state
return port_dict
- except Exception, e:
- LOG.error("Failed to create port: %s" % str(e))
+ except Exception, exc:
+ LOG.error("Failed to create port: %s" % str(exc))
def delete_port(self, net_id, port_id):
"""Delete a port"""
port_dict = {}
port_dict["port-id"] = str(port.uuid)
return port_dict
- except Exception, e:
- raise Exception("Failed to delete port: %s" % str(e))
+ except Exception, exc:
+ raise Exception("Failed to delete port: %s" % str(exc))
def update_port(self, net_id, port_id, port_state):
"""Update a port"""
port_dict["int-id"] = port.interface_id
port_dict["state"] = port.state
return port_dict
- except Exception, e:
- raise Exception("Failed to update port state: %s" % str(e))
+ except Exception, exc:
+ raise Exception("Failed to update port state: %s" % str(exc))
def plug_interface(self, net_id, port_id, int_id):
"""Plug interface to a port"""
port_dict["int-id"] = port.interface_id
port_dict["state"] = port.state
return port_dict
- except Exception, e:
- raise Exception("Failed to plug interface: %s" % str(e))
+ except Exception, exc:
+ raise Exception("Failed to plug interface: %s" % str(exc))
def unplug_interface(self, net_id, port_id):
"""Unplug interface to a port"""
port_dict["int-id"] = port.interface_id
port_dict["state"] = port.state
return port_dict
- except Exception, e:
- raise Exception("Failed to unplug interface: %s" % str(e))
+ except Exception, exc:
+ raise Exception("Failed to unplug interface: %s" % str(exc))
class L2networkDBTest(unittest.TestCase):
"""Class conisting of L2network DB unit tests"""
def setUp(self):
"""Setup for tests"""
+ l2network_db.initialize()
self.dbtest = L2networkDB()
self.quantum = QuantumDB()
LOG.debug("Setup")
- def testACreateVlanBinding(self):
+ def tearDown(self):
+ """Tear Down"""
+ db.clear_db()
+
+ def testa_create_vlanbinding(self):
"""test add vlan binding"""
net1 = self.quantum.create_network("t1", "netid1")
vlan1 = self.dbtest.create_vlan_binding(10, "vlan1", net1["net-id"])
self.assertTrue(vlan1["vlan-id"] == "10")
- self.tearDownVlanBinding()
- self.tearDownNetwork()
+ self.teardown_vlanbinding()
+ self.teardown_network()
- def testBGetAllVlanBindings(self):
+ def testb_getall_vlanbindings(self):
"""test get all vlan binding"""
net1 = self.quantum.create_network("t1", "netid1")
net2 = self.quantum.create_network("t1", "netid2")
if "vlan" in vlan["vlan-name"]:
count += 1
self.assertTrue(count == 2)
- self.tearDownVlanBinding()
- self.tearDownNetwork()
+ self.teardown_vlanbinding()
+ self.teardown_network()
- def testCDeleteVlanBinding(self):
+ def testc_delete_vlanbinding(self):
"""test delete vlan binding"""
net1 = self.quantum.create_network("t1", "netid1")
vlan1 = self.dbtest.create_vlan_binding(10, "vlan1", net1["net-id"])
if "vlan " in vlan["vlan-name"]:
count += 1
self.assertTrue(count == 0)
- self.tearDownVlanBinding()
- self.tearDownNetwork()
+ self.teardown_vlanbinding()
+ self.teardown_network()
- def testDUpdateVlanBinding(self):
+ def testd_update_vlanbinding(self):
"""test update vlan binding"""
net1 = self.quantum.create_network("t1", "netid1")
vlan1 = self.dbtest.create_vlan_binding(10, "vlan1", net1["net-id"])
if "new" in vlan["vlan-name"]:
count += 1
self.assertTrue(count == 1)
- self.tearDownVlanBinding()
- self.tearDownNetwork()
+ self.teardown_vlanbinding()
+ self.teardown_network()
- def testICreatePortProfile(self):
+ def teste_create_portprofile(self):
"""test add port profile"""
pp1 = self.dbtest.create_portprofile("t1", "portprofile1", 10, "qos1")
self.assertTrue(pp1["portprofile-name"] == "portprofile1")
- self.tearDownPortProfile()
- self.tearDownNetwork()
+ self.teardown_portprofile()
+ self.teardown_network()
- def testJGetAllPortProfile(self):
+ def testf_getall_portprofile(self):
"""test get all portprofiles"""
pp1 = self.dbtest.create_portprofile("t1", "portprofile1", 10, "qos1")
self.assertTrue(pp1["portprofile-name"] == "portprofile1")
if "portprofile" in pprofile["portprofile-name"]:
count += 1
self.assertTrue(count == 2)
- self.tearDownPortProfile()
+ self.teardown_portprofile()
- def testKDeletePortProfile(self):
+ def testg_delete_portprofile(self):
"""test delete portprofile"""
pp1 = self.dbtest.create_portprofile("t1", "portprofile1", 10, "qos1")
self.assertTrue(pp1["portprofile-name"] == "portprofile1")
if "portprofile " in pprofile["portprofile-name"]:
count += 1
self.assertTrue(count == 0)
- self.tearDownPortProfile()
+ self.teardown_portprofile()
- def testLUpdatePortProfile(self):
+ def testh_update_portprofile(self):
"""test update portprofile"""
pp1 = self.dbtest.create_portprofile("t1", "portprofile1", 10, "qos1")
self.assertTrue(pp1["portprofile-name"] == "portprofile1")
if "new" in pprofile["portprofile-name"]:
count += 1
self.assertTrue(count == 1)
- self.tearDownPortProfile()
+ self.teardown_portprofile()
- def testMCreatePortProfileBinding(self):
+ def testi_create_portprofilebinding(self):
"""test create portprofile binding"""
net1 = self.quantum.create_network("t1", "netid1")
port1 = self.quantum.create_port(net1["net-id"])
pp_binding1 = self.dbtest.create_pp_binding("t1", port1["port-id"], \
pp1["portprofile-id"], "0")
self.assertTrue(pp_binding1["tenant-id"] == "t1")
- self.tearDownPortProfileBinding()
- self.tearDownPort()
- self.tearDownNetwork()
- self.tearDownPortProfile()
+ self.teardown_portprofilebinding()
+ self.teardown_port()
+ self.teardown_network()
+ self.teardown_portprofile()
- def testNGetAllPortProfileBinding(self):
+ def testj_getall_portprofilebinding(self):
"""test get all portprofile binding"""
net1 = self.quantum.create_network("t1", "netid1")
port1 = self.quantum.create_port(net1["net-id"])
if "t1" in pp_bind["tenant-id"]:
count += 1
self.assertTrue(count == 2)
- self.tearDownPortProfileBinding()
- self.tearDownPort()
- self.tearDownNetwork()
- self.tearDownPortProfile()
+ self.teardown_portprofilebinding()
+ self.teardown_port()
+ self.teardown_network()
+ self.teardown_portprofile()
- def testODeletePortProfileBinding(self):
+ def testk_delete_portprofilebinding(self):
"""test delete portprofile binding"""
net1 = self.quantum.create_network("t1", "netid1")
port1 = self.quantum.create_port(net1["net-id"])
if "t1 " in pp_bind["tenant-id"]:
count += 1
self.assertTrue(count == 0)
- self.tearDownPortProfileBinding()
- self.tearDownPort()
- self.tearDownNetwork()
- self.tearDownPortProfile()
+ self.teardown_portprofilebinding()
+ self.teardown_port()
+ self.teardown_network()
+ self.teardown_portprofile()
- def testPUpdatePortProfileBinding(self):
+ def testl_update_portprofilebinding(self):
"""test update portprofile binding"""
net1 = self.quantum.create_network("t1", "netid1")
port1 = self.quantum.create_port(net1["net-id"])
if "new" in pp_bind["tenant-id"]:
count += 1
self.assertTrue(count == 1)
- self.tearDownPortProfileBinding()
- self.tearDownPort()
- self.tearDownNetwork()
- self.tearDownPortProfile()
+ self.teardown_portprofilebinding()
+ self.teardown_port()
+ self.teardown_network()
+ self.teardown_portprofile()
- def testQtest_vlanids(self):
+ def testm_test_vlanids(self):
"""test vlanid methods"""
l2network_db.create_vlanids()
vlanids = l2network_db.get_all_vlanids()
self.assertTrue(used == True)
used = l2network_db.release_vlanid(vlanid)
self.assertTrue(used == False)
- self.tearDownVlanID()
+ self.teardown_vlanid()
- def tearDownNetwork(self):
+ def teardown_network(self):
"""tearDown Network table"""
LOG.debug("Tearing Down Network")
nets = self.quantum.get_all_networks("t1")
netid = net["net-id"]
self.quantum.delete_network(netid)
- def tearDownPort(self):
+ def teardown_port(self):
"""tearDown Port table"""
LOG.debug("Tearing Down Port")
nets = self.quantum.get_all_networks("t1")
portid = port["port-id"]
self.quantum.delete_port(netid, portid)
- def tearDownVlanBinding(self):
+ def teardown_vlanbinding(self):
"""tearDown VlanBinding table"""
LOG.debug("Tearing Down Vlan Binding")
vlans = self.dbtest.get_all_vlan_bindings()
netid = vlan["net-id"]
self.dbtest.delete_vlan_binding(netid)
- def tearDownPortProfile(self):
+ def teardown_portprofile(self):
"""tearDown PortProfile table"""
LOG.debug("Tearing Down Port Profile")
pps = self.dbtest.get_all_portprofiles()
ppid = pprofile["portprofile-id"]
self.dbtest.delete_portprofile("t1", ppid)
- def tearDownPortProfileBinding(self):
+ def teardown_portprofilebinding(self):
"""tearDown PortProfileBinding table"""
LOG.debug("Tearing Down Port Profile Binding")
pp_bindings = self.dbtest.get_all_pp_bindings()
portid = pp_binding["port-id"]
self.dbtest.delete_pp_binding("t1", portid, ppid)
- def tearDownVlanID(self):
+ def teardown_vlanid(self):
"""tearDown VlanID table"""
LOG.debug("Tearing Down Vlan IDs")
vlanids = l2network_db.get_all_vlanids()
"""Class conisting of Quantum DB unit tests"""
def setUp(self):
"""Setup for tests"""
+ l2network_db.initialize()
self.dbtest = QuantumDB()
self.tenant_id = "t1"
LOG.debug("Setup")
- def testACreateNetwork(self):
+ def tearDown(self):
+ """Tear Down"""
+ db.clear_db()
+
+ def testa_create_network(self):
"""test to create network"""
net1 = self.dbtest.create_network(self.tenant_id, "plugin_test1")
self.assertTrue(net1["net-name"] == "plugin_test1")
- self.tearDownNetworkPort()
+ self.teardown_network_port()
- def testBGetNetworks(self):
+ def testb_get_networks(self):
"""test to get all networks"""
net1 = self.dbtest.create_network(self.tenant_id, "plugin_test1")
self.assertTrue(net1["net-name"] == "plugin_test1")
if "plugin_test" in net["net-name"]:
count += 1
self.assertTrue(count == 2)
- self.tearDownNetworkPort()
+ self.teardown_network_port()
- def testCDeleteNetwork(self):
+ def testc_delete_network(self):
"""test to delete network"""
net1 = self.dbtest.create_network(self.tenant_id, "plugin_test1")
self.assertTrue(net1["net-name"] == "plugin_test1")
if "plugin_test1" in net["net-name"]:
count += 1
self.assertTrue(count == 0)
- self.tearDownNetworkPort()
+ self.teardown_network_port()
- def testDRenameNetwork(self):
+ def testd_rename_network(self):
"""test to rename network"""
net1 = self.dbtest.create_network(self.tenant_id, "plugin_test1")
self.assertTrue(net1["net-name"] == "plugin_test1")
net = self.dbtest.rename_network(self.tenant_id, net1["net-id"],
"plugin_test1_renamed")
self.assertTrue(net["net-name"] == "plugin_test1_renamed")
- self.tearDownNetworkPort()
+ self.teardown_network_port()
- def testECreatePort(self):
+ def teste_create_port(self):
"""test to create port"""
net1 = self.dbtest.create_network(self.tenant_id, "plugin_test1")
port = self.dbtest.create_port(net1["net-id"])
for por in ports:
count += 1
self.assertTrue(count == 1)
- self.tearDownNetworkPort()
+ self.teardown_network_port()
- def testFDeletePort(self):
+ def testf_delete_port(self):
"""test to delete port"""
net1 = self.dbtest.create_network(self.tenant_id, "plugin_test1")
port = self.dbtest.create_port(net1["net-id"])
for por in ports:
count += 1
self.assertTrue(count == 0)
- self.tearDownNetworkPort()
+ self.teardown_network_port()
- def testGPlugUnPlugInterface(self):
+ def testg_plug_unplug_interface(self):
"""test to plug/unplug interface"""
net1 = self.dbtest.create_network(self.tenant_id, "plugin_test1")
port1 = self.dbtest.create_port(net1["net-id"])
self.dbtest.unplug_interface(net1["net-id"], port1["port-id"])
port = self.dbtest.get_port(net1["net-id"], port1["port-id"])
self.assertTrue(port[0]["int-id"] == None)
- self.tearDownNetworkPort()
+ self.teardown_network_port()
- def testIJoinedTest(self):
+ def testh_joined_test(self):
"""test to get network and port"""
net1 = self.dbtest.create_network("t1", "net1")
port1 = self.dbtest.create_port(net1["net-id"])
for port in ports:
net = port["net"]
LOG.debug("Port id %s Net id %s" % (port["port-id"], net.uuid))
- self.tearDownJoinedTest()
+ self.teardown_joined_test()
- def tearDownNetworkPort(self):
+ def teardown_network_port(self):
"""tearDown for Network and Port table"""
networks = self.dbtest.get_all_networks(self.tenant_id)
for net in networks:
self.dbtest.delete_port(netid, por["port-id"])
self.dbtest.delete_network(netid)
- def tearDownJoinedTest(self):
+ def teardown_joined_test(self):
"""tearDown for joined Network and Port test"""
LOG.debug("Tearing Down Network and Ports")
nets = self.dbtest.get_all_networks("t1")
self.dbtest.delete_port(port["net-id"], port["port-id"])
self.dbtest.delete_network(netid)
-
+"""
if __name__ == "__main__":
usagestr = "Usage: %prog [OPTIONS] <command> [args]"
parser = OptionParser(usage=usagestr)
unittest.TextTestRunner(verbosity=2).run(suite)
suite = unittest.TestLoader().loadTestsFromTestCase(L2networkDBTest)
unittest.TextTestRunner(verbosity=2).run(suite)
+"""