Adding zuul coverage
Change-Id: I451fbc00eaa765f3b32b7e273750c88ca38f4964
This commit is contained in:
parent
b9dbc5cf43
commit
4bdaf6b628
24
.zuul.yaml
Normal file
24
.zuul.yaml
Normal file
@ -0,0 +1,24 @@
|
||||
- project:
|
||||
name: openstack/ansible-role-k8s-mariadb
|
||||
check:
|
||||
jobs:
|
||||
- ansible-role-k8s-mariadb-centos
|
||||
|
||||
- nodeset:
|
||||
name: ansible-role-k8s-centos
|
||||
nodes:
|
||||
- name: primary
|
||||
label: centos-7
|
||||
|
||||
- job:
|
||||
name: ansible-role-k8s-base
|
||||
pre-run: tests/pre
|
||||
run: tests/run
|
||||
post-run: tests/post
|
||||
attempts: 1
|
||||
timeout: 10800
|
||||
|
||||
- job:
|
||||
name: ansible-role-k8s-mariadb-centos
|
||||
parent: ansible-role-k8s-base
|
||||
nodeset: ansible-role-k8s-centos
|
@ -1,4 +1,4 @@
|
||||
coe_host: "https://127.0.0.1:8443"
|
||||
coe_host:
|
||||
coe_config_context:
|
||||
coe_config_file:
|
||||
action: provision
|
||||
|
@ -17,4 +17,8 @@ galaxy_info:
|
||||
- database
|
||||
- mariadb
|
||||
|
||||
dependencies: []
|
||||
dependencies:
|
||||
- role: ansible.kubernetes-modules
|
||||
install_python_requirements: no
|
||||
|
||||
- role: ansible-role-k8s-tripleo
|
||||
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
ansible>=2,<2.4
|
||||
openshift
|
@ -170,8 +170,4 @@
|
||||
namespace: "{{namespace}}"
|
||||
state: present
|
||||
data:
|
||||
my.cnf: |
|
||||
{{my_cnf | b64encode}}
|
||||
|
||||
|
||||
- debug: var=create_deployment
|
||||
my.cnf: "{{ my_cnf | b64encode }}"
|
||||
|
84
tests/get_logs.sh
Normal file
84
tests/get_logs.sh
Normal file
@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
|
||||
set +o errexit
|
||||
|
||||
check_failure() {
|
||||
# All docker container's status are created, restarting, running, removing,
|
||||
# paused, exited and dead. Containers without running status are treated as
|
||||
# failure. removing is added in docker 1.13, just ignore it now.
|
||||
failed_containers=$(docker ps -a --format "{{.Names}}" \
|
||||
--filter status=created \
|
||||
--filter status=restarting \
|
||||
--filter status=paused \
|
||||
--filter status=exited \
|
||||
--filter status=dead)
|
||||
|
||||
if [[ -n "$failed_containers" ]]; then
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
|
||||
copy_logs() {
|
||||
LOG_DIR=/tmp/logs
|
||||
|
||||
if [[ -d "$HOME/.ansible" ]]; then
|
||||
cp -rvnL $HOME/.ansible/* ${LOG_DIR}/ansible/
|
||||
fi
|
||||
|
||||
cp -rvnL /etc ${LOG_DIR}/
|
||||
cp -rvnL /var/log/* ${LOG_DIR}/system_logs/
|
||||
cp -rvnL /tmp/kubespray ${LOG_DIR}/
|
||||
|
||||
|
||||
if [[ -x "$(command -v journalctl)" ]]; then
|
||||
journalctl --no-pager > ${LOG_DIR}/system_logs/syslog.txt
|
||||
journalctl --no-pager -u docker.service > ${LOG_DIR}/system_logs/docker.log
|
||||
else
|
||||
cp /var/log/upstart/docker.log ${LOG_DIR}/system_logs/docker.log
|
||||
fi
|
||||
|
||||
cp -r /etc/sudoers.d ${LOG_DIR}/system_logs/
|
||||
cp /etc/sudoers ${LOG_DIR}/system_logs/sudoers.txt
|
||||
|
||||
df -h > ${LOG_DIR}/system_logs/df.txt
|
||||
free > ${LOG_DIR}/system_logs/free.txt
|
||||
parted -l > ${LOG_DIR}/system_logs/parted-l.txt
|
||||
mount > ${LOG_DIR}/system_logs/mount.txt
|
||||
env > ${LOG_DIR}/system_logs/env.txt
|
||||
|
||||
if [ `command -v dpkg` ]; then
|
||||
dpkg -l > ${LOG_DIR}/system_logs/dpkg-l.txt
|
||||
fi
|
||||
if [ `command -v rpm` ]; then
|
||||
rpm -qa > ${LOG_DIR}/system_logs/rpm-qa.txt
|
||||
fi
|
||||
|
||||
# final memory usage and process list
|
||||
ps -eo user,pid,ppid,lwp,%cpu,%mem,size,rss,cmd > ${LOG_DIR}/system_logs/ps.txt
|
||||
|
||||
if [ `command -v docker` ]; then
|
||||
# docker related information
|
||||
(docker info && docker images && docker ps -a) > ${LOG_DIR}/system_logs/docker-info.txt
|
||||
|
||||
for container in $(docker ps -a --format "{{.Names}}"); do
|
||||
docker logs --tail all ${container} > ${LOG_DIR}/docker_logs/${container}.txt
|
||||
done
|
||||
fi
|
||||
|
||||
# Rename files to .txt; this is so that when displayed via
|
||||
# logs.openstack.org clicking results in the browser shows the
|
||||
# files, rather than trying to send it to another app or make you
|
||||
# download it, etc.
|
||||
|
||||
# Rename all .log files to .txt files
|
||||
for f in $(find ${LOG_DIR}/{system_logs,docker_logs} -name "*.log"); do
|
||||
mv $f ${f/.log/.txt}
|
||||
done
|
||||
|
||||
chmod -R 777 ${LOG_DIR}
|
||||
find ${LOG_DIR}/{system_logs,docker_logs} -iname '*.txt' -execdir gzip -f -9 {} \+
|
||||
find ${LOG_DIR}/{system_logs,docker_logs} -iname '*.json' -execdir gzip -f -9 {} \+
|
||||
}
|
||||
|
||||
copy_logs
|
||||
check_failure
|
28
tests/post.yml
Normal file
28
tests/post.yml
Normal file
@ -0,0 +1,28 @@
|
||||
---
|
||||
- hosts: all
|
||||
vars:
|
||||
logs_dir: "/tmp/logs"
|
||||
tasks:
|
||||
- name: Run diagnostics script
|
||||
script: get_logs.sh
|
||||
register: get_logs_result
|
||||
become: true
|
||||
failed_when: false
|
||||
|
||||
- name: Print get_logs output
|
||||
debug:
|
||||
msg: "{{ get_logs_result.stdout }}"
|
||||
|
||||
- name: Download logs to executor
|
||||
synchronize:
|
||||
dest: "{{ zuul.executor.log_root }}/{{ inventory_hostname }}"
|
||||
mode: pull
|
||||
src: "{{ logs_dir }}/"
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Download /etc/hosts file to executor
|
||||
synchronize:
|
||||
src: "/etc/hosts"
|
||||
dest: "{{ zuul.executor.log_root }}/{{inventory_hostname }}/"
|
||||
mode: pull
|
||||
ignore_errors: yes
|
55
tests/pre.yml
Normal file
55
tests/pre.yml
Normal file
@ -0,0 +1,55 @@
|
||||
---
|
||||
- hosts: all
|
||||
vars:
|
||||
logs_dir: "/tmp/logs"
|
||||
tasks:
|
||||
- name: "Ensure {{item}} dir exists"
|
||||
file:
|
||||
path: "{{item}}"
|
||||
state: "directory"
|
||||
with_items:
|
||||
- "{{ logs_dir }}"
|
||||
|
||||
- name: Ensure node directories
|
||||
file:
|
||||
path: "{{ logs_dir }}/{{ item }}"
|
||||
state: "directory"
|
||||
mode: 0777
|
||||
with_items:
|
||||
- "docker_logs"
|
||||
- "system_logs"
|
||||
- "ansible"
|
||||
|
||||
- include: pre_rhel.yml
|
||||
when: ansible_os_family == 'RedHat'
|
||||
|
||||
- include: pre_debian.yml
|
||||
when: ansible_os_family == 'Debian'
|
||||
|
||||
- name: Create symlink for this role
|
||||
become: true
|
||||
file:
|
||||
src: "{{ ansible_env.HOME }}/{{ zuul.project.src_dir }}"
|
||||
dest: "/etc/ansible/roles/ansible-role-k8s-mariadb"
|
||||
state: link
|
||||
delegate_to: primary
|
||||
|
||||
- name: Clone kubespray
|
||||
git:
|
||||
repo: https://github.com/kubernetes-incubator/kubespray/
|
||||
dest: "/tmp/kubespray"
|
||||
delegate_to: primary
|
||||
|
||||
- name: Clone ansible-role-k8s-tripleo for now
|
||||
become: true
|
||||
git:
|
||||
repo: https://github.com/tripleo-apb/ansible-role-k8s-tripleo
|
||||
dest: "/etc/ansible/roles/ansible-role-k8s-tripleo"
|
||||
delegate_to: primary
|
||||
|
||||
- name: Clone ansible-role-k8s-tripleo for now
|
||||
become: true
|
||||
git:
|
||||
repo: https://github.com/openstack/openstack-ansible-plugins
|
||||
dest: "/etc/ansible/roles/openstack-ansible-plugins"
|
||||
delegate_to: primary
|
1
tests/pre_debian.yml
Normal file
1
tests/pre_debian.yml
Normal file
@ -0,0 +1 @@
|
||||
---
|
54
tests/pre_rhel.yml
Normal file
54
tests/pre_rhel.yml
Normal file
@ -0,0 +1,54 @@
|
||||
---
|
||||
- name: Add ASB repo for ansible-kubernetes-modules
|
||||
become: true
|
||||
yum_repository:
|
||||
name: asb
|
||||
description: Copr repo for ansible-service-broker-latest owned by @ansible-service-broker
|
||||
file: asb
|
||||
baseurl: https://copr-be.cloud.fedoraproject.org/results/@ansible-service-broker/ansible-service-broker-latest/epel-7-$basearch/
|
||||
gpgkey: https://copr-be.cloud.fedoraproject.org/results/@ansible-service-broker/ansible-service-broker-latest/pubkey.gpg
|
||||
gpgcheck: true
|
||||
enabled: true
|
||||
skip_if_unavailable: true
|
||||
repo_gpgcheck: false
|
||||
|
||||
- name: Enable/Install epel-release/centos-release-openshift-origin
|
||||
become: true
|
||||
yum:
|
||||
name: "{{item}}"
|
||||
state: present
|
||||
with_items:
|
||||
- epel-release
|
||||
- centos-release-openshift-origin
|
||||
|
||||
# NOTE(flaper87): python-openshift requires a specific version of
|
||||
# python-requests. We need to update it to the version in the asb repo, hence
|
||||
# this step. We have to enable epel so we can meet the python2-pysocks
|
||||
# dependency, which is a python-requests requirement.
|
||||
- name: Force update for requests/urllib3
|
||||
become: true
|
||||
yum:
|
||||
name: "{{item}}"
|
||||
state: latest
|
||||
update_cache: true
|
||||
enablerepo: asb,epel
|
||||
disablerepo: centos-openstack-ocata
|
||||
with_items:
|
||||
- python-requests
|
||||
|
||||
- name: Install required packages
|
||||
become: true
|
||||
yum:
|
||||
name: "{{item}}"
|
||||
state: latest
|
||||
with_items:
|
||||
- ansible
|
||||
- python-netaddr
|
||||
|
||||
- name: Install required packages from asb
|
||||
become: true
|
||||
yum:
|
||||
name: "{{item}}"
|
||||
state: latest
|
||||
with_items:
|
||||
- ansible-kubernetes-modules
|
46
tests/run.yml
Normal file
46
tests/run.yml
Normal file
@ -0,0 +1,46 @@
|
||||
---
|
||||
- hosts: all
|
||||
vars:
|
||||
project_name: ansible-role-k8s-mariadb
|
||||
tasks:
|
||||
- set_fact:
|
||||
nodes: |
|
||||
{% for host in hostvars %}
|
||||
{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_become=true ansible_user={{ hostvars[host]['ansible_user'] }}
|
||||
{% endfor %}
|
||||
|
||||
- name: Build inventory
|
||||
template:
|
||||
src: "{{ zuul.executor.work_root }}/{{ zuul.project.src_dir }}/tests/templates/inventory.j2"
|
||||
dest: "/tmp/kubespray/ci_inventory"
|
||||
delegate_to: "primary"
|
||||
|
||||
- name: Build playbook
|
||||
template:
|
||||
src: "{{ zuul.executor.work_root }}/{{ zuul.project.src_dir }}/tests/templates/playbook.j2"
|
||||
dest: "{{ ansible_env.HOME }}/{{ zuul.project.src_dir }}/playbook.yml"
|
||||
delegate_to: "primary"
|
||||
|
||||
- shell:
|
||||
cmd: |
|
||||
set -e
|
||||
set -x
|
||||
|
||||
ansible-playbook -i ci_inventory --skip-tags bastion-ssh-config -e skip_downloads=true cluster.yml
|
||||
executable: /bin/bash
|
||||
chdir: "/tmp/kubespray"
|
||||
delegate_to: "primary"
|
||||
environment: '{{ zuul | zuul_legacy_vars }}'
|
||||
register: kubespray_output
|
||||
|
||||
- shell:
|
||||
cmd: |
|
||||
set -e
|
||||
set -x
|
||||
|
||||
ansible-playbook -vvvvvv playbook.yml
|
||||
executable: /bin/bash
|
||||
chdir: "{{ ansible_env.HOME }}/{{ zuul.project.src_dir }}"
|
||||
delegate_to: "primary"
|
||||
environment: '{{ zuul | zuul_legacy_vars }}'
|
||||
register: "{{project_name}}-output"
|
12
tests/templates/inventory.j2
Normal file
12
tests/templates/inventory.j2
Normal file
@ -0,0 +1,12 @@
|
||||
[kube-master]
|
||||
{{nodes}}
|
||||
|
||||
[kube-node]
|
||||
{{nodes}}
|
||||
|
||||
[etcd:children]
|
||||
kube-master
|
||||
|
||||
[k8s-cluster:children]
|
||||
kube-master
|
||||
kube-node
|
12
tests/templates/playbook.j2
Normal file
12
tests/templates/playbook.j2
Normal file
@ -0,0 +1,12 @@
|
||||
- name: Provision mariadb
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
connection: local
|
||||
|
||||
vars:
|
||||
namespace: default
|
||||
coe_host: "http://localhost:8080"
|
||||
|
||||
roles:
|
||||
- role: {{project_name}}
|
||||
playbook_debug: false
|
Loading…
x
Reference in New Issue
Block a user