Commit 0c2c3568 authored by Michael Schurter's avatar Michael Schurter
Browse files

Skip tests that require root when not root

Also skip Chown on allocdir migration on Windows and when non-root.
Windows doesn't support it, and it will always fail as a non-root user.
parent 0a5e4ee5
Showing with 20 additions and 3 deletions
+20 -3
......@@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"sync"
"syscall"
"time"
"github.com/hashicorp/consul/lib"
......@@ -517,9 +518,14 @@ func (p *remotePrevAlloc) streamAllocDir(ctx context.Context, resp io.ReadCloser
f.Close()
return fmt.Errorf("error chmoding file %v", err)
}
if err := f.Chown(hdr.Uid, hdr.Gid); err != nil {
f.Close()
return fmt.Errorf("error chowning file %v", err)
// Can't change owner if not root. Returns false on
// Windows as Chown always errors there.
if syscall.Geteuid() == 0 {
if err := f.Chown(hdr.Uid, hdr.Gid); err != nil {
f.Close()
return fmt.Errorf("error chowning file %v", err)
}
}
// We write in chunks so that we can test if the client
......
......@@ -10,6 +10,7 @@ import (
"time"
"github.com/hashicorp/nomad/client/config"
ctestutil "github.com/hashicorp/nomad/client/testutil"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/testutil"
lxc "gopkg.in/lxc/go-lxc.v2"
......@@ -61,6 +62,7 @@ func TestLxcDriver_Start_Wait(t *testing.T) {
if !lxcPresent(t) {
t.Skip("lxc not present")
}
ctestutil.RequireRoot(t)
task := &structs.Task{
Name: "foo",
......@@ -137,6 +139,7 @@ func TestLxcDriver_Open_Wait(t *testing.T) {
if !lxcPresent(t) {
t.Skip("lxc not present")
}
ctestutil.RequireRoot(t)
task := &structs.Task{
Name: "foo",
......
......@@ -127,6 +127,7 @@ func TestQemuDriver_GracefulShutdown(t *testing.T) {
t.Parallel()
}
ctestutils.QemuCompatible(t)
ctestutils.RequireRoot(t)
task := &structs.Task{
Name: "linux",
Driver: "qemu",
......
......@@ -7,6 +7,13 @@ import (
"testing"
)
// RequireRoot skips tests unless running on a Unix as root.
func RequireRoot(t *testing.T) {
if syscall.Geteuid() != 0 {
t.Skip("Must run as root on Unix")
}
}
func ExecCompatible(t *testing.T) {
if runtime.GOOS != "linux" || syscall.Geteuid() != 0 {
t.Skip("Test only available running as root on linux")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment