diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..33defe4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.tox/ diff --git a/.zuul.yaml b/.zuul.yaml new file mode 100644 index 0000000..619066b --- /dev/null +++ b/.zuul.yaml @@ -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 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..bc0879f --- /dev/null +++ b/ci/playbooks/deploy_microshift.yaml @@ -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 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