]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Enable quantum agents to work with global cfg.CONF
authorGary Kotton <gkotton@redhat.com>
Sun, 8 Jul 2012 12:05:46 +0000 (08:05 -0400)
committerGary Kotton <gkotton@redhat.com>
Wed, 11 Jul 2012 17:41:25 +0000 (13:41 -0400)
This implements blueprint global-config-support

A common configuration parse function is used by the service and the agent.

In the case of the service, when loading the plugin, the configuration file
will be appended to the existing cfg.CONF (this was originally created when
quantum.conf was loaded).

In the case of the agent a global cfg.CONF will be created.

This task is a prerequisite for the RPC integration into Quantum.

Change-Id: I24ef4a804578502bcce484f44dc55c8fe2aa913e

quantum/plugins/linuxbridge/common/config.py
quantum/plugins/openvswitch/common/config.py
quantum/plugins/ryu/common/config.py
quantum/tests/unit/test_lb_config.py [new file with mode: 0644]
quantum/tests/unit/test_ovs_config.py
quantum/tests/unit/test_ryu_config.py [new file with mode: 0644]

index 7e77147f44fa99d342175bb222107a9c8d9520d0..7be75b0285486b3e4c7b7fb7ab3c0fa00aa89399 100644 (file)
@@ -42,8 +42,12 @@ agent_opts = [
 
 
 def parse(config_file):
-    conf = cfg.ConfigOpts()
-    conf(args=[], default_config_files=[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")
index 9774b82de41dfdd1ef63188591e5499aa210b957..f73a53852c3aed73b634e8b6f345d2f8a411d956 100644 (file)
@@ -40,8 +40,12 @@ agent_opts = [
 
 
 def parse(config_file):
-    conf = cfg.ConfigOpts()
-    conf(args=[], default_config_files=[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")
index 871ef54e37451f8f4af4f05913dbb663c90dfb9c..a18097924eba9d48bf5e19c2541ac03ae6d12c99 100644 (file)
@@ -35,8 +35,12 @@ agent_opts = [
 
 
 def parse(config_file):
-    conf = cfg.ConfigOpts()
-    conf(args=[], default_config_files=[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")
diff --git a/quantum/tests/unit/test_lb_config.py b/quantum/tests/unit/test_lb_config.py
new file mode 100644 (file)
index 0000000..f314040
--- /dev/null
@@ -0,0 +1,81 @@
+# 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
+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(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(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")
index 6603022de00ebf74fc808397b258d52de2998b50..624fa09038f70a23b32f0e4a61868806f8e3722b 100644 (file)
@@ -21,7 +21,7 @@ import os
 import tempfile
 import unittest
 
-from quantum.openstack.common.cfg import ConfigFileValueError
+from quantum.openstack.common import cfg
 from quantum.plugins.openvswitch.common import config
 
 
@@ -54,6 +54,8 @@ polling_interval=50
             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)
 
@@ -75,6 +77,10 @@ polling_interval=50
             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)
 
@@ -106,12 +112,20 @@ enable_tunneling = notbool
         try:
             os.write(fd, configs)
             os.close(fd)
+
             conf = config.parse(path)
             exception_raised = False
             try:
                 tunnel = conf.OVS.enable_tunneling
-            except ConfigFileValueError:
+            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
new file mode 100644 (file)
index 0000000..1a375c1
--- /dev/null
@@ -0,0 +1,85 @@
+# 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
+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(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(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")