]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Enable OVS and NETNS utilities to perform logging
authorGary Kotton <gkotton@redhat.com>
Thu, 7 Feb 2013 16:22:20 +0000 (16:22 +0000)
committerGary Kotton <gkotton@redhat.com>
Thu, 7 Feb 2013 16:23:14 +0000 (16:23 +0000)
Fixes bug 1118517

Change-Id: I623c39b7d05accc49f88922d5d2c7ecfb8562a52

quantum/agent/netns_cleanup_util.py
quantum/agent/ovs_cleanup_util.py
quantum/tests/unit/test_agent_netns_cleanup.py
quantum/tests/unit/test_agent_ovs_cleanup.py

index aed80bec5e9c88d28ac2b50a9359e37e69a43fc4..9c6660d52456b3452dcc80b50925ac1b16e8e550 100644 (file)
@@ -68,11 +68,10 @@ def setup_conf():
                     help=_('Delete the namespace by removing all devices.')),
     ]
 
-    conf = cfg.ConfigOpts()
+    conf = cfg.CONF
     conf.register_opts(opts)
     agent_config.register_root_helper(conf)
     conf.register_opts(dhcp.OPTS)
-    config.setup_logging(conf)
     return conf
 
 
@@ -168,6 +167,7 @@ def main():
 
     conf = setup_conf()
     conf()
+    config.setup_logging(conf)
 
     root_helper = agent_config.get_root_helper(conf)
     # Identify namespaces that are candidates for deletion.
index 12d2fe9e6daaf2a85001dab4f3cbf269d76b4677..d9ee6459197d5b11a2b85a107ec7b22ffa2615c4 100644 (file)
@@ -43,12 +43,11 @@ def setup_conf():
                            'bridges.'))
     ]
 
-    conf = cfg.ConfigOpts()
+    conf = cfg.CONF
     conf.register_cli_opts(opts)
     conf.register_opts(l3_agent.L3NATAgent.OPTS)
     conf.register_opts(interface.OPTS)
     agent_config.register_root_helper(conf)
-    config.setup_logging(conf)
     return conf
 
 
@@ -81,6 +80,7 @@ def main():
 
     conf = setup_conf()
     conf()
+    config.setup_logging(conf)
 
     configuration_bridges = set([conf.ovs_integration_bridge,
                                  conf.external_network_bridge])
index a08dc2766ed6916abb4563e24fb9ef1a3041bcfd..2bf6254b29661be4c41f0366f4baadc3acbbd476 100644 (file)
@@ -19,6 +19,7 @@ import mock
 import unittest2 as unittest
 
 from quantum.agent import netns_cleanup_util as util
+from quantum.openstack.common import cfg
 
 
 class TestNullDelegate(unittest.TestCase):
@@ -28,10 +29,8 @@ class TestNullDelegate(unittest.TestCase):
 
 
 class TestNetnsCleanup(unittest.TestCase):
-    def test_setup_conf(self):
-        with mock.patch('quantum.common.config.setup_logging'):
-            conf = util.setup_conf()
-            self.assertFalse(conf.force)
+    def tearDown(self):
+        cfg.CONF.reset()
 
     def test_kill_dhcp(self, dhcp_active=True):
         conf = mock.Mock()
@@ -213,20 +212,21 @@ class TestNetnsCleanup(unittest.TestCase):
                 with mock.patch.multiple(util, **methods_to_mock) as mocks:
                     mocks['eligible_for_deletion'].return_value = True
                     mocks['setup_conf'].return_value = conf
-                    util.main()
+                    with mock.patch('quantum.common.config.setup_logging'):
+                        util.main()
 
-                    mocks['eligible_for_deletion'].assert_has_calls(
-                        [mock.call(conf, 'ns1', False),
-                         mock.call(conf, 'ns2', False)])
+                        mocks['eligible_for_deletion'].assert_has_calls(
+                            [mock.call(conf, 'ns1', False),
+                             mock.call(conf, 'ns2', False)])
 
-                    mocks['destroy_namespace'].assert_has_calls(
-                        [mock.call(conf, 'ns1', False),
-                         mock.call(conf, 'ns2', False)])
+                        mocks['destroy_namespace'].assert_has_calls(
+                            [mock.call(conf, 'ns1', False),
+                             mock.call(conf, 'ns2', False)])
 
-                    ip_wrap.assert_has_calls(
-                        [mock.call.get_namespaces(conf.AGENT.root_helper)])
+                        ip_wrap.assert_has_calls(
+                            [mock.call.get_namespaces(conf.AGENT.root_helper)])
 
-                    eventlet_sleep.assert_called_once_with(2)
+                        eventlet_sleep.assert_called_once_with(2)
 
     def test_main_no_candidates(self):
         namespaces = ['ns1', 'ns2']
@@ -244,15 +244,16 @@ class TestNetnsCleanup(unittest.TestCase):
                 with mock.patch.multiple(util, **methods_to_mock) as mocks:
                     mocks['eligible_for_deletion'].return_value = False
                     mocks['setup_conf'].return_value = conf
-                    util.main()
+                    with mock.patch('quantum.common.config.setup_logging'):
+                        util.main()
 
-                    ip_wrap.assert_has_calls(
-                        [mock.call.get_namespaces(conf.AGENT.root_helper)])
+                        ip_wrap.assert_has_calls(
+                            [mock.call.get_namespaces(conf.AGENT.root_helper)])
 
-                    mocks['eligible_for_deletion'].assert_has_calls(
-                        [mock.call(conf, 'ns1', False),
-                         mock.call(conf, 'ns2', False)])
+                        mocks['eligible_for_deletion'].assert_has_calls(
+                            [mock.call(conf, 'ns1', False),
+                             mock.call(conf, 'ns2', False)])
 
-                    self.assertFalse(mocks['destroy_namespace'].called)
+                        self.assertFalse(mocks['destroy_namespace'].called)
 
-                    self.assertFalse(eventlet_sleep.called)
+                        self.assertFalse(eventlet_sleep.called)
index 1f3556103fe6b244c0a4e74a9991681223704264..b607a99aeb1a253bf7241f7b2b61435baea6ea4c 100644 (file)
@@ -23,17 +23,20 @@ import unittest2 as unittest
 from quantum.agent.linux import ip_lib
 from quantum.agent.linux import ovs_lib
 from quantum.agent import ovs_cleanup_util as util
+from quantum.openstack.common import cfg
 from quantum.openstack.common import uuidutils
 
 
 class TestOVSCleanup(unittest.TestCase):
+    def tearDown(self):
+        cfg.CONF.reset()
+
     def test_setup_conf(self):
-        with mock.patch('quantum.common.config.setup_logging'):
-            conf = util.setup_conf()
-            self.assertEqual(conf.external_network_bridge, 'br-ex')
-            self.assertEqual(conf.ovs_integration_bridge, 'br-int')
-            self.assertFalse(conf.ovs_all_ports)
-            self.assertEqual(conf.AGENT.root_helper, 'sudo')
+        conf = util.setup_conf()
+        self.assertEqual(conf.external_network_bridge, 'br-ex')
+        self.assertEqual(conf.ovs_integration_bridge, 'br-int')
+        self.assertFalse(conf.ovs_all_ports)
+        self.assertEqual(conf.AGENT.root_helper, 'sudo')
 
     def test_main(self):
         bridges = ['br-int', 'br-ex']
@@ -54,10 +57,12 @@ class TestOVSCleanup(unittest.TestCase):
                               return_value=ports),
             mock.patch.object(util, 'delete_quantum_ports')
         ) as (_log, _conf, _get, ovs, collect, delete):
-            util.main()
-            ovs.assert_has_calls([mock.call().delete_ports(all_ports=False)])
-            collect.assert_called_once_with(set(bridges), 'dummy_sudo')
-            delete.assert_called_once_with(ports, 'dummy_sudo')
+            with mock.patch('quantum.common.config.setup_logging'):
+                util.main()
+                ovs.assert_has_calls([mock.call().delete_ports(
+                    all_ports=False)])
+                collect.assert_called_once_with(set(bridges), 'dummy_sudo')
+                delete.assert_called_once_with(ports, 'dummy_sudo')
 
     def test_collect_quantum_ports(self):
         port1 = ovs_lib.VifPort('tap1234', 1, uuidutils.generate_uuid(),