github.com/hernad/nomad@v1.6.112/e2e/isolation/devices_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package isolation
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/hernad/nomad/e2e/e2eutil"
    10  	"github.com/hernad/nomad/helper/uuid"
    11  	"github.com/shoenig/test/must"
    12  )
    13  
    14  func TestCgroupDevices(t *testing.T) {
    15  	nomad := e2eutil.NomadClient(t)
    16  
    17  	e2eutil.WaitForLeader(t, nomad)
    18  	e2eutil.WaitForNodesReady(t, nomad, 1)
    19  
    20  	t.Run("testDevicesUsable", testDevicesUsable)
    21  }
    22  
    23  func testDevicesUsable(t *testing.T) {
    24  	nomad := e2eutil.NomadClient(t)
    25  
    26  	jobID := "cgroup-devices-" + uuid.Short()
    27  	jobIDs := []string{jobID}
    28  	t.Cleanup(e2eutil.CleanupJobsAndGC(t, &jobIDs))
    29  
    30  	// start job
    31  	allocs := e2eutil.RegisterAndWaitForAllocs(t, nomad, "./input/cgroup_devices.hcl", jobID, "")
    32  	must.Len(t, 2, allocs)
    33  
    34  	// pick one to stop and one to verify
    35  	allocA := allocs[0].ID
    36  	allocB := allocs[1].ID
    37  
    38  	// verify devices are working
    39  	checkDev(t, allocA)
    40  	checkDev(t, allocB)
    41  
    42  	// stop the chosen alloc
    43  	_, err := e2eutil.Command("nomad", "alloc", "stop", "-detach", allocA)
    44  	must.NoError(t, err)
    45  	e2eutil.WaitForAllocStopped(t, nomad, allocA)
    46  
    47  	// verify device of remaining alloc
    48  	checkDev(t, allocB)
    49  }
    50  
    51  func checkDev(t *testing.T, allocID string) {
    52  	_, err := e2eutil.Command("nomad", "alloc", "exec", allocID, "dd", "if=/dev/zero", "of=/dev/null", "count=1")
    53  	must.NoError(t, err)
    54  }