Skip to content

Commit

Permalink
Add basic CI job to verify code
Browse files Browse the repository at this point in the history
This project should be verified by the CI test job.
So far, it will just simply deploy microshift role with basic parameters
and run the linters: ansible-lint and markdown lint.
  • Loading branch information
danpawlik committed Mar 23, 2023
1 parent 0f04ada commit 585b68d
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.tox/
20 changes: 20 additions & 0 deletions .zuul.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# FIXME: find a way to provide pull-secret.txt secret to the CI
# job and skip using base-microshift-openstack base job.
- job:
name: test-ansible-microshift-role
parent: base-microshift-openstack
nodeset: centos-9-microshift-single-node
timeout: 10800
required-projects:
- opendev.org/zuul/zuul-jobs
run: ci/playbooks/deploy_microshift.yaml
post-run: ci/playbooks/collect_logs.yaml

- project:
name: openstack-k8s-operators/ansible-microshift-role
github-check:
jobs:
- tox-linters
- markdownlint
- test-ansible-microshift-role
35 changes: 35 additions & 0 deletions ci/playbooks/collect_logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- hosts: all
gather_facts: false
vars:
log_dir: "{{ ansible_user_dir }}/zuul-output/logs"
tasks:
- name: Create log dir
file:
path: "{{ log_dir }}"
state: directory
mode: 0755

- name: Collect pod logs
ansible.builtin.shell: |
oc get pods > all_pods.txt
oc get secrets > all_secrets.txt
oc get pv > all_pv.txt
oc get events > oc_events.txt
oc get routes > oc_routes.txt
mkdir pod
all_pods=$(oc get pods -o name)
for pod in $all_pods; do
echo $pod
oc logs $pod > ${pod}-logs.txt
oc get -o yaml $pod > ${pod}.yaml
oc describe $pod > ${pod}-describe.txt
done
oc get all --all-namespaces > all-resources.txt
args:
chdir: "{{ log_dir }}"
changed_when: true

- name: Copy files from {{ work_dir }} on node
include_role:
name: fetch-output
45 changes: 45 additions & 0 deletions ci/playbooks/deploy_microshift.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
- hosts: controller
vars:
fqdn: microshift.dev
pv_storageclass: somestorage
setup_olm: true
pv_count:
start: 1
end: 12
overwrite_container_policy: true
delete_openshift_storage: true
tasks:
- name: Setup Microshift
block:
- name: Start Microshift deployment
include_role:
name: ansible-microshift-role

# NOTE: The topolvm requires additional volume and create a lvm
# on that volume. We don't use that for CI, so just skip it.
- name: Create script to verify deployment
copy:
content: |
for i in {1..20}; do
echo "Ensuring that containers are spawned... ${i}"
count=$(/usr/local/bin/oc get pods --all-namespaces | grep openshift | grep -viE 'topolvm|running' -c)
if [ "$count" -eq "0" ]; then
echo "Microshift is deployed, we can continue..."
break
else
echo "The Microshift containers are not ready..."
sleep 15
fi
done
echo "Skipping waiting for openshift-storage - topolvm"
dest: /tmp/check-microshift.sh
mode: "0755"

- name: Check if all containers are up and ready
shell: /tmp/check-microshift.sh
always:
- name: Remove sensitive data
include_role:
name: ansible-microshift-role
tasks_from: cleanup.yaml
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ansible-lint
12 changes: 12 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[tox]
envlist = ansiblelint
skipsdist = True

[testenv]
basepython = python3
deps = -r{toxinidir}/test-requirements.txt

[testenv:ansiblelint]
show-source = True
commands =
ansible-lint

0 comments on commit 585b68d

Please sign in to comment.