Log the configuration options for metadata-proxy and agent.

Bug #1144370

Change-Id: I35ac570dd55006d0133736588f0302d6f70294de
This commit is contained in:
gongysh 2013-03-04 21:21:04 +08:00
parent 1001685a9f
commit 0109231fcd
9 changed files with 155 additions and 52 deletions

View File

@ -15,6 +15,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import os
from oslo.config import cfg from oslo.config import cfg
from quantum.common import config from quantum.common import config
@ -35,6 +37,27 @@ AGENT_STATE_OPTS = [
] ]
def get_log_args(conf, log_file_name):
cmd_args = []
if conf.debug:
cmd_args.append('--debug')
if conf.verbose:
cmd_args.append('--verbose')
if (conf.log_dir or conf.log_file):
cmd_args.append('--log-file=%s' % log_file_name)
log_dir = None
if conf.log_dir and conf.log_file:
log_dir = os.path.dirname(
os.path.join(conf.log_dir, conf.log_file))
elif conf.log_dir:
log_dir = conf.log_dir
elif conf.log_file:
log_dir = os.path.dirname(conf.log_file)
if log_dir:
cmd_args.append('--log-dir=%s' % log_dir)
return cmd_args
def register_root_helper(conf): def register_root_helper(conf):
# The first call is to ensure backward compatibility # The first call is to ensure backward compatibility
conf.register_opts(ROOT_HELPER_OPTS) conf.register_opts(ROOT_HELPER_OPTS)

View File

@ -282,11 +282,15 @@ class DhcpAgent(manager.Manager):
router_ports[0].device_id) router_ports[0].device_id)
def callback(pid_file): def callback(pid_file):
return ['quantum-ns-metadata-proxy', proxy_cmd = ['quantum-ns-metadata-proxy',
'--pid_file=%s' % pid_file, '--pid_file=%s' % pid_file,
quantum_lookup_param, quantum_lookup_param,
'--state_path=%s' % self.conf.state_path, '--state_path=%s' % self.conf.state_path,
'--metadata_port=%d' % METADATA_PORT] '--metadata_port=%d' % METADATA_PORT]
proxy_cmd.extend(config.get_log_args(
cfg.CONF, 'quantum-ns-metadata-proxy%s.log' % network.id))
return proxy_cmd
pm = external_process.ProcessManager( pm = external_process.ProcessManager(
self.conf, self.conf,
network.id, network.id,

View File

@ -254,10 +254,14 @@ class L3NATAgent(manager.Manager):
def _spawn_metadata_proxy(self, router_info): def _spawn_metadata_proxy(self, router_info):
def callback(pid_file): def callback(pid_file):
return ['quantum-ns-metadata-proxy', proxy_cmd = ['quantum-ns-metadata-proxy',
'--pid_file=%s' % pid_file, '--pid_file=%s' % pid_file,
'--router_id=%s' % router_info.router_id, '--router_id=%s' % router_info.router_id,
'--state_path=%s' % self.conf.state_path] '--state_path=%s' % self.conf.state_path]
proxy_cmd.extend(config.get_log_args(
cfg.CONF, 'quantum-ns-metadata-proxy%s.log' %
router_info.router_id))
return proxy_cmd
pm = external_process.ProcessManager( pm = external_process.ProcessManager(
self.conf, self.conf,
@ -742,7 +746,7 @@ def main():
config.register_root_helper(conf) config.register_root_helper(conf)
conf.register_opts(interface.OPTS) conf.register_opts(interface.OPTS)
conf.register_opts(external_process.OPTS) conf.register_opts(external_process.OPTS)
conf() conf(project='quantum')
config.setup_logging(conf) config.setup_logging(conf)
server = quantum_service.Service.create( server = quantum_service.Service.create(
binary='quantum-l3-agent', binary='quantum-l3-agent',

View File

@ -29,6 +29,7 @@ from quantumclient.v2_0 import client
import webob import webob
from quantum.common import config from quantum.common import config
from quantum.common import utils
from quantum.openstack.common import log as logging from quantum.openstack.common import log as logging
from quantum import wsgi from quantum import wsgi
@ -221,6 +222,6 @@ def main():
cfg.CONF.register_opts(MetadataProxyHandler.OPTS) cfg.CONF.register_opts(MetadataProxyHandler.OPTS)
cfg.CONF(project='quantum') cfg.CONF(project='quantum')
config.setup_logging(cfg.CONF) config.setup_logging(cfg.CONF)
utils.log_opt_values(LOG)
proxy = UnixDomainMetadataProxy(cfg.CONF) proxy = UnixDomainMetadataProxy(cfg.CONF)
proxy.run() proxy.run()

View File

@ -27,6 +27,7 @@ import webob
from quantum.agent.linux import daemon from quantum.agent.linux import daemon
from quantum.common import config from quantum.common import config
from quantum.common import utils
from quantum.openstack.common import log as logging from quantum.openstack.common import log as logging
from quantum import wsgi from quantum import wsgi
@ -151,9 +152,10 @@ def main():
] ]
cfg.CONF.register_cli_opts(opts) cfg.CONF.register_cli_opts(opts)
cfg.CONF(project='quantum') # Don't get the default configuration file
cfg.CONF(project='quantum', default_config_files=[])
config.setup_logging(cfg.CONF) config.setup_logging(cfg.CONF)
utils.log_opt_values(LOG)
proxy = ProxyDaemon(cfg.CONF.pid_file, proxy = ProxyDaemon(cfg.CONF.pid_file,
cfg.CONF.metadata_port, cfg.CONF.metadata_port,
network_id=cfg.CONF.network_id, network_id=cfg.CONF.network_id,

View File

@ -21,6 +21,7 @@
"""Utilities and helper functions.""" """Utilities and helper functions."""
import logging as std_logging
import os import os
import signal import signal
import socket import socket
@ -188,3 +189,7 @@ def diff_list_of_dict(old_list, new_list):
def is_extension_supported(plugin, ext_alias): def is_extension_supported(plugin, ext_alias):
return ext_alias in getattr( return ext_alias in getattr(
plugin, "supported_extension_aliases", []) plugin, "supported_extension_aliases", [])
def log_opt_values(log):
cfg.CONF.log_opt_values(log, std_logging.DEBUG)

View File

@ -325,6 +325,55 @@ class TestDhcpAgent(base.BaseTestCase):
self.assertFalse(dhcp.needs_resync) self.assertFalse(dhcp.needs_resync)
class TestLogArgs(base.BaseTestCase):
def test_log_args_without_log_dir_and_file(self):
conf_dict = {'debug': True,
'verbose': False,
'log_dir': None,
'log_file': None}
conf = dhcp_agent.DictModel(conf_dict)
expected_args = ['--debug']
args = config.get_log_args(conf, 'log_file_name')
self.assertEqual(expected_args, args)
def test_log_args_without_log_file(self):
conf_dict = {'debug': True,
'verbose': True,
'log_dir': '/etc/tests',
'log_file': None}
conf = dhcp_agent.DictModel(conf_dict)
expected_args = ['--debug', '--verbose',
'--log-file=log_file_name',
'--log-dir=/etc/tests']
args = config.get_log_args(conf, 'log_file_name')
self.assertEqual(expected_args, args)
def test_log_args_with_log_dir_and_file(self):
conf_dict = {'debug': True,
'verbose': False,
'log_dir': '/etc/tests',
'log_file': 'tests/filelog'}
conf = dhcp_agent.DictModel(conf_dict)
expected_args = ['--debug',
'--log-file=log_file_name',
'--log-dir=/etc/tests/tests']
args = config.get_log_args(conf, 'log_file_name')
self.assertEqual(expected_args, args)
def test_log_args_without_log_dir(self):
conf_dict = {'debug': True,
'verbose': False,
'log_file': 'tests/filelog',
'log_dir': None}
conf = dhcp_agent.DictModel(conf_dict)
expected_args = ['--debug',
'--log-file=log_file_name',
'--log-dir=tests']
args = config.get_log_args(conf, 'log_file_name')
self.assertEqual(expected_args, args)
class TestDhcpAgentEventHandler(base.BaseTestCase): class TestDhcpAgentEventHandler(base.BaseTestCase):
def setUp(self): def setUp(self):
super(TestDhcpAgentEventHandler, self).setUp() super(TestDhcpAgentEventHandler, self).setUp()
@ -359,6 +408,7 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
self.call_driver_p.stop() self.call_driver_p.stop()
self.cache_p.stop() self.cache_p.stop()
self.plugin_p.stop() self.plugin_p.stop()
cfg.CONF.reset()
super(TestDhcpAgentEventHandler, self).tearDown() super(TestDhcpAgentEventHandler, self).tearDown()
def test_enable_dhcp_helper(self): def test_enable_dhcp_helper(self):
@ -477,6 +527,8 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
def test_enable_isolated_metadata_proxy_with_metadata_network(self): def test_enable_isolated_metadata_proxy_with_metadata_network(self):
cfg.CONF.set_override('enable_metadata_network', True) cfg.CONF.set_override('enable_metadata_network', True)
cfg.CONF.set_override('debug', True)
cfg.CONF.set_override('log_file', 'test.log')
class_path = 'quantum.agent.linux.ip_lib.IPWrapper' class_path = 'quantum.agent.linux.ip_lib.IPWrapper'
self.external_process_p.stop() self.external_process_p.stop()
# Ensure the mock is restored if this test fail # Ensure the mock is restored if this test fail
@ -486,15 +538,18 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
ip_wrapper.assert_has_calls([mock.call( ip_wrapper.assert_has_calls([mock.call(
'sudo', 'sudo',
'qdhcp-12345678-1234-5678-1234567890ab'), 'qdhcp-12345678-1234-5678-1234567890ab'),
mock.call().netns.execute(['quantum-ns-metadata-proxy', mock.call().netns.execute([
mock.ANY, 'quantum-ns-metadata-proxy',
'--router_id=forzanapoli', mock.ANY,
mock.ANY, '--router_id=forzanapoli',
mock.ANY]) mock.ANY,
mock.ANY,
'--debug',
('--log-file=quantum-ns-metadata-proxy%s.log' %
fake_meta_network.id)])
]) ])
finally: finally:
self.external_process_p.start() self.external_process_p.start()
cfg.CONF.set_override('enable_metadata_network', False)
def test_network_create_end(self): def test_network_create_end(self):
payload = dict(network=dict(id=fake_network.id)) payload = dict(network=dict(id=fake_network.id))

View File

@ -24,6 +24,7 @@ import webob
from quantum.agent.metadata import agent from quantum.agent.metadata import agent
from quantum.tests import base from quantum.tests import base
from quantum.common import utils
class FakeConf(object): class FakeConf(object):
@ -354,11 +355,12 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
with mock.patch('eventlet.monkey_patch') as eventlet: with mock.patch('eventlet.monkey_patch') as eventlet:
with mock.patch.object(agent, 'config') as config: with mock.patch.object(agent, 'config') as config:
with mock.patch.object(agent, 'cfg') as cfg: with mock.patch.object(agent, 'cfg') as cfg:
agent.main() with mock.patch.object(utils, 'cfg') as utils_cfg:
agent.main()
self.assertTrue(eventlet.called) self.assertTrue(eventlet.called)
self.assertTrue(config.setup_logging.called) self.assertTrue(config.setup_logging.called)
proxy.assert_has_calls([ proxy.assert_has_calls([
mock.call(cfg.CONF), mock.call(cfg.CONF),
mock.call().run()] mock.call().run()]
) )

View File

@ -24,6 +24,7 @@ import webob
from quantum.agent.metadata import namespace_proxy as ns_proxy from quantum.agent.metadata import namespace_proxy as ns_proxy
from quantum.tests import base from quantum.tests import base
from quantum.common import utils
class FakeConf(object): class FakeConf(object):
@ -256,37 +257,43 @@ class TestProxyDaemon(base.BaseTestCase):
with mock.patch('eventlet.monkey_patch') as eventlet: with mock.patch('eventlet.monkey_patch') as eventlet:
with mock.patch.object(ns_proxy, 'config') as config: with mock.patch.object(ns_proxy, 'config') as config:
with mock.patch.object(ns_proxy, 'cfg') as cfg: with mock.patch.object(ns_proxy, 'cfg') as cfg:
cfg.CONF.router_id = 'router_id' with mock.patch.object(utils, 'cfg') as utils_cfg:
cfg.CONF.network_id = None cfg.CONF.router_id = 'router_id'
cfg.CONF.metadata_port = 9697 cfg.CONF.network_id = None
cfg.CONF.pid_file = 'pidfile' cfg.CONF.metadata_port = 9697
cfg.CONF.daemonize = True cfg.CONF.pid_file = 'pidfile'
ns_proxy.main() cfg.CONF.daemonize = True
utils_cfg.CONF.log_opt_values.return_value = None
ns_proxy.main()
self.assertTrue(eventlet.called) self.assertTrue(eventlet.called)
self.assertTrue(config.setup_logging.called) self.assertTrue(config.setup_logging.called)
daemon.assert_has_calls([ daemon.assert_has_calls([
mock.call('pidfile', 9697, router_id='router_id', mock.call('pidfile', 9697,
network_id=None), router_id='router_id',
mock.call().start()] network_id=None),
) mock.call().start()]
)
def test_main_dont_fork(self): def test_main_dont_fork(self):
with mock.patch.object(ns_proxy, 'ProxyDaemon') as daemon: with mock.patch.object(ns_proxy, 'ProxyDaemon') as daemon:
with mock.patch('eventlet.monkey_patch') as eventlet: with mock.patch('eventlet.monkey_patch') as eventlet:
with mock.patch.object(ns_proxy, 'config') as config: with mock.patch.object(ns_proxy, 'config') as config:
with mock.patch.object(ns_proxy, 'cfg') as cfg: with mock.patch.object(ns_proxy, 'cfg') as cfg:
cfg.CONF.router_id = 'router_id' with mock.patch.object(utils, 'cfg') as utils_cfg:
cfg.CONF.network_id = None cfg.CONF.router_id = 'router_id'
cfg.CONF.metadata_port = 9697 cfg.CONF.network_id = None
cfg.CONF.pid_file = 'pidfile' cfg.CONF.metadata_port = 9697
cfg.CONF.daemonize = False cfg.CONF.pid_file = 'pidfile'
ns_proxy.main() cfg.CONF.daemonize = False
utils_cfg.CONF.log_opt_values.return_value = None
ns_proxy.main()
self.assertTrue(eventlet.called) self.assertTrue(eventlet.called)
self.assertTrue(config.setup_logging.called) self.assertTrue(config.setup_logging.called)
daemon.assert_has_calls([ daemon.assert_has_calls([
mock.call('pidfile', 9697, router_id='router_id', mock.call('pidfile', 9697,
network_id=None), router_id='router_id',
mock.call().run()] network_id=None),
) mock.call().run()]
)