Merge "Add integration test playbook"

This commit is contained in:
Zuul 2020-03-31 17:52:01 +00:00 committed by Gerrit Code Review
commit f3e9e7cccf
6 changed files with 231 additions and 1 deletions

View File

@ -2,7 +2,9 @@
description: Operator integration tests
name: zuul-operator-functional
abstract: true
run: playbooks/zuul-operator-functional/run.yaml
run:
- playbooks/zuul-operator-functional/run.yaml
- playbooks/zuul-operator-functional/test.yaml
post-run: playbooks/zuul-operator-functional/post.yaml
vars:
# We disable userland-proxy to enable scheduler deployement to connect to the gearman service

View File

@ -12,3 +12,6 @@
- '8.8.8.8'
- role: use-buildset-registry
buildset_registry_docker_user: root
post_tasks:
- name: check kubernetes connection
command: kubectl get pods

View File

@ -0,0 +1,52 @@
- name: create config directory
become: yes
file:
path: /srv/git/config/
state: directory
mode: 0777
- name: copy config content
copy:
dest: "/srv/git/config/{{ item.name }}"
content: "{{ item.content }}"
loop:
- name: zuul.yaml
content: |
- pipeline:
name: periodic
manager: independent
trigger:
timer:
- time: '* * * * * *'
success:
sql:
failure:
sql:
- nodeset:
name: localhost
nodes: []
- job:
name: test-job
run: test.yaml
nodeset: localhost
- project:
periodic:
jobs:
- test-job
- name: test.yaml
content: |
- hosts: localhost
tasks:
- debug: msg='Demo job is running'
- pause: seconds=30
- name: commit config
shell: |
cd /srv/git/config/
test -d .git || git init .
git add *.yaml
git commit -m 'Setup config project' || true

View File

@ -0,0 +1,34 @@
- name: setup gitconfig
shell: |
if ! test -f ~/.gitconfig && ! test -d ~/.config/git ; then
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
fi
sudo mkdir -p /srv/git
- name: setup local-git service
become: yes
copy:
dest: /etc/systemd/system/local-git.service
content: |
[Unit]
Description=local git service
After=syslogp.target network.target
[Service]
Type=simple
SyslogIdentifier=local-git
ExecStart=/usr/bin/git daemon --export-all --reuseaddr --verbose --base-path=/srv/git/ /srv/git/
Restart=always
RestartSec=3s
[Install]
WantedBy=multi-user.target
- name: start local-git service
become: yes
systemd:
daemon_reload: true
name: "local-git"
state: started

View File

@ -0,0 +1,7 @@
- name: "check api {{ zuul_web_url }}{{ endpoint }}"
uri:
url: "{{ zuul_web_url }}{{ endpoint }}"
register: result
until: "result.json is defined and result.json{% if expected is defined %} and result.json == expected{% endif %}"
retries: 600
delay: 1

View File

@ -0,0 +1,132 @@
- name: run functional tst
hosts: all
pre_tasks:
- name: install git
become: yes
package:
name:
- git
- jq
- name: install websocket client
become: yes
command: python3 -m pip install websocket-client
tasks:
- name: get rest api url
command: kubectl get svc web -o jsonpath='{.spec.clusterIP}'
register: zuul_web_ip
- name: set fact zuul_web_url
set_fact:
zuul_web_url: "http://{{ zuul_web_ip.stdout_lines[0] }}:9000"
zuul_ws_url: "ws://{{ zuul_web_ip.stdout_lines[0] }}:9000"
- name: ensure zuul web api is working
when: skip_check is not defined
include_tasks: tasks/zuul_web_check.yaml
vars:
endpoint: "/api/tenants"
expected:
- name: local
projects: 1
queue: 0
- name: setup git service
include_tasks: tasks/git_setup.yaml
- name: create a config project
include_tasks: tasks/create_config.yaml
- name: update kubernetes resources
vars:
tenants:
- tenant:
name: local
source:
opendev.org:
config-projects:
- zuul/zuul-base-jobs
untrusted-projects:
- zuul/zuul-jobs
local-git:
config-projects:
- config
block:
- k8s:
namespace: default
definition:
apiVersion: v1
kind: Secret
metadata:
name: "zuul-yaml-conf"
stringData:
main.yaml: "{{ tenants | to_yaml }}"
- k8s:
namespace: default
definition:
apiVersion: operator.zuul-ci.org/v1alpha1
kind: Zuul
metadata:
name: zuul
spec:
executor:
count: 1
ssh_key:
secretName: executor-ssh-key
merger:
count: 1
scheduler:
config:
secretName: zuul-yaml-conf
launcher:
config:
secretName: nodepool-yaml-conf
connections:
gits:
- baseurl: https://opendev.org
name: opendev.org
- baseurl: "git://{{ ansible_all_ipv4_addresses[0] }}/"
name: local-git
- name: ensure a job is running
when: skip_check is not defined
include_tasks: tasks/zuul_web_check.yaml
vars:
endpoint: "/api/tenants"
expected:
- name: local
projects: 1
# 1 queue means a job is running
queue: 1
- name: get buillds results
include_tasks: tasks/zuul_web_check.yaml
vars:
endpoint: "/api/tenant/local/builds"
- name: ensure success build
assert:
that:
- result.json[0].result == 'SUCCESS'
- name: grab job uuid
shell: |
curl -s {{ zuul_web_url }}/api/tenant/local/status | jq -r '.pipelines[].change_queues[].heads[][].jobs[].uuid'
register: _job_uuid
- name: connect to console-stream
command: |
wsdump.py -r --eof-wait 5 -t '{"uuid":"{{ _job_uuid.stdout_lines[0] }}","logfile":"console.log"}' {{ zuul_ws_url }}/api/tenant/local/console-stream
register: console_stream
- name: show console stream
debug:
var: console_stream
- name: fail if console stream does not contains expected job output
when: "'Job console starting...' not in console_stream.stdout"
# It seems like wsdump.py doesn't always stay connected for the whole job duration
# when: "'Demo job is running' not in console_stream.stdout"
fail:
msg: "Task output is missing from: {{ console_stream.stdout }}"