2018-01-24 13:01:37 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/client/config"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2018-02-14 19:35:15 +00:00
|
|
|
func TestFingerprintManager_Run_ResourcesFingerprint(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
2018-10-16 03:07:16 +00:00
|
|
|
testClient, cleanup := TestClient(t, nil)
|
|
|
|
defer cleanup()
|
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-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-01-25 16:30:15 +00:00
|
|
|
func TestFimgerprintManager_Run_InWhitelist(t *testing.T) {
|
2018-02-05 23:02:52 +00:00
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
|
|
|
|
2018-10-16 03:07:16 +00:00
|
|
|
testClient, cleanup := TestClient(t, func(c *config.Config) {
|
2018-03-14 17:10:41 +00:00
|
|
|
c.Options = map[string]string{
|
|
|
|
"test.shutdown_periodic_after": "true",
|
|
|
|
"test.shutdown_periodic_duration": "2",
|
|
|
|
}
|
|
|
|
})
|
2018-10-16 03:07:16 +00:00
|
|
|
defer cleanup()
|
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-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-10-16 03:07:16 +00:00
|
|
|
testClient, cleanup := TestClient(t, func(c *config.Config) {
|
2018-03-14 17:10:41 +00:00
|
|
|
c.Options = map[string]string{
|
|
|
|
"fingerprint.whitelist": " arch,memory,foo,bar ",
|
|
|
|
"fingerprint.blacklist": " cpu ",
|
|
|
|
}
|
|
|
|
})
|
2018-10-16 03:07:16 +00:00
|
|
|
defer cleanup()
|
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-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-10-16 03:07:16 +00:00
|
|
|
testClient, cleanup := TestClient(t, func(c *config.Config) {
|
2018-03-14 17:10:41 +00:00
|
|
|
c.Options = map[string]string{
|
|
|
|
"fingerprint.whitelist": " arch,cpu,memory,foo,bar ",
|
2018-12-08 23:47:37 +00:00
|
|
|
"fingerprint.blacklist": " memory,host ",
|
2018-03-14 17:10:41 +00:00
|
|
|
}
|
|
|
|
})
|
2018-10-16 03:07:16 +00:00
|
|
|
defer cleanup()
|
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-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")
|
2018-12-08 23:47:37 +00:00
|
|
|
require.NotContains(node.Attributes, "os.name")
|
2018-02-05 23:02:52 +00:00
|
|
|
}
|