open-nomad/client/fingerprint_manager_test.go
Nick Ethier 82175d1328
client/drivermananger: add driver manager
The driver manager is modeled after the device manager and is started by the client.
It's responsible for handling driver lifecycle and reattachment state, as well as
processing the incomming fingerprint and task events from each driver. The mananger
exposes a method for registering event handlers for task events that is used by the
task runner to update the server when a task has been updated with an event.

Since driver fingerprinting has been implemented by the driver manager, it is no
longer needed in the fingerprint mananger and has been removed.
2018-12-18 22:55:18 -05:00

124 lines
2.8 KiB
Go

package client
import (
"testing"
"github.com/hashicorp/nomad/client/config"
"github.com/stretchr/testify/require"
)
func TestFingerprintManager_Run_ResourcesFingerprint(t *testing.T) {
t.Parallel()
require := require.New(t)
testClient, cleanup := TestClient(t, nil)
defer cleanup()
fm := NewFingerprintManager(
testClient.config.PluginSingletonLoader,
testClient.GetConfig,
testClient.config.Node,
testClient.shutdownCh,
testClient.updateNodeFromFingerprint,
testClient.logger,
)
err := fm.Run()
require.Nil(err)
node := testClient.config.Node
require.NotEqual(0, node.Resources.CPU)
require.NotEqual(0, node.Resources.MemoryMB)
require.NotZero(node.Resources.DiskMB)
}
func TestFimgerprintManager_Run_InWhitelist(t *testing.T) {
t.Parallel()
require := require.New(t)
testClient, cleanup := TestClient(t, func(c *config.Config) {
c.Options = map[string]string{
"test.shutdown_periodic_after": "true",
"test.shutdown_periodic_duration": "2",
}
})
defer cleanup()
fm := NewFingerprintManager(
testClient.config.PluginSingletonLoader,
testClient.GetConfig,
testClient.config.Node,
testClient.shutdownCh,
testClient.updateNodeFromFingerprint,
testClient.logger,
)
err := fm.Run()
require.Nil(err)
node := testClient.config.Node
require.NotEqual(node.Attributes["cpu.frequency"], "")
}
func TestFingerprintManager_Run_InBlacklist(t *testing.T) {
t.Parallel()
require := require.New(t)
testClient, cleanup := TestClient(t, func(c *config.Config) {
c.Options = map[string]string{
"fingerprint.whitelist": " arch,memory,foo,bar ",
"fingerprint.blacklist": " cpu ",
}
})
defer cleanup()
fm := NewFingerprintManager(
testClient.config.PluginSingletonLoader,
testClient.GetConfig,
testClient.config.Node,
testClient.shutdownCh,
testClient.updateNodeFromFingerprint,
testClient.logger,
)
err := fm.Run()
require.Nil(err)
node := testClient.config.Node
require.NotContains(node.Attributes, "cpu.frequency")
require.NotEqual(node.Attributes["memory.totalbytes"], "")
}
func TestFingerprintManager_Run_Combination(t *testing.T) {
t.Parallel()
require := require.New(t)
testClient, cleanup := TestClient(t, func(c *config.Config) {
c.Options = map[string]string{
"fingerprint.whitelist": " arch,cpu,memory,foo,bar ",
"fingerprint.blacklist": " memory,host ",
}
})
defer cleanup()
fm := NewFingerprintManager(
testClient.config.PluginSingletonLoader,
testClient.GetConfig,
testClient.config.Node,
testClient.shutdownCh,
testClient.updateNodeFromFingerprint,
testClient.logger,
)
err := fm.Run()
require.Nil(err)
node := testClient.config.Node
require.NotEqual(node.Attributes["cpu.frequency"], "")
require.NotEqual(node.Attributes["cpu.arch"], "")
require.NotContains(node.Attributes, "memory.totalbytes")
require.NotContains(node.Attributes, "os.name")
}