Running smoke tests
Smoke tests for argocd-oc-apps are tricky to implement, as the repo is on GitHub but the smoke tests need to access ATLNZ's intranet to fetch images hosted on an internal docker repository (harbor). External services can't innitiate network requests into ATLNZ's intranet, due to the corporate firewall.
To get around these limitations, part of the smoke tests are run on Jenkins in ATLNZ's intranet. A technique using GitHub statuses on commits is used so a PR on GitHub can indicate a Jenkins smoke test needs to be run, and Jenkins can update the status on GitHub when it starts running a job and when it passes/fails.
A brief overview of how this is done:
- When a push request is created or modified for argocd-oc-apps, the GitHub workflow
init-jenkins-smoke-tests-checktriggers and (using GitHub's API) adds a check with the context/namejenkins/smoke-testsand descriptionstate=waiting-for-jenkins-jobto theHEADcommit on the pull request. - A Jenkins job (argocd-oc-apps-continuous-polling) runs on a schedule at ATLNZ, checking for
argocd-oc-appspull requests that are requesting a smoke test. It does this by calling GitHub's API to get all open pull requests forargocd-oc-apps, and then for each pull request, it calls GitHub's API to get all statuses on theHEADcommit. If the job finds a status with the contextjenkins/smoke-tests, statepending, and descriptionstate=waiting-for-jenkins-job, then the job succeeds, else it fails. - A 2nd Jenkins job (the actual smoke test job) argocd-oc-apps_smoke-tests triggers when a argocd-oc-apps-continuous-polling job succeeds.
- The 2nd Jenkins job, the actual smoke test job (argocd-oc-apps_smoke-tests), does the same check as
argocd-oc-apps-continuous-pollingto check if there is aargocd-oc-appspull request that is requesting a smoke test, and gets the branch andHEADcommit SHA. argocd-oc-apps_smoke-testsexists early if it does not find a pull request that is requesting a smoke test.argocd-oc-apps_smoke-tests, when there is a valid pull request, immediately calls GitHub's API on the PR'sHEADcommit to update the status with contextjenkins/smoke-tests. It sets the status description tostate=jenkins-job-running, as alock, so other jobs do not process that PR too.argocd-oc-apps_smoke-testssets up the local KinD based One Connect Kubernetes cluster.argocd-oc-apps_smoke-testsgets the One Connect IP address by querying the nginx-ingress-controller, andcat's to a file so it can be read in the test environment later.argocd-oc-apps_smoke-testsruns the serenity tests using theoneconnect-test-env.shenvironment.oneconnect-test-env.shruns a docker container with the--network=kindargument, to connect the test container to the same docker custom bridge network One Connect is in, in theKinDcluster.oneconnect-test-env.shalso runs the docker container with the--add-host local.oneconnect.st.atlnz.lc:$ONE_CONNECT_IPargument, to setup a/etc/hostsDNS entry to point thelocal.oneconnect.st.atlnz.lcURL at the IP address of the local One Connect app. The combination of these two arguments lets the serenity tests access One Connect running in KinD, without modifying anything on the host OS (like the host's/etc/hostsfile).- Finally, depending on whether something in the tests failed or everything passed, the
argocd-oc-apps_smoke-testsJenkins job sends a final API call to GitHub to update the PR HEAD commit status with contextjenkins/smoke-tests, to statesuccessorfailure, and description tostate=jenkins-job-successorstate=jenkins-job-failed. - The status description
state=jenkins-job-running,state=jenkins-job-success, ..., and the statepending/success/failurecan all be viewed in the checks area on a pull request, so the result of the Jenkins smoke tests can be seen on GitHub.