Address some of the remaining TODOs and general cleanup

This commit is contained in:
Brad Hall 2011-06-04 13:17:32 -07:00
parent 1c37bde8cb
commit 1e441b67d1
2 changed files with 72 additions and 38 deletions

View File

@ -35,7 +35,7 @@ def configure_db(options):
global _ENGINE
if not _ENGINE:
_ENGINE = create_engine(options['sql_connection'],
echo=True,
echo=False,
echo_pool=True,
pool_recycle=3600)
register_models()
@ -94,7 +94,6 @@ def network_get(net_id):
def network_rename(net_id, tenant_id, new_name):
session = get_session()
# TODO(bgh): Make sure another network doesn't have that name
try:
res = session.query(models.Network).\
filter_by(name=new_name).\
@ -144,13 +143,21 @@ def port_get(port_id):
def port_set_attachment(port_id, new_interface_id):
session = get_session()
# TODO(bgh): check to make sure new_inteface_id is
# unique if it is not None
port = port_get(port_id)
port.interface_id = new_interface_id
session.merge(port)
session.flush()
return port
ports = None
try:
ports = session.query(models.Port).\
filter_by(interface_id=new_interface_id).\
all()
except exc.NoResultFound:
pass
if len(ports) == 0:
port = port_get(port_id)
port.interface_id = new_interface_id
session.merge(port)
session.flush()
return port
else:
raise Exception("Port with attachment \"%s\" already exists" % (new_interface_id))
def port_destroy(port_id):
session = get_session()

View File

@ -24,15 +24,14 @@ import sys
import unittest
from quantum.quantum_plugin_base import QuantumPluginBase
from optparse import OptionParser
import quantum.db.api as db
import ovs_db
# TODO(bgh): Make sure we delete from network bindings when deleting a port,
# network, etc.
CONF_FILE="ovs_quantum_plugin.ini"
LOG.basicConfig(level=LOG.DEBUG)
LOG.basicConfig(level=LOG.WARN)
LOG.getLogger("ovs_quantum_plugin")
def find_config(basepath):
@ -63,7 +62,7 @@ class VlanMap(object):
self.vlans[x] = None
# LOG.debug("VlanMap::release %s" % (x))
return
raise Exception("No vlan found with network \"%s\"" % network_id)
LOG.error("No vlan found with network \"%s\"" % network_id)
class OVSQuantumPlugin(QuantumPluginBase):
def __init__(self, configfile=None):
@ -76,7 +75,7 @@ class OVSQuantumPlugin(QuantumPluginBase):
if configfile == None:
raise Exception("Configuration file \"%s\" doesn't exist" %
(configfile))
LOG.info("Using configuration file: %s" % configfile)
LOG.debug("Using configuration file: %s" % configfile)
config.read(configfile)
LOG.debug("Config: %s" % config)
@ -124,7 +123,7 @@ class OVSQuantumPlugin(QuantumPluginBase):
def delete_network(self, tenant_id, net_id):
net = db.network_destroy(net_id)
d = {}
d["net-id"] = net.uuid
d["net-id"] = str(net.uuid)
ovs_db.remove_vlan_binding(net_id)
self.vmap.release(net_id)
return d
@ -201,8 +200,8 @@ class OVSQuantumPlugin(QuantumPluginBase):
ovs_db.update_network_binding(net_id, remote_iface_id)
def unplug_interface(self, tenant_id, net_id, port_id):
db.port_set_attachment(port_id, "None")
ovs_db.update_network_binding(net_id, remote_iface_id)
db.port_set_attachment(port_id, "")
ovs_db.update_network_binding(net_id, None)
def get_interface_details(self, tenant_id, net_id, port_id):
res = db.port_get(port_id)
@ -237,7 +236,6 @@ class OVSPluginTest(unittest.TestCase):
nets = self.quantum.get_all_networks(self.tenant_id)
count = 0
for x in nets:
print x
if "plugin_test" in x["net-name"]:
count += 1
self.assertTrue(count == 2)
@ -248,7 +246,6 @@ class OVSPluginTest(unittest.TestCase):
nets = self.quantum.get_all_networks(self.tenant_id)
count = 0
for x in nets:
print x
if "plugin_test" in x["net-name"]:
count += 1
self.assertTrue(count == 0)
@ -269,20 +266,49 @@ class OVSPluginTest(unittest.TestCase):
self.assertTrue(count == 1)
def testDeletePort(self):
pass
net1 = self.quantum.create_network(self.tenant_id, "plugin_test1")
port = self.quantum.create_port(self.tenant_id, net1["net-id"])
ports = self.quantum.get_all_ports(self.tenant_id, net1["net-id"])
count = 0
for p in ports:
count += 1
self.assertTrue(count == 1)
for p in ports:
self.quantum.delete_port(self.tenant_id, id, p["port-id"])
ports = self.quantum.get_all_ports(self.tenant_id, net1["net-id"])
count = 0
for p in ports:
count += 1
self.assertTrue(count == 0)
def testGetPorts(self):
pass
def testPlugInterface(self):
pass
net1 = self.quantum.create_network(self.tenant_id, "plugin_test1")
port = self.quantum.create_port(self.tenant_id, net1["net-id"])
self.quantum.plug_interface(self.tenant_id, net1["net-id"],
port["port-id"], "vif1.1")
port = self.quantum.get_port_details(self.tenant_id, net1["net-id"],
port["port-id"])
self.assertTrue(port["attachment"] == "vif1.1")
def testUnPlugInterface(self):
pass
net1 = self.quantum.create_network(self.tenant_id, "plugin_test1")
port = self.quantum.create_port(self.tenant_id, net1["net-id"])
self.quantum.plug_interface(self.tenant_id, net1["net-id"],
port["port-id"], "vif1.1")
port = self.quantum.get_port_details(self.tenant_id, net1["net-id"],
port["port-id"])
self.assertTrue(port["attachment"] == "vif1.1")
self.quantum.unplug_interface(self.tenant_id, net1["net-id"],
port["port-id"])
port = self.quantum.get_port_details(self.tenant_id, net1["net-id"],
port["port-id"])
self.assertTrue(port["attachment"] == "")
def tearDown(self):
networks = self.quantum.get_all_networks(self.tenant_id)
print networks
# Clean up any test networks lying around
for net in networks:
id = net["net-id"]
@ -290,26 +316,27 @@ class OVSPluginTest(unittest.TestCase):
if "plugin_test" in name:
# Clean up any test ports lying around
ports = self.quantum.get_all_ports(self.tenant_id, id)
print ports
for p in ports:
self.quantum.delete_port(self.tenant_id, id, p["port-id"])
self.quantum.delete_network(self.tenant_id, id)
if __name__ == "__main__":
usagestr = "Usage: %prog [OPTIONS] <command> [args]"
parser = OptionParser(usage=usagestr)
parser.add_option("-v", "--verbose", dest="verbose",
action="store_true", default=False, help="turn on verbose logging")
options, args = parser.parse_args()
if options.verbose:
LOG.basicConfig(level=LOG.DEBUG)
else:
LOG.basicConfig(level=LOG.WARN)
# Make sqlalchemy quieter
LOG.getLogger('sqlalchemy.engine').setLevel(LOG.WARN)
# Run the tests
suite = unittest.TestLoader().loadTestsFromTestCase(OVSPluginTest)
unittest.TextTestRunner(verbosity=2).run(suite)
suite = unittest.TestLoader().loadTestsFromTestCase(VlanMapTest)
unittest.TextTestRunner(verbosity=2).run(suite)
# TODO(bgh) move to unit tets
if False:
quantum.plug_interface(tenant_id, net1, port, "vif1.1")
portdetails = quantum.get_port_details(tenant_id, net1, port)
LOG.DEBUG(portdetails)
LOG.info("=== PORT: %s" % quantum.get_port_details(tenant_id, net1, port))
assert(portdetails["interface_id"] == "vif1.1")
networks = quantum.get_all_networks(tenant_id)
LOG.debug(networks)
for nid, name in networks.iteritems():
ports = quantum.get_all_ports(tenant_id, nid)
LOG.debug(ports)