diff --git a/etc/octavia.conf b/etc/octavia.conf index 8fe2e1fc52..3a8583988d 100644 --- a/etc/octavia.conf +++ b/etc/octavia.conf @@ -195,6 +195,19 @@ # facilitate "fail fast" scenarios like failovers # active_connection_max_retries = 15 # active_connection_rety_interval = 2 +# +# Sets the syslog LOG_LOCAL[0-7] facility number for amphora log offloading. +# user_log_facility will receive the traffic flow logs. +# administrative_log_facility will receive the amphora processes logs. +# Note: Some processes only support LOG_LOCAL, so we are restricted to the +# LOG_LOCAL facilities. +# user_log_facility = 0 +# administrative_log_facility = 1 +# +# The user flow log format for HAProxy. +# {{ project_id }} and {{ lb_id }} will be automatically substituted by the +# controller when configuring HAProxy if they are present in the string. +# user_log_format = '{{ project_id }} {{ lb_id }} %f %ci %cp %t %{+Q}r %ST %B %U %[ssl_c_verify] %{+Q}[ssl_c_s_dn] %b %s %Tt %tsc' [controller_worker] # workers = 1 diff --git a/octavia/amphorae/backends/agent/agent_jinja_cfg.py b/octavia/amphorae/backends/agent/agent_jinja_cfg.py index 75125eb3c4..7563e387c7 100644 --- a/octavia/amphorae/backends/agent/agent_jinja_cfg.py +++ b/octavia/amphorae/backends/agent/agent_jinja_cfg.py @@ -59,4 +59,7 @@ class AgentJinjaTemplater(object): 'respawn_interval': CONF.haproxy_amphora.respawn_interval, 'amphora_udp_driver': CONF.amphora_agent.amphora_udp_driver, 'agent_tls_protocol': CONF.amphora_agent.agent_tls_protocol, - 'topology': topology}) + 'topology': topology, + 'administrative_log_facility': + CONF.haproxy_amphora.administrative_log_facility, + 'user_log_facility': CONF.haproxy_amphora.user_log_facility}) diff --git a/octavia/amphorae/backends/agent/api_server/keepalived.py b/octavia/amphorae/backends/agent/api_server/keepalived.py index 045b64056f..22e761d7a5 100644 --- a/octavia/amphorae/backends/agent/api_server/keepalived.py +++ b/octavia/amphorae/backends/agent/api_server/keepalived.py @@ -18,6 +18,7 @@ import subprocess import flask import jinja2 +from oslo_config import cfg from oslo_log import log as logging import webob @@ -27,6 +28,7 @@ from octavia.common import constants as consts BUFFER = 100 +CONF = cfg.CONF LOG = logging.getLogger(__name__) @@ -92,7 +94,9 @@ class Keepalived(object): keepalived_cfg=util.keepalived_cfg_path(), keepalived_log=util.keepalived_log_path(), amphora_nsname=consts.AMPHORA_NAMESPACE, - amphora_netns=consts.AMP_NETNS_SVC_PREFIX + amphora_netns=consts.AMP_NETNS_SVC_PREFIX, + administrative_log_facility=( + CONF.haproxy_amphora.administrative_log_facility), ) text_file.write(text) diff --git a/octavia/amphorae/backends/agent/api_server/keepalivedlvs.py b/octavia/amphorae/backends/agent/api_server/keepalivedlvs.py index 46301b1fe5..4282d49d39 100644 --- a/octavia/amphorae/backends/agent/api_server/keepalivedlvs.py +++ b/octavia/amphorae/backends/agent/api_server/keepalivedlvs.py @@ -20,6 +20,7 @@ import subprocess import flask import jinja2 +from oslo_config import cfg from oslo_log import log as logging import webob from werkzeug import exceptions @@ -32,6 +33,7 @@ from octavia.common import constants as consts BUFFER = 100 CHECK_SCRIPT_NAME = 'udp_check.sh' +CONF = cfg.CONF KEEPALIVED_CHECK_SCRIPT_NAME = 'lvs_udp_check.sh' LOG = logging.getLogger(__name__) @@ -127,7 +129,9 @@ class KeepalivedLvs(udp_listener_base.UdpListenerApiServerBase): keepalived_cmd=consts.KEEPALIVED_CMD, keepalived_cfg=util.keepalived_lvs_cfg_path(listener_id), amphora_nsname=consts.AMPHORA_NAMESPACE, - amphora_netns=consts.AMP_NETNS_SVC_PREFIX + amphora_netns=consts.AMP_NETNS_SVC_PREFIX, + administrative_log_facility=( + CONF.haproxy_amphora.administrative_log_facility), ) text_file.write(text) diff --git a/octavia/amphorae/backends/agent/api_server/templates/keepalived.systemd.j2 b/octavia/amphorae/backends/agent/api_server/templates/keepalived.systemd.j2 index 374be22771..de9b1ea06c 100644 --- a/octavia/amphorae/backends/agent/api_server/templates/keepalived.systemd.j2 +++ b/octavia/amphorae/backends/agent/api_server/templates/keepalived.systemd.j2 @@ -10,9 +10,9 @@ SELinuxContext=system_u:system_r:keepalived_t:s0 Type=forking KillMode=process {% if vrrp_pid and check_pid %} -ExecStart=/sbin/ip netns exec {{ amphora_nsname }} {{ keepalived_cmd }} -D -d -f {{ keepalived_cfg }} -p {{ keepalived_pid }} -r {{ vrrp_pid }} -c {{ check_pid }} +ExecStart=/sbin/ip netns exec {{ amphora_nsname }} {{ keepalived_cmd }} --log-facility={{ administrative_log_facility }} -f {{ keepalived_cfg }} -p {{ keepalived_pid }} -r {{ vrrp_pid }} -c {{ check_pid }} {% else %} -ExecStart=/sbin/ip netns exec {{ amphora_nsname }} {{ keepalived_cmd }} -D -d -f {{ keepalived_cfg }} -p {{ keepalived_pid }} +ExecStart=/sbin/ip netns exec {{ amphora_nsname }} {{ keepalived_cmd }} --log-facility={{ administrative_log_facility }} -f {{ keepalived_cfg }} -p {{ keepalived_pid }} {% endif %} ExecReload=/bin/kill -HUP $MAINPID PIDFile={{ keepalived_pid }} diff --git a/octavia/amphorae/backends/agent/api_server/templates/keepalived.sysvinit.j2 b/octavia/amphorae/backends/agent/api_server/templates/keepalived.sysvinit.j2 index 9689a5ca62..147761a932 100644 --- a/octavia/amphorae/backends/agent/api_server/templates/keepalived.sysvinit.j2 +++ b/octavia/amphorae/backends/agent/api_server/templates/keepalived.sysvinit.j2 @@ -19,9 +19,9 @@ NAME=octavia-keepalived DESC=octavia-keepalived TMPFILES="/tmp/.vrrp /tmp/.healthcheckers" {% if vrrp_pid and check_pid %} -DAEMON_ARGS="-D -d -f {{ keepalived_cfg }} -p {{ keepalived_pid }} -r {{ vrrp_pid }} -c {{ check_pid }}" +DAEMON_ARGS="--log-facility={{ administrative_log_facility }} -f {{ keepalived_cfg }} -p {{ keepalived_pid }} -r {{ vrrp_pid }} -c {{ check_pid }}" {% else %} -DAEMON_ARGS="-D -d -f {{ keepalived_cfg }} -p {{ keepalived_pid }}" +DAEMON_ARGS="-log-facility={{ administrative_log_facility }} -f {{ keepalived_cfg }} -p {{ keepalived_pid }}" {% endif %} #includes lsb functions diff --git a/octavia/amphorae/backends/agent/api_server/templates/keepalived.upstart.j2 b/octavia/amphorae/backends/agent/api_server/templates/keepalived.upstart.j2 index 554005169a..1faf89d2e9 100644 --- a/octavia/amphorae/backends/agent/api_server/templates/keepalived.upstart.j2 +++ b/octavia/amphorae/backends/agent/api_server/templates/keepalived.upstart.j2 @@ -23,7 +23,7 @@ stop on runlevel [!2345] respawn {% if vrrp_pid and check_pid %} -exec /sbin/ip netns exec {{ amphora_nsname }} {{ keepalived_cmd }} -n -D -d -f {{ keepalived_cfg }} -p {{ keepalived_pid }} -r {{ vrrp_pid }} -c {{ check_pid }} +exec /sbin/ip netns exec {{ amphora_nsname }} {{ keepalived_cmd }} -n --log-facility={{ administrative_log_facility }} -f {{ keepalived_cfg }} -p {{ keepalived_pid }} -r {{ vrrp_pid }} -c {{ check_pid }} {% else %} -exec /sbin/ip netns exec {{ amphora_nsname }} {{ keepalived_cmd }} -n -D -d -f {{ keepalived_cfg }} -p {{ keepalived_pid }} +exec /sbin/ip netns exec {{ amphora_nsname }} {{ keepalived_cmd }} -n --log-facility={{ administrative_log_facility }} -f {{ keepalived_cfg }} -p {{ keepalived_pid }} {% endif %} diff --git a/octavia/amphorae/backends/agent/templates/amphora_agent_conf.template b/octavia/amphorae/backends/agent/templates/amphora_agent_conf.template index 2d62363ce6..0e3c02743a 100644 --- a/octavia/amphorae/backends/agent/templates/amphora_agent_conf.template +++ b/octavia/amphorae/backends/agent/templates/amphora_agent_conf.template @@ -14,6 +14,8 @@ #} [DEFAULT] debug = {{ debug }} +use_syslog = True +syslog_log_facility = LOG_LOCAL{{ administrative_log_facility }} [haproxy_amphora] base_cert_dir = {{ base_cert_dir }} @@ -24,6 +26,8 @@ haproxy_cmd = {{ haproxy_cmd }} respawn_count = {{ respawn_count }} respawn_interval = {{ respawn_interval }} use_upstart = {{ use_upstart }} +user_log_facility = {{ user_log_facility }} +administrative_log_facility = {{ administrative_log_facility }} [health_manager] controller_ip_port_list = {{ controller_list|join(', ') }} diff --git a/octavia/cmd/agent.py b/octavia/cmd/agent.py index 02d3031dd1..b9ce222429 100644 --- a/octavia/cmd/agent.py +++ b/octavia/cmd/agent.py @@ -80,5 +80,10 @@ def main(): 'accesslog': '/var/log/amphora-agent.log', 'errorlog': '/var/log/amphora-agent.log', 'loglevel': 'debug', + 'syslog': True, + 'syslog_facility': 'local{}'.format( + CONF.haproxy_amphora.administrative_log_facility), + 'syslog_addr': 'unix://dev/log', + } AmphoraAgent(server_instance.app, options).run() diff --git a/octavia/common/config.py b/octavia/common/config.py index 55a0be082e..64b5c63088 100644 --- a/octavia/common/config.py +++ b/octavia/common/config.py @@ -253,6 +253,16 @@ haproxy_amphora_opts = [ cfg.StrOpt('haproxy_stick_size', default='10k', help=_('Size of the HAProxy stick table. Accepts k, m, g ' 'suffixes. Example: 10k')), + cfg.IntOpt('user_log_facility', default=0, min=0, max=7, + help=_('LOG_LOCAL facility number to use for user traffic ' + 'logs.')), + cfg.IntOpt('administrative_log_facility', default=1, min=0, max=7, + help=_('LOG_LOCAL facility number to use for amphora processes ' + 'logs.')), + cfg.StrOpt('user_log_format', + default='{project_id} {lb_id} %f %ci %cp %t %{+Q}r %ST %B %U ' + '%[ssl_c_verify] %{+Q}[ssl_c_s_dn] %b %s %Tt %tsc', + help=_('Log format string for user flow logging.')), # REST server cfg.IPOpt('bind_host', default='::', # nosec diff --git a/octavia/common/jinja/haproxy/jinja_cfg.py b/octavia/common/jinja/haproxy/jinja_cfg.py index f28ff0824d..ebbd7ff186 100644 --- a/octavia/common/jinja/haproxy/jinja_cfg.py +++ b/octavia/common/jinja/haproxy/jinja_cfg.py @@ -123,6 +123,13 @@ class JinjaTemplater(object): JINJA_ENV.filters['hash_amp_id'] = octavia_utils.base64_sha1_string return JINJA_ENV.get_template(os.path.basename(self.haproxy_template)) + def _format_log_string(self, load_balancer): + log_format = CONF.haproxy_amphora.user_log_format.replace( + '{project_id}', load_balancer.project_id) + log_format = log_format.replace('{lb_id}', load_balancer.id) + log_format = log_format.replace(' ', '\ ') + return log_format + def render_loadbalancer_obj(self, host_amphora, listener, tls_cert=None, socket_path=None, feature_compatibility=None, @@ -154,6 +161,9 @@ class JinjaTemplater(object): 'stats_sock': socket_path, 'log_http': self.log_http, 'log_server': self.log_server, + 'administrative_log_facility': + CONF.haproxy_amphora.administrative_log_facility, + 'user_log_facility': CONF.haproxy_amphora.user_log_facility, 'connection_logging': self.connection_logging}, constants=constants) @@ -166,7 +176,7 @@ class JinjaTemplater(object): be processed by the templating system """ t_listener = self._transform_listener( - listener, tls_cert, feature_compatibility, + listener, tls_cert, feature_compatibility, loadbalancer, client_ca_filename=client_ca_filename, client_crl=client_crl, pool_tls_certs=pool_tls_certs) ret_value = { @@ -208,8 +218,8 @@ class JinjaTemplater(object): } def _transform_listener(self, listener, tls_cert, feature_compatibility, - client_ca_filename=None, client_crl=None, - pool_tls_certs=None): + loadbalancer, client_ca_filename=None, + client_crl=None, pool_tls_certs=None): """Transforms a listener into an object that will be processed by the templating system @@ -224,6 +234,7 @@ class JinjaTemplater(object): 'topology': listener.load_balancer.topology, 'amphorae': listener.load_balancer.amphorae, 'enabled': listener.enabled, + 'user_log_format': self._format_log_string(loadbalancer), 'timeout_client_data': ( listener.timeout_client_data or CONF.haproxy_amphora.timeout_client_data), diff --git a/octavia/common/jinja/haproxy/templates/base.j2 b/octavia/common/jinja/haproxy/templates/base.j2 index b94e800714..734cf8d020 100644 --- a/octavia/common/jinja/haproxy/templates/base.j2 +++ b/octavia/common/jinja/haproxy/templates/base.j2 @@ -17,8 +17,8 @@ global daemon user nobody - log {{ log_http | default('/dev/log', true)}} local0 - log {{ log_server | default('/dev/log', true)}} local1 notice + log {{ log_http | default('/dev/log', true)}} local{{ user_log_facility }} + log {{ log_server | default('/dev/log', true)}} local{{ administrative_log_facility }} notice stats socket {{ sock_path }} mode 0666 level user {% if loadbalancer.global_connection_limit is defined %} maxconn {{ loadbalancer.global_connection_limit }} diff --git a/octavia/common/jinja/haproxy/templates/macros.j2 b/octavia/common/jinja/haproxy/templates/macros.j2 index 0823593be9..fb24e0cb4c 100644 --- a/octavia/common/jinja/haproxy/templates/macros.j2 +++ b/octavia/common/jinja/haproxy/templates/macros.j2 @@ -139,14 +139,7 @@ bind {{ lb_vip_address }}:{{ listener.protocol_port }} {{ {% macro frontend_macro(constants, listener, lb_vip_address) %} frontend {{ listener.id }} - {% if (listener.protocol.lower() == - constants.PROTOCOL_TERMINATED_HTTPS.lower() or - listener.protocol.lower() == - constants.PROTOCOL_HTTP.lower()) %} - option httplog - {% else %} - option tcplog - {% endif %} + log-format {{ listener.user_log_format }} {% if listener.connection_limit is defined %} maxconn {{ listener.connection_limit }} {% endif %} diff --git a/octavia/tests/unit/amphorae/backends/agent/api_server/test_haproxy_compatibility.py b/octavia/tests/unit/amphorae/backends/agent/api_server/test_haproxy_compatibility.py index c457532e37..3696e37b4b 100644 --- a/octavia/tests/unit/amphorae/backends/agent/api_server/test_haproxy_compatibility.py +++ b/octavia/tests/unit/amphorae/backends/agent/api_server/test_haproxy_compatibility.py @@ -41,7 +41,9 @@ class HAProxyCompatTestCase(base.TestCase): " option splice-response\n" " option http-keep-alive\n\n\n\n" "frontend sample_listener_id_1\n" - " option httplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ %tsc\n" " maxconn {maxconn}\n" " bind 10.0.0.2:80\n" " mode http\n" diff --git a/octavia/tests/unit/amphorae/backends/agent/test_agent_jinja_cfg.py b/octavia/tests/unit/amphorae/backends/agent/test_agent_jinja_cfg.py index d6e5860a75..5c4e06fad6 100644 --- a/octavia/tests/unit/amphorae/backends/agent/test_agent_jinja_cfg.py +++ b/octavia/tests/unit/amphorae/backends/agent/test_agent_jinja_cfg.py @@ -57,8 +57,13 @@ class AgentJinjaTestCase(base.TestCase): # Test execution order could influence this with the test below self.conf.config(group='amphora_agent', agent_server_network_file=None) + self.conf.config(group="haproxy_amphora", + administrative_log_facility=1) + self.conf.config(group="haproxy_amphora", user_log_facility=0) expected_config = ('\n[DEFAULT]\n' - 'debug = False\n\n' + 'debug = False\n' + 'use_syslog = True\n' + 'syslog_log_facility = LOG_LOCAL1\n\n' '[haproxy_amphora]\n' 'base_cert_dir = /var/lib/octavia/certs\n' 'base_path = /var/lib/octavia\n' @@ -67,7 +72,9 @@ class AgentJinjaTestCase(base.TestCase): 'haproxy_cmd = /usr/sbin/haproxy\n' 'respawn_count = 2\n' 'respawn_interval = 2\n' - 'use_upstart = True\n\n' + 'use_upstart = True\n' + 'user_log_facility = 0\n' + 'administrative_log_facility = 1\n\n' '[health_manager]\n' 'controller_ip_port_list = 192.0.2.10:5555\n' 'heartbeat_interval = 10\n' @@ -94,8 +101,13 @@ class AgentJinjaTestCase(base.TestCase): self.conf.config(group="amphora_agent", agent_server_network_file='/etc/network/interfaces') self.conf.config(group="haproxy_amphora", use_upstart='False') + self.conf.config(group="haproxy_amphora", + administrative_log_facility=1) + self.conf.config(group="haproxy_amphora", user_log_facility=0) expected_config = ('\n[DEFAULT]\n' - 'debug = False\n\n' + 'debug = False\n' + 'use_syslog = True\n' + 'syslog_log_facility = LOG_LOCAL1\n\n' '[haproxy_amphora]\n' 'base_cert_dir = /var/lib/octavia/certs\n' 'base_path = /var/lib/octavia\n' @@ -104,7 +116,9 @@ class AgentJinjaTestCase(base.TestCase): 'haproxy_cmd = /usr/sbin/haproxy\n' 'respawn_count = 2\n' 'respawn_interval = 2\n' - 'use_upstart = False\n\n' + 'use_upstart = False\n' + 'user_log_facility = 0\n' + 'administrative_log_facility = 1\n\n' '[health_manager]\n' 'controller_ip_port_list = 192.0.2.10:5555\n' 'heartbeat_interval = 10\n' @@ -135,8 +149,13 @@ class AgentJinjaTestCase(base.TestCase): agent_server_network_file=None) self.conf.config(group="amphora_agent", amphora_udp_driver='new_udp_driver') + self.conf.config(group="haproxy_amphora", + administrative_log_facility=1) + self.conf.config(group="haproxy_amphora", user_log_facility=0) expected_config = ('\n[DEFAULT]\n' - 'debug = False\n\n' + 'debug = False\n' + 'use_syslog = True\n' + 'syslog_log_facility = LOG_LOCAL1\n\n' '[haproxy_amphora]\n' 'base_cert_dir = /var/lib/octavia/certs\n' 'base_path = /var/lib/octavia\n' @@ -145,7 +164,9 @@ class AgentJinjaTestCase(base.TestCase): 'haproxy_cmd = /usr/sbin/haproxy\n' 'respawn_count = 2\n' 'respawn_interval = 2\n' - 'use_upstart = True\n\n' + 'use_upstart = True\n' + 'user_log_facility = 0\n' + 'administrative_log_facility = 1\n\n' '[health_manager]\n' 'controller_ip_port_list = 192.0.2.10:5555\n' 'heartbeat_interval = 10\n' diff --git a/octavia/tests/unit/common/jinja/haproxy/test_jinja_cfg.py b/octavia/tests/unit/common/jinja/haproxy/test_jinja_cfg.py index 6e0ab44aee..102c5889bf 100644 --- a/octavia/tests/unit/common/jinja/haproxy/test_jinja_cfg.py +++ b/octavia/tests/unit/common/jinja/haproxy/test_jinja_cfg.py @@ -35,7 +35,10 @@ class TestHaproxyCfg(base.TestCase): def test_render_template_tls(self): fe = ("frontend sample_listener_id_1\n" - " option httplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn {maxconn}\n" " redirect scheme https if !{{ ssl_fc }}\n" " bind 10.0.0.2:443 " @@ -86,7 +89,10 @@ class TestHaproxyCfg(base.TestCase): def test_render_template_tls_no_sni(self): fe = ("frontend sample_listener_id_1\n" - " option httplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn {maxconn}\n" " redirect scheme https if !{{ ssl_fc }}\n" " bind 10.0.0.2:443 " @@ -185,7 +191,10 @@ class TestHaproxyCfg(base.TestCase): def test_render_template_custom_timeouts(self): fe = ("frontend sample_listener_id_1\n" - " option httplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn {maxconn}\n" " bind 10.0.0.2:80\n" " mode http\n" @@ -221,7 +230,10 @@ class TestHaproxyCfg(base.TestCase): def test_render_template_null_timeouts(self): fe = ("frontend sample_listener_id_1\n" - " option httplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn {maxconn}\n" " bind 10.0.0.2:80\n" " mode http\n" @@ -285,7 +297,10 @@ class TestHaproxyCfg(base.TestCase): def test_render_template_https_real_monitor(self): fe = ("frontend sample_listener_id_1\n" - " option tcplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn {maxconn}\n" " bind 10.0.0.2:443\n" " mode tcp\n" @@ -318,7 +333,10 @@ class TestHaproxyCfg(base.TestCase): def test_render_template_https_hello_monitor(self): fe = ("frontend sample_listener_id_1\n" - " option tcplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn {maxconn}\n" " bind 10.0.0.2:443\n" " mode tcp\n" @@ -420,7 +438,10 @@ class TestHaproxyCfg(base.TestCase): def test_render_template_no_monitor_https(self): fe = ("frontend sample_listener_id_1\n" - " option tcplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn {maxconn}\n" " bind 10.0.0.2:443\n" " mode tcp\n" @@ -476,7 +497,10 @@ class TestHaproxyCfg(base.TestCase): def test_render_template_no_persistence_https(self): fe = ("frontend sample_listener_id_1\n" - " option tcplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn {maxconn}\n" " bind 10.0.0.2:443\n" " mode tcp\n" @@ -574,7 +598,10 @@ class TestHaproxyCfg(base.TestCase): def test_render_template_unlimited_connections(self): fe = ("frontend sample_listener_id_1\n" - " option tcplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn {maxconn}\n" " bind 10.0.0.2:443\n" " mode tcp\n" @@ -602,7 +629,10 @@ class TestHaproxyCfg(base.TestCase): def test_render_template_limited_connections(self): fe = ("frontend sample_listener_id_1\n" - " option tcplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{+Q}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{+Q}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn 2014\n" " bind 10.0.0.2:443\n" " mode tcp\n" @@ -630,7 +660,10 @@ class TestHaproxyCfg(base.TestCase): def test_render_template_l7policies(self): fe = ("frontend sample_listener_id_1\n" - " option httplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn {maxconn}\n" " bind 10.0.0.2:80\n" " mode http\n" @@ -896,12 +929,14 @@ class TestHaproxyCfg(base.TestCase): def test_transform_listener(self): in_listener = sample_configs.sample_listener_tuple() - ret = self.jinja_cfg._transform_listener(in_listener, None, {}) + ret = self.jinja_cfg._transform_listener(in_listener, None, {}, + in_listener.load_balancer) self.assertEqual(sample_configs.RET_LISTENER, ret) def test_transform_listener_with_l7(self): in_listener = sample_configs.sample_listener_tuple(l7=True) - ret = self.jinja_cfg._transform_listener(in_listener, None, {}) + ret = self.jinja_cfg._transform_listener(in_listener, None, {}, + in_listener.load_balancer) self.assertEqual(sample_configs.RET_LISTENER_L7, ret) def test_transform_loadbalancer(self): @@ -1069,7 +1104,10 @@ class TestHaproxyCfg(base.TestCase): base_amp_path='/var/lib/octavia', base_crt_dir='/var/lib/octavia/certs') fe = ("frontend sample_listener_id_1\n" - " option httplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{+Q}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{+Q}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn 1000000\n" " redirect scheme https if !{ ssl_fc }\n" " bind 10.0.0.2:443\n" diff --git a/octavia/tests/unit/common/sample_configs/sample_configs.py b/octavia/tests/unit/common/sample_configs/sample_configs.py index 38dfed951c..b0ad9bed74 100644 --- a/octavia/tests/unit/common/sample_configs/sample_configs.py +++ b/octavia/tests/unit/common/sample_configs/sample_configs.py @@ -295,6 +295,9 @@ RET_LISTENER = { 'amphorae': [sample_amphora_tuple()], 'peer_port': 1024, 'topology': 'SINGLE', + 'user_log_format': '12345\\ sample_loadbalancer_id_1\\ %f\\ %ci\\ %cp\\ ' + '%t\\ %{+Q}r\\ %ST\\ %B\\ %U\\ %[ssl_c_verify]\\ ' + '%{+Q}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ %tsc', 'pools': [RET_POOL_1], 'l7policies': [], 'enabled': True, @@ -315,6 +318,9 @@ RET_LISTENER_L7 = { 'amphorae': [sample_amphora_tuple()], 'peer_port': 1024, 'topology': 'SINGLE', + 'user_log_format': '12345\\ sample_loadbalancer_id_1\\ %f\\ %ci\\ %cp\\ ' + '%t\\ %{+Q}r\\ %ST\\ %B\\ %U\\ %[ssl_c_verify]\\ ' + '%{+Q}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ %tsc', 'pools': [RET_POOL_1, RET_POOL_2], 'l7policies': [RET_L7POLICY_1, RET_L7POLICY_2, RET_L7POLICY_3, RET_L7POLICY_4, RET_L7POLICY_5, RET_L7POLICY_6, @@ -504,7 +510,7 @@ def sample_listener_loadbalancer_tuple(proto=None, topology=None, topology = constants.TOPOLOGY_SINGLE in_lb = collections.namedtuple( 'load_balancer', 'id, name, protocol, vip, amphorae, topology, ' - 'enabled') + 'enabled, project_id') return in_lb( id='sample_loadbalancer_id_1', name='test-lb', @@ -518,7 +524,8 @@ def sample_listener_loadbalancer_tuple(proto=None, topology=None, role=constants.ROLE_BACKUP)] if more_amp else [sample_amphora_tuple()], topology=topology, - enabled=enabled + enabled=enabled, + project_id='12345' ) @@ -991,7 +998,10 @@ def sample_base_expected_config(frontend=None, backend=None, peers=None, global_opts=None, defaults=None): if frontend is None: frontend = ("frontend sample_listener_id_1\n" - " option httplog\n" + " log-format 12345\\ sample_loadbalancer_id_1\\ %f\\ " + "%ci\\ %cp\\ %t\\ %{{+Q}}r\\ %ST\\ %B\\ %U\\ " + "%[ssl_c_verify]\\ %{{+Q}}[ssl_c_s_dn]\\ %b\\ %s\\ %Tt\\ " + "%tsc\n" " maxconn {maxconn}\n" " bind 10.0.0.2:80\n" " mode http\n"