Skip to content

Commit

Permalink
Merge pull request #588 from ashetty1/kompose_labels_test
Browse files Browse the repository at this point in the history
Adding tests for kompose-specific labels and buildconfig dockerfile construct
  • Loading branch information
kadel authored Jun 8, 2017
2 parents f066834 + fb0966f commit aa84680
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "2"

services:
foo:
build:
context: "../../../examples/buildconfig/build"
dockerfile: "Dockerfile"
command: "sleep 3600"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '2'

services:
pival:
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restart: "always"
6 changes: 3 additions & 3 deletions script/test_in_openshift/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -192,7 +192,7 @@ function convert::kompose_up () {
# Usage: convert::kompose_up <docker_compose_file>
local compose_file=$1
convert::print_msg "Running kompose up ..."
kompose --provider=openshift --emptyvols -f $compose_file up
kompose up --provider=openshift --emptyvols -f $compose_file
exit_status=$?

if [ $exit_status -ne 0 ]; then
Expand Down
18 changes: 14 additions & 4 deletions script/test_in_openshift/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions script/test_in_openshift/tests/buildconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ convert::kompose_up $docker_compose_file
convert::kompose_up_check -p foo

# Kompose down for buildconfig fails being tracked at #382
# convert::kompose_down $docker_compose_file
convert::kompose_down $docker_compose_file

# convert::kompose_down_check 2
convert::kompose_down_check 2
35 changes: 35 additions & 0 deletions script/test_in_openshift/tests/buildconfig_dockerfile.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion script/test_in_openshift/tests/redis-replica-2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ source $KOMPOSE_ROOT/script/test_in_openshift/lib.sh
convert::print_msg "Running tests for replica option"

# Run kompose up
kompose --provider=openshift --emptyvols --replicas 2 -f ${KOMPOSE_ROOT}/examples/docker-compose-counter.yaml up; exit_status=$?
kompose up --provider=openshift --emptyvols --replicas 2 -f ${KOMPOSE_ROOT}/examples/docker-compose-counter.yaml; exit_status=$?

if [ $exit_status -ne 0 ]; then
convert::print_fail "kompose up has failed"
Expand Down
50 changes: 50 additions & 0 deletions script/test_in_openshift/tests/restart-options.sh
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions script/test_in_openshift/tests/routes-service-expose-hostname.sh
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions script/test_in_openshift/tests/routes-service-expose-true.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit aa84680

Please sign in to comment.