Skip to content

Commit

Permalink
exec2: more tweaks to driver harness (#20221)
Browse files Browse the repository at this point in the history
Also add an explicit exit code to subproc package for when a child
process is instructed to run an unrunnable command (i.e. cannot be
found or is not executable) - with the 127 return code folks using bash
are familiar with
  • Loading branch information
shoenig authored Mar 26, 2024
1 parent a50e626 commit 77889a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 6 additions & 3 deletions helper/subproc/subproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ import (

const (
// ExitSuccess indicates the subprocess completed successfully.
ExitSuccess = iota
ExitSuccess = 0

// ExitFailure indicates the subprocess terminated unsuccessfully.
ExitFailure
ExitFailure = 1

// ExitTimeout indicates the subprocess timed out before completion.
ExitTimeout
ExitTimeout = 2

// ExitNotRunnable indicates a command cannot be run.
ExitNotRunnable = 127 // bash-ism
)

// MainFunc is the function that runs for this sub-process.
Expand Down
13 changes: 11 additions & 2 deletions plugins/drivers/testutils/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ func (h *DriverHarness) MkAllocDir(t *drivers.TaskConfig, enableLogs bool) func(
dir, err := os.MkdirTemp("", "nomad_driver_harness-")
must.NoError(h.t, err)

allocDir := allocdir.NewAllocDir(h.logger, dir, dir, t.AllocID)
mountsDir, err := os.MkdirTemp("", "nomad_driver_harness-mounts-")
must.NoError(h.t, err)
must.NoError(h.t, os.Chmod(mountsDir, 0755))

allocDir := allocdir.NewAllocDir(h.logger, dir, mountsDir, t.AllocID)
must.NoError(h.t, allocDir.Build())

t.AllocDir = allocDir.AllocDir
Expand Down Expand Up @@ -261,7 +265,12 @@ func SetEnvvars(envBuilder *taskenv.Builder, fsmode fsisolation.Mode, taskDir *a

// Set driver-specific environment variables
switch fsmode {
case fsisolation.None, fsisolation.Unveil:
case fsisolation.Unveil:
// Use mounts host paths
envBuilder.SetAllocDir(filepath.Join(taskDir.MountsAllocDir, "alloc"))
envBuilder.SetTaskLocalDir(filepath.Join(taskDir.MountsTaskDir, "local"))
envBuilder.SetSecretsDir(filepath.Join(taskDir.SecretsDir, "secrets"))
case fsisolation.None:
// Use host paths
envBuilder.SetAllocDir(taskDir.SharedAllocDir)
envBuilder.SetTaskLocalDir(taskDir.LocalDir)
Expand Down

0 comments on commit 77889a1

Please sign in to comment.