open-nomad/client/fingerprint_manager_test.go

159 lines
3.7 KiB
Go
Raw Normal View History

2018-01-24 13:01:37 +00:00
package client
import (
"testing"
"github.com/hashicorp/nomad/ci"
2018-01-24 13:01:37 +00:00
"github.com/hashicorp/nomad/client/config"
"github.com/stretchr/testify/require"
)
func TestFingerprintManager_Run_ResourcesFingerprint(t *testing.T) {
ci.Parallel(t)
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)
2018-02-23 20:01:57 +00:00
require.NotZero(node.Resources.DiskMB)
}
func TestFimgerprintManager_Run_InWhitelist(t *testing.T) {
ci.Parallel(t)
2018-02-05 23:02:52 +00:00
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()
2018-02-05 23:02:52 +00:00
fm := NewFingerprintManager(
testClient.config.PluginSingletonLoader,
testClient.GetConfig,
testClient.config.Node,
testClient.shutdownCh,
testClient.updateNodeFromFingerprint,
testClient.logger,
2018-02-05 23:02:52 +00:00
)
err := fm.Run()
require.Nil(err)
node := testClient.config.Node
2018-02-05 23:02:52 +00:00
require.NotEqual(node.Attributes["cpu.frequency"], "")
}
func TestFingerprintManager_Run_InDenylist(t *testing.T) {
ci.Parallel(t)
2018-02-05 23:02:52 +00:00
require := require.New(t)
testClient, cleanup := TestClient(t, func(c *config.Config) {
c.Options = map[string]string{
"fingerprint.allowlist": " arch,memory,foo,bar ",
"fingerprint.denylist": " cpu ",
}
})
defer cleanup()
2018-02-05 23:02:52 +00:00
fm := NewFingerprintManager(
testClient.config.PluginSingletonLoader,
testClient.GetConfig,
testClient.config.Node,
testClient.shutdownCh,
testClient.updateNodeFromFingerprint,
testClient.logger,
2018-02-05 23:02:52 +00:00
)
err := fm.Run()
require.Nil(err)
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) {
ci.Parallel(t)
2018-02-05 23:02:52 +00:00
require := require.New(t)
testClient, cleanup := TestClient(t, func(c *config.Config) {
c.Options = map[string]string{
"fingerprint.allowlist": " arch,cpu,memory,foo,bar ",
"fingerprint.denylist": " 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")
}
func TestFingerprintManager_Run_CombinationLegacyNames(t *testing.T) {
ci.Parallel(t)
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()
2018-02-05 23:02:52 +00:00
fm := NewFingerprintManager(
testClient.config.PluginSingletonLoader,
testClient.GetConfig,
testClient.config.Node,
testClient.shutdownCh,
testClient.updateNodeFromFingerprint,
testClient.logger,
2018-02-05 23:02:52 +00:00
)
err := fm.Run()
require.Nil(err)
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, "os.name")
2018-02-05 23:02:52 +00:00
}