zuul-jobs/test-playbooks/upload-logs-s3.yaml
Albin Vass 838b0c8877 Add upload-logs-s3
Change-Id: I6ce64734ed5f20a212e6cb953d09ea2769238bea
2020-07-19 21:22:36 +02:00

71 lines
2.1 KiB
YAML

- hosts: all
vars:
zuul_log_aws_access_key: minioadmin
zuul_log_aws_secret_key: minioadmin
zuul_log_bucket: zuul
test_content: "123abc"
_undocumented_test_worker_node_: "{{ inventory_hostname }}"
roles:
- ensure-docker
- ensure-pip
tasks:
- name: Install boto
pip:
name:
- boto3
- botocore
- name: Start minio server
command: >-
docker run -d -p 9000:9000
-e MINIO_ACCESS_KEY={{ zuul_log_aws_access_key }}
-e MINIO_SECRET_KEY={{ zuul_log_aws_secret_key }}
minio/minio server /data
- name: Make sure bucket exists
s3_bucket:
name: "{{ zuul_log_bucket }}"
state: present
s3_url: 'http://localhost:9000'
aws_access_key: "{{ zuul_log_aws_access_key }}"
aws_secret_key: "{{ zuul_log_aws_secret_key }}"
- name: Create tempdir to upload to s3
tempfile:
state: directory
register: fake_zuul_logdir
- name: Add content to tempfile
copy:
content: "{{ test_content }}"
dest: "{{ fake_zuul_logdir.path }}/testfile"
- name: Save zuul variables
set_fact:
old_zuul: "{{ zuul }}"
- name: Set simulated zuul variables
set_fact:
new_zuul: "{{ old_zuul | combine({'executor': {'log_root': fake_zuul_logdir.path}}, recursive=True) }}"
- name: Upload file to s3
include_role:
name: upload-logs-s3
vars:
upload_logs_s3_endpoint: 'http://localhost:9000'
zuul: "{{ new_zuul }}"
- name: Download mc
get_url:
url: https://dl.min.io/client/mc/release/linux-amd64/mc
dest: "{{ fake_zuul_logdir.path }}/mc"
mode: 0755
- name: Add localhost minio host
command: "{{ fake_zuul_logdir.path }}/mc config host add local http://localhost:9000 {{ zuul_log_aws_access_key }} {{ zuul_log_aws_secret_key }}"
- name: List files in minio bucket
command: "{{ fake_zuul_logdir.path }}/mc find local/zuul"
- name: Check for testfile in minio bucket
command: "{{ fake_zuul_logdir.path }}/mc find local/zuul/{{ zuul_log_path }}/testfile"