From 068a754badf7efcf78983d2d5800988839319fca Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Thu, 25 Jan 2018 14:45:57 -0600 Subject: [PATCH] Add modified upload-logs as test-upload-logs to base-test Change-Id: I645727fb30de6abe325c694d04886711c205e620 --- playbooks/base-test/post-logs.yaml | 2 +- roles/test-upload-logs/README.rst | 23 ++++++++++ roles/test-upload-logs/tasks/main.yaml | 58 ++++++++++++++++++++++++++ roles/test-upload-logs/vars/main.yaml | 1 + 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 roles/test-upload-logs/README.rst create mode 100644 roles/test-upload-logs/tasks/main.yaml create mode 100644 roles/test-upload-logs/vars/main.yaml diff --git a/playbooks/base-test/post-logs.yaml b/playbooks/base-test/post-logs.yaml index 7ffe9cab21..7b874c48e5 100644 --- a/playbooks/base-test/post-logs.yaml +++ b/playbooks/base-test/post-logs.yaml @@ -7,7 +7,7 @@ - hosts: "{{ site_logs.fqdn }}" gather_facts: False roles: - - role: upload-logs + - role: test-upload-logs zuul_log_url: "http://logs.openstack.org" - hosts: localhost diff --git a/roles/test-upload-logs/README.rst b/roles/test-upload-logs/README.rst new file mode 100644 index 0000000000..98dcb43f83 --- /dev/null +++ b/roles/test-upload-logs/README.rst @@ -0,0 +1,23 @@ +Upload logs to a static webserver + +This uploads logs to a static webserver using SSH. + +**Role Variables** + +.. zuul:rolevar:: zuul_log_url + + Base URL where logs are to be found. + +.. zuul:rolevar:: zuul_logserver_root + :default: /srv/static/logs + + The root path to the logs on the logserver. + +.. zuul:rolevar:: zuul_site_upload_logs + :default: true + + Controls when logs are uploaded. true, the default, means always upload + logs. false means never upload logs. 'failure' means to only upload logs + when the job has failed. + + .. note:: Intended to be set by admins via site-variables. diff --git a/roles/test-upload-logs/tasks/main.yaml b/roles/test-upload-logs/tasks/main.yaml new file mode 100644 index 0000000000..661ce9aec2 --- /dev/null +++ b/roles/test-upload-logs/tasks/main.yaml @@ -0,0 +1,58 @@ +- name: Set zuul-log-path fact + include_role: + name: set-zuul-log-path-fact + +# Always upload (true), never upload (false) or only on failure ('failure') +- when: zuul_site_upload_logs | default(true) | bool or + (zuul_site_upload_logs == 'failure' and not zuul_success | bool) + block: + + - name: Create log directories + file: + path: "{{zuul_logserver_root}}/{{ zuul_log_path }}" + state: directory + recurse: yes + mode: 0775 + + - name: Ensure logs are readable before uploading + delegate_to: localhost + file: + path: "{{ zuul.executor.log_root }}/" + mode: u=rwX,g=rX,o=rX + state: directory + recurse: yes + + - name: Upload logs to log server + synchronize: + src: "{{ zuul.executor.log_root }}/" + dest: "{{zuul_logserver_root}}/{{ zuul_log_path }}/" + rsync_opts: + - "--exclude=job-output.txt" + - "--exclude=job-output.json" + no_log: true + + # After this point there are no more logs + - name: gzip console log and json output + delegate_to: localhost + archive: + path: "{{ zuul.executor.log_root }}/{{ item }}" + with_items: + - job-output.txt + - job-output.json + + - name: Upload console log and json output + synchronize: + src: "{{ zuul.executor.log_root }}/{{ item }}.gz" + dest: "{{zuul_logserver_root}}/{{ zuul_log_path }}/{{ item }}.gz" + verify_host: true + with_items: + - job-output.txt + - job-output.json + +- name: Return log URL to Zuul + delegate_to: localhost + zuul_return: + data: + zuul: + log_url: "{{ zuul_log_url }}/{{ zuul_log_path }}/" + when: zuul_log_url is defined diff --git a/roles/test-upload-logs/vars/main.yaml b/roles/test-upload-logs/vars/main.yaml new file mode 100644 index 0000000000..4b6a101307 --- /dev/null +++ b/roles/test-upload-logs/vars/main.yaml @@ -0,0 +1 @@ +zuul_logserver_root: /srv/static/logs