Merge pull request #1407 from hashicorp/f-resource-isolation-fingerprinter
Conditionalize platform tests
This commit is contained in:
commit
b58a58e47e
|
@ -5,6 +5,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/client/testutil"
|
||||
|
@ -12,6 +13,11 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
osMountSharedDirSupport = map[string]bool{
|
||||
"darwin": true,
|
||||
"linux": true,
|
||||
}
|
||||
|
||||
t1 = &structs.Task{
|
||||
Name: "web",
|
||||
Driver: "exec",
|
||||
|
@ -193,7 +199,11 @@ func TestAllocDir_MountSharedAlloc(t *testing.T) {
|
|||
for _, task := range tasks {
|
||||
// Mount and then check that the file exists in the task directory.
|
||||
if err := d.MountSharedDir(task.Name); err != nil {
|
||||
t.Fatalf("MountSharedDir(%v) failed: %v", task.Name, err)
|
||||
if v, ok := osMountSharedDirSupport[runtime.GOOS]; v && ok {
|
||||
t.Fatalf("MountSharedDir(%v) failed: %v", task.Name, err)
|
||||
} else {
|
||||
t.Skipf("MountShareDir(%v) failed, no OS support")
|
||||
}
|
||||
}
|
||||
|
||||
taskDir, ok := d.TaskDirs[task.Name]
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -22,7 +23,13 @@ import (
|
|||
ctestutil "github.com/hashicorp/nomad/client/testutil"
|
||||
)
|
||||
|
||||
var nextPort uint32 = 16000
|
||||
var (
|
||||
nextPort uint32 = 16000
|
||||
|
||||
osExecDriverSupport = map[string]bool{
|
||||
"linux": true,
|
||||
}
|
||||
)
|
||||
|
||||
func getPort() int {
|
||||
return int(atomic.AddUint32(&nextPort, 1))
|
||||
|
@ -225,7 +232,11 @@ func TestClient_Drivers(t *testing.T) {
|
|||
|
||||
node := c.Node()
|
||||
if node.Attributes["driver.exec"] == "" {
|
||||
t.Fatalf("missing exec driver")
|
||||
if v, ok := osExecDriverSupport[runtime.GOOS]; v && ok {
|
||||
t.Fatalf("missing exec driver")
|
||||
} else {
|
||||
t.Skipf("missing exec driver, no OS support")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,7 +253,11 @@ func TestClient_Drivers_InWhitelist(t *testing.T) {
|
|||
|
||||
node := c.Node()
|
||||
if node.Attributes["driver.exec"] == "" {
|
||||
t.Fatalf("missing exec driver")
|
||||
if v, ok := osExecDriverSupport[runtime.GOOS]; v && ok {
|
||||
t.Fatalf("missing exec driver")
|
||||
} else {
|
||||
t.Skipf("missing exec driver, no OS support")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//+build windows darwin dragonfly freebsd netbsd openbsd solaris
|
||||
//+build darwin dragonfly freebsd netbsd openbsd solaris windows
|
||||
|
||||
package driver
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -15,6 +16,12 @@ import (
|
|||
ctestutils "github.com/hashicorp/nomad/client/testutil"
|
||||
)
|
||||
|
||||
var (
|
||||
osJavaDriverSupport = map[string]bool{
|
||||
"linux": true,
|
||||
}
|
||||
)
|
||||
|
||||
// javaLocated checks whether java is installed so we can run java stuff.
|
||||
func javaLocated() bool {
|
||||
_, err := exec.Command("java", "-version").CombinedOutput()
|
||||
|
@ -40,7 +47,11 @@ func TestJavaDriver_Fingerprint(t *testing.T) {
|
|||
t.Fatalf("Fingerprinter should detect Java when it is installed")
|
||||
}
|
||||
if node.Attributes["driver.java"] != "1" {
|
||||
t.Fatalf("missing driver")
|
||||
if v, ok := osJavaDriverSupport[runtime.GOOS]; v && ok {
|
||||
t.Fatalf("missing java driver")
|
||||
} else {
|
||||
t.Skipf("missing java driver, no OS support")
|
||||
}
|
||||
}
|
||||
for _, key := range []string{"driver.java.version", "driver.java.runtime", "driver.java.vm"} {
|
||||
if node.Attributes[key] == "" {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build linux
|
||||
|
||||
package fingerprint
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
// +build !linux
|
||||
|
||||
package fingerprint
|
||||
|
||||
import (
|
||||
client "github.com/hashicorp/nomad/client/config"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
// FindCgroupMountpointDir returns an empty path on non-Linux systems
|
||||
func FindCgroupMountpointDir() (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// Fingerprint tries to find a valid cgroup moint point
|
||||
func (f *CGroupFingerprint) Fingerprint(cfg *client.Config, node *structs.Node) (bool, error) {
|
||||
return false, nil
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
// +build linux
|
||||
|
||||
package fingerprint
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// +build windows darwin dragonfly freebsd netbsd openbsd solaris
|
||||
// +build darwin dragonfly freebsd netbsd openbsd solaris windows
|
||||
|
||||
package fingerprint
|
||||
|
||||
|
|
|
@ -55,12 +55,11 @@ func (f *NetworkFingerprint) Fingerprint(cfg *config.Config, node *structs.Node)
|
|||
var ip string
|
||||
|
||||
intf, err := f.findInterface(cfg.NetworkInterface)
|
||||
if err != nil {
|
||||
switch {
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("Error while detecting network interface during fingerprinting: %v", err)
|
||||
}
|
||||
|
||||
// No interface could be found
|
||||
if intf == nil {
|
||||
case intf == nil:
|
||||
// No interface could be found
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -3,12 +3,17 @@ package fingerprint
|
|||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/client/config"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
// Set skipOnlineTestEnvVar to a non-empty value to skip network tests. Useful
|
||||
// when working offline (e.g. an airplane).
|
||||
const skipOnlineTestsEnvVar = "TEST_NOMAD_SKIP_ONLINE_NET"
|
||||
|
||||
var (
|
||||
lo = net.Interface{
|
||||
Index: 2,
|
||||
|
@ -138,6 +143,10 @@ func (n *NetworkInterfaceDetectorMultipleInterfaces) Addrs(intf *net.Interface)
|
|||
}
|
||||
|
||||
func TestNetworkFingerprint_basic(t *testing.T) {
|
||||
if v := os.Getenv(skipOnlineTestsEnvVar); v != "" {
|
||||
t.Skipf("Environment variable %+q not empty, skipping test", skipOnlineTestsEnvVar)
|
||||
}
|
||||
|
||||
f := &NetworkFingerprint{logger: testLogger(), interfaceDetector: &DefaultNetworkInterfaceDetector{}}
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
|
@ -149,7 +158,7 @@ func TestNetworkFingerprint_basic(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if !ok {
|
||||
t.Fatalf("should apply")
|
||||
t.Fatalf("should apply (HINT: working offline? Set env %q=y", skipOnlineTestsEnvVar)
|
||||
}
|
||||
|
||||
assertNodeAttributeContains(t, node, "unique.network.ip-address")
|
||||
|
|
Loading…
Reference in a new issue