-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial travis file to set up openshift * adding a project and template to test * set oc binary location * Test image build * downgrade oc * try xenial distro * downgrade to 3.10 * fix command * Try again * Refactor and tests * more updates * Applier 2.0.10 * Ensure openshift login succeeds, add status checks * Move applier to main folder so we can use it for more things; add testing doc * Fix script * Ensure script exits when oc fails * boom
- Loading branch information
Showing
21 changed files
with
199 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
NAME=jenkins-slave-golang | ||
PIPELINE_CONTEXT_DIR=jenkins-slaves/jenkins-slave-golang |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
dist: xenial | ||
language: python | ||
python: | ||
- "3.7" | ||
|
||
cache: | ||
directories: | ||
- $HOME/.cache/pip | ||
|
||
env: | ||
global: | ||
- ANSIBLE_HOST_KEY_CHECKING=False | ||
- PIP_DOWNLOAD_CACHE=$HOME/.cache/pip | ||
- OC_BINARY_URL=https://mirror.openshift.com/pub/openshift-v3/clients/3.10.45/linux/oc.tar.gz | ||
- ANSIBLE_VERSION="2.7" | ||
|
||
before_install: | ||
- sudo apt-get update -qq | ||
|
||
install: | ||
- pip install -U pip | ||
- if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible; else pip install ansible~=$ANSIBLE_VERSION; fi | ||
#- pip install "ansible-lint<4.0" yamllint flake8 molecule docker "pytest<3.10" "testinfra==3.0.4" | ||
# Configure OpenShift Binary | ||
- sudo wget -qO- ${OC_BINARY_URL} | sudo tar -xvz -C /bin | ||
|
||
before_script: | ||
# Configure Docker | ||
- sudo service docker stop | ||
- sudo mkdir -p /etc/docker | ||
- echo '{"insecure-registries":["172.30.0.0/16"]}' | sudo tee /etc/docker/daemon.json | ||
- sudo service docker start | ||
# Launch OpenShift Environment | ||
- _test/setup.sh cluster_up | ||
# Run Applier to provision all of the builds | ||
- _test/setup.sh applier | ||
|
||
script: | ||
# Test to ensure that builds all succeed | ||
- _test/setup.sh test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Testing this Repository | ||
|
||
Containers-quickstarts is outfitted with a set of automated tests. This document deals with writing and running tests for your contributions. | ||
|
||
## Tesing Architecture | ||
|
||
We use Travis-CI to test this repo. You can start to examine how we set up and invoke tests by examining the [.travis.yml](/.travis.yml) file. | ||
|
||
We have split the architect of the tests up into 4 phases: | ||
|
||
1. Environment setup and prereqs | ||
2. Launching an openshift test cluster, using `oc cluster up` | ||
3. Running [openshift-applier](https://github.com/redhat-cop/openshift-applier) to deploy a set of builds | ||
4. Checking `.status.phase` in each build to validate all builds end with in a `Completed` state. | ||
|
||
The 3 phases of testing are captured in a [script](/_test/setup.sh) that is executed by travis, but can also be run locally in order to validate your changes before committing code. | ||
|
||
## Writing Tests | ||
|
||
Adding a new test to our CI is as simple as adding one or more `BuildConfig`s to the [global Applier inventory](/.applier). Currently we deploy all assets into a single namespace to make all builds "discoverable" by our test scripts. | ||
|
||
Every build that gets created will then be executed, and the test script will wait until all builds complete, and ensure that none of them fail. | ||
|
||
## Running the tests locally. | ||
|
||
There are a number of ways to run the tests, but the easiest is to run all phases against a local cluster with `oc cluster up`: | ||
|
||
``` | ||
oc cluster up --base-dir=$HOME/ocp && \ | ||
./_test/setup.sh applier && \ | ||
./_test/setup.sh test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
trap "exit 1" TERM | ||
export TOP_PID=$$ | ||
NAMESPACE=containers-quickstarts-tests | ||
|
||
cluster_up() { | ||
set +e | ||
built=false | ||
while true; do | ||
if [ -z $IP_ADDR ]; then | ||
DEV=$(ip link | awk '/state UP/{ gsub(":", ""); print $2}') | ||
IP_ADDR=$(ip addr show $DEV | awk '/inet /{ gsub("/.*", ""); print $2}') | ||
fi | ||
oc cluster up --public-hostname=${IP_ADDR} --routing-suffix=${IP_ADDR}.nip.io --base-dir=$HOME/ocp | ||
if [ "$?" -eq 0 ]; then | ||
built=true | ||
break | ||
fi | ||
echo "Retrying oc cluster up after failure" | ||
oc cluster down | ||
sleep 5 | ||
done | ||
echo "OpenShift Cluster Running" | ||
} | ||
|
||
applier() { | ||
echo "${TRAVIS_BRANCH:=master}" | ||
echo "${TRAVIS_REPO_SLUG:=redhat-cop/containers-quickstarts}" | ||
ansible-galaxy install -r requirements.yml -p galaxy --force | ||
ansible-playbook -i .applier/ galaxy/openshift-applier/playbooks/openshift-cluster-seed.yml -e namespace=containers-quickstarts-tests -e slave_repo_ref=${TRAVIS_BRANCH} -e repository_url=https://github.com/${TRAVIS_REPO_SLUG}.git | ||
} | ||
|
||
get_build_phases() { | ||
phase=$1 | ||
result=$(oc get builds -o jsonpath="{.items[?(@.status.phase==\"${phase}\")].metadata.name}" -n $NAMESPACE) || kill -s TERM $TOP_PID | ||
echo ${result} | wc -w | ||
} | ||
|
||
test() { | ||
#oc status || exit 1 | ||
|
||
echo "Ensure all Builds are executed..." | ||
for pipeline in $(oc get bc -n ${NAMESPACE} -o jsonpath='{.items[*].metadata.name}'); do | ||
if [ "$(oc get build -n containers-quickstarts-tests -o jsonpath="{.items[?(@.metadata.annotations.openshift\.io/build-config\.name==\"${pipeline}\")].metadata.name}")" == "" ]; then | ||
oc start-build ${pipeline} -n ${NAMESPACE} | ||
fi | ||
done | ||
|
||
echo "Waiting for all builds to start..." | ||
while [[ "$(get_build_phases "New")" -ne 0 || $(get_build_phases "Pending") -ne 0 ]]; do | ||
echo -ne "New Builds: $(get_build_phases "New"), Pending Builds: $(get_build_phases "Pending")\r" | ||
sleep 1 | ||
done | ||
|
||
echo "Waiting for all builds to complete..." | ||
while [ $(get_build_phases "Running") -ne 0 ]; do | ||
echo -ne "Running Builds: $(get_build_phases "Running")\r" | ||
sleep 1 | ||
done | ||
|
||
echo "Check to see how many builds Failed" | ||
if [ $(get_build_phases "Failed") -ne 0 ]; then | ||
echo "Some builds failed. Printing Report" | ||
oc get builds -n $NAMESPACE -o custom-columns=NAME:.metadata.name,TYPE:.spec.strategy.type,FROM:.spec.source.type,STATUS:.status.phase,REASON:.status.reason | ||
exit 1 | ||
fi | ||
|
||
echo "Tests Completed Successfully!" | ||
} | ||
|
||
# Process arguments | ||
case $1 in | ||
cluster_up) | ||
cluster_up | ||
;; | ||
applier) | ||
applier | ||
;; | ||
test) | ||
test | ||
;; | ||
*) | ||
echo "Not an option" | ||
exit 1 | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
pipeline { | ||
agent { | ||
label 'jenkins-slave-golang' | ||
} | ||
|
||
stages { | ||
stage ('Run Test') { | ||
steps { | ||
sh """ | ||
go version | ||
""" | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters