github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/e2e/podman/podman.go (about)

     1  package podman
     2  
     3  import (
     4  	"github.com/hashicorp/nomad/e2e/e2eutil"
     5  	"github.com/hashicorp/nomad/e2e/framework"
     6  	"github.com/hashicorp/nomad/helper/uuid"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  type PodmanTest struct {
    11  	framework.TC
    12  	jobIDs []string
    13  }
    14  
    15  func init() {
    16  	framework.AddSuites(&framework.TestSuite{
    17  		Component:   "Podman",
    18  		CanRunLocal: true,
    19  		Cases: []framework.TestCase{
    20  			new(PodmanTest),
    21  		},
    22  	})
    23  }
    24  
    25  func (tc *PodmanTest) BeforeAll(f *framework.F) {
    26  	e2eutil.WaitForLeader(f.T(), tc.Nomad())
    27  	e2eutil.WaitForNodesReady(f.T(), tc.Nomad(), 2)
    28  }
    29  
    30  func (tc *PodmanTest) TestRedisDeployment(f *framework.F) {
    31  	t := f.T()
    32  	// https://github.com/hashicorp/nomad-driver-podman/issues/57
    33  	t.Skip("skipping podman test until driver api issue is resolved")
    34  	nomadClient := tc.Nomad()
    35  	uuid := uuid.Generate()
    36  	jobID := "deployment" + uuid[0:8]
    37  	tc.jobIDs = append(tc.jobIDs, jobID)
    38  	e2eutil.RegisterAndWaitForAllocs(t, nomadClient, "podman/input/redis.nomad", jobID, "")
    39  	ds := e2eutil.DeploymentsForJob(t, nomadClient, jobID)
    40  	require.Equal(t, 1, len(ds))
    41  
    42  	jobs := nomadClient.Jobs()
    43  	allocs, _, err := jobs.Allocations(jobID, true, nil)
    44  	require.NoError(t, err)
    45  
    46  	var allocIDs []string
    47  	for _, alloc := range allocs {
    48  		allocIDs = append(allocIDs, alloc.ID)
    49  	}
    50  
    51  	// Wait for allocations to get past initial pending state
    52  	e2eutil.WaitForAllocsNotPending(t, nomadClient, allocIDs)
    53  
    54  	jobs = nomadClient.Jobs()
    55  	allocs, _, err = jobs.Allocations(jobID, true, nil)
    56  	require.NoError(t, err)
    57  
    58  	require.Len(t, allocs, 1)
    59  	require.Equal(t, allocs[0].ClientStatus, "running")
    60  }
    61  
    62  func (tc *PodmanTest) AfterEach(f *framework.F) {
    63  	nomadClient := tc.Nomad()
    64  
    65  	// Mark all nodes eligible
    66  	nodesAPI := tc.Nomad().Nodes()
    67  	nodes, _, _ := nodesAPI.List(nil)
    68  	for _, node := range nodes {
    69  		nodesAPI.ToggleEligibility(node.ID, true, nil)
    70  	}
    71  
    72  	jobs := nomadClient.Jobs()
    73  	// Stop all jobs in test
    74  	for _, id := range tc.jobIDs {
    75  		jobs.Deregister(id, true, nil)
    76  	}
    77  	tc.jobIDs = []string{}
    78  	// Garbage collect
    79  	nomadClient.System().GarbageCollect()
    80  }