Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
tests: Add initial swarm tests
Browse files Browse the repository at this point in the history
This will enable basic swarm tests.

Fixes #198

Signed-off-by: Gabriela Cervantes <[email protected]>
  • Loading branch information
GabyCT committed Apr 9, 2018
1 parent e831c4b commit 74fec7c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ kubernetes:
bash -f .ci/install_bats.sh
bash -f integration/kubernetes/run_kubernetes_tests.sh

swarm:
bash -f .ci/install_bats.sh
cd integration/swarm && \
bats swarm.bats

log-parser:
make -C cmd/log-parser

test: functional integration crio docker-compose kubernetes
test: functional integration crio docker-compose kubernetes swarm

check: checkcommits log-parser

.PHONY: check checkcommits integration ginkgo log-parser test crio functional docker-compose kubernetes
.PHONY: check checkcommits integration ginkgo log-parser test crio functional docker-compose kubernetes swarm
76 changes: 76 additions & 0 deletions integration/swarm/swarm.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bats
# *-*- Mode: sh; sh-basic-offset: 8; indent-tabs-mode: nil -*-*
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
# Swarm testing : This will start swarm as well as it will create and
# run swarm replicas using Nginx

# Image for swarm testing
nginx_image="gabyct/nginx"
# Name of service to test swarm
SERVICE_NAME="testswarm"
# Number of replicas that will be launch
number_of_replicas=1
# Timeout in seconds to verify replicas are running
timeout=10
# Retry number for the curl
number_of_retries=5
# SHIM PATH
SHIM_PATH="${SHIM_PATH:-/usr/libexec/kata-containers/kata-shim}"
# PROXY PATH
PROXY_PATH="${PROXY_PATH:-/usr/libexec/kata-containers/kata-proxy}"

# This function checks if active processes were
# left behind by kata-runtime.

check_processes() {
process=$1
pgrep -f "$process"
if [ $? -eq 0 ]; then
echo "Found unexpected ${process} present"
ps -ef | grep $process
return 1
fi
}

setup() {
interfaces=$(basename -a /sys/class/net/*)
swarm_interface_arg=""
for i in ${interfaces[@]}; do
if [ "$(cat /sys/class/net/${i}/operstate)" == "up" ]; then
swarm_interface_arg="--advertise-addr ${i}"
break;
fi
done
docker swarm init ${swarm_interface_arg}
nginx_command="hostname > /usr/share/nginx/html/hostname; nginx -g \"daemon off;\""
docker service create \
--name "${SERVICE_NAME}" --replicas $number_of_replicas \
--publish 8080:80 "${nginx_image}" sh -c "$nginx_command"
running_regex='Running\s+\d+\s(seconds|minutes)\s+ago'
for i in $(seq "$timeout") ; do
docker service ls --filter name="$SERVICE_NAME"
replicas_running=$(docker service ps "$SERVICE_NAME" | grep -c -P "${running_regex}")
if [ "$replicas_running" -ge "$number_of_replicas" ]; then
break
fi
sleep 1
done
}

@test "check_replicas_interfaces" {
# here we are checking that each replica has two interfaces
# and they should be always eth0 and eth1
REPLICA_ID=$(docker ps -q)
docker exec ${REPLICA_ID} sh -c "ip route show | grep -E eth0 && ip route show | grep -E eth1" > /dev/null
}

teardown() {
docker service remove "${SERVICE_NAME}"
docker swarm leave --force
check_processes ${PROXY_PATH}
check_processes ${SHIM_PATH}
}

0 comments on commit 74fec7c

Please sign in to comment.