diff --git a/neutron/agent/common/config.py b/neutron/agent/common/config.py index 273a01c76..c4c7c795e 100644 --- a/neutron/agent/common/config.py +++ b/neutron/agent/common/config.py @@ -56,7 +56,11 @@ def get_log_args(conf, log_file_name): if log_dir: cmd_args.append('--log-dir=%s' % log_dir) else: - cmd_args.append('--use-syslog') + if conf.use_syslog: + cmd_args.append('--use-syslog') + if conf.syslog_log_facility: + cmd_args.append( + '--syslog-log-facility=%s' % conf.syslog_log_facility) return cmd_args diff --git a/neutron/tests/unit/test_dhcp_agent.py b/neutron/tests/unit/test_dhcp_agent.py index 675bda03f..7f139ec25 100644 --- a/neutron/tests/unit/test_dhcp_agent.py +++ b/neutron/tests/unit/test_dhcp_agent.py @@ -378,9 +378,13 @@ class TestLogArgs(base.BaseTestCase): conf_dict = {'debug': True, 'verbose': False, 'log_dir': None, - 'log_file': None} + 'log_file': None, + 'use_syslog': True, + 'syslog_log_facility': 'LOG_USER'} conf = dhcp_agent.DictModel(conf_dict) - expected_args = ['--debug', '--use-syslog'] + expected_args = ['--debug', + '--use-syslog', + '--syslog-log-facility=LOG_USER'] args = config.get_log_args(conf, 'log_file_name') self.assertEqual(expected_args, args) @@ -388,9 +392,12 @@ class TestLogArgs(base.BaseTestCase): conf_dict = {'debug': True, 'verbose': True, 'log_dir': '/etc/tests', - 'log_file': None} + 'log_file': None, + 'use_syslog': False, + 'syslog_log_facility': 'LOG_USER'} conf = dhcp_agent.DictModel(conf_dict) - expected_args = ['--debug', '--verbose', + expected_args = ['--debug', + '--verbose', '--log-file=log_file_name', '--log-dir=/etc/tests'] args = config.get_log_args(conf, 'log_file_name') @@ -400,7 +407,9 @@ class TestLogArgs(base.BaseTestCase): conf_dict = {'debug': True, 'verbose': False, 'log_dir': '/etc/tests', - 'log_file': 'tests/filelog'} + 'log_file': 'tests/filelog', + 'use_syslog': False, + 'syslog_log_facility': 'LOG_USER'} conf = dhcp_agent.DictModel(conf_dict) expected_args = ['--debug', '--log-file=log_file_name', @@ -412,7 +421,9 @@ class TestLogArgs(base.BaseTestCase): conf_dict = {'debug': True, 'verbose': False, 'log_file': 'tests/filelog', - 'log_dir': None} + 'log_dir': None, + 'use_syslog': False, + 'syslog_log_facility': 'LOG_USER'} conf = dhcp_agent.DictModel(conf_dict) expected_args = ['--debug', '--log-file=log_file_name', @@ -420,6 +431,21 @@ class TestLogArgs(base.BaseTestCase): args = config.get_log_args(conf, 'log_file_name') self.assertEqual(expected_args, args) + def test_log_args_with_filelog_and_syslog(self): + conf_dict = {'debug': True, + 'verbose': True, + 'log_file': 'tests/filelog', + 'log_dir': '/etc/tests', + 'use_syslog': True, + 'syslog_log_facility': 'LOG_USER'} + conf = dhcp_agent.DictModel(conf_dict) + expected_args = ['--debug', + '--verbose', + '--log-file=log_file_name', + '--log-dir=/etc/tests/tests'] + args = config.get_log_args(conf, 'log_file_name') + self.assertEqual(expected_args, args) + class TestDhcpAgentEventHandler(base.BaseTestCase): def setUp(self):