diff --git a/e2e/podman/doc.go b/e2e/podman/doc.go new file mode 100644 index 000000000..8dfdc7090 --- /dev/null +++ b/e2e/podman/doc.go @@ -0,0 +1,3 @@ +// Package podman contains test cases related to the nomad-driver-podman task +// driver. +package podman diff --git a/e2e/podman/input/podman_basic.hcl b/e2e/podman/input/podman_basic.hcl new file mode 100644 index 000000000..0719cc097 --- /dev/null +++ b/e2e/podman/input/podman_basic.hcl @@ -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 + } + } + } +} diff --git a/e2e/podman/input/redis.nomad b/e2e/podman/input/redis.nomad deleted file mode 100644 index e63b51aad..000000000 --- a/e2e/podman/input/redis.nomad +++ /dev/null @@ -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" {} - } - } - } - } -} diff --git a/e2e/podman/podman.go b/e2e/podman/podman.go deleted file mode 100644 index c4d629075..000000000 --- a/e2e/podman/podman.go +++ /dev/null @@ -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() -} diff --git a/e2e/podman/podman_test.go b/e2e/podman/podman_test.go new file mode 100644 index 000000000..11e81cbb4 --- /dev/null +++ b/e2e/podman/podman_test.go @@ -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") +}