e2e: modernize podman test suite (#17564)

Use the new style of e2e test for the podman suite ... which is all of
one test case that was skipped out. Turn the case back on, and we will
add more tests in the near future.
This commit is contained in:
Seth Hoenig
2023-06-16 10:36:17 -05:00
committed by GitHub
parent 2d7bead0ad
commit f5fcaba1c7
5 changed files with 71 additions and 119 deletions

3
e2e/podman/doc.go Normal file
View File

@@ -0,0 +1,3 @@
// Package podman contains test cases related to the nomad-driver-podman task
// driver.
package podman

View File

@@ -0,0 +1,32 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
job "podman_basic" {
constraint {
attribute = "${attr.kernel.name}"
value = "linux"
}
group "cache" {
network {
port "db" {
to = 6379
}
}
task "redis" {
driver = "podman"
config {
image = "redis:7"
ports = ["db"]
}
resources {
cpu = 50
memory = 128
}
}
}
}

View File

@@ -1,36 +0,0 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
job "podman-redis" {
datacenters = ["dc1"]
type = "service"
constraint {
attribute = "${attr.kernel.name}"
value = "linux"
}
group "redis" {
task "redis" {
driver = "podman"
config {
image = "docker://redis"
port_map {
redis = 6379
}
}
resources {
cpu = 500
memory = 256
network {
mbits = 20
port "redis" {}
}
}
}
}
}

View File

@@ -1,83 +0,0 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package podman
import (
"github.com/hashicorp/nomad/e2e/e2eutil"
"github.com/hashicorp/nomad/e2e/framework"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/stretchr/testify/require"
)
type PodmanTest struct {
framework.TC
jobIDs []string
}
func init() {
framework.AddSuites(&framework.TestSuite{
Component: "Podman",
CanRunLocal: true,
Cases: []framework.TestCase{
new(PodmanTest),
},
})
}
func (tc *PodmanTest) BeforeAll(f *framework.F) {
e2eutil.WaitForLeader(f.T(), tc.Nomad())
e2eutil.WaitForNodesReady(f.T(), tc.Nomad(), 2)
}
func (tc *PodmanTest) TestRedisDeployment(f *framework.F) {
t := f.T()
// https://github.com/hashicorp/nomad-driver-podman/issues/57
t.Skip("skipping podman test until driver api issue is resolved")
nomadClient := tc.Nomad()
uuid := uuid.Generate()
jobID := "deployment" + uuid[0:8]
tc.jobIDs = append(tc.jobIDs, jobID)
e2eutil.RegisterAndWaitForAllocs(t, nomadClient, "podman/input/redis.nomad", jobID, "")
ds := e2eutil.DeploymentsForJob(t, nomadClient, jobID)
require.Equal(t, 1, len(ds))
jobs := nomadClient.Jobs()
allocs, _, err := jobs.Allocations(jobID, true, nil)
require.NoError(t, err)
var allocIDs []string
for _, alloc := range allocs {
allocIDs = append(allocIDs, alloc.ID)
}
// Wait for allocations to get past initial pending state
e2eutil.WaitForAllocsNotPending(t, nomadClient, allocIDs)
jobs = nomadClient.Jobs()
allocs, _, err = jobs.Allocations(jobID, true, nil)
require.NoError(t, err)
require.Len(t, allocs, 1)
require.Equal(t, allocs[0].ClientStatus, "running")
}
func (tc *PodmanTest) AfterEach(f *framework.F) {
nomadClient := tc.Nomad()
// Mark all nodes eligible
nodesAPI := tc.Nomad().Nodes()
nodes, _, _ := nodesAPI.List(nil)
for _, node := range nodes {
nodesAPI.ToggleEligibility(node.ID, true, nil)
}
jobs := nomadClient.Jobs()
// Stop all jobs in test
for _, id := range tc.jobIDs {
jobs.Deregister(id, true, nil)
}
tc.jobIDs = []string{}
// Garbage collect
nomadClient.System().GarbageCollect()
}

36
e2e/podman/podman_test.go Normal file
View File

@@ -0,0 +1,36 @@
package podman
import (
"testing"
"github.com/hashicorp/nomad/e2e/e2eutil"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/shoenig/test/must"
)
func TestPodman(t *testing.T) {
nomad := e2eutil.NomadClient(t)
e2eutil.WaitForLeader(t, nomad)
e2eutil.WaitForNodesReady(t, nomad, 1)
t.Run("testBasic", testBasic)
}
func testBasic(t *testing.T) {
nomad := e2eutil.NomadClient(t)
jobID := "podman-basic-" + uuid.Short()
jobIDs := []string{jobID}
t.Cleanup(e2eutil.CleanupJobsAndGC(t, &jobIDs))
// start job
e2eutil.RegisterAndWaitForAllocs(t, nomad, "./input/podman_basic.hcl", jobID, "")
// get alloc id
allocID := e2eutil.SingleAllocID(t, jobID, "", 0)
// check logs for redis startup
logs, err := e2eutil.AllocTaskLogs(allocID, "redis", e2eutil.LogsStdOut)
must.NoError(t, err)
must.StrContains(t, logs, "oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo")
}