From 1daa50cc6364797a2010b49d986780a7039a6865 Mon Sep 17 00:00:00 2001 From: Bob Kukura Date: Tue, 14 Aug 2012 12:21:05 -0400 Subject: [PATCH] Trivial openvswitch plugin cleanup. Part of provider-networks phase 3 development, but merging separately to avoid confusion later. - eliminate target_v2_api config variable - eliminate old V1 version of Port - remove unused import Change-Id: I913def752ec537a7e74a6173f2b6f82372a4dce8 --- .../openvswitch/ovs_quantum_plugin.ini | 4 -- .../openvswitch/agent/ovs_quantum_agent.py | 62 +++---------------- quantum/plugins/openvswitch/common/config.py | 1 - .../plugins/openvswitch/ovs_quantum_plugin.py | 5 +- .../openvswitch/tests/unit/test_tunnel.py | 12 ++-- 5 files changed, 14 insertions(+), 70 deletions(-) diff --git a/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini b/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini index b7495dd389..2c77db535e 100644 --- a/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini +++ b/etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini @@ -41,8 +41,6 @@ polling_interval = 2 # Change to "sudo quantum-rootwrap" to limit commands that can be run # as root. root_helper = sudo -# Use Quantumv2 API -target_v2_api = False #----------------------------------------------------------------------------- # Sample Configurations. @@ -58,8 +56,6 @@ target_v2_api = False # root_helper = sudo # Add the following setting, if you want to log to a file # log_file = /var/log/quantum/ovs_quantum_agent.log -# Use Quantumv2 API -# target_v2_api = False # # 2. With tunneling. # [DATABASE] diff --git a/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py b/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py index cb4b473c5c..a4371fb936 100755 --- a/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py +++ b/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py @@ -74,36 +74,6 @@ class Port(object): still available even if a row has been deleted. """ - def __init__(self, p): - self.uuid = p.uuid - self.network_id = p.network_id - self.interface_id = p.interface_id - self.state = p.state - self.status = p.op_status - - def __eq__(self, other): - '''Compare only fields that will cause us to re-wire.''' - try: - return (self and other - and self.interface_id == other.interface_id - and self.state == other.state) - except: - return False - - def __ne__(self, other): - return not self.__eq__(other) - - def __hash__(self): - return hash(self.uuid) - - -class Portv2(object): - """Represents a quantumv2 port. - - Class stores port data in a ORM-free way, so attributres are - still available even if a row has been deleted. - """ - def __init__(self, p): self.id = p.id self.network_id = p.network_id @@ -180,12 +150,11 @@ class OVSRpcCallbacks(): class OVSQuantumAgent(object): def __init__(self, integ_br, root_helper, polling_interval, - reconnect_interval, target_v2_api, rpc): + reconnect_interval, rpc): self.root_helper = root_helper self.setup_integration_br(integ_br) self.polling_interval = polling_interval self.reconnect_interval = reconnect_interval - self.target_v2_api = target_v2_api self.rpc = rpc if rpc: self.setup_rpc(integ_br) @@ -251,10 +220,7 @@ class OVSQuantumAgent(object): continue for port in ports: - if self.target_v2_api: - all_bindings[port.id] = port - else: - all_bindings[port.interface_id] = port + all_bindings[port.id] = port vlan_bindings = {} try: @@ -448,8 +414,7 @@ class OVSQuantumTunnelAgent(object): MAX_VLAN_TAG = 4094 def __init__(self, integ_br, tun_br, local_ip, root_helper, - polling_interval, reconnect_interval, target_v2_api, - rpc): + polling_interval, reconnect_interval, rpc): '''Constructor. :param integ_br: name of the integration bridge. @@ -458,7 +423,6 @@ class OVSQuantumTunnelAgent(object): :param root_helper: utility to use when running shell cmds. :param polling_interval: interval (secs) to poll DB. :param reconnect_internal: retry interval (secs) on DB error. - :param target_v2_api: if True use v2 api. :param rpc: if True use RPC interface to interface with plugin. ''' self.root_helper = root_helper @@ -474,7 +438,6 @@ class OVSQuantumTunnelAgent(object): self.local_ip = local_ip self.tunnel_count = 0 self.setup_tunnel_br(tun_br) - self.target_v2_api = target_v2_api self.rpc = rpc if rpc: self.setup_rpc(integ_br) @@ -647,12 +610,8 @@ class OVSQuantumTunnelAgent(object): while True: try: - if self.target_v2_api: - all_bindings = dict((p.id, Portv2(p)) - for p in db.ports.all()) - else: - all_bindings = dict((p.interface_id, Port(p)) - for p in db.ports.all()) + all_bindings = dict((p.id, Port(p)) + for p in db.ports.all()) all_bindings_vif_port_ids = set(all_bindings) lsw_id_bindings = dict((bind.network_id, bind.vlan_id) for bind in db.vlan_bindings.all()) @@ -881,13 +840,6 @@ def main(): root_helper = cfg.CONF.AGENT.root_helper rpc = cfg.CONF.AGENT.rpc - # Determine API Version to use - target_v2_api = cfg.CONF.AGENT.target_v2_api - - # RPC only works with v2 - if rpc and not target_v2_api: - rpc = False - if enable_tunneling: # Get parameters for OVSQuantumTunnelAgent tun_br = cfg.CONF.OVS.tunnel_bridge @@ -895,11 +847,11 @@ def main(): local_ip = cfg.CONF.OVS.local_ip plugin = OVSQuantumTunnelAgent(integ_br, tun_br, local_ip, root_helper, polling_interval, reconnect_interval, - target_v2_api, rpc) + rpc) else: # Get parameters for OVSQuantumAgent. plugin = OVSQuantumAgent(integ_br, root_helper, polling_interval, - reconnect_interval, target_v2_api, rpc) + reconnect_interval, rpc) # Start everything. plugin.daemon_loop(db_connection_url) diff --git a/quantum/plugins/openvswitch/common/config.py b/quantum/plugins/openvswitch/common/config.py index 36b787bbbb..df83327bb1 100644 --- a/quantum/plugins/openvswitch/common/config.py +++ b/quantum/plugins/openvswitch/common/config.py @@ -36,7 +36,6 @@ ovs_opts = [ ] agent_opts = [ - cfg.BoolOpt('target_v2_api', default=True), cfg.IntOpt('polling_interval', default=2), cfg.StrOpt('root_helper', default='sudo'), cfg.StrOpt('log_file', default=None), diff --git a/quantum/plugins/openvswitch/ovs_quantum_plugin.py b/quantum/plugins/openvswitch/ovs_quantum_plugin.py index 9bc15886ba..2c4dbb8d42 100644 --- a/quantum/plugins/openvswitch/ovs_quantum_plugin.py +++ b/quantum/plugins/openvswitch/ovs_quantum_plugin.py @@ -27,7 +27,6 @@ from quantum.api import api_common from quantum.api.v2 import attributes from quantum.common import exceptions as q_exc from quantum.common import topics -from quantum.common.utils import find_config_file from quantum.db import api as db from quantum.db import db_base_plugin_v2 from quantum.db import models_v2 @@ -196,10 +195,8 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2): # update the vlan_id table based on current configuration ovs_db_v2.update_vlan_id_pool() self.rpc = cfg.CONF.AGENT.rpc - if cfg.CONF.AGENT.rpc and cfg.CONF.AGENT.target_v2_api: + if cfg.CONF.AGENT.rpc: self.setup_rpc() - if not cfg.CONF.AGENT.target_v2_api: - self.rpc = False def setup_rpc(self): # RPC support diff --git a/quantum/plugins/openvswitch/tests/unit/test_tunnel.py b/quantum/plugins/openvswitch/tests/unit/test_tunnel.py index 6589b6425d..58563a03b1 100644 --- a/quantum/plugins/openvswitch/tests/unit/test_tunnel.py +++ b/quantum/plugins/openvswitch/tests/unit/test_tunnel.py @@ -81,7 +81,7 @@ class TunnelTest(unittest.TestCase): b = ovs_quantum_agent.OVSQuantumTunnelAgent(self.INT_BRIDGE, self.TUN_BRIDGE, '10.0.0.1', - 'sudo', 2, 2, False, False) + 'sudo', 2, 2, False) self.mox.VerifyAll() def testProvisionLocalVlan(self): @@ -98,7 +98,7 @@ class TunnelTest(unittest.TestCase): a = ovs_quantum_agent.OVSQuantumTunnelAgent(self.INT_BRIDGE, self.TUN_BRIDGE, '10.0.0.1', - 'sudo', 2, 2, False, False) + 'sudo', 2, 2, False) a.available_local_vlans = set([LV_ID]) a.provision_local_vlan(NET_UUID, LS_ID) self.mox.VerifyAll() @@ -112,7 +112,7 @@ class TunnelTest(unittest.TestCase): a = ovs_quantum_agent.OVSQuantumTunnelAgent(self.INT_BRIDGE, self.TUN_BRIDGE, '10.0.0.1', - 'sudo', 2, 2, False, False) + 'sudo', 2, 2, False) a.available_local_vlans = set() a.local_vlan_map[NET_UUID] = LVM a.reclaim_local_vlan(NET_UUID, LVM) @@ -128,7 +128,7 @@ class TunnelTest(unittest.TestCase): a = ovs_quantum_agent.OVSQuantumTunnelAgent(self.INT_BRIDGE, self.TUN_BRIDGE, '10.0.0.1', - 'sudo', 2, 2, False, False) + 'sudo', 2, 2, False) a.local_vlan_map[NET_UUID] = LVM a.port_bound(VIF_PORT, NET_UUID, LS_ID) self.mox.VerifyAll() @@ -138,7 +138,7 @@ class TunnelTest(unittest.TestCase): a = ovs_quantum_agent.OVSQuantumTunnelAgent(self.INT_BRIDGE, self.TUN_BRIDGE, '10.0.0.1', - 'sudo', 2, 2, False, False) + 'sudo', 2, 2, False) a.available_local_vlans = set([LV_ID]) a.local_vlan_map[NET_UUID] = LVM a.port_unbound(VIF_PORT, NET_UUID) @@ -155,7 +155,7 @@ class TunnelTest(unittest.TestCase): a = ovs_quantum_agent.OVSQuantumTunnelAgent(self.INT_BRIDGE, self.TUN_BRIDGE, '10.0.0.1', - 'sudo', 2, 2, False, False) + 'sudo', 2, 2, False) a.available_local_vlans = set([LV_ID]) a.local_vlan_map[NET_UUID] = LVM a.port_dead(VIF_PORT)