Modularize tests.
This commit is contained in:
parent
797cbc81ad
commit
2c28030f5e
@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
source $SRCDIR/utils.sh
|
||||
|
||||
test_redis_nomad_job() {
|
||||
pushd ~/go/src/github.com/Roblox/nomad-driver-containerd/example
|
||||
|
||||
@ -16,7 +18,7 @@ test_redis_nomad_job() {
|
||||
# The actual container process might not be running yet.
|
||||
# We need to wait for actual container to start running before trying exec.
|
||||
echo "INFO: Wait for redis container to get into RUNNING state, before trying exec."
|
||||
is_redis_container_active
|
||||
is_container_active redis false
|
||||
|
||||
echo "INFO: Inspecting redis job."
|
||||
redis_status=$(nomad job inspect redis|jq -r '.Job .Status')
|
||||
@ -53,24 +55,4 @@ test_redis_nomad_job() {
|
||||
popd
|
||||
}
|
||||
|
||||
is_redis_container_active() {
|
||||
i="0"
|
||||
while test $i -lt 5
|
||||
do
|
||||
sudo CONTAINERD_NAMESPACE=nomad ctr task ls|grep -q RUNNING
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "INFO: redis container is up and running"
|
||||
break
|
||||
fi
|
||||
echo "INFO: redis container is down, sleep for 4 seconds."
|
||||
sleep 4s
|
||||
i=$[$i+1]
|
||||
done
|
||||
|
||||
if [ $i -ge 5 ]; then
|
||||
echo "ERROR: redis container didn't come up. exit 1."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
test_redis_nomad_job
|
||||
|
@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
source $SRCDIR/utils.sh
|
||||
|
||||
test_signal_handler_nomad_job() {
|
||||
pushd ~/go/src/github.com/Roblox/nomad-driver-containerd/example
|
||||
|
||||
@ -24,7 +26,7 @@ test_signal_handler_nomad_job() {
|
||||
# The actual container process might not be running yet.
|
||||
# We need to wait for actual container to start running before trying to send invalid signal.
|
||||
echo "INFO: Wait for signal container to get into RUNNING state, before trying to send invalid signal."
|
||||
is_signal_container_active
|
||||
is_container_active signal false
|
||||
|
||||
echo "INFO: Test invalid signal."
|
||||
alloc_id=$(nomad job status signal|awk 'END{print}'|cut -d ' ' -f 1)
|
||||
@ -55,24 +57,4 @@ cleanup() {
|
||||
rm $tmpfile > /dev/null 2>&1
|
||||
}
|
||||
|
||||
is_signal_container_active() {
|
||||
i="0"
|
||||
while test $i -lt 5
|
||||
do
|
||||
sudo CONTAINERD_NAMESPACE=nomad ctr task ls|grep -q RUNNING
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "INFO: signal container is up and running"
|
||||
break
|
||||
fi
|
||||
echo "INFO: signal container is down, sleep for 4 seconds."
|
||||
sleep 4s
|
||||
i=$[$i+1]
|
||||
done
|
||||
|
||||
if [ $i -ge 5 ]; then
|
||||
echo "ERROR: signal container didn't come up. exit 1."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
test_signal_handler_nomad_job
|
||||
|
@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
source $SRCDIR/utils.sh
|
||||
|
||||
# readonly_rootfs, cap_add and cap_drop flags are tested as part of this test.
|
||||
test_capabilities_nomad_job() {
|
||||
pushd ~/go/src/github.com/Roblox/nomad-driver-containerd/example
|
||||
@ -18,7 +20,7 @@ test_capabilities_nomad_job() {
|
||||
# The actual container process might not be running yet.
|
||||
# We need to wait for actual container to start running before trying exec.
|
||||
echo "INFO: Wait for capabilities container to get into RUNNING state, before trying exec."
|
||||
is_capabilities_container_active
|
||||
is_container_active capabilities true
|
||||
|
||||
echo "INFO: Inspecting capabilities job."
|
||||
cap_status=$(nomad job inspect capabilities|jq -r '.Job .Status')
|
||||
@ -74,25 +76,4 @@ cleanup() {
|
||||
rm $tmpfile > /dev/null 2>&1
|
||||
}
|
||||
|
||||
is_capabilities_container_active() {
|
||||
i="0"
|
||||
while test $i -lt 5
|
||||
do
|
||||
sudo CONTAINERD_NAMESPACE=nomad ctr task ls|grep -q RUNNING
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "INFO: capabilities container is up and running"
|
||||
sleep 5s
|
||||
break
|
||||
fi
|
||||
echo "INFO: capabilities container is down, sleep for 4 seconds."
|
||||
sleep 4s
|
||||
i=$[$i+1]
|
||||
done
|
||||
|
||||
if [ $i -ge 5 ]; then
|
||||
echo "ERROR: capabilities container didn't come up. exit 1."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
test_capabilities_nomad_job
|
||||
|
@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
source $SRCDIR/utils.sh
|
||||
|
||||
# privileged mode, devices and mounts are tested as part of this test.
|
||||
test_privileged_nomad_job() {
|
||||
pushd ~/go/src/github.com/Roblox/nomad-driver-containerd/example
|
||||
@ -20,7 +22,7 @@ test_privileged_nomad_job() {
|
||||
# The actual container process might not be running yet.
|
||||
# We need to wait for actual container to start running before trying exec.
|
||||
echo "INFO: Wait for privileged container to get into RUNNING state, before trying exec."
|
||||
is_privileged_container_active
|
||||
is_container_active privileged true
|
||||
|
||||
echo "INFO: Inspecting privileged job."
|
||||
job_status=$(nomad job inspect privileged|jq -r '.Job .Status')
|
||||
@ -73,25 +75,4 @@ setup_bind_source() {
|
||||
echo hello > /tmp/s1/bind.txt
|
||||
}
|
||||
|
||||
is_privileged_container_active() {
|
||||
i="0"
|
||||
while test $i -lt 5
|
||||
do
|
||||
sudo CONTAINERD_NAMESPACE=nomad ctr task ls|grep -q RUNNING
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "INFO: privileged container is up and running"
|
||||
sleep 5s
|
||||
break
|
||||
fi
|
||||
echo "INFO: privileged container is down, sleep for 4 seconds."
|
||||
sleep 4s
|
||||
i=$[$i+1]
|
||||
done
|
||||
|
||||
if [ $i -ge 5 ]; then
|
||||
echo "ERROR: privileged container didn't come up. exit 1."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
test_privileged_nomad_job
|
||||
|
@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
source $SRCDIR/utils.sh
|
||||
|
||||
job_name=volume_mount
|
||||
host_volume_path=/tmp/host_volume/s1
|
||||
|
||||
@ -16,7 +18,7 @@ test_volume_mount_nomad_job() {
|
||||
# The actual container process might not be running yet.
|
||||
# We need to wait for actual container to start running before trying exec.
|
||||
echo "INFO: Wait for ${job_name} container to get into RUNNING state, before trying exec."
|
||||
is_${job_name}_container_active
|
||||
is_container_active ${job_name} true
|
||||
|
||||
echo "INFO: Checking status of $job_name job."
|
||||
job_status=$(nomad job status -short $job_name|grep Status|awk '{split($0,a,"="); print a[2]}'|tr -d ' ')
|
||||
@ -71,25 +73,4 @@ setup_bind_source() {
|
||||
echo hello > ${host_volume_path}/bind.txt
|
||||
}
|
||||
|
||||
is_volume_mount_container_active() {
|
||||
i="0"
|
||||
while test $i -lt 5
|
||||
do
|
||||
sudo CONTAINERD_NAMESPACE=nomad ctr task ls|grep -q RUNNING
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "INFO: ${job_name} container is up and running"
|
||||
sleep 5s
|
||||
break
|
||||
fi
|
||||
echo "INFO: ${job_name} container is down, sleep for 4 seconds."
|
||||
sleep 4s
|
||||
i=$[$i+1]
|
||||
done
|
||||
|
||||
if [ $i -ge 5 ]; then
|
||||
echo "ERROR: ${job_name} container didn't come up. exit 1."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
test_volume_mount_nomad_job
|
||||
|
@ -1,5 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
source $SRCDIR/utils.sh
|
||||
|
||||
job_name=dns
|
||||
|
||||
test_dns_nomad_job() {
|
||||
@ -12,7 +14,7 @@ test_dns_nomad_job() {
|
||||
# The actual container process might not be running yet.
|
||||
# We need to wait for actual container to start running before trying exec.
|
||||
echo "INFO: Wait for ${job_name} container to get into RUNNING state, before trying exec."
|
||||
is_${job_name}_container_active
|
||||
is_container_active ${job_name} true
|
||||
|
||||
echo "INFO: Checking status of $job_name job."
|
||||
job_status=$(nomad job status -short $job_name|grep Status|awk '{split($0,a,"="); print a[2]}'|tr -d ' ')
|
||||
@ -58,25 +60,4 @@ test_dns_nomad_job() {
|
||||
popd
|
||||
}
|
||||
|
||||
is_dns_container_active() {
|
||||
i="0"
|
||||
while test $i -lt 5
|
||||
do
|
||||
sudo CONTAINERD_NAMESPACE=nomad ctr task ls|grep -q RUNNING
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "INFO: ${job_name} container is up and running"
|
||||
sleep 5s
|
||||
break
|
||||
fi
|
||||
echo "INFO: ${job_name} container is down, sleep for 4 seconds."
|
||||
sleep 4s
|
||||
i=$[$i+1]
|
||||
done
|
||||
|
||||
if [ $i -ge 5 ]; then
|
||||
echo "ERROR: ${job_name} container didn't come up. exit 1."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
test_dns_nomad_job
|
||||
|
@ -12,6 +12,8 @@ else
|
||||
export GOPATH=$HOME/go
|
||||
fi
|
||||
export GO_VERSION=1.14.3
|
||||
export SRCDIR=`dirname $0`
|
||||
source $SRCDIR/utils.sh
|
||||
|
||||
# Keeps track of overall pass/failure status of tests. Even if single test
|
||||
# fails, PASS_STATUS will be set to 1 and returned to caller when all
|
||||
@ -47,11 +49,10 @@ run_test () {
|
||||
}
|
||||
|
||||
run_tests() {
|
||||
local srcdir=`dirname $0`
|
||||
if [ $# -gt 0 ]; then
|
||||
local files=$@
|
||||
else
|
||||
local files="$srcdir/[0-9][0-9][0-9]-test-*"
|
||||
local files="$SRCDIR/[0-9][0-9][0-9]-test-*"
|
||||
fi
|
||||
for t in $files;do
|
||||
run_test ./$t
|
||||
|
27
tests/utils.sh
Executable file
27
tests/utils.sh
Executable file
@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
is_container_active() {
|
||||
local job_name=$1
|
||||
local is_sleep=$2
|
||||
|
||||
i="0"
|
||||
while test $i -lt 5
|
||||
do
|
||||
sudo CONTAINERD_NAMESPACE=nomad ctr task ls|grep -q RUNNING
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "INFO: ${job_name} container is up and running"
|
||||
if [ "$is_sleep" = true ]; then
|
||||
sleep 5s
|
||||
fi
|
||||
break
|
||||
fi
|
||||
echo "INFO: ${job_name} container is down, sleep for 4 seconds."
|
||||
sleep 4s
|
||||
i=$[$i+1]
|
||||
done
|
||||
|
||||
if [ $i -ge 5 ]; then
|
||||
echo "ERROR: ${job_name} container didn't come up. exit 1."
|
||||
exit 1
|
||||
fi
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user