From 9fd77b3856b470acca05c2ffc6296ee4061cf500 Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Mon, 14 May 2018 10:43:46 +0200 Subject: [PATCH] install default logging config By default gear dies not deliver default logging configuration. If it is started in this configuration it floods /var/log/messages with debug info. Log configuration activation should be done via systemd override.conf file by setting proper ARGS Update jobs to also collect /var/logs/gear in post-run task. Change-Id: Ib69c976062afd38a91a3d882e9389c5cbef244c3 Signed-off-by: Paul Belanger --- .zuul.yaml | 1 + defaults/main.yaml | 6 ++++ tasks/config.yaml | 10 ++++++ templates/etc/gear/logging.conf | 39 +++++++++++++++++++++++ templates/etc/systemd/system/gear.service | 2 ++ tests/collect-logs.yaml | 10 ++++++ tests/playbooks/run.yaml | 15 +++++++++ 7 files changed, 83 insertions(+) create mode 100644 templates/etc/gear/logging.conf create mode 100644 tests/collect-logs.yaml diff --git a/.zuul.yaml b/.zuul.yaml index 82f866e..b13b718 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -2,6 +2,7 @@ name: ansible-role-gearman-base pre-run: tests/playbooks/pre.yaml run: tests/playbooks/run.yaml + post-run: tests/collect-logs.yaml roles: - zuul: openstack/ansible-role-gearman diff --git a/defaults/main.yaml b/defaults/main.yaml index b3aa5f8..ac0f57b 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -45,6 +45,12 @@ gear_file_ssl_key_mode: 0600 gear_file_ssl_key_owner: "{{ gear_user_name }}" gear_file_ssl_key_src: etc/gear/ssl/server.key +gear_file_log_config_dest: /etc/gear/logging.conf +gear_file_log_config_group: "{{ gear_user_group }}" +gear_file_log_config_mode: 0644 +gear_file_log_config_owner: "{{ gear_user_name }}" +gear_file_log_config_src: etc/gear/logging.conf + # tasks/install.yaml gear_git_dest: "{{ ansible_user_dir }}/src/git.openstack.org/openstack-infra/gear" gear_git_uri: https://git.openstack.org/openstack-infra/gear diff --git a/tasks/config.yaml b/tasks/config.yaml index 0969b97..6d59f31 100644 --- a/tasks/config.yaml +++ b/tasks/config.yaml @@ -53,3 +53,13 @@ owner: "{{ gear_file_ssl_key_owner }}" src: "{{ gear_file_ssl_key_src }}" register: gear_file_ssl_key + +- name: Install gear logging configuration. + become: yes + template: + dest: "{{ gear_file_log_config_dest }}" + group: "{{ gear_file_log_config_group }}" + mode: "{{ gear_file_log_config_mode }}" + owner: "{{ gear_file_log_config_owner }}" + src: "{{ gear_file_log_config_src }}" + register: gear_file_log_config diff --git a/templates/etc/gear/logging.conf b/templates/etc/gear/logging.conf new file mode 100644 index 0000000..6fcb23a --- /dev/null +++ b/templates/etc/gear/logging.conf @@ -0,0 +1,39 @@ +[loggers] +keys=root,gear + +[handlers] +keys=console,debug,normal + +[formatters] +keys=simple + +[logger_root] +level=WARNING +handlers=console + +[logger_gear] +level=DEBUG +handlers=debug,normal +qualname=gear + +[handler_console] +level=WARNING +class=StreamHandler +formatter=simple +args=(sys.stdout,) + +[handler_debug] +level=DEBUG +class=logging.handlers.WatchedFileHandler +formatter=simple +args=('/var/log/gear/debug.log',) + +[handler_normal] +level=WARNING +class=logging.handlers.WatchedFileHandler +formatter=simple +args=('/var/log/gear/gear.log',) + +[formatter_simple] +format=%(asctime)s %(levelname)s %(name)s: %(message)s +datefmt= diff --git a/templates/etc/systemd/system/gear.service b/templates/etc/systemd/system/gear.service index bffd362..005e472 100644 --- a/templates/etc/systemd/system/gear.service +++ b/templates/etc/systemd/system/gear.service @@ -7,6 +7,8 @@ Type=simple # The prefix used when gear was installed. Be sure to update this # value if you are using a virtualenv. Environment="PREFIX=/usr/local" +# Options to pass to gear. +Environment="ARGS=--log-config /etc/gear/logging.conf" Group=gear User=gear ExecStart=/bin/sh -c "${PREFIX}/bin/geard -d ${ARGS}" diff --git a/tests/collect-logs.yaml b/tests/collect-logs.yaml new file mode 100644 index 0000000..d080eed --- /dev/null +++ b/tests/collect-logs.yaml @@ -0,0 +1,10 @@ +- hosts: all + tasks: + - name: Collect gear log files + synchronize: + dest: "{{ zuul.executor.log_root }}/logs" + mode: pull + rsync_opts: + - "--relative" + src: /var/log/gear + verify_host: true diff --git a/tests/playbooks/run.yaml b/tests/playbooks/run.yaml index d43825a..213df47 100644 --- a/tests/playbooks/run.yaml +++ b/tests/playbooks/run.yaml @@ -23,6 +23,7 @@ - name: Assert results are registered. assert: that: + - gear_file_log_config - gear_file_ssl_ca - gear_file_ssl_cert - gear_file_ssl_key @@ -110,3 +111,17 @@ - _gear_file_ssl_key_stat.stat.pw_name == 'gear' - _gear_file_ssl_key_stat.stat.gr_name == 'gear' - _gear_file_ssl_key_stat.stat.mode == '0600' + + - name: Register /etc/gear/logging.conf + stat: + path: /etc/gear/logging.conf + register: _gear_file_log_config_stat + + - name: Assert _gear_file_log_config_stat tests. + assert: + that: + - _gear_file_log_config_stat.stat.exists + - _gear_file_log_config_stat.stat.isreg + - _gear_file_log_config_stat.stat.pw_name == 'gear' + - _gear_file_log_config_stat.stat.gr_name == 'gear' + - _gear_file_log_config_stat.stat.mode == '0644'