Skip to content

Commit

Permalink
e2e: add hostname interpolation test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell committed Sep 9, 2021
1 parent b3f68e9 commit 62f1386
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions e2e/networking/inputs/docker_bridged_hostname_interpolation.nomad
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
job "networking" {
datacenters = ["dc1", "dc2"]

constraint {
attribute = "${attr.kernel.name}"
value = "linux"
}

group "bridged" {
network {
hostname = "mylittlepony-${NOMAD_ALLOC_INDEX}"
mode = "bridge"
}

task "sleep" {
driver = "docker"
config {
image = "busybox:1"
command = "/bin/sleep"
args = ["300"]
}
}
}
}
24 changes: 24 additions & 0 deletions e2e/networking/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,27 @@ func (tc *NetworkingE2ETest) TestNetworking_DockerBridgedHostname(f *framework.F
f.NoError(err, "failed to run hostname exec command")
f.Contains(hostsOutput, "mylittlepony", "/etc/hosts doesn't contain hostname entry")
}

func (tc *NetworkingE2ETest) TestNetworking_DockerBridgedHostnameInterpolation(f *framework.F) {

jobID := "test-networking-" + uuid.Generate()[0:8]
f.NoError(e2eutil.Register(jobID, "networking/inputs/docker_bridged_hostname_interpolation.nomad"))
tc.jobIDs = append(tc.jobIDs, jobID)
f.NoError(e2eutil.WaitForAllocStatusExpected(jobID, "default", []string{"running"}),
"job should be running with 1 alloc")

// Grab the allocations for the job.
allocs, _, err := tc.Nomad().Jobs().Allocations(jobID, false, nil)
f.NoError(err, "failed to get allocs for job")
f.Len(allocs, 1, "job should have one alloc")

// Run the hostname command within the allocation.
hostnameOutput, err := e2eutil.AllocExec(allocs[0].ID, "sleep", "hostname", "default", nil)
f.NoError(err, "failed to run hostname exec command")
f.Equal("mylittlepony-0", strings.TrimSpace(hostnameOutput), "incorrect hostname set within container")

// Check the /etc/hosts file for the correct IP address and hostname entry.
hostsOutput, err := e2eutil.AllocExec(allocs[0].ID, "sleep", "cat /etc/hosts", "default", nil)
f.NoError(err, "failed to run hostname exec command")
f.Contains(hostsOutput, "mylittlepony-0", "/etc/hosts doesn't contain hostname entry")
}

0 comments on commit 62f1386

Please sign in to comment.