From b390ff4f005bd37d96459827c64692724271352a Mon Sep 17 00:00:00 2001 From: Shishir Mahajan Date: Thu, 25 Mar 2021 16:40:14 -0700 Subject: [PATCH] entrypoint: Add integration test. --- example/entrypoint.nomad | 20 ++++++++++ tests/008-test-entrypoint.sh | 40 +++++++++++++++++++ ...ileged.sh => 009-test-allow-privileged.sh} | 0 3 files changed, 60 insertions(+) create mode 100644 example/entrypoint.nomad create mode 100755 tests/008-test-entrypoint.sh rename tests/{008-test-allow-privileged.sh => 009-test-allow-privileged.sh} (100%) diff --git a/example/entrypoint.nomad b/example/entrypoint.nomad new file mode 100644 index 0000000..4721969 --- /dev/null +++ b/example/entrypoint.nomad @@ -0,0 +1,20 @@ +job "entrypoint" { + datacenters = ["dc1"] + + group "entrypoint-group" { + task "entrypoint-task" { + driver = "containerd-driver" + + config { + image = "ubuntu:16.04" + entrypoint = ["/bin/echo"] + args = ["container1", "container2"] + } + + resources { + cpu = 500 + memory = 256 + } + } + } +} diff --git a/tests/008-test-entrypoint.sh b/tests/008-test-entrypoint.sh new file mode 100755 index 0000000..82e0f17 --- /dev/null +++ b/tests/008-test-entrypoint.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +source $SRCDIR/utils.sh + +job_name=entrypoint + +test_entrypoint_nomad_job() { + pushd ~/go/src/github.com/Roblox/nomad-driver-containerd/example + + echo "INFO: Starting nomad $job_name job using nomad-driver-containerd." + nomad job run $job_name.nomad + + # Even though $(nomad job status) reports job status as "running" + # The actual container process might not be running yet. + # We need to wait for actual container to start running before executing $(nomad alloc logs). + echo "INFO: Wait for ${job_name} container to get into RUNNING state." + 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 ' ') + if [ "$job_status" != "running" ];then + echo "ERROR: Error in getting ${job_name} job status." + return 1 + fi + + output=$(nomad logs -job ${job_name}) + for result in "container1" "container2" ; do + echo -e "$output" |grep "$result" &>/dev/null + if [ $? -ne 0 ];then + echo "ERROR: $result not found in the output." + return 1 + fi + done + + echo "INFO: purge nomad ${job_name} job." + nomad job stop -purge ${job_name} + popd +} + +test_entrypoint_nomad_job diff --git a/tests/008-test-allow-privileged.sh b/tests/009-test-allow-privileged.sh similarity index 100% rename from tests/008-test-allow-privileged.sh rename to tests/009-test-allow-privileged.sh