From 940410dadeb6a27e0a73d9f8b27e404852a411dc Mon Sep 17 00:00:00 2001 From: Daniel Pawlik Date: Mon, 20 Mar 2023 09:40:10 +0100 Subject: [PATCH] Add basic CI job to verify code 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. --- .gitignore | 1 + ci/playbooks/collect_logs.yaml | 35 ++++++++++++++++++++++ ci/playbooks/deploy_microshift.yaml | 45 +++++++++++++++++++++++++++++ test-requirements.txt | 1 + tox.ini | 12 ++++++++ zuul.d/jobs.yaml | 12 ++++++++ zuul.d/projects.yaml | 8 +++++ 7 files changed, 114 insertions(+) create mode 100644 .gitignore create mode 100644 ci/playbooks/collect_logs.yaml create mode 100644 ci/playbooks/deploy_microshift.yaml create mode 100644 test-requirements.txt create mode 100644 tox.ini create mode 100644 zuul.d/jobs.yaml create mode 100644 zuul.d/projects.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..33defe4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.tox/ diff --git a/ci/playbooks/collect_logs.yaml b/ci/playbooks/collect_logs.yaml new file mode 100644 index 0000000..5b1e78a --- /dev/null +++ b/ci/playbooks/collect_logs.yaml @@ -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 diff --git a/ci/playbooks/deploy_microshift.yaml b/ci/playbooks/deploy_microshift.yaml new file mode 100644 index 0000000..1134c08 --- /dev/null +++ b/ci/playbooks/deploy_microshift.yaml @@ -0,0 +1,45 @@ +--- +- hosts: microshift.dev + 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 diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..6dd128e --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +ansible-lint diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..e001f21 --- /dev/null +++ b/tox.ini @@ -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 diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml new file mode 100644 index 0000000..6b645ca --- /dev/null +++ b/zuul.d/jobs.yaml @@ -0,0 +1,12 @@ +--- +# 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 diff --git a/zuul.d/projects.yaml b/zuul.d/projects.yaml new file mode 100644 index 0000000..fe79712 --- /dev/null +++ b/zuul.d/projects.yaml @@ -0,0 +1,8 @@ +--- +- project: + name: openstack-k8s-operators/ansible-microshift-role + github-check: + jobs: + - tox-linters + - markdownlint + - test-ansible-microshift-role