2018-01-24 13:01:37 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2018-10-11 19:42:08 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
2018-01-24 13:01:37 +00:00
|
|
|
"github.com/hashicorp/nomad/client/config"
|
2018-06-11 20:33:18 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/testlog"
|
2018-10-11 19:42:08 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/base"
|
|
|
|
"github.com/hashicorp/nomad/plugins/shared/loader"
|
2018-01-24 13:01:37 +00:00
|
|
|
"github.com/hashicorp/nomad/testutil"
|
|
|
|
"github.com/stretchr/testify/require"
|
2018-10-10 03:01:20 +00:00
|
|
|
|
|
|
|
// registering raw_exec driver plugin used in testing
|
|
|
|
_ "github.com/hashicorp/nomad/drivers/rawexec"
|
2018-01-24 13:01:37 +00:00
|
|
|
)
|
|
|
|
|
2018-02-05 23:02:52 +00:00
|
|
|
func TestFingerprintManager_Run_MockDriver(t *testing.T) {
|
2018-10-10 03:01:20 +00:00
|
|
|
t.Skip("missing mock driver plugin implementation")
|
2018-01-24 13:01:37 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
2018-04-12 21:29:30 +00:00
|
|
|
testClient := TestClient(t, nil)
|
2018-03-14 17:10:41 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-01-24 13:01:37 +00:00
|
|
|
|
2018-02-05 23:02:52 +00:00
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-02-23 22:52:06 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromDriver,
|
2018-09-16 00:48:59 +00:00
|
|
|
testlog.HCLogger(t),
|
2018-02-05 23:02:52 +00:00
|
|
|
)
|
2018-01-24 13:01:37 +00:00
|
|
|
|
2018-02-05 23:02:52 +00:00
|
|
|
err := fm.Run()
|
2018-01-24 13:01:37 +00:00
|
|
|
require.Nil(err)
|
2018-03-14 17:10:41 +00:00
|
|
|
|
|
|
|
node := testClient.config.Node
|
|
|
|
|
2018-04-12 21:29:30 +00:00
|
|
|
require.NotNil(node.Drivers["mock_driver"])
|
|
|
|
require.True(node.Drivers["mock_driver"].Detected)
|
|
|
|
require.True(node.Drivers["mock_driver"].Healthy)
|
2018-01-24 13:01:37 +00:00
|
|
|
}
|
|
|
|
|
2018-02-14 19:35:15 +00:00
|
|
|
func TestFingerprintManager_Run_ResourcesFingerprint(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
2018-04-12 21:29:30 +00:00
|
|
|
testClient := TestClient(t, nil)
|
2018-03-14 17:10:41 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-02-14 19:35:15 +00:00
|
|
|
|
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-02-23 22:52:06 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromDriver,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.logger,
|
2018-02-14 19:35:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
err := fm.Run()
|
|
|
|
require.Nil(err)
|
2018-03-14 17:10:41 +00:00
|
|
|
|
|
|
|
node := testClient.config.Node
|
|
|
|
|
2018-02-14 19:35:15 +00:00
|
|
|
require.NotEqual(0, node.Resources.CPU)
|
|
|
|
require.NotEqual(0, node.Resources.MemoryMB)
|
2018-02-23 20:01:57 +00:00
|
|
|
require.NotZero(node.Resources.DiskMB)
|
2018-02-14 19:35:15 +00:00
|
|
|
}
|
|
|
|
|
2018-02-05 23:02:52 +00:00
|
|
|
func TestFingerprintManager_Fingerprint_Run(t *testing.T) {
|
2018-01-24 13:01:37 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient := TestClient(t, func(c *config.Config) {
|
|
|
|
c.Options = map[string]string{
|
|
|
|
"driver.raw_exec.enable": "true",
|
|
|
|
}
|
|
|
|
})
|
2018-03-14 17:10:41 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-01-24 13:01:37 +00:00
|
|
|
|
2018-02-05 23:02:52 +00:00
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-02-23 22:52:06 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromDriver,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.logger,
|
2018-02-05 23:02:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
err := fm.Run()
|
2018-01-24 13:01:37 +00:00
|
|
|
require.Nil(err)
|
|
|
|
|
2018-03-14 17:10:41 +00:00
|
|
|
node := testClient.config.Node
|
|
|
|
|
2018-04-12 21:29:30 +00:00
|
|
|
require.NotNil(node.Drivers["raw_exec"])
|
2018-01-25 16:30:15 +00:00
|
|
|
require.True(node.Drivers["raw_exec"].Detected)
|
2018-03-07 16:58:14 +00:00
|
|
|
require.True(node.Drivers["raw_exec"].Healthy)
|
2018-01-24 13:01:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFingerprintManager_Fingerprint_Periodic(t *testing.T) {
|
2018-10-10 03:01:20 +00:00
|
|
|
t.Skip("missing mock driver plugin implementation")
|
2018-01-24 13:01:37 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient := TestClient(t, func(c *config.Config) {
|
|
|
|
c.Options = map[string]string{
|
|
|
|
"test.shutdown_periodic_after": "true",
|
|
|
|
"test.shutdown_periodic_duration": "2",
|
|
|
|
}
|
|
|
|
})
|
2018-01-24 13:01:37 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-02-05 17:20:07 +00:00
|
|
|
|
2018-02-05 23:02:52 +00:00
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-02-23 22:52:06 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromDriver,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.logger,
|
2018-02-05 23:02:52 +00:00
|
|
|
)
|
2018-01-24 13:01:37 +00:00
|
|
|
|
2018-02-05 23:02:52 +00:00
|
|
|
err := fm.Run()
|
2018-01-24 13:01:37 +00:00
|
|
|
require.Nil(err)
|
|
|
|
|
2018-03-03 01:21:13 +00:00
|
|
|
{
|
|
|
|
// Ensure the mock driver is registered and healthy on the client
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
fm.nodeLock.Lock()
|
2018-03-14 17:10:41 +00:00
|
|
|
defer fm.nodeLock.Unlock()
|
2018-04-12 21:29:30 +00:00
|
|
|
node := fm.node
|
|
|
|
dinfo, ok := node.Drivers["mock_driver"]
|
|
|
|
if !ok || !dinfo.Detected || !dinfo.Healthy {
|
|
|
|
return false, fmt.Errorf("mock driver should be detected and healthy: %+v", dinfo)
|
2018-03-03 01:21:13 +00:00
|
|
|
}
|
2018-04-12 21:29:30 +00:00
|
|
|
|
2018-03-03 01:21:13 +00:00
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
})
|
|
|
|
}
|
2018-01-25 16:30:15 +00:00
|
|
|
// Ensure that the client fingerprinter eventually removes this attribute and
|
|
|
|
// marks the driver as unhealthy
|
2018-03-03 01:21:13 +00:00
|
|
|
{
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
fm.nodeLock.Lock()
|
2018-03-14 17:10:41 +00:00
|
|
|
defer fm.nodeLock.Unlock()
|
2018-04-12 21:29:30 +00:00
|
|
|
node := fm.node
|
|
|
|
dinfo, ok := node.Drivers["mock_driver"]
|
|
|
|
if !ok || dinfo.Detected || dinfo.Healthy {
|
|
|
|
return false, fmt.Errorf("mock driver should not be detected and healthy")
|
2018-03-03 01:21:13 +00:00
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
})
|
|
|
|
}
|
2018-01-24 13:01:37 +00:00
|
|
|
}
|
2018-02-05 23:02:52 +00:00
|
|
|
|
2018-01-25 16:30:15 +00:00
|
|
|
// This is a temporary measure to check that a driver has both attributes on a
|
|
|
|
// node set as well as DriverInfo.
|
|
|
|
func TestFingerprintManager_HealthCheck_Driver(t *testing.T) {
|
2018-10-10 03:01:20 +00:00
|
|
|
t.Skip("missing mock driver plugin implementation")
|
2018-01-25 16:30:15 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient := TestClient(t, func(c *config.Config) {
|
|
|
|
c.Options = map[string]string{
|
|
|
|
"driver.raw_exec.enable": "1",
|
|
|
|
"test.shutdown_periodic_after": "true",
|
|
|
|
"test.shutdown_periodic_duration": "2",
|
|
|
|
}
|
|
|
|
})
|
2018-01-25 16:30:15 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-01-25 16:30:15 +00:00
|
|
|
|
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
|
|
|
testClient.updateNodeFromDriver,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.logger,
|
2018-01-25 16:30:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
err := fm.Run()
|
|
|
|
require.Nil(err)
|
|
|
|
|
|
|
|
// Ensure the mock driver is registered and healthy on the client
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
2018-03-14 17:10:41 +00:00
|
|
|
fm.nodeLock.Lock()
|
|
|
|
node := fm.node
|
|
|
|
defer fm.nodeLock.Unlock()
|
|
|
|
|
2018-01-25 16:30:15 +00:00
|
|
|
mockDriverAttribute := node.Attributes["driver.mock_driver"]
|
2018-04-12 21:52:50 +00:00
|
|
|
if mockDriverAttribute == "" {
|
|
|
|
return false, fmt.Errorf("mock driver info should be set on the client attributes")
|
2018-01-25 16:30:15 +00:00
|
|
|
}
|
|
|
|
mockDriverInfo := node.Drivers["mock_driver"]
|
|
|
|
if mockDriverInfo == nil {
|
|
|
|
return false, fmt.Errorf("mock driver info should be set on the client")
|
|
|
|
}
|
|
|
|
if !mockDriverInfo.Healthy {
|
|
|
|
return false, fmt.Errorf("mock driver info should be healthy")
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
})
|
|
|
|
|
|
|
|
// Ensure that a default driver without health checks enabled is registered and healthy on the client
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
2018-03-14 17:10:41 +00:00
|
|
|
fm.nodeLock.Lock()
|
|
|
|
node := fm.node
|
|
|
|
defer fm.nodeLock.Unlock()
|
|
|
|
|
2018-01-25 16:30:15 +00:00
|
|
|
rawExecAttribute := node.Attributes["driver.raw_exec"]
|
2018-04-12 21:52:50 +00:00
|
|
|
if rawExecAttribute == "" {
|
|
|
|
return false, fmt.Errorf("raw exec info should be set on the client attributes")
|
2018-01-25 16:30:15 +00:00
|
|
|
}
|
|
|
|
rawExecInfo := node.Drivers["raw_exec"]
|
|
|
|
if rawExecInfo == nil {
|
|
|
|
return false, fmt.Errorf("raw exec driver info should be set on the client")
|
|
|
|
}
|
|
|
|
if !rawExecInfo.Detected {
|
|
|
|
return false, fmt.Errorf("raw exec driver should be detected")
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
})
|
2018-03-07 16:58:14 +00:00
|
|
|
|
2018-04-12 21:52:50 +00:00
|
|
|
// Ensure the mock driver is registered
|
2018-03-07 16:58:14 +00:00
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
2018-03-14 17:10:41 +00:00
|
|
|
fm.nodeLock.Lock()
|
|
|
|
node := fm.node
|
|
|
|
defer fm.nodeLock.Unlock()
|
|
|
|
|
2018-03-07 16:58:14 +00:00
|
|
|
mockDriverAttribute := node.Attributes["driver.mock_driver"]
|
2018-04-12 21:52:50 +00:00
|
|
|
if mockDriverAttribute == "" {
|
|
|
|
return false, fmt.Errorf("mock driver info should set on the client attributes")
|
2018-03-07 16:58:14 +00:00
|
|
|
}
|
|
|
|
mockDriverInfo := node.Drivers["mock_driver"]
|
|
|
|
if mockDriverInfo == nil {
|
|
|
|
return false, fmt.Errorf("mock driver info should be set on the client")
|
|
|
|
}
|
|
|
|
if !mockDriverInfo.Healthy {
|
|
|
|
return false, fmt.Errorf("mock driver info should not be healthy")
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
})
|
2018-03-22 22:09:36 +00:00
|
|
|
|
|
|
|
// Ensure that we don't duplicate health check information on the driver
|
|
|
|
// health information
|
|
|
|
fm.nodeLock.Lock()
|
|
|
|
node := fm.node
|
|
|
|
fm.nodeLock.Unlock()
|
|
|
|
mockDriverAttributes := node.Drivers["mock_driver"].Attributes
|
2018-04-12 21:29:30 +00:00
|
|
|
require.NotContains(mockDriverAttributes, "driver.mock_driver")
|
2018-01-25 16:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFingerprintManager_HealthCheck_Periodic(t *testing.T) {
|
2018-10-10 03:01:20 +00:00
|
|
|
t.Skip("missing mock driver plugin implementation")
|
2018-01-25 16:30:15 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient := TestClient(t, func(c *config.Config) {
|
|
|
|
c.Options = map[string]string{
|
|
|
|
"test.shutdown_periodic_after": "true",
|
|
|
|
"test.shutdown_periodic_duration": "2",
|
|
|
|
}
|
|
|
|
})
|
2018-01-25 16:30:15 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-01-25 16:30:15 +00:00
|
|
|
|
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-03-03 01:21:13 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromDriver,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.logger,
|
2018-01-25 16:30:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
err := fm.Run()
|
|
|
|
require.Nil(err)
|
|
|
|
|
2018-03-03 01:21:13 +00:00
|
|
|
{
|
|
|
|
// Ensure the mock driver is registered and healthy on the client
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
fm.nodeLock.Lock()
|
2018-03-14 17:10:41 +00:00
|
|
|
node := fm.node
|
|
|
|
defer fm.nodeLock.Unlock()
|
|
|
|
|
2018-03-03 01:21:13 +00:00
|
|
|
mockDriverInfo := node.Drivers["mock_driver"]
|
|
|
|
if mockDriverInfo == nil {
|
|
|
|
return false, fmt.Errorf("mock driver info should be set on the client")
|
|
|
|
}
|
|
|
|
if !mockDriverInfo.Detected {
|
|
|
|
return false, fmt.Errorf("mock driver info should be detected")
|
|
|
|
}
|
|
|
|
if !mockDriverInfo.Healthy {
|
|
|
|
return false, fmt.Errorf("mock driver info should be healthy")
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Ensure that the client health check eventually removes this attribute and
|
|
|
|
// marks the driver as unhealthy
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
fm.nodeLock.Lock()
|
2018-03-14 17:10:41 +00:00
|
|
|
node := fm.node
|
|
|
|
defer fm.nodeLock.Unlock()
|
|
|
|
|
2018-03-03 01:21:13 +00:00
|
|
|
mockDriverInfo := node.Drivers["mock_driver"]
|
|
|
|
if mockDriverInfo == nil {
|
|
|
|
return false, fmt.Errorf("mock driver info should be set on the client")
|
|
|
|
}
|
|
|
|
if !mockDriverInfo.Detected {
|
|
|
|
return false, fmt.Errorf("mock driver info should be detected")
|
|
|
|
}
|
|
|
|
if !mockDriverInfo.Healthy {
|
|
|
|
return false, fmt.Errorf("mock driver info should be healthy")
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Ensure that the client health check eventually removes this attribute and
|
|
|
|
// marks the driver as unhealthy
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
fm.nodeLock.Lock()
|
2018-03-14 17:10:41 +00:00
|
|
|
node := fm.node
|
|
|
|
defer fm.nodeLock.Unlock()
|
|
|
|
|
2018-03-03 01:21:13 +00:00
|
|
|
mockDriverInfo := node.Drivers["mock_driver"]
|
|
|
|
if mockDriverInfo == nil {
|
|
|
|
return false, fmt.Errorf("mock driver info should be set on the client")
|
|
|
|
}
|
2018-03-09 17:28:01 +00:00
|
|
|
if mockDriverInfo.Detected {
|
2018-03-03 01:21:13 +00:00
|
|
|
return false, fmt.Errorf("mock driver should be detected")
|
|
|
|
}
|
|
|
|
if mockDriverInfo.Healthy {
|
|
|
|
return false, fmt.Errorf("mock driver should not be healthy")
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
})
|
|
|
|
}
|
2018-01-25 16:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFimgerprintManager_Run_InWhitelist(t *testing.T) {
|
2018-10-10 03:01:20 +00:00
|
|
|
t.Skip("missing mock driver plugin implementation")
|
2018-02-05 23:02:52 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
|
|
|
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient := TestClient(t, func(c *config.Config) {
|
|
|
|
c.Options = map[string]string{
|
|
|
|
"test.shutdown_periodic_after": "true",
|
|
|
|
"test.shutdown_periodic_duration": "2",
|
|
|
|
}
|
|
|
|
})
|
2018-02-05 23:02:52 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-02-05 23:02:52 +00:00
|
|
|
|
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-02-23 22:52:06 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromDriver,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.logger,
|
2018-02-05 23:02:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
err := fm.Run()
|
|
|
|
require.Nil(err)
|
2018-03-14 17:10:41 +00:00
|
|
|
|
|
|
|
node := testClient.config.Node
|
|
|
|
|
2018-02-05 23:02:52 +00:00
|
|
|
require.NotEqual(node.Attributes["cpu.frequency"], "")
|
|
|
|
}
|
|
|
|
|
2018-03-11 18:07:37 +00:00
|
|
|
func TestFingerprintManager_Run_InBlacklist(t *testing.T) {
|
2018-02-05 23:02:52 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient := TestClient(t, func(c *config.Config) {
|
|
|
|
c.Options = map[string]string{
|
|
|
|
"fingerprint.whitelist": " arch,memory,foo,bar ",
|
|
|
|
"fingerprint.blacklist": " cpu ",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-02-05 23:02:52 +00:00
|
|
|
|
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-02-23 22:52:06 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromDriver,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.logger,
|
2018-02-05 23:02:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
err := fm.Run()
|
|
|
|
require.Nil(err)
|
2018-03-14 17:10:41 +00:00
|
|
|
|
|
|
|
node := testClient.config.Node
|
|
|
|
|
2018-04-12 21:29:30 +00:00
|
|
|
require.NotContains(node.Attributes, "cpu.frequency")
|
2018-02-05 23:02:52 +00:00
|
|
|
require.NotEqual(node.Attributes["memory.totalbytes"], "")
|
|
|
|
}
|
|
|
|
|
2018-03-11 18:07:37 +00:00
|
|
|
func TestFingerprintManager_Run_Combination(t *testing.T) {
|
2018-02-05 23:02:52 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
|
|
|
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient := TestClient(t, func(c *config.Config) {
|
|
|
|
c.Options = map[string]string{
|
|
|
|
"fingerprint.whitelist": " arch,cpu,memory,foo,bar ",
|
|
|
|
"fingerprint.blacklist": " memory,nomad ",
|
|
|
|
}
|
|
|
|
})
|
2018-02-05 23:02:52 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-02-05 23:02:52 +00:00
|
|
|
|
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-02-23 22:52:06 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromDriver,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.logger,
|
2018-02-05 23:02:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
err := fm.Run()
|
|
|
|
require.Nil(err)
|
2018-03-14 17:10:41 +00:00
|
|
|
|
|
|
|
node := testClient.config.Node
|
|
|
|
|
2018-02-05 23:02:52 +00:00
|
|
|
require.NotEqual(node.Attributes["cpu.frequency"], "")
|
|
|
|
require.NotEqual(node.Attributes["cpu.arch"], "")
|
2018-04-12 21:29:30 +00:00
|
|
|
require.NotContains(node.Attributes, "memory.totalbytes")
|
|
|
|
require.NotContains(node.Attributes, "nomad.version")
|
2018-02-05 23:02:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-11 18:07:37 +00:00
|
|
|
func TestFingerprintManager_Run_WhitelistDrivers(t *testing.T) {
|
2018-02-05 23:02:52 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient := TestClient(t, func(c *config.Config) {
|
|
|
|
c.Options = map[string]string{
|
|
|
|
"driver.raw_exec.enable": "1",
|
|
|
|
"driver.whitelist": " raw_exec , foo ",
|
|
|
|
}
|
|
|
|
})
|
2018-02-05 23:02:52 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-02-05 23:02:52 +00:00
|
|
|
|
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-02-23 22:52:06 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromDriver,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.logger,
|
2018-02-05 23:02:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
err := fm.Run()
|
|
|
|
require.Nil(err)
|
2018-03-14 17:10:41 +00:00
|
|
|
|
|
|
|
node := testClient.config.Node
|
2018-04-12 21:29:30 +00:00
|
|
|
require.NotNil(node.Drivers["raw_exec"])
|
|
|
|
require.NotContains(node.Drivers, "java")
|
2018-02-05 23:02:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-11 18:07:37 +00:00
|
|
|
func TestFingerprintManager_Run_AllDriversBlacklisted(t *testing.T) {
|
2018-02-05 23:02:52 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
|
|
|
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient := TestClient(t, func(c *config.Config) {
|
|
|
|
c.Options = map[string]string{
|
2018-10-10 03:01:20 +00:00
|
|
|
"driver.raw_exec.enable": "1",
|
2018-03-14 17:10:41 +00:00
|
|
|
"driver.whitelist": " foo,bar,baz ",
|
|
|
|
}
|
|
|
|
})
|
2018-02-05 23:02:52 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-02-05 23:02:52 +00:00
|
|
|
|
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-02-23 22:52:06 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromDriver,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.logger,
|
2018-02-05 23:02:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
err := fm.Run()
|
|
|
|
require.Nil(err)
|
2018-03-14 17:10:41 +00:00
|
|
|
|
|
|
|
node := testClient.config.Node
|
|
|
|
|
2018-04-12 21:52:50 +00:00
|
|
|
require.NotContains(node.Attributes, "driver.raw_exec")
|
2018-10-11 00:08:57 +00:00
|
|
|
// TODO(nickethier): uncomment after missing driver implementations added
|
2018-10-10 03:01:20 +00:00
|
|
|
//require.NotContains(node.Attributes, "driver.exec")
|
|
|
|
//require.NotContains(node.Attributes, "driver.docker")
|
2018-02-05 23:02:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-11 18:07:37 +00:00
|
|
|
func TestFingerprintManager_Run_DriversWhiteListBlacklistCombination(t *testing.T) {
|
2018-02-05 23:02:52 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
|
|
|
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient := TestClient(t, func(c *config.Config) {
|
|
|
|
c.Options = map[string]string{
|
|
|
|
"driver.raw_exec.enable": "1",
|
|
|
|
"driver.whitelist": " raw_exec,exec,foo,bar,baz ",
|
|
|
|
"driver.blacklist": " exec,foo,bar,baz ",
|
|
|
|
}
|
|
|
|
})
|
2018-02-05 23:02:52 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-02-05 23:02:52 +00:00
|
|
|
|
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-02-23 22:52:06 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromDriver,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.logger,
|
2018-02-05 23:02:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
err := fm.Run()
|
|
|
|
require.Nil(err)
|
2018-03-14 17:10:41 +00:00
|
|
|
|
|
|
|
node := testClient.config.Node
|
|
|
|
|
2018-04-12 21:29:30 +00:00
|
|
|
require.NotNil(node.Drivers["raw_exec"])
|
|
|
|
require.NotContains(node.Drivers, "exec")
|
2018-02-05 23:02:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 19:42:08 +00:00
|
|
|
func TestFingerprintManager_Run_DriverFailure(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
testClient := TestClient(t, func(c *config.Config) {
|
|
|
|
c.Options = map[string]string{
|
|
|
|
"driver.raw_exec.enable": "1",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
testClient.logger = testlog.HCLogger(t)
|
|
|
|
defer testClient.Shutdown()
|
|
|
|
|
|
|
|
singLoader := testClient.config.PluginSingletonLoader
|
|
|
|
|
|
|
|
dispenseCalls := 0
|
|
|
|
loader := &loader.MockCatalog{
|
|
|
|
DispenseF: func(name, pluginType string, logger log.Logger) (loader.PluginInstance, error) {
|
|
|
|
if pluginType == base.PluginTypeDriver && name == "raw_exec" {
|
|
|
|
dispenseCalls++
|
|
|
|
}
|
|
|
|
return singLoader.Dispense(name, pluginType, logger)
|
|
|
|
},
|
|
|
|
ReattachF: singLoader.Reattach,
|
|
|
|
CatalogF: singLoader.Catalog,
|
|
|
|
}
|
|
|
|
|
|
|
|
fm := NewFingerprintManager(
|
|
|
|
loader,
|
|
|
|
testClient.GetConfig,
|
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
|
|
|
testClient.updateNodeFromFingerprint,
|
|
|
|
testClient.updateNodeFromDriver,
|
|
|
|
testClient.logger,
|
|
|
|
)
|
|
|
|
|
|
|
|
fpChan, cancel, err := fm.dispenseDriverFingerprint("raw_exec")
|
|
|
|
require.NoError(err)
|
|
|
|
require.Equal(1, dispenseCalls)
|
|
|
|
|
|
|
|
cancel()
|
|
|
|
go fm.watchDriverFingerprint(fpChan, "raw_exec", cancel)
|
|
|
|
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
if 2 != dispenseCalls {
|
|
|
|
return false, fmt.Errorf("expected dispenseCalls to be 2 but was %d", dispenseCalls)
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
require.NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-11 18:07:37 +00:00
|
|
|
func TestFingerprintManager_Run_DriversInBlacklist(t *testing.T) {
|
2018-02-05 23:02:52 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
|
|
|
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient := TestClient(t, func(c *config.Config) {
|
|
|
|
c.Options = map[string]string{
|
|
|
|
"driver.raw_exec.enable": "1",
|
|
|
|
"driver.whitelist": " raw_exec,foo,bar,baz ",
|
|
|
|
"driver.blacklist": " exec,foo,bar,baz ",
|
|
|
|
}
|
|
|
|
})
|
2018-02-05 23:02:52 +00:00
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
testClient.logger = testlog.HCLogger(t)
|
2018-03-14 17:10:41 +00:00
|
|
|
defer testClient.Shutdown()
|
2018-02-05 23:02:52 +00:00
|
|
|
|
|
|
|
fm := NewFingerprintManager(
|
2018-10-10 03:01:20 +00:00
|
|
|
testClient.config.PluginSingletonLoader,
|
2018-02-23 22:52:06 +00:00
|
|
|
testClient.GetConfig,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.config.Node,
|
|
|
|
testClient.shutdownCh,
|
2018-02-23 22:52:06 +00:00
|
|
|
testClient.updateNodeFromFingerprint,
|
2018-03-09 17:28:01 +00:00
|
|
|
testClient.updateNodeFromDriver,
|
2018-03-14 17:10:41 +00:00
|
|
|
testClient.logger,
|
2018-02-05 23:02:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
err := fm.Run()
|
|
|
|
require.Nil(err)
|
2018-03-14 17:10:41 +00:00
|
|
|
|
|
|
|
node := testClient.config.Node
|
|
|
|
|
2018-04-12 21:29:30 +00:00
|
|
|
require.NotNil(node.Drivers["raw_exec"])
|
|
|
|
require.NotContains(node.Drivers, "exec")
|
2018-02-05 23:02:52 +00:00
|
|
|
}
|