Skip to content

Commit c94fd39

Browse files
Add extra_hosts integration test.
1 parent b3b891f commit c94fd39

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

example/extra_hosts.nomad

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
job "extra_hosts" {
2+
datacenters = ["dc1"]
3+
4+
group "extra_hosts-group" {
5+
task "extra_hosts-task" {
6+
driver = "containerd-driver"
7+
config {
8+
image = "docker.io/library/ubuntu:16.04"
9+
extra_hosts = ["postgres:127.0.1.1", "redis:127.0.1.2"]
10+
host_network = true
11+
command = "sleep"
12+
args = ["600s"]
13+
}
14+
15+
resources {
16+
cpu = 500
17+
memory = 256
18+
}
19+
}
20+
}
21+
}

tests/007-test-extra-hosts.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)