Skip to content

Commit

Permalink
apb tests - disable openshift tests (#107)
Browse files Browse the repository at this point in the history
disable test on openshift since the old registry is not supported anymore
and the new requires auth.

Signed-off-by: Filippe Spolti <[email protected]>
  • Loading branch information
spolti authored Sep 13, 2019
1 parent 5d53d19 commit 68b841c
Show file tree
Hide file tree
Showing 5 changed files with 428 additions and 159 deletions.
34 changes: 15 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,33 @@ sevices:

language: python
python:
- '2.7'
- '3.6'

env:
- OPENSHIFT_VERSION=v3.9
- OPENSHIFT_VERSION=v3.10
#- OPENSHIFT_VERSION=v3.10
- OPENSHIFT_VERSION=v3.11
#- KUBERNETES_VERSION=v1.9.0 --> ImageStreams don't work on K8S
#- KUBERNETES_VERSION=v1.10.0 --> ImageStreams don't work on K8S
# Allow failures on oc latest
# TODO: re-enable latest when it isn't busted
matrix:
allow_failures:
- env: OPENSHIFT_VERSION=v3.10
- env: OPENSHIFT_VERSION=v3.11

#matrix:
# allow_failures:
# - env: OPENSHIFT_VERSION=v3.10

script:
# Configure test values
- export apb_name='rhpam-apb'
- export dockerfile='target/image/Dockerfile'
- export resources='https://github.com/jboss-container-images/rhpam-7-openshift-image/blob/7.3.x/rhpam73-image-streams.yaml'
- export resources_namespace='openshift'
# - export image_stream='https://raw.githubusercontent.com/jboss-container-images/rhpam-7-openshift-image/7.4.1.GA/rhpam74-image-streams.yaml'

# workaround for bypass odcs auth
- |
sed -i "s/ content_sets_file: content_sets.yml//g" ${PWD}/image.yaml
# Install and run cekit
- virtualenv ~/cekit
- source ~/cekit/bin/activate
- pip install -q -U cekit
- cekit build --overrides-file dev-overrides.yaml
- pip install --pre docker docker-squash 'cekit>=3.2.0,<3.3.0' odcs
- cekit build --overrides-file dev-overrides.yaml docker --no-squash

# Download test shim.
- wget -O ${PWD}/apb-test.sh https://raw.githubusercontent.com/ansibleplaybookbundle/apb-test-shim/master/apb-test.sh
# add execution permission to the test script.
- chmod +x ${PWD}/apb-test.sh



# Run tests.
- ${PWD}/apb-test.sh
272 changes: 272 additions & 0 deletions apb-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
#!/bin/bash

# Idea and code snippets taken from:
# https://gist.github.com/geerlingguy/73ef1e5ee45d8694570f334be385e181

# Exit on any individual command failure.
set -ex

# Pretty colors.
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
neutral='\033[0m'

apb_name=${apb_name:-"rhpam7-dev-apb"}
apb_image=rhpam-7/rhpam7-dev-apb
dockerfile=${dockerfile:-"Dockerfile"}
cluster_role=${cluster_role:-"admin"}
binding=${binding:-"rolebinding"}

# Lock Helm version until latest is functional
DESIRED_HELM_VERSION="v2.8.2"

function run_apb() {
local action=$1
local pod_name="$apb_name-$action"

printf ${green}"Run $action Playbook"${neutral}"\n"
echo -en 'travis_fold:start:'$pod_name'\\r'
$CMD run "$pod_name" \
--namespace=$apb_name \
--env="POD_NAME=$pod_name" \
--env="POD_NAMESPACE=$apb_name" \
--image=$apb_image \
--image-pull-policy=Never \
--restart=Never \
--attach=true \
--serviceaccount=$apb_name \
-- $action --extra-vars '{ "namespace": "'$apb_name'", "cluster": "'$CLUSTER'" }'
printf "\n"
$CMD get all -n $apb_name
echo -en 'travis_fold:end:'$pod_name'\\r'
printf "\n"
}

function setup_openshift() {
printf ${green}"Testing APB in OpenShift"${neutral}"\n"
echo -en 'travis_fold:start:openshift\\r'
printf ${yellow}"Setting up docker for insecure registry"${neutral}"\n"
sudo apt-get update -qq
sudo cat /etc/docker/daemon.json

#{"registry-mirrors": ["https://mirror.gcr.io"], "mtu": 1460}
# sudo echo "{ \"insecure-registries\": [\"172.30.0.0/16\"] }" > /etc/docker/daemon.json
# sudo rm -rf /etc/docker/daemon.json
sudo sed -i "s/\DOCKER_OPTS=\"/DOCKER_OPTS=\"--insecure-registry=172.30.0.0\/16 /g" /etc/default/docker
sudo cat /etc/default/docker
sudo iptables -F
sudo service docker restart
sudo ps faux | grep docker

printf "\n"

printf ${yellow}"Bringing up an openshift cluster and logging in"${neutral}"\n"
# sudo docker cp $(docker create docker.io/openshift/origin:$OPENSHIFT_VERSION):/bin/oc /usr/local/bin/oc
# sudo cp /usr/local/bin/oc /usr/local/bin/kubectl
if [ "$OPENSHIFT_VERSION" == "v3.11" ]; then
wget https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
tar -xzvf openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz --strip-components=1 openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit/oc

elif [ "${OPENSHIFT_VERSION}" == "v3.10" ]; then
wget https://github.com/openshift/origin/releases/download/v3.10.0/openshift-origin-client-tools-v3.10.0-dd10d17-linux-64bit.tar.gz
tar -xzvf openshift-origin-client-tools-v3.10.0-dd10d17-linux-64bit.tar.gz --strip-components=1 openshift-origin-client-tools-v3.10.0-dd10d17-linux-64bit/oc

elif [ "${OPENSHIFT_VERSION}" == "v3.9" ]; then
wget https://github.com/openshift/origin/releases/download/v3.9.0/openshift-origin-client-tools-v3.9.0-191fece-linux-64bit.tar.gz
tar -xzvf openshift-origin-client-tools-v3.9.0-191fece-linux-64bit.tar.gz --strip-components=1 openshift-origin-client-tools-v3.9.0-191fece-linux-64bit/oc
fi
sudo cp oc /usr/local/bin/
sudo cp /usr/local/bin/oc /usr/local/bin/kubectl
oc cluster up \
--skip-registry-check=true \
--routing-suffix=172.17.0.1.nip.io \
--public-hostname=172.17.0.1 \
--enable=service-catalog,template-service-broker,router,registry,web-console,persistent-volumes,sample-templates,rhel-imagestreams

echo -en 'travis_fold:end:openshift\\r'
printf "\n"

oc login -u system:admin

# Use for cluster operations
export CMD=oc
export CLUSTER=openshift
alias kubectl='oc'
}

function setup_kubernetes() {
printf ${green}"Setup: Testing APB in Kubernetes"${neutral}"\n"

# https://github.com/kubernetes/minikube#linux-continuous-integration-without-vm-support
printf ${yellow}"Bringing up minikube"${neutral}"\n"
echo -en 'travis_fold:start:minikube\\r'
sudo curl -Lo /usr/bin/minikube https://storage.googleapis.com/minikube/releases/v0.27.0/minikube-linux-amd64
sudo chmod +x /usr/bin/minikube
if [ "$KUBERNETES_VERSION" == "latest" ]; then
sudo curl -Lo /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
else
sudo curl -Lo /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/$KUBERNETES_VERSION/bin/linux/amd64/kubectl
fi
sudo chmod +x /usr/bin/kubectl
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | DESIRED_VERSION=$DESIRED_HELM_VERSION bash

export MINIKUBE_WANTUPDATENOTIFICATION=false
export MINIKUBE_WANTREPORTERRORPROMPT=false
export MINIKUBE_HOME=$HOME
export CHANGE_MINIKUBE_NONE_USER=true
mkdir $HOME/.kube || true
touch $HOME/.kube/config
export KUBECONFIG=$HOME/.kube/config

if [ "$KUBERNETES_VERSION" == "v1.9.0" ]; then
export AUTO_ESCALATE=true
fi

if [ "$KUBERNETES_VERSION" == "latest" ]; then
sudo minikube start \
--vm-driver=none \
--bootstrapper=localkube \
--extra-config=apiserver.Authorization.Mode=RBAC
else
sudo minikube start \
--vm-driver=none \
--bootstrapper=localkube \
--extra-config=apiserver.Authorization.Mode=RBAC \
--kubernetes-version=$KUBERNETES_VERSION
fi
minikube update-context

# this for loop waits until kubectl can access the api server that Minikube has created
for i in {1..150}; do # timeout for 5 minutes
kubectl get po &> /dev/null && break
sleep 2
done

# Install service-catalog
helm init --wait
kubectl create clusterrolebinding tiller-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:default
helm repo add svc-cat https://svc-catalog-charts.storage.googleapis.com
# TODO: Remove when 0.1.29 is released
helm install svc-cat/catalog --version 0.1.27 --name catalog --namespace catalog
# Wait until the catalog is ready before moving on
until kubectl get pods -n catalog -l app=catalog-catalog-apiserver | grep 2/2; do sleep 1; done
until kubectl get pods -n catalog -l app=catalog-catalog-controller-manager | grep 1/1; do sleep 1; done

echo -en 'travis_fold:end:minikube\\r'
printf "\n"

# Use for cluster operations
export CMD=kubectl
export CLUSTER=kubernetes
alias oc='kubectl'
}

function requirements() {
printf ${yellow}"Installing requirements"${neutral}"\n"
echo -en 'travis_fold:start:install_requirements\\r'
if [ -z "$TRAVIS_PYTHON_VERSION" ]; then
export PATH=$HOME/.local/bin:$PATH
pip install --pre apb yamllint --user
else
pip install --pre apb yamllint
fi

# Install nsenter
docker run --rm jpetazzo/nsenter cat /nsenter > /tmp/nsenter 2> /dev/null; sudo cp /tmp/nsenter /usr/local/bin/; sudo chmod +x /usr/local/bin/nsenter; which nsenter
echo -en 'travis_fold:end:install_requirements\\r'
printf "\n"
}

function lint_apb() {
printf ${green}"Linting apb.yml"${neutral}"\n"
echo -en 'travis_fold:start:lint.1\\r'
yamllint apb.yml
echo -en 'travis_fold:end:lint.1\\r'
printf "\n"
}

function build_apb() {
printf ${green}"Building apb"${neutral}"\n"
echo -en 'travis_fold:start:build.1\\r'
encoded_apb=$(base64 -w 0 apb.yml)
encoded_apb_from_dockerfile=$(sed -e :a -e '/\\$/N; s/\\\n//; ta' target/image/Dockerfile | grep LABEL | sed 's/[[:blank:]]\+/ /g' | tr ' ' '\n' | grep 'com.redhat.apb.spec' | sed -e 's/^com.redhat.apb.spec=//' -e 's/"//g')

if [ "${encoded_apb}" != "${encoded_apb_from_dockerfile}" ]; then
printf ${red}"Committed APB spec differs from built apb.yml spec"${neutral}"\n"
exit 1
fi

echo -en 'travis_fold:end:build.1\\r'
printf "\n"
}

function lint_playbooks() {
printf ${green}"Linting playbooks"${neutral}"\n"
echo -en 'travis_fold:start:lint.2\\r'
playbooks=$(find playbooks/ -maxdepth 1 -type f -printf "%f\n" -name '*.yml' -o -name '*.yaml')
if [ -z "$playbooks" ]; then
printf ${red}"No playbooks"${neutral}"\n"
exit 1
fi
for playbook in $playbooks; do
docker run --entrypoint ansible-playbook $apb_image /opt/apb/project/$playbook --syntax-check
done
echo -en 'travis_fold:end:lint.2\\r'
printf "\n"
}

function setup_cluster() {
if [ -n "$OPENSHIFT_VERSION" ]; then
setup_openshift
elif [ -n "$KUBERNETES_VERSION" ]; then
setup_kubernetes
else
printf ${red}"No cluster environment variables set"${neutral}"\n"
exit 1
fi
}

function create_apb_namespace() {
if [ -n "$OPENSHIFT_VERSION" ]; then
oc new-project $apb_name
oc get is -n openshift
oc create -f $image_stream -n $apb_name
elif [ -n "$KUBERNETES_VERSION" ]; then
kubectl create namespace $apb_name
else
printf ${red}"No cluster environment variables set"${neutral}"\n"
exit 1
fi
$CMD get namespace $apb_name -o yaml
}

function create_sa() {
printf ${yellow}"Get enough permissions for APB to run"${neutral}"\n"
$CMD create serviceaccount $apb_name --namespace=$apb_name
$CMD create $binding $apb_name \
--namespace=$apb_name \
--clusterrole=$cluster_role \
--serviceaccount=$apb_name:$apb_name
$CMD get serviceaccount $apb_name --namespace=$apb_name -o yaml
$CMD get $binding $apb_name --namespace=$apb_name -o yaml
sleep 5
printf "\n"
}

# Run the test
function test_apb() {
requirements
lint_apb
build_apb
lint_playbooks
#setup_cluster
#create_apb_namespace
#create_sa
#run_apb "test"
}

# Allow the functions to be loaded, skipping the test run
if [ -z $SOURCE_ONLY ]; then
test_apb
fi
8 changes: 4 additions & 4 deletions apb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ _apb_kieserver_mode: &_apb_kieserver_mode
description: The KIE server mode. Valid values are 'DEVELOPMENT' or 'PRODUCTION'. In production mode, you can not deploy SNAPSHOT versions of artifacts on the KIE server and can not change the version of an artifact in an existing container. (Sets the org.kie.server.mode system property).
required: true
type: enum
enum: ['DEVELOPMENT', 'PRODUCTION']
enum: [ 'DEVELOPMENT', 'PRODUCTION' ]
default: DEVELOPMENT
display_group: Process Server
_apb_kieserver_image_stream_name: &_apb_kieserver_image_stream_name
Expand Down Expand Up @@ -214,7 +214,7 @@ _apb_kieserver_startup_strategy: &_apb_kieserver_startup_strategy
description: "When set to OpenShiftStartupStrategy, allows KIE server to start up independently using shared state from OpenShift API service; when set to ControllerBasedStartupStrategy, allows KIE server to start up and function with configuration from a controller. Default: OpenShiftStartupStrategy"
required: true
type: enum
enum: ['OpenShiftStartupStrategy', 'ControllerBasedStartupStrategy']
enum: [ 'OpenShiftStartupStrategy', 'ControllerBasedStartupStrategy' ]
default: OpenShiftStartupStrategy
display_group: Process Server
_apb_kieserver_prometheus_ext_disabled: &_apb_kieserver_prometheus_ext_disabled
Expand Down Expand Up @@ -981,10 +981,10 @@ plans:
display_group: Process Server
- <<: *_apb_kieserver_startup_strategy
description: "When set to OpenShiftStartupStrategy, allows KIE server to start up independently using shared state from OpenShift API service; when set to LocalContainersStartupStrategy, allows KIE server to start up and function with local configuration, even when a controller is configured and unavailable. Default: OpenShiftStartupStrategy"
enum: ['OpenShiftStartupStrategy', 'LocalContainersStartupStrategy']
enum: [ 'OpenShiftStartupStrategy', 'LocalContainersStartupStrategy' ]
default: OpenShiftStartupStrategy
- *_apb_kieserver_image_stream_name
# Prometheus
# Prometheus
- *_apb_kieserver_prometheus_ext_disabled

# External Database
Expand Down
Loading

0 comments on commit 68b841c

Please sign in to comment.