First cut of zuul jobs for charms
This includes: * project templates and jobs for charm projects to use * linter for this repo Change-Id: Id7be6711513f42aedd5aba841f9b19652540e8cf
This commit is contained in:
parent
0cf3796586
commit
18de79e126
23
.ansible-lint
Normal file
23
.ansible-lint
Normal file
@ -0,0 +1,23 @@
|
||||
parseable: true
|
||||
quiet: false
|
||||
skip_list:
|
||||
- meta-no-info # No 'galaxy_info' found
|
||||
- no-changed-when # Commands should not change things if nothing needs doing
|
||||
- no-tabs # Most files should not contain tabs
|
||||
- role-name # Role name does not match ``^[a-z][a-z0-9_]+$`` pattern
|
||||
- fqcn-builtins # It would probably be good to enforce this, but it's a lot
|
||||
- risky-file-permissions # It would probably also good to enforce this if someone wants to look at them
|
||||
- schema # This is a stricter form of schema per https://github.com/ansible/schemas. might also be good if someone has motivation?
|
||||
use_default_rules: true
|
||||
verbosity: 1
|
||||
mock_modules:
|
||||
- zuul_console
|
||||
- zuul_return
|
||||
loop_var_prefix: zj_
|
||||
# Enable rules that are disabled by default:
|
||||
enable_list:
|
||||
- no-same-owner
|
||||
|
||||
# Local variables:
|
||||
# mode: yaml
|
||||
# End:
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.cache
|
||||
.tox
|
76
playbooks/build-charm.yaml
Normal file
76
playbooks/build-charm.yaml
Normal file
@ -0,0 +1,76 @@
|
||||
- hosts: all
|
||||
tasks:
|
||||
|
||||
- name: lxd apt packages are not present
|
||||
apt:
|
||||
name:
|
||||
- lxd
|
||||
- lxd-client
|
||||
state: absent
|
||||
purge: true
|
||||
become: true
|
||||
|
||||
- name: snapd is installed
|
||||
apt:
|
||||
name: snapd
|
||||
become: true
|
||||
|
||||
- name: lxd snap is installed
|
||||
snap:
|
||||
name: lxd
|
||||
channel: latest/stable
|
||||
become: true
|
||||
|
||||
- name: lxd is initialised
|
||||
command: lxd init --auto
|
||||
become: true
|
||||
|
||||
- name: current user is in lxd group
|
||||
user:
|
||||
name: "{{ ansible_user }}"
|
||||
groups: lxd
|
||||
append: true
|
||||
become: true
|
||||
|
||||
- name: reset ssh connection to apply permissions from new group
|
||||
meta: reset_connection
|
||||
|
||||
- name: charmcraft is installed
|
||||
snap:
|
||||
name: charmcraft
|
||||
channel: latest/stable
|
||||
classic: true
|
||||
become: true
|
||||
|
||||
- name: charm is packed
|
||||
command:
|
||||
cmd: charmcraft --verbosity trace pack
|
||||
chdir: "{{ zuul.project.src_dir }}"
|
||||
|
||||
- name: local charm is named consistently
|
||||
command:
|
||||
cmd: ./rename.sh
|
||||
chdir: "{{ zuul.project.src_dir }}"
|
||||
|
||||
- name: Compress built charm
|
||||
archive:
|
||||
dest: "{{ zuul.project.src_dir }}/{{ charm_build_name }}.charm.gz"
|
||||
path: "{{ zuul.project.src_dir }}/{{ charm_build_name }}.charm"
|
||||
format: gz
|
||||
|
||||
- name: built charm is available in the zuul log root for auto artifact upload
|
||||
fetch:
|
||||
src: "{{ zuul.project.src_dir }}/{{ charm_build_name }}.charm.gz"
|
||||
dest: "{{ zuul.executor.log_root }}/"
|
||||
flat: true
|
||||
become: true
|
||||
|
||||
- name: Upload artifacts
|
||||
zuul_return:
|
||||
data:
|
||||
zuul:
|
||||
artifacts:
|
||||
- name: charm
|
||||
url: "{{ charm_build_name }}.charm.gz"
|
||||
metadata:
|
||||
type: charm
|
29
playbooks/func-tests.yaml
Normal file
29
playbooks/func-tests.yaml
Normal file
@ -0,0 +1,29 @@
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: test runner packages are installed
|
||||
apt:
|
||||
name:
|
||||
- tox
|
||||
- jq
|
||||
- gzip
|
||||
become: true
|
||||
|
||||
- name: built charm is present locally (artefact from previous job)
|
||||
include_role:
|
||||
name: download-artifact
|
||||
vars:
|
||||
download_artifact_api: "https://zuul.opendev.org/api/tenant/{{ zuul.tenant }}"
|
||||
download_artifact_type: charm
|
||||
download_artifact_pipeline: check
|
||||
download_artifact_job: build-charm
|
||||
download_artifact_directory: "{{ zuul.project.src_dir }}"
|
||||
|
||||
- name: Gunzip built charm
|
||||
command:
|
||||
cmd: gunzip {{ charm_build_name }}.charm.gz
|
||||
chdir: "{{ zuul.project.src_dir }}"
|
||||
|
||||
- name: run smoke tests
|
||||
command:
|
||||
cmd: tox -e func-smoke
|
||||
chdir: "{{ zuul.project.src_dir }}"
|
82
playbooks/microk8s-cloud.yaml
Normal file
82
playbooks/microk8s-cloud.yaml
Normal file
@ -0,0 +1,82 @@
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: snapd is installed
|
||||
apt:
|
||||
name: snapd
|
||||
become: true
|
||||
|
||||
- name: microk8s is installed
|
||||
snap:
|
||||
name: microk8s
|
||||
classic: true
|
||||
become: true
|
||||
|
||||
- name: current user is in microk8s group
|
||||
user:
|
||||
name: "{{ ansible_user }}"
|
||||
groups: microk8s
|
||||
append: true
|
||||
become: true
|
||||
|
||||
- name: reset ssh connection to apply permissions from new group
|
||||
meta: reset_connection
|
||||
|
||||
- name: microk8s is started
|
||||
command:
|
||||
cmd: microk8s start
|
||||
|
||||
- name: microk8s is running and ready
|
||||
command:
|
||||
cmd: microk8s status --wait-ready
|
||||
register: res
|
||||
failed_when: '"is running" not in res.stdout'
|
||||
|
||||
- name: microk8s dns addon is enabled
|
||||
command:
|
||||
cmd: microk8s enable dns
|
||||
register: res
|
||||
changed_when: '"already enabled" not in res.stdout'
|
||||
|
||||
- name: microk8s hostpath storage addon is enabled
|
||||
command:
|
||||
cmd: microk8s enable hostpath-storage
|
||||
register: res
|
||||
changed_when: '"already enabled" not in res.stdout'
|
||||
|
||||
- name: microk8s metallb addon is enabled
|
||||
command:
|
||||
# ip range is an arbitrary choice; may need to be changed later
|
||||
cmd: microk8s enable metallb:10.170.0.1-10.170.0.100
|
||||
register: res
|
||||
changed_when: '"already enabled" not in res.stdout'
|
||||
|
||||
- name: microk8s addons are ready
|
||||
command:
|
||||
cmd: microk8s status --format short
|
||||
register: res
|
||||
retries: 18
|
||||
delay: 10 # 18 * 10 = 3 minutes
|
||||
until: >
|
||||
"core/dns: enabled" in res.stdout and
|
||||
"core/hostpath-storage: enabled" in res.stdout and
|
||||
"core/metallb: enabled" in res.stdout
|
||||
changed_when: res.attempts > 1
|
||||
|
||||
- name: juju is installed
|
||||
snap:
|
||||
name: juju
|
||||
classic: true
|
||||
become: true
|
||||
|
||||
- name: juju is bootstrapped on microk8s
|
||||
command:
|
||||
cmd: juju bootstrap microk8s microk8s
|
||||
register: res
|
||||
changed_when: '"already exists" not in res.stderr'
|
||||
failed_when: '"ERROR" in res.stderr and "already exists" not in res.stderr'
|
||||
|
||||
- name: current juju controller is microk8s
|
||||
command:
|
||||
cmd: juju switch microk8s
|
||||
register: res
|
||||
changed_when: '"no change" not in res.stderr'
|
10
playbooks/microk8s-juju-post.yaml
Normal file
10
playbooks/microk8s-juju-post.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: debug output for debugging the functional test # noqa risky-shell-pipe
|
||||
shell: |
|
||||
set -x
|
||||
MODEL="$(juju models --format=json | jq -r '.models[]["short-name"]' | grep '^zaza-')"
|
||||
juju switch $MODEL
|
||||
juju status
|
||||
juju debug-log --replay
|
||||
exit 0
|
7
test-requirements.txt
Normal file
7
test-requirements.txt
Normal file
@ -0,0 +1,7 @@
|
||||
flake8
|
||||
# ansible-lint requires ansible>=2.9
|
||||
ansible>=5,<6
|
||||
# pin until https://github.com/ansible/ansible-lint/issues/2320 is fixed
|
||||
ansible-lint>=6,<6.5
|
||||
bashate>=0.2
|
||||
|
39
tools/ansible-lint-roles-cache.sh
Executable file
39
tools/ansible-lint-roles-cache.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script is taken from the openstack-zuul-jobs
|
||||
# projects https://github.com/openstack/openstack-zuul-jobs
|
||||
|
||||
if [[ ! ${ANSIBLE_ROLES_PATH} =~ \.cache.* ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -d .cache/ansible-lint ]; then
|
||||
mkdir -p .cache/ansible-lint
|
||||
fi
|
||||
|
||||
pushd .cache/ansible-lint
|
||||
|
||||
repos=(opendev/base-jobs
|
||||
opendev/system-config
|
||||
openstack/openstack-zuul-jobs
|
||||
zuul/zuul-jobs)
|
||||
|
||||
for repo in ${repos[@]}; do
|
||||
dir=$(dirname $repo)
|
||||
echo "Updating Ansible roles repo ${dir}"
|
||||
if [ ! -d $repo ]; then
|
||||
echo "Cloning fresh"
|
||||
mkdir -p $dir
|
||||
pushd $dir
|
||||
git clone https://opendev.org/$repo
|
||||
popd
|
||||
else
|
||||
echo "Updating repo"
|
||||
pushd $repo
|
||||
git fetch -a
|
||||
git pull
|
||||
popd
|
||||
fi
|
||||
echo "Done"
|
||||
done
|
||||
|
23
tox.ini
Normal file
23
tox.ini
Normal file
@ -0,0 +1,23 @@
|
||||
[tox]
|
||||
minversion = 3.2.0
|
||||
skipsdist = True
|
||||
envlist = linters
|
||||
|
||||
[testenv]
|
||||
basepython = python3
|
||||
deps = -r{toxinidir}/test-requirements.txt
|
||||
|
||||
[testenv:linters]
|
||||
whitelist_externals = bash
|
||||
setenv =
|
||||
ANSIBLE_ROLES_PATH={env:ANSIBLE_ROLES_PATH:{toxinidir}/.cache/ansible-lint/opendev/base-jobs/roles:{toxinidir}/.cache/ansible-lint/opendev/system-config/roles:{toxinidir}/.cache/ansible-lint/zuul/zuul-jobs/roles:{toxinidir}/.cache/ansible-lint/openstack/openstack-zuul-jobs/roles}
|
||||
commands =
|
||||
flake8 {posargs}
|
||||
{toxinidir}/tools/ansible-lint-roles-cache.sh
|
||||
ansible-lint
|
||||
|
||||
[testenv:venv]
|
||||
commands = {posargs}
|
||||
|
||||
[flake8]
|
||||
exclude = .venv,.tox,dist,doc,build,*.egg,.cache
|
13
zuul.d/jobs.yaml
Normal file
13
zuul.d/jobs.yaml
Normal file
@ -0,0 +1,13 @@
|
||||
- job:
|
||||
name: charmbuild
|
||||
run: playbooks/build-charm.yaml
|
||||
provides: charm
|
||||
timeout: 3600
|
||||
- job:
|
||||
name: zaza-smoke-test
|
||||
pre-run: playbooks/microk8s-cloud.yaml
|
||||
run: playbooks/func-tests.yaml
|
||||
cleanup-run: playbooks/microk8s-juju-post.yaml
|
||||
requires: charm
|
||||
dependencies:
|
||||
- name: charmbuild
|
9
zuul.d/project-templates.yaml
Normal file
9
zuul.d/project-templates.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
- project-template:
|
||||
name: microk8s-func-test
|
||||
description: |
|
||||
This project template is defined to run zaza functional tests
|
||||
inside microk8s
|
||||
check:
|
||||
jobs:
|
||||
- charmbuild
|
||||
- zaza-smoke-test
|
7
zuul.d/project.yaml
Normal file
7
zuul.d/project.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
- project:
|
||||
check:
|
||||
jobs:
|
||||
- openstack-zuul-jobs-linters
|
||||
gate:
|
||||
jobs:
|
||||
- openstack-zuul-jobs-linters
|
Loading…
Reference in New Issue
Block a user