]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Enable agents and plugins to use the same configuration file.
authorGary Kotton <gkotton@redhat.com>
Tue, 24 Jul 2012 17:15:54 +0000 (13:15 -0400)
committerGary Kotton <gkotton@redhat.com>
Wed, 25 Jul 2012 15:18:33 +0000 (11:18 -0400)
The change also implements blueprint agent-logging (this
was due to the fact that the existing logging in the agents
did not work with the change)

Devstack support for the above is in
https://review.openstack.org/10267

Notes:
- The service and agent can be run with multiple configuration
  files by using the CLI parameters --config-file <filename>
- The agent now makes use of the logging and debugging flags
  defined in quantum.conf. This follows the standard common
  configuration command line rules.

Change-Id: I3bd7701526a950c360d7c2cf14b31045010b46ca

18 files changed:
quantum/plugins/linuxbridge/README
quantum/plugins/linuxbridge/agent/linuxbridge_quantum_agent.py
quantum/plugins/linuxbridge/common/config.py
quantum/plugins/linuxbridge/db/l2network_db.py
quantum/plugins/linuxbridge/tests/unit/test_database.py
quantum/plugins/openvswitch/agent/ovs_quantum_agent.py
quantum/plugins/openvswitch/common/config.py
quantum/plugins/openvswitch/ovs_quantum_plugin.py
quantum/plugins/openvswitch/tests/unit/test_defaults.py [new file with mode: 0644]
quantum/plugins/ryu/agent/ryu_quantum_agent.py
quantum/plugins/ryu/common/config.py
quantum/plugins/ryu/ovs_quantum_plugin_base.py
quantum/plugins/ryu/ryu_quantum_plugin.py
quantum/plugins/ryu/tests/unit/test_plugin_base.py
quantum/plugins/ryu/tests/unit/test_ryu_driver.py
quantum/tests/unit/test_lb_config.py [deleted file]
quantum/tests/unit/test_ovs_config.py [deleted file]
quantum/tests/unit/test_ryu_config.py [deleted file]

index 6a5baefae70917cbb659fe42f715596042eb0458..1b152f714e4f6958130f6787e4ccfd1060cdb4c3 100644 (file)
@@ -98,6 +98,8 @@ mysql> FLUSH PRIVILEGES;
   Make sure it matches your mysql configuration.  This file must be updated
   with the addresses and credentials to access the database.
 
+  Note: debug and logging information should be updated in etc/quantum.conf
+
   Note: When running the tests, set the connection type to sqlite, and when
   actually running the server set it to mysql. At any given time, only one
   of these should be active in the conf file (you can comment out the other).
@@ -116,9 +118,13 @@ mysql> FLUSH PRIVILEGES;
   and etc/quantum/plugins/linuxbridge/linuxbridge_conf.ini
   to the compute node.
 
+- Copy the quantum.conf file to the compute node
+
+  Note: debug and logging information should be updated in etc/quantum.conf
+
 $ Run the following:
-  python linuxbridge_quantum_agent.py linuxbridge_conf.ini
-  (Use --verbose option to see the logs)
+  python linuxbridge_quantum_agent.py --config-file quantum.conf 
+                                      --config-file linuxbridge_conf.ini
 
   Note that the the user running the agent must have sudo priviliges
   to run various networking commands. Also, the agent can be
index 4168d784a08672b1ce157a8c89c94d0b627c3731..00629c331265f6cdf3889f7b6bbed5e1c9649ecb 100755 (executable)
@@ -23,7 +23,6 @@
 # @author: Sumit Naiksatam, Cisco Systems, Inc.
 
 import logging
-from optparse import OptionParser
 import os
 import shlex
 import signal
@@ -33,6 +32,8 @@ import time
 
 from sqlalchemy.ext.sqlsoup import SqlSoup
 
+from quantum.openstack.common import cfg
+from quantum.common import config as logging_config
 from quantum.plugins.linuxbridge.common import config
 
 from quantum.agent.linux import utils
@@ -486,35 +487,21 @@ class LinuxBridgeQuantumAgent:
 
 
 def main():
-    usagestr = "%prog [OPTIONS] <config file>"
-    parser = OptionParser(usage=usagestr)
-    parser.add_option("-v", "--verbose", dest="verbose",
-                      action="store_true", default=False,
-                      help="turn on verbose logging")
+    cfg.CONF(args=sys.argv, project='quantum')
 
-    options, args = parser.parse_args()
+    # (TODO) gary - swap with common logging
+    logging_config.setup_logging(cfg.CONF)
 
-    if options.verbose:
-        LOG.setLevel(logging.DEBUG)
-    else:
-        LOG.setLevel(logging.WARNING)
-
-    if len(args) != 1:
-        parser.print_help()
-        sys.exit(1)
-
-    config_file = args[0]
-    conf = config.parse(config_file)
     br_name_prefix = BRIDGE_NAME_PREFIX
-    physical_interface = conf.LINUX_BRIDGE.physical_interface
-    polling_interval = conf.AGENT.polling_interval
-    reconnect_interval = conf.DATABASE.reconnect_interval
-    root_helper = conf.AGENT.root_helper
+    physical_interface = cfg.CONF.LINUX_BRIDGE.physical_interface
+    polling_interval = cfg.CONF.AGENT.polling_interval
+    reconnect_interval = cfg.CONF.DATABASE.reconnect_interval
+    root_helper = cfg.CONF.AGENT.root_helper
     'Establish database connection and load models'
-    db_connection_url = conf.DATABASE.sql_connection
+    db_connection_url = cfg.CONF.DATABASE.sql_connection
     plugin = LinuxBridgeQuantumAgent(br_name_prefix, physical_interface,
                                      polling_interval, reconnect_interval,
-                                     root_helper, conf.AGENT.target_v2_api)
+                                     root_helper, cfg.CONF.AGENT.target_v2_api)
     LOG.info("Agent initialized successfully, now running... ")
     plugin.daemon_loop(db_connection_url)
 
index 6e2aa9b86c23c4d8bf244bf4b3a625f4ec4652c3..290fb2a418ed4b43676a4b0047f2d41ec1386376 100644 (file)
@@ -42,15 +42,7 @@ agent_opts = [
 ]
 
 
-def parse(config_file):
-    conf = cfg.CONF
-    if 'config_file' in conf:
-        conf.config_file.append(config_file)
-    else:
-        conf.config_file = [config_file]
-    conf(args=[], default_config_files=conf.config_file)
-    conf.register_opts(vlan_opts, "VLANS")
-    conf.register_opts(database_opts, "DATABASE")
-    conf.register_opts(bridge_opts, "LINUX_BRIDGE")
-    conf.register_opts(agent_opts, "AGENT")
-    return conf
+cfg.CONF.register_opts(vlan_opts, "VLANS")
+cfg.CONF.register_opts(database_opts, "DATABASE")
+cfg.CONF.register_opts(bridge_opts, "LINUX_BRIDGE")
+cfg.CONF.register_opts(agent_opts, "AGENT")
index b2e87bf709568b011e846be2026804531a0fd1db..ff5b0b0cb77661a013044a6b4a133b039d7a99ea 100644 (file)
@@ -21,17 +21,14 @@ from sqlalchemy import func
 from sqlalchemy.orm import exc
 
 from quantum.common import exceptions as q_exc
-from quantum.common.utils import find_config_file
 import quantum.db.api as db
+from quantum.openstack.common import cfg
 from quantum.plugins.linuxbridge.common import config
 from quantum.plugins.linuxbridge.common import exceptions as c_exc
 from quantum.plugins.linuxbridge.db import l2network_models
 from quantum.plugins.linuxbridge.db import l2network_models_v2
 
 LOG = logging.getLogger(__name__)
-CONF_FILE = find_config_file({'plugin': 'linuxbridge'},
-                             "linuxbridge_conf.ini")
-CONF = config.parse(CONF_FILE)
 
 # The global variable for the database version model
 L2_MODEL = l2network_models
@@ -39,9 +36,10 @@ L2_MODEL = l2network_models
 
 def initialize(base=None):
     global L2_MODEL
-    options = {"sql_connection": "%s" % CONF.DATABASE.sql_connection}
-    options.update({"sql_max_retries": CONF.DATABASE.sql_max_retries})
-    options.update({"reconnect_interval": CONF.DATABASE.reconnect_interval})
+    options = {"sql_connection": "%s" % cfg.CONF.DATABASE.sql_connection}
+    options.update({"sql_max_retries": cfg.CONF.DATABASE.sql_max_retries})
+    options.update({"reconnect_interval":
+                   cfg.CONF.DATABASE.reconnect_interval})
     if base:
         options.update({"base": base})
         L2_MODEL = l2network_models_v2
@@ -53,8 +51,8 @@ def create_vlanids():
     """Prepopulate the vlan_bindings table"""
     LOG.debug("create_vlanids() called")
     session = db.get_session()
-    start = CONF.VLANS.vlan_start
-    end = CONF.VLANS.vlan_end
+    start = cfg.CONF.VLANS.vlan_start
+    end = cfg.CONF.VLANS.vlan_end
     try:
         vlanid = session.query(L2_MODEL.VlanID).one()
     except exc.MultipleResultsFound:
@@ -120,7 +118,8 @@ def release_vlanid(vlan_id):
                   filter_by(vlan_id=vlan_id).
                   one())
         vlanid["vlan_used"] = False
-        if vlan_id >= CONF.VLANS.vlan_start and vlan_id <= CONF.VLANS.vlan_end:
+        if (vlan_id >= cfg.CONF.VLANS.vlan_start and
+            vlan_id <= cfg.CONF.VLANS.vlan_end):
             session.merge(vlanid)
         else:
             session.delete(vlanid)
index 230315390dc37bddd64263d1957a70d33223ae22..8a80ef98005b56cd7c5d8d05269bd289a8271248 100644 (file)
@@ -24,6 +24,7 @@ import logging
 import unittest2 as unittest
 
 import quantum.db.api as db
+from quantum.openstack.common import cfg
 import quantum.plugins.linuxbridge.common.exceptions as c_exc
 import quantum.plugins.linuxbridge.db.l2network_db as l2network_db
 
@@ -265,3 +266,24 @@ class L2networkDBTest(unittest.TestCase):
         for vlan in vlans:
             netid = vlan["net-id"]
             self.dbtest.delete_vlan_binding(netid)
+
+
+class ConfigurationTest(unittest.TestCase):
+
+    def test_defaults(self):
+        self.assertEqual('sqlite://',
+                         cfg.CONF.DATABASE.sql_connection)
+        self.assertEqual(-1,
+                         cfg.CONF.DATABASE.sql_max_retries)
+        self.assertEqual(2,
+                         cfg.CONF.DATABASE.reconnect_interval)
+        self.assertEqual(2,
+                         cfg.CONF.AGENT.polling_interval)
+        self.assertEqual('sudo',
+                         cfg.CONF.AGENT.root_helper)
+        self.assertEqual(1000,
+                         cfg.CONF.VLANS.vlan_start)
+        self.assertEqual(3000,
+                         cfg.CONF.VLANS.vlan_end)
+        self.assertEqual('eth1',
+                         cfg.CONF.LINUX_BRIDGE.physical_interface)
index 8fae799fed010664abed6ef74b8f29c47e7feb29..6a239a14866668c89a34874c703fd195a8ba4c89 100755 (executable)
 # @author: Aaron Rosen, Nicira Networks, Inc.
 
 import logging
-from optparse import OptionParser
 import sys
 import time
 
 from sqlalchemy.ext import sqlsoup
 
 from quantum.agent.linux import ovs_lib
+from quantum.common import config as logging_config
+from quantum.openstack.common import cfg
 from quantum.plugins.openvswitch.common import config
 
 logging.basicConfig()
@@ -548,51 +549,27 @@ class OVSQuantumTunnelAgent(object):
 
 
 def main():
-    usagestr = "%prog [OPTIONS] <config file>"
-    parser = OptionParser(usage=usagestr)
-    parser.add_option("-v", "--verbose", dest="verbose",
-                      action="store_true", default=False,
-                      help="turn on verbose logging")
+    cfg.CONF(args=sys.argv, project='quantum')
 
-    options, args = parser.parse_args()
-
-    if options.verbose:
-        LOG.setLevel(logging.DEBUG)
-    else:
-        LOG.setLevel(logging.WARNING)
-
-    if len(args) != 1:
-        parser.print_help()
-        sys.exit(1)
-
-    config_file = args[0]
-    conf = config.parse(config_file)
-
-    if conf.AGENT.log_file:
-        # Avoid to redirect traces to stdout/stderr
-        logging.getLogger().handlers = []
-        handler = logging.FileHandler(conf.AGENT.log_file)
-        formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
-        handler.setFormatter(formatter)
-        LOG.addHandler(handler)
-        LOG.debug('Verbose: %s', options.verbose)
+    # (TODO) gary - swap with common logging
+    logging_config.setup_logging(cfg.CONF)
 
     # Determine which agent type to use.
-    enable_tunneling = conf.OVS.enable_tunneling
-    integ_br = conf.OVS.integration_bridge
-    db_connection_url = conf.DATABASE.sql_connection
-    polling_interval = conf.AGENT.polling_interval
-    reconnect_interval = conf.DATABASE.reconnect_interval
-    root_helper = conf.AGENT.root_helper
+    enable_tunneling = cfg.CONF.OVS.enable_tunneling
+    integ_br = cfg.CONF.OVS.integration_bridge
+    db_connection_url = cfg.CONF.DATABASE.sql_connection
+    polling_interval = cfg.CONF.AGENT.polling_interval
+    reconnect_interval = cfg.CONF.DATABASE.reconnect_interval
+    root_helper = cfg.CONF.AGENT.root_helper
 
     # Determine API Version to use
-    target_v2_api = conf.AGENT.target_v2_api
+    target_v2_api = cfg.CONF.AGENT.target_v2_api
 
     if enable_tunneling:
         # Get parameters for OVSQuantumTunnelAgent
-        tun_br = conf.OVS.tunnel_bridge
+        tun_br = cfg.CONF.OVS.tunnel_bridge
         # Mandatory parameter.
-        local_ip = conf.OVS.local_ip
+        local_ip = cfg.CONF.OVS.local_ip
         plugin = OVSQuantumTunnelAgent(integ_br, tun_br, local_ip, root_helper,
                                        polling_interval, reconnect_interval,
                                        target_v2_api)
index 0e0f61a330f2b74b2edeaf8c08744ecd92b5a360..e11ac94c7fcd939a2d04566fddb547f563196ec8 100644 (file)
@@ -40,14 +40,6 @@ agent_opts = [
 ]
 
 
-def parse(config_file):
-    conf = cfg.CONF
-    if 'config_file' in conf:
-        conf.config_file.append(config_file)
-    else:
-        conf.config_file = [config_file]
-    conf(args=[], default_config_files=conf.config_file)
-    conf.register_opts(database_opts, "DATABASE")
-    conf.register_opts(ovs_opts, "OVS")
-    conf.register_opts(agent_opts, "AGENT")
-    return conf
+cfg.CONF.register_opts(database_opts, "DATABASE")
+cfg.CONF.register_opts(ovs_opts, "OVS")
+cfg.CONF.register_opts(agent_opts, "AGENT")
index 7ae993015106f3aa51026f0f336fa18cef8bbefd..4cc754b1570f45f297dc3deed834c6c889a575af 100644 (file)
@@ -30,6 +30,7 @@ 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
+from quantum.openstack.common import cfg
 from quantum.plugins.openvswitch.common import config
 from quantum.plugins.openvswitch import ovs_db
 from quantum.plugins.openvswitch import ovs_db_v2
@@ -38,8 +39,6 @@ from quantum import policy
 
 
 LOG = logging.getLogger("ovs_quantum_plugin")
-CONF_FILE = find_config_file({"plugin": "openvswitch"},
-                             "ovs_quantum_plugin.ini")
 
 
 # Exception thrown if no more VLANs are available
@@ -117,15 +116,14 @@ class VlanMap(object):
 class OVSQuantumPlugin(QuantumPluginBase):
 
     def __init__(self, configfile=None):
-        conf = config.parse(CONF_FILE)
-        options = {"sql_connection": conf.DATABASE.sql_connection}
-        sql_max_retries = conf.DATABASE.sql_max_retries
+        options = {"sql_connection": cfg.CONF.DATABASE.sql_connection}
+        sql_max_retries = cfg.CONF.DATABASE.sql_max_retries
         options.update({"sql_max_retries": sql_max_retries})
-        reconnect_interval = conf.DATABASE.reconnect_interval
+        reconnect_interval = cfg.CONF.DATABASE.reconnect_interval
         options.update({"reconnect_interval": reconnect_interval})
         db.configure_db(options)
 
-        self.vmap = VlanMap(conf.OVS.vlan_min, conf.OVS.vlan_max)
+        self.vmap = VlanMap(cfg.CONF.OVS.vlan_min, cfg.CONF.OVS.vlan_max)
         # Populate the map with anything that is already present in the
         # database
         self.vmap.populate_already_used(ovs_db.get_vlans())
@@ -267,18 +265,16 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
     supported_extension_aliases = ["provider"]
 
     def __init__(self, configfile=None):
-        conf = config.parse(CONF_FILE)
-        self.enable_tunneling = conf.OVS.enable_tunneling
-
-        options = {"sql_connection": conf.DATABASE.sql_connection}
+        self.enable_tunneling = cfg.CONF.OVS.enable_tunneling
+        options = {"sql_connection": cfg.CONF.DATABASE.sql_connection}
         options.update({'base': models_v2.model_base.BASEV2})
-        sql_max_retries = conf.DATABASE.sql_max_retries
+        sql_max_retries = cfg.CONF.DATABASE.sql_max_retries
         options.update({"sql_max_retries": sql_max_retries})
         reconnect_interval = conf.DATABASE.reconnect_interval
         options.update({"reconnect_interval": reconnect_interval})
         db.configure_db(options)
 
-        self.vmap = VlanMap(conf.OVS.vlan_min, conf.OVS.vlan_max)
+        self.vmap = VlanMap(cfg.CONF.OVS.vlan_min, cfg.CONF.OVS.vlan_max)
         self.vmap.populate_already_used(ovs_db_v2.get_vlans())
 
     # TODO(rkukura) Use core mechanism for attribute authorization
diff --git a/quantum/plugins/openvswitch/tests/unit/test_defaults.py b/quantum/plugins/openvswitch/tests/unit/test_defaults.py
new file mode 100644 (file)
index 0000000..1987d8e
--- /dev/null
@@ -0,0 +1,31 @@
+# Copyright (c) 2012 OpenStack, LLC.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+
+from quantum.openstack.common import cfg
+
+
+class ConfigurationTest(unittest.TestCase):
+
+    def test_defaults(self):
+        self.assertFalse(cfg.CONF.OVS.enable_tunneling)
+        self.assertEqual('br-int', cfg.CONF.OVS.integration_bridge)
+        self.assertEqual('br-tun', cfg.CONF.OVS.tunnel_bridge)
+        self.assertEqual('sqlite://', cfg.CONF.DATABASE.sql_connection)
+        self.assertEqual(-1, cfg.CONF.DATABASE.sql_max_retries)
+        self.assertEqual(2, cfg.CONF.DATABASE.reconnect_interval)
+        self.assertEqual(2, cfg.CONF.AGENT.polling_interval)
+        self.assertEqual('sudo', cfg.CONF.AGENT.root_helper)
index 15056b8381c82a130c9ff09fe4c7a20544906a89..815c2a52ccfabdca6d3795c4d7e847247de11454 100755 (executable)
@@ -21,7 +21,6 @@
 # @author: Isaku Yamahata
 
 import logging as LOG
-from optparse import OptionParser
 import sys
 import time
 
@@ -31,6 +30,7 @@ from sqlalchemy.ext.sqlsoup import SqlSoup
 
 from quantum.agent.linux import ovs_lib
 from quantum.agent.linux.ovs_lib import VifPort
+from quantum.openstack.common import cfg
 from quantum.plugins.ryu.common import config
 
 OP_STATUS_UP = "UP"
@@ -224,29 +224,15 @@ class OVSQuantumOFPRyuAgent:
 
 
 def main():
-    usagestr = "%prog [OPTIONS] <config file>"
-    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)
-
-    if len(args) != 1:
-        parser.print_help()
-        sys.exit(1)
-
-    config_file = args[0]
-    conf = config.parse(config_file)
-    integ_br = conf.OVS.integration_bridge
-    root_helper = conf.AGENT.root_helper
-    target_v2_api = conf.AGENT.target_v2_api
-    options = {"sql_connection": conf.DATABASE.sql_connection}
+    cfg.CONF(args=sys.argv, project='quantum')
+
+    # (TODO) gary - swap with common logging
+    logging_config.setup_logging(cfg.CONF)
+
+    integ_br = cfg.CONF.OVS.integration_bridge
+    root_helper = cfg.CONF.AGENT.root_helper
+    target_v2_api = cfg.CONF.AGENT.target_v2_api
+    options = {"sql_connection": cfg.CONF.DATABASE.sql_connection}
     db = SqlSoup(options["sql_connection"])
 
     LOG.info("Connecting to database \"%s\" on %s",
index 9c1c3f6a1d18d47f89b593edc5c8f61aca518a66..66f2656f1ab3aa1c062a91efb0ca79d9417586cb 100644 (file)
@@ -36,14 +36,6 @@ agent_opts = [
 ]
 
 
-def parse(config_file):
-    conf = cfg.CONF
-    if 'config_file' in conf:
-        conf.config_file.append(config_file)
-    else:
-        conf.config_file = [config_file]
-    conf(args=[], default_config_files=conf.config_file)
-    conf.register_opts(database_opts, "DATABASE")
-    conf.register_opts(ovs_opts, "OVS")
-    conf.register_opts(agent_opts, "AGENT")
-    return conf
+cfg.CONF.register_opts(database_opts, "DATABASE")
+cfg.CONF.register_opts(ovs_opts, "OVS")
+cfg.CONF.register_opts(agent_opts, "AGENT")
index 9d6a553cb7a838c81dbbb288235afeacf0ce6734..da941799d407f4628b91b748377d7641b650f22b 100644 (file)
@@ -23,6 +23,7 @@ import os
 from quantum.api.api_common import OperationalStatus
 from quantum.common import exceptions as q_exc
 import quantum.db.api as db
+from quantum.openstack.common import cfg
 from quantum.plugins.ryu.common import config
 from quantum.quantum_plugin_base import QuantumPluginBase
 
@@ -54,25 +55,14 @@ class OVSQuantumPluginBase(QuantumPluginBase):
     """
     def __init__(self, conf_file, mod_file, configfile=None):
         super(OVSQuantumPluginBase, self).__init__()
-        if configfile is None:
-            if os.path.exists(conf_file):
-                configfile = conf_file
-            else:
-                configfile = find_config(os.path.abspath(
-                    os.path.dirname(__file__)))
-        if configfile is None:
-            raise Exception("Configuration file \"%s\" doesn't exist" %
-                            (configfile))
-        LOG.debug("Using configuration file: %s" % configfile)
-        conf = config.parse(configfile)
-        options = {"sql_connection": conf.DATABASE.sql_connection}
-        sql_max_retries = conf.DATABASE.sql_max_retries
+        options = {"sql_connection": cfg.CONF.DATABASE.sql_connection}
+        sql_max_retries = cfg.CONF.DATABASE.sql_max_retries
         options.update({"sql_max_retries": sql_max_retries})
-        reconnect_interval = conf.DATABASE.reconnect_interval
+        reconnect_interval = cfg.CONF.DATABASE.reconnect_interval
         options.update({"reconnect_interval": reconnect_interval})
         db.configure_db(options)
 
-        self.conf = conf
+        self.conf = cfg.CONF
         # Subclass must set self.driver to its own OVSQuantumPluginDriverBase
         self.driver = None
 
index b1dbe686f49b2daaba3a6efcc02ed2fb70259c3f..f88a78601c28715b6912dab0bed9aa9949755297 100644 (file)
@@ -34,7 +34,6 @@ from quantum.plugins.ryu import ovs_quantum_plugin_base
 from quantum.plugins.ryu.common import config
 
 LOG = logging.getLogger(__name__)
-CONF_FILE = find_config_file({"plugin": "ryu"}, "ryu.ini")
 
 
 class OFPRyuDriver(ovs_quantum_plugin_base.OVSQuantumPluginDriverBase):
@@ -70,28 +69,20 @@ class OFPRyuDriver(ovs_quantum_plugin_base.OVSQuantumPluginDriverBase):
 
 class RyuQuantumPlugin(ovs_quantum_plugin_base.OVSQuantumPluginBase):
     def __init__(self, configfile=None):
-        super(RyuQuantumPlugin, self).__init__(CONF_FILE, __file__, configfile)
+        super(RyuQuantumPlugin, self).__init__(__file__, configfile)
         self.driver = OFPRyuDriver(self.conf)
 
 
 class RyuQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2):
     def __init__(self, configfile=None):
-        if configfile is None:
-            if os.path.exists(CONF_FILE):
-                configfile = CONF_FILE
-        if configfile is None:
-            raise Exception("Configuration file \"%s\" doesn't exist" %
-                            (configfile))
-        LOG.debug("Using configuration file: %s" % configfile)
-        conf = config.parse(configfile)
-        options = {"sql_connection": conf.DATABASE.sql_connection}
+        options = {"sql_connection": cfg.CONF.DATABASE.sql_connection}
         options.update({'base': models_v2.model_base.BASEV2})
-        reconnect_interval = conf.DATABASE.reconnect_interval
+        reconnect_interval = cfg.CONF.DATABASE.reconnect_interval
         options.update({"reconnect_interval": reconnect_interval})
         db.configure_db(options)
 
-        ofp_con_host = conf.OVS.openflow_controller
-        ofp_api_host = conf.OVS.openflow_rest_api
+        ofp_con_host = cfg.CONF.OVS.openflow_controller
+        ofp_api_host = cfg.CONF.OVS.openflow_rest_api
 
         if ofp_con_host is None or ofp_api_host is None:
             raise q_exc.Invalid("invalid configuration. check ryu.ini")
index ded216d4e5739c8dc700632a8e8b4a2203f26de8..c9391877a4518e3d9c94d7a3bc810f652070f2d6 100644 (file)
@@ -19,6 +19,7 @@ import os
 
 import mox
 
+from quantum.openstack.common import cfg
 from quantum.plugins.ryu.tests.unit.basetest import BaseRyuTest
 from quantum.plugins.ryu.tests.unit import fake_plugin
 from quantum.plugins.ryu.tests.unit import utils
@@ -53,3 +54,13 @@ class PluginBaseTest(BaseRyuTest):
 
         plugin.delete_network(tenant_id, ret['net-id'])
         self.mox.VerifyAll()
+
+    def test_defaults(self):
+        self.assertEqual('br-int', cfg.CONF.OVS.integration_bridge)
+        self.assertEqual('sqlite://', cfg.CONF.DATABASE.sql_connection)
+        self.assertEqual(-1, cfg.CONF.DATABASE.sql_max_retries)
+        self.assertEqual(2, cfg.CONF.DATABASE.reconnect_interval)
+        self.assertEqual(2, cfg.CONF.AGENT.polling_interval)
+        self.assertEqual('sudo', cfg.CONF.AGENT.root_helper)
+        self.assertEqual('127.0.0.1:6633', cfg.CONF.OVS.openflow_controller)
+        self.assertEqual('127.0.0.1:8080', cfg.CONF.OVS.openflow_rest_api)
index 0cc30cd57f892d4fd11a22774b4697ee19c8bd25..dde741d65cdd44622bfc051547a0c506b10822d8 100644 (file)
 
 import uuid
 
-from quantum.common.utils import find_config_file
 import quantum.db.api as db
+from quantum.openstack.common import cfg
 from quantum.plugins.ryu.common import config
 from quantum.plugins.ryu.tests.unit.basetest import BaseRyuTest
 from quantum.plugins.ryu.tests.unit import utils
 from quantum.plugins.ryu.tests.unit.utils import patch_fake_ryu_client
 
 
-CONF_FILE = find_config_file({"plugin": "ryu"}, "ryu.ini")
-
-
 class RyuDriverTest(BaseRyuTest):
     """Class conisting of OFPRyuDriver unit tests"""
     def setUp(self):
         super(RyuDriverTest, self).setUp()
-        self.conf = config.parse(CONF_FILE)
+        self.conf = cfg.CONF
         # fake up ryu.app.client and ryu.app.rest_nw_id
         # With those, plugin can be tested without ryu installed
         self.module_patcher = patch_fake_ryu_client()
diff --git a/quantum/tests/unit/test_lb_config.py b/quantum/tests/unit/test_lb_config.py
deleted file mode 100644 (file)
index d8278e4..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-# Copyright (c) 2012 OpenStack, LLC.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import os
-import tempfile
-import unittest
-
-from quantum.openstack.common import cfg
-from quantum.plugins.linuxbridge.common import config
-
-
-class LinuxBridgeConfigTestCase(unittest.TestCase):
-    def test_dummy(self):
-        configs = """[DATABASE]
-sql_connection = testlink
-sql_max_retries = 200
-reconnect_interval=100
-[AGENT]
-root_helper = mysudo
-polling_interval=50
-"""
-
-        (fd, path) = tempfile.mkstemp(prefix='lb_config', suffix='.ini')
-
-        try:
-            os.write(fd, configs)
-            os.close(fd)
-
-            conf = config.parse(path)
-            self.assertEqual('testlink', conf.DATABASE.sql_connection)
-            self.assertEqual(200, conf.DATABASE.sql_max_retries)
-            self.assertEqual(100, conf.DATABASE.reconnect_interval)
-            self.assertEqual(50, conf.AGENT.polling_interval)
-            self.assertEqual('mysudo', conf.AGENT.root_helper)
-            self.assertEqual(conf.AGENT.polling_interval,
-                             cfg.CONF.AGENT.polling_interval)
-        finally:
-            os.remove(path)
-
-    def test_defaults(self):
-        configs = """
-"""
-
-        (fd, path) = tempfile.mkstemp(prefix='lb_config', suffix='.ini')
-
-        try:
-            os.write(fd, configs)
-            os.close(fd)
-
-            conf = config.parse(path)
-            self.assertEqual('sqlite://', conf.DATABASE.sql_connection)
-            self.assertEqual(-1, conf.DATABASE.sql_max_retries)
-            self.assertEqual(2, conf.DATABASE.reconnect_interval)
-            self.assertEqual(2, conf.AGENT.polling_interval)
-            self.assertEqual('sudo', conf.AGENT.root_helper)
-            self.assertEqual(1000, conf.VLANS.vlan_start)
-            self.assertEqual(3000, conf.VLANS.vlan_end)
-            self.assertEqual('eth1', conf.LINUX_BRIDGE.physical_interface)
-            self.assertEqual(conf.DATABASE.sql_connection,
-                             cfg.CONF.DATABASE.sql_connection)
-            self.assertEqual(conf.AGENT.root_helper,
-                             cfg.CONF.AGENT.root_helper)
-        finally:
-            os.remove(path)
-
-    def tearDown(self):
-        """Clear the test environment"""
-        cfg.CONF.reset()
-        cfg.CONF.unregister_opts(config.vlan_opts, "VLANS")
-        cfg.CONF.unregister_opts(config.database_opts, "DATABASE")
-        cfg.CONF.unregister_opts(config.bridge_opts, "LINUX_BRIDGE")
-        cfg.CONF.unregister_opts(config.agent_opts, "AGENT")
diff --git a/quantum/tests/unit/test_ovs_config.py b/quantum/tests/unit/test_ovs_config.py
deleted file mode 100644 (file)
index 44c0211..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2010 United States Government as represented by the
-# Administrator of the National Aeronautics and Space Administration.
-# All Rights Reserved.
-# Copyright 2011 Red Hat, Inc.
-#
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
-#    not use this file except in compliance with the License. You may obtain
-#    a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#    Unless required by applicable law or agreed to in writing, software
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-#    License for the specific language governing permissions and limitations
-#    under the License.
-
-import os
-import tempfile
-import unittest
-
-from quantum.openstack.common import cfg
-from quantum.plugins.openvswitch.common import config
-
-
-class OvsConfigTestCase(unittest.TestCase):
-    def test_tunnel(self):
-        configs = """[DATABASE]
-sql_connection = testlink
-sql_max_retries = 200
-reconnect_interval=100
-[OVS]
-enable_tunneling = True
-integration_bridge = mybrint
-tunnel_bridge = mybrtun
-local_ip = 10.0.0.3
-[AGENT]
-root_helper = mysudo
-polling_interval=50
-"""
-
-        (fd, path) = tempfile.mkstemp(prefix='ovs_config', suffix='.ini')
-
-        try:
-            os.write(fd, configs)
-            os.close(fd)
-
-            conf = config.parse(path)
-            self.assertTrue(conf.OVS.enable_tunneling)
-            self.assertEqual('mybrint', conf.OVS.integration_bridge)
-            self.assertEqual('mybrtun', conf.OVS.tunnel_bridge)
-            self.assertEqual('testlink', conf.DATABASE.sql_connection)
-            self.assertEqual(200, conf.DATABASE.sql_max_retries)
-            self.assertEqual(100, conf.DATABASE.reconnect_interval)
-            self.assertEqual(50, conf.AGENT.polling_interval)
-            self.assertEqual('mysudo', conf.AGENT.root_helper)
-            self.assertEqual(conf.OVS.integration_bridge,
-                             cfg.CONF.OVS.integration_bridge)
-        finally:
-            os.remove(path)
-
-    def test_defaults(self):
-        configs = """
-"""
-
-        (fd, path) = tempfile.mkstemp(prefix='ovs_config', suffix='.ini')
-
-        try:
-            os.write(fd, configs)
-            os.close(fd)
-
-            conf = config.parse(path)
-            self.assertFalse(conf.OVS.enable_tunneling)
-            self.assertEqual('br-int', conf.OVS.integration_bridge)
-            self.assertEqual('br-tun', conf.OVS.tunnel_bridge)
-            self.assertEqual('sqlite://', conf.DATABASE.sql_connection)
-            self.assertEqual(-1, conf.DATABASE.sql_max_retries)
-            self.assertEqual(2, conf.DATABASE.reconnect_interval)
-            self.assertEqual(2, conf.AGENT.polling_interval)
-            self.assertEqual('sudo', conf.AGENT.root_helper)
-            self.assertEqual(conf.DATABASE.sql_connection,
-                             cfg.CONF.DATABASE.sql_connection)
-            self.assertEqual(conf.AGENT.root_helper,
-                             cfg.CONF.AGENT.root_helper)
-        finally:
-            os.remove(path)
-
-    def test_without_tunnel(self):
-        configs = """
-[OVS]
-enable_tunneling = False
-"""
-
-        (fd, path) = tempfile.mkstemp(prefix='ovs_config', suffix='.ini')
-
-        try:
-            os.write(fd, configs)
-            os.close(fd)
-
-            conf = config.parse(path)
-            self.assertFalse(conf.OVS.enable_tunneling)
-        finally:
-            os.remove(path)
-
-    def test_invalid_values(self):
-        configs = """
-[OVS]
-enable_tunneling = notbool
-"""
-
-        (fd, path) = tempfile.mkstemp(prefix='ovs_config', suffix='.ini')
-
-        try:
-            os.write(fd, configs)
-            os.close(fd)
-
-            conf = config.parse(path)
-            exception_raised = False
-            try:
-                tunnel = conf.OVS.enable_tunneling
-            except cfg.ConfigFileValueError:
-                exception_raised = True
-            self.assertTrue(exception_raised)
-        finally:
-            os.remove(path)
-
-    def tearDown(self):
-        """Clear the test environment"""
-        cfg.CONF.reset()
-        cfg.CONF.unregister_opts(config.database_opts, "DATABASE")
-        cfg.CONF.unregister_opts(config.ovs_opts, "OVS")
-        cfg.CONF.unregister_opts(config.agent_opts, "AGENT")
diff --git a/quantum/tests/unit/test_ryu_config.py b/quantum/tests/unit/test_ryu_config.py
deleted file mode 100644 (file)
index 132f60e..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-# Copyright (c) 2012 OpenStack, LLC.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import os
-import tempfile
-import unittest
-
-from quantum.openstack.common import cfg
-from quantum.plugins.ryu.common import config
-
-
-class RyuConfigTestCase(unittest.TestCase):
-    def test_config(self):
-        configs = """[DATABASE]
-sql_connection = testlink
-sql_max_retries = 200
-reconnect_interval=100
-[OVS]
-enable_tunneling = True
-integration_bridge = mybrint
-local_ip = 10.0.0.3
-[AGENT]
-root_helper = mysudo
-polling_interval=50
-"""
-
-        (fd, path) = tempfile.mkstemp(prefix='ryu_config', suffix='.ini')
-
-        try:
-            os.write(fd, configs)
-            os.close(fd)
-
-            conf = config.parse(path)
-            self.assertEqual('mybrint', conf.OVS.integration_bridge)
-            self.assertEqual('testlink', conf.DATABASE.sql_connection)
-            self.assertEqual(200, conf.DATABASE.sql_max_retries)
-            self.assertEqual(100, conf.DATABASE.reconnect_interval)
-            self.assertEqual(50, conf.AGENT.polling_interval)
-            self.assertEqual('mysudo', conf.AGENT.root_helper)
-            self.assertEqual(conf.OVS.integration_bridge,
-                             cfg.CONF.OVS.integration_bridge)
-        finally:
-            os.remove(path)
-
-    def test_defaults(self):
-        configs = """
-"""
-
-        (fd, path) = tempfile.mkstemp(prefix='ryu_config', suffix='.ini')
-
-        try:
-            os.write(fd, configs)
-            os.close(fd)
-
-            conf = config.parse(path)
-            self.assertEqual('br-int', conf.OVS.integration_bridge)
-            self.assertEqual('sqlite://', conf.DATABASE.sql_connection)
-            self.assertEqual(-1, conf.DATABASE.sql_max_retries)
-            self.assertEqual(2, conf.DATABASE.reconnect_interval)
-            self.assertEqual(2, conf.AGENT.polling_interval)
-            self.assertEqual('sudo', conf.AGENT.root_helper)
-            self.assertEqual('127.0.0.1:6633', conf.OVS.openflow_controller)
-            self.assertEqual('127.0.0.1:8080', conf.OVS.openflow_rest_api)
-            self.assertEqual(conf.DATABASE.sql_connection,
-                             cfg.CONF.DATABASE.sql_connection)
-            self.assertEqual(conf.AGENT.root_helper,
-                             cfg.CONF.AGENT.root_helper)
-        finally:
-            os.remove(path)
-
-    def tearDown(self):
-        """Clear the test environment"""
-        cfg.CONF.reset()
-        cfg.CONF.unregister_opts(config.database_opts, "DATABASE")
-        cfg.CONF.unregister_opts(config.ovs_opts, "OVS")
-        cfg.CONF.unregister_opts(config.agent_opts, "AGENT")