Log the configuration options for metadata-proxy and agent.
Bug #1144370 Change-Id: I35ac570dd55006d0133736588f0302d6f70294de
This commit is contained in:
parent
1500a54820
commit
c51b3ff25c
@ -15,6 +15,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
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):
|
||||
# The first call is to ensure backward compatibility
|
||||
conf.register_opts(ROOT_HELPER_OPTS)
|
||||
|
@ -282,11 +282,15 @@ class DhcpAgent(manager.Manager):
|
||||
router_ports[0].device_id)
|
||||
|
||||
def callback(pid_file):
|
||||
return ['quantum-ns-metadata-proxy',
|
||||
'--pid_file=%s' % pid_file,
|
||||
quantum_lookup_param,
|
||||
'--state_path=%s' % self.conf.state_path,
|
||||
'--metadata_port=%d' % METADATA_PORT]
|
||||
proxy_cmd = ['quantum-ns-metadata-proxy',
|
||||
'--pid_file=%s' % pid_file,
|
||||
quantum_lookup_param,
|
||||
'--state_path=%s' % self.conf.state_path,
|
||||
'--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(
|
||||
self.conf,
|
||||
network.id,
|
||||
|
@ -254,10 +254,14 @@ class L3NATAgent(manager.Manager):
|
||||
|
||||
def _spawn_metadata_proxy(self, router_info):
|
||||
def callback(pid_file):
|
||||
return ['quantum-ns-metadata-proxy',
|
||||
'--pid_file=%s' % pid_file,
|
||||
'--router_id=%s' % router_info.router_id,
|
||||
'--state_path=%s' % self.conf.state_path]
|
||||
proxy_cmd = ['quantum-ns-metadata-proxy',
|
||||
'--pid_file=%s' % pid_file,
|
||||
'--router_id=%s' % router_info.router_id,
|
||||
'--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(
|
||||
self.conf,
|
||||
@ -742,7 +746,7 @@ def main():
|
||||
config.register_root_helper(conf)
|
||||
conf.register_opts(interface.OPTS)
|
||||
conf.register_opts(external_process.OPTS)
|
||||
conf()
|
||||
conf(project='quantum')
|
||||
config.setup_logging(conf)
|
||||
server = quantum_service.Service.create(
|
||||
binary='quantum-l3-agent',
|
||||
|
@ -29,6 +29,7 @@ from quantumclient.v2_0 import client
|
||||
import webob
|
||||
|
||||
from quantum.common import config
|
||||
from quantum.common import utils
|
||||
from quantum.openstack.common import log as logging
|
||||
from quantum import wsgi
|
||||
|
||||
@ -221,6 +222,6 @@ def main():
|
||||
cfg.CONF.register_opts(MetadataProxyHandler.OPTS)
|
||||
cfg.CONF(project='quantum')
|
||||
config.setup_logging(cfg.CONF)
|
||||
|
||||
utils.log_opt_values(LOG)
|
||||
proxy = UnixDomainMetadataProxy(cfg.CONF)
|
||||
proxy.run()
|
||||
|
@ -27,6 +27,7 @@ import webob
|
||||
|
||||
from quantum.agent.linux import daemon
|
||||
from quantum.common import config
|
||||
from quantum.common import utils
|
||||
from quantum.openstack.common import log as logging
|
||||
from quantum import wsgi
|
||||
|
||||
@ -151,9 +152,10 @@ def main():
|
||||
]
|
||||
|
||||
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)
|
||||
|
||||
utils.log_opt_values(LOG)
|
||||
proxy = ProxyDaemon(cfg.CONF.pid_file,
|
||||
cfg.CONF.metadata_port,
|
||||
network_id=cfg.CONF.network_id,
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
"""Utilities and helper functions."""
|
||||
|
||||
import logging as std_logging
|
||||
import os
|
||||
import signal
|
||||
import socket
|
||||
@ -188,3 +189,7 @@ def diff_list_of_dict(old_list, new_list):
|
||||
def is_extension_supported(plugin, ext_alias):
|
||||
return ext_alias in getattr(
|
||||
plugin, "supported_extension_aliases", [])
|
||||
|
||||
|
||||
def log_opt_values(log):
|
||||
cfg.CONF.log_opt_values(log, std_logging.DEBUG)
|
||||
|
@ -325,6 +325,55 @@ class TestDhcpAgent(base.BaseTestCase):
|
||||
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):
|
||||
def setUp(self):
|
||||
super(TestDhcpAgentEventHandler, self).setUp()
|
||||
@ -359,6 +408,7 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
|
||||
self.call_driver_p.stop()
|
||||
self.cache_p.stop()
|
||||
self.plugin_p.stop()
|
||||
cfg.CONF.reset()
|
||||
super(TestDhcpAgentEventHandler, self).tearDown()
|
||||
|
||||
def test_enable_dhcp_helper(self):
|
||||
@ -477,6 +527,8 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
|
||||
|
||||
def test_enable_isolated_metadata_proxy_with_metadata_network(self):
|
||||
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'
|
||||
self.external_process_p.stop()
|
||||
# Ensure the mock is restored if this test fail
|
||||
@ -486,15 +538,18 @@ class TestDhcpAgentEventHandler(base.BaseTestCase):
|
||||
ip_wrapper.assert_has_calls([mock.call(
|
||||
'sudo',
|
||||
'qdhcp-12345678-1234-5678-1234567890ab'),
|
||||
mock.call().netns.execute(['quantum-ns-metadata-proxy',
|
||||
mock.ANY,
|
||||
'--router_id=forzanapoli',
|
||||
mock.ANY,
|
||||
mock.ANY])
|
||||
mock.call().netns.execute([
|
||||
'quantum-ns-metadata-proxy',
|
||||
mock.ANY,
|
||||
'--router_id=forzanapoli',
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
'--debug',
|
||||
('--log-file=quantum-ns-metadata-proxy%s.log' %
|
||||
fake_meta_network.id)])
|
||||
])
|
||||
finally:
|
||||
self.external_process_p.start()
|
||||
cfg.CONF.set_override('enable_metadata_network', False)
|
||||
|
||||
def test_network_create_end(self):
|
||||
payload = dict(network=dict(id=fake_network.id))
|
||||
|
@ -24,6 +24,7 @@ import webob
|
||||
|
||||
from quantum.agent.metadata import agent
|
||||
from quantum.tests import base
|
||||
from quantum.common import utils
|
||||
|
||||
|
||||
class FakeConf(object):
|
||||
@ -354,11 +355,12 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
|
||||
with mock.patch('eventlet.monkey_patch') as eventlet:
|
||||
with mock.patch.object(agent, 'config') as config:
|
||||
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(config.setup_logging.called)
|
||||
proxy.assert_has_calls([
|
||||
mock.call(cfg.CONF),
|
||||
mock.call().run()]
|
||||
)
|
||||
self.assertTrue(eventlet.called)
|
||||
self.assertTrue(config.setup_logging.called)
|
||||
proxy.assert_has_calls([
|
||||
mock.call(cfg.CONF),
|
||||
mock.call().run()]
|
||||
)
|
||||
|
@ -24,6 +24,7 @@ import webob
|
||||
|
||||
from quantum.agent.metadata import namespace_proxy as ns_proxy
|
||||
from quantum.tests import base
|
||||
from quantum.common import utils
|
||||
|
||||
|
||||
class FakeConf(object):
|
||||
@ -256,37 +257,43 @@ class TestProxyDaemon(base.BaseTestCase):
|
||||
with mock.patch('eventlet.monkey_patch') as eventlet:
|
||||
with mock.patch.object(ns_proxy, 'config') as config:
|
||||
with mock.patch.object(ns_proxy, 'cfg') as cfg:
|
||||
cfg.CONF.router_id = 'router_id'
|
||||
cfg.CONF.network_id = None
|
||||
cfg.CONF.metadata_port = 9697
|
||||
cfg.CONF.pid_file = 'pidfile'
|
||||
cfg.CONF.daemonize = True
|
||||
ns_proxy.main()
|
||||
with mock.patch.object(utils, 'cfg') as utils_cfg:
|
||||
cfg.CONF.router_id = 'router_id'
|
||||
cfg.CONF.network_id = None
|
||||
cfg.CONF.metadata_port = 9697
|
||||
cfg.CONF.pid_file = 'pidfile'
|
||||
cfg.CONF.daemonize = True
|
||||
utils_cfg.CONF.log_opt_values.return_value = None
|
||||
ns_proxy.main()
|
||||
|
||||
self.assertTrue(eventlet.called)
|
||||
self.assertTrue(config.setup_logging.called)
|
||||
daemon.assert_has_calls([
|
||||
mock.call('pidfile', 9697, router_id='router_id',
|
||||
network_id=None),
|
||||
mock.call().start()]
|
||||
)
|
||||
self.assertTrue(eventlet.called)
|
||||
self.assertTrue(config.setup_logging.called)
|
||||
daemon.assert_has_calls([
|
||||
mock.call('pidfile', 9697,
|
||||
router_id='router_id',
|
||||
network_id=None),
|
||||
mock.call().start()]
|
||||
)
|
||||
|
||||
def test_main_dont_fork(self):
|
||||
with mock.patch.object(ns_proxy, 'ProxyDaemon') as daemon:
|
||||
with mock.patch('eventlet.monkey_patch') as eventlet:
|
||||
with mock.patch.object(ns_proxy, 'config') as config:
|
||||
with mock.patch.object(ns_proxy, 'cfg') as cfg:
|
||||
cfg.CONF.router_id = 'router_id'
|
||||
cfg.CONF.network_id = None
|
||||
cfg.CONF.metadata_port = 9697
|
||||
cfg.CONF.pid_file = 'pidfile'
|
||||
cfg.CONF.daemonize = False
|
||||
ns_proxy.main()
|
||||
with mock.patch.object(utils, 'cfg') as utils_cfg:
|
||||
cfg.CONF.router_id = 'router_id'
|
||||
cfg.CONF.network_id = None
|
||||
cfg.CONF.metadata_port = 9697
|
||||
cfg.CONF.pid_file = 'pidfile'
|
||||
cfg.CONF.daemonize = False
|
||||
utils_cfg.CONF.log_opt_values.return_value = None
|
||||
ns_proxy.main()
|
||||
|
||||
self.assertTrue(eventlet.called)
|
||||
self.assertTrue(config.setup_logging.called)
|
||||
daemon.assert_has_calls([
|
||||
mock.call('pidfile', 9697, router_id='router_id',
|
||||
network_id=None),
|
||||
mock.call().run()]
|
||||
)
|
||||
self.assertTrue(eventlet.called)
|
||||
self.assertTrue(config.setup_logging.called)
|
||||
daemon.assert_has_calls([
|
||||
mock.call('pidfile', 9697,
|
||||
router_id='router_id',
|
||||
network_id=None),
|
||||
mock.call().run()]
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user