diff --git a/neutron/agent/metadata/driver.py b/neutron/agent/metadata/driver.py index d29ecd1f38d..5422c9f527d 100644 --- a/neutron/agent/metadata/driver.py +++ b/neutron/agent/metadata/driver.py @@ -39,6 +39,7 @@ PROXY_CONFIG_DIR = "ns-metadata-proxy" _HAPROXY_CONFIG_TEMPLATE = """ global log /dev/log local0 %(log_level)s + log-tag %(log_tag)s user %(user)s group %(group)s maxconn 1024 @@ -86,6 +87,12 @@ class HaproxyConfigurator(object): self.pidfile = pid_file self.log_level = ( 'debug' if logging.is_debug_enabled(cfg.CONF) else 'info') + # log-tag will cause entries to have the string pre-pended, so use + # the uuid haproxy will be started with. Additionally, if it + # starts with "haproxy" then things will get logged to + # /var/log/haproxy.log on Debian distros, instead of to syslog. + uuid = network_id or router_id + self.log_tag = "haproxy-" + METADATA_SERVICE_NAME + "-" + uuid def create_config_file(self): """Create the config file for haproxy.""" @@ -114,7 +121,8 @@ class HaproxyConfigurator(object): 'user': username, 'group': groupname, 'pidfile': self.pidfile, - 'log_level': self.log_level + 'log_level': self.log_level, + 'log_tag': self.log_tag } if self.network_id: cfg_info['res_type'] = 'Network' diff --git a/neutron/tests/unit/agent/metadata/test_driver.py b/neutron/tests/unit/agent/metadata/test_driver.py index 1f883a63827..21649733640 100644 --- a/neutron/tests/unit/agent/metadata/test_driver.py +++ b/neutron/tests/unit/agent/metadata/test_driver.py @@ -161,6 +161,8 @@ class TestMetadataDriverProcess(base.BaseTestCase): 'haproxy', '-f', cfg_file] + log_tag = ("haproxy-" + metadata_driver.METADATA_SERVICE_NAME + + "-" + router_id) cfg_contents = metadata_driver._HAPROXY_CONFIG_TEMPLATE % { 'user': self.EUNAME, 'group': self.EGNAME, @@ -169,7 +171,8 @@ class TestMetadataDriverProcess(base.BaseTestCase): 'res_type': 'Router', 'res_id': router_id, 'pidfile': self.PIDFILE, - 'log_level': 'debug'} + 'log_level': 'debug', + 'log_tag': log_tag} mock_open.assert_has_calls([ mock.call(cfg_file, 'w'), @@ -184,7 +187,7 @@ class TestMetadataDriverProcess(base.BaseTestCase): def test_create_config_file_wrong_user(self): with mock.patch('pwd.getpwnam', side_effect=KeyError): - config = metadata_driver.HaproxyConfigurator(mock.ANY, mock.ANY, + config = metadata_driver.HaproxyConfigurator(_uuid(), mock.ANY, mock.ANY, mock.ANY, self.EUNAME, self.EGNAME, @@ -196,7 +199,7 @@ class TestMetadataDriverProcess(base.BaseTestCase): with mock.patch('grp.getgrnam', side_effect=KeyError),\ mock.patch('pwd.getpwnam', return_value=test_utils.FakeUser(self.EUNAME)): - config = metadata_driver.HaproxyConfigurator(mock.ANY, mock.ANY, + config = metadata_driver.HaproxyConfigurator(_uuid(), mock.ANY, mock.ANY, mock.ANY, self.EUNAME, self.EGNAME,