|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +source $SRCDIR/utils.sh |
| 4 | + |
| 5 | +job_name=extra_hosts |
| 6 | + |
| 7 | +test_extra_hosts_nomad_job() { |
| 8 | + pushd ~/go/src/github.com/Roblox/nomad-driver-containerd/example |
| 9 | + |
| 10 | + echo "INFO: Starting nomad $job_name job using nomad-driver-containerd." |
| 11 | + nomad job run $job_name.nomad |
| 12 | + |
| 13 | + # Even though $(nomad job status) reports job status as "running" |
| 14 | + # The actual container process might not be running yet. |
| 15 | + # We need to wait for actual container to start running before trying exec. |
| 16 | + echo "INFO: Wait for ${job_name} container to get into RUNNING state, before trying exec." |
| 17 | + is_container_active ${job_name} true |
| 18 | + |
| 19 | + echo "INFO: Checking status of $job_name job." |
| 20 | + job_status=$(nomad job status -short $job_name|grep Status|awk '{split($0,a,"="); print a[2]}'|tr -d ' ') |
| 21 | + if [ "$job_status" != "running" ];then |
| 22 | + echo "ERROR: Error in getting ${job_name} job status." |
| 23 | + return 1 |
| 24 | + fi |
| 25 | + |
| 26 | + echo "INFO: Checking extra hosts info in /etc/hosts." |
| 27 | + output=$(nomad alloc exec -job ${job_name} cat /etc/hosts) |
| 28 | + for host in "127.0.1.1 postgres" "127.0.1.2 redis" ; do |
| 29 | + echo -e "$output" |grep "$host" &>/dev/null |
| 30 | + if [ $? -ne 0 ];then |
| 31 | + echo "ERROR: extra host $host not found." |
| 32 | + return 1 |
| 33 | + fi |
| 34 | + done |
| 35 | + |
| 36 | + echo "INFO: Stopping nomad ${job_name} job." |
| 37 | + nomad job stop ${job_name} |
| 38 | + job_status=$(nomad job status -short ${job_name}|grep Status|awk '{split($0,a,"="); print a[2]}'|tr -d ' ') |
| 39 | + if [ $job_status != "dead(stopped)" ];then |
| 40 | + echo "ERROR: Error in stopping ${job_name} job." |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + |
| 44 | + echo "INFO: purge nomad ${job_name} job." |
| 45 | + nomad job stop -purge ${job_name} |
| 46 | + popd |
| 47 | +} |
| 48 | + |
| 49 | +test_extra_hosts_nomad_job |
0 commit comments