From 43fa4a3fa6807bb56d10e0dba390ccffd105d3d2 Mon Sep 17 00:00:00 2001 From: Anush Shetty Date: Fri, 5 May 2017 15:32:20 +0530 Subject: [PATCH] Adding tests for kompose-specific labels and buildconfig dockerfile construct * Two new scripts testing kompose-specific labels have been added: script/test_in_openshift/tests/routes-service-expose-hostname.sh script/test_in_openshift/tests/routes-service-expose-true.sh * Tests for buildconfig dockerfile construct has been added: script/test_in_openshift/tests/buildconfig_dockerfile.sh * Tests for restart option: script/test_in_openshift/tests/restart-options.sh * Ability to run individual scripts: Changes have been made to script/test_in_openshift/run.sh for running individual scripts: Eg. ./script/test_in_openshift/run.sh script/test_in_openshift/tests/routes-service-expose-true.sh --- 0 | 0 1 | 0 .../docker-compose-bc-dockerfile.yml | 8 +++ .../docker-compose-restart-always.yml | 7 +++ script/test_in_openshift/lib.sh | 4 +- script/test_in_openshift/run.sh | 18 +++++-- .../tests/buildconfig_dockerfile.sh | 35 +++++++++++++ .../tests/restart-options.sh | 50 +++++++++++++++++++ .../tests/routes-service-expose-hostname.sh | 40 +++++++++++++++ .../tests/routes-service-expose-true.sh | 40 +++++++++++++++ 10 files changed, 196 insertions(+), 6 deletions(-) create mode 100644 0 create mode 100644 1 create mode 100644 script/test_in_openshift/compose-files/docker-compose-bc-dockerfile.yml create mode 100644 script/test_in_openshift/compose-files/docker-compose-restart-always.yml create mode 100755 script/test_in_openshift/tests/buildconfig_dockerfile.sh create mode 100755 script/test_in_openshift/tests/restart-options.sh create mode 100755 script/test_in_openshift/tests/routes-service-expose-hostname.sh create mode 100755 script/test_in_openshift/tests/routes-service-expose-true.sh diff --git a/0 b/0 new file mode 100644 index 00000000..e69de29b diff --git a/1 b/1 new file mode 100644 index 00000000..e69de29b diff --git a/script/test_in_openshift/compose-files/docker-compose-bc-dockerfile.yml b/script/test_in_openshift/compose-files/docker-compose-bc-dockerfile.yml new file mode 100644 index 00000000..a7e67699 --- /dev/null +++ b/script/test_in_openshift/compose-files/docker-compose-bc-dockerfile.yml @@ -0,0 +1,8 @@ +version: "2" + +services: + foo: + build: + context: "../../../examples/buildconfig/build" + dockerfile: "Dockerfile" + command: "sleep 3600" diff --git a/script/test_in_openshift/compose-files/docker-compose-restart-always.yml b/script/test_in_openshift/compose-files/docker-compose-restart-always.yml new file mode 100644 index 00000000..a70efade --- /dev/null +++ b/script/test_in_openshift/compose-files/docker-compose-restart-always.yml @@ -0,0 +1,7 @@ +version: '2' + +services: + pival: + image: perl + command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"] + restart: "always" diff --git a/script/test_in_openshift/lib.sh b/script/test_in_openshift/lib.sh index b243f952..dd2f115d 100644 --- a/script/test_in_openshift/lib.sh +++ b/script/test_in_openshift/lib.sh @@ -130,7 +130,7 @@ function convert::kompose_up_check () { [ $(oc get pods | eval ${query_2} | awk '{ print $3 }' | \ grep ${query_2_status} | wc -l) -eq $replica_2 ]; then oc get pods - convert::print_pass "All pods are Running now. kompose up is successful." + convert::print_pass "All pods are Running now. kompose up is successful.\n" fi } @@ -178,7 +178,7 @@ function convert::oc_check_route () { fi if [ $(oc get route | grep ${route_key} | wc -l ) -gt 0 ]; then - convert::print_pass "Route *.${route_key} has been exposed" + convert::print_pass "Route *.${route_key} has been exposed\n" else convert::print_fail "Route *.${route_key} has not been exposed\n" fi diff --git a/script/test_in_openshift/run.sh b/script/test_in_openshift/run.sh index 680533ed..419bc264 100755 --- a/script/test_in_openshift/run.sh +++ b/script/test_in_openshift/run.sh @@ -34,13 +34,23 @@ fi convert::oc_cluster_up -for test_case in $KOMPOSE_ROOT/script/test_in_openshift/tests/*; do - $test_case; exit_status=$? + +if [ -z $1 ]; then + for test_case in $KOMPOSE_ROOT/script/test_in_openshift/tests/*; do + $test_case; exit_status=$? + if [ $exit_status -ne 0 ]; then + openshift_exit_status=1 + fi + convert::oc_cleanup + done +else + # Run individual test scripts + test_to_run=$1 + $test_to_run; exit_status=$? if [ $exit_status -ne 0 ]; then openshift_exit_status=1 fi - convert::oc_cleanup -done +fi convert::oc_cluster_down diff --git a/script/test_in_openshift/tests/buildconfig_dockerfile.sh b/script/test_in_openshift/tests/buildconfig_dockerfile.sh new file mode 100755 index 00000000..da1ace2a --- /dev/null +++ b/script/test_in_openshift/tests/buildconfig_dockerfile.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# Copyright 2017 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Test case for buildconfig on kompose + +KOMPOSE_ROOT=$(readlink -f $(dirname "${BASH_SOURCE}")/../../..) +source $KOMPOSE_ROOT/script/test/cmd/lib.sh +source $KOMPOSE_ROOT/script/test_in_openshift/lib.sh + +convert::print_msg "Testing buildconfig dockerfile construct in kompose" + +docker_compose_file="${KOMPOSE_ROOT}/script/test_in_openshift/compose-files/docker-compose-bc-dockerfile.yml" + +# Run kompose up +convert::kompose_up $docker_compose_file + +# Check if the pods are up. +convert::kompose_up_check -p foo + +# Kompose down for buildconfig fails being tracked at #382 +# convert::kompose_down $docker_compose_file + +# convert::kompose_down_check 2 diff --git a/script/test_in_openshift/tests/restart-options.sh b/script/test_in_openshift/tests/restart-options.sh new file mode 100755 index 00000000..6ed7fb2f --- /dev/null +++ b/script/test_in_openshift/tests/restart-options.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Copyright 2017 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +KOMPOSE_ROOT=$(readlink -f $(dirname "${BASH_SOURCE}")/../../..) +source $KOMPOSE_ROOT/script/test/cmd/lib.sh +source $KOMPOSE_ROOT/script/test_in_openshift/lib.sh + +convert::print_msg "Testing restart: 'always'" + +docker_compose_file="${KOMPOSE_ROOT}/script/test_in_openshift/compose-files/docker-compose-restart-always.yml" + +# Run kompose up +convert::kompose_up $docker_compose_file + +# Check if the pods are up +retry_up=0 + +while [ $(oc get pods --no-headers | wc -l ) -ne 1 ] || + [ $(oc get pods --no-headers | awk '{ print $4 }') -eq 0 ]; do + if [ $retry_up -lt 240 ]; then + retry_up=$(($retry_up + 1)) + sleep 1 + else + exit 1 + fi +done + +if [ $(oc get pods --no-headers | awk '{ print $4 }') > 0 ]; then + convert::print_pass "restart option set to 'always' is working as expected\n" + oc get pods +fi + +# Run Kompose down +convert::kompose_down $docker_compose_file + +convert::kompose_down_check 1 diff --git a/script/test_in_openshift/tests/routes-service-expose-hostname.sh b/script/test_in_openshift/tests/routes-service-expose-hostname.sh new file mode 100755 index 00000000..5e47f0f8 --- /dev/null +++ b/script/test_in_openshift/tests/routes-service-expose-hostname.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Copyright 2017 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Test case for checking kompose.service.expose label in kompose + +KOMPOSE_ROOT=$(readlink -f $(dirname "${BASH_SOURCE}")/../../..) +source $KOMPOSE_ROOT/script/test/cmd/lib.sh +source $KOMPOSE_ROOT/script/test_in_openshift/lib.sh + +docker_compose_file="${KOMPOSE_ROOT}/script/test/fixtures/expose-service/compose-files/docker-compose-expose-hostname.yml" + +convert::print_msg "Testing kompose-specific label:kompose.service.expose=hostname " + +# Run kompose up +convert::kompose_up $docker_compose_file + +# Check if the pods are up +convert::kompose_up_check -p "web redis" + +# Check if the service has been exposed +convert::oc_check_route "batman.example.com" + +# Run Kompose down +convert::kompose_down $docker_compose_file + +# Check if the pods have been terminated +convert::kompose_down_check 2 diff --git a/script/test_in_openshift/tests/routes-service-expose-true.sh b/script/test_in_openshift/tests/routes-service-expose-true.sh new file mode 100755 index 00000000..4cd9ee75 --- /dev/null +++ b/script/test_in_openshift/tests/routes-service-expose-true.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Copyright 2017 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Test case for checking routes construct with kompose + +KOMPOSE_ROOT=$(readlink -f $(dirname "${BASH_SOURCE}")/../../..) +source $KOMPOSE_ROOT/script/test/cmd/lib.sh +source $KOMPOSE_ROOT/script/test_in_openshift/lib.sh + +docker_compose_file="${KOMPOSE_ROOT}/script/test/fixtures/expose-service/compose-files/docker-compose-expose-true.yml" + +convert::print_msg "Running tests for kompose-specific labels: 'kompose.service.expose:True'" + +# Run kompose up +convert::kompose_up $docker_compose_file + +# Check if the pods are up +convert::kompose_up_check -p "web redis" + +# Check if the service has been exposed +convert::oc_check_route "true" + +# Run Kompose down +convert::kompose_down $docker_compose_file + +# Check if the pods have been term +convert::kompose_down_check 2