Skip to content

Commit

Permalink
improved testing; node networks comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
chelseakomlo committed Feb 26, 2018
1 parent 4271123 commit ac91ee4
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 89 deletions.
11 changes: 8 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,12 @@ func resourcesAreEqual(first, second *structs.Resources) bool {
if first.IOPS != second.IOPS {
return false
}
if len(first.Networks) != len(second.Networks) {
return false
for _, e := range first.Networks {
for _, f := range second.Networks {
if e != f {
return false
}
}
}
return true
}
Expand Down Expand Up @@ -1542,8 +1546,9 @@ func (c *Client) watchNodeUpdates() {
c.configLock.Unlock()

c.retryRegisterNode()

hasChanged = false
}
hasChanged = false
case <-c.triggerNodeUpdate:
hasChanged = true
case <-c.shutdownCh:
Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestClient_TriggerNodeUpdate(t *testing.T) {

// These constants are only defined when nomad_test is enabled, so these fail
// our linter without explicit disabling.
c1 := testClient(t, func(c *config.Config) {
c1 := TestClient(t, func(c *config.Config) {
c.Options = map[string]string{
driver.ShutdownPeriodicAfter: "true", // nolint: varcheck
driver.ShutdownPeriodicDuration: "3", // nolint: varcheck
Expand Down
153 changes: 68 additions & 85 deletions client/fingerprint_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/client/driver"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/require"
Expand All @@ -19,15 +18,13 @@ func TestFingerprintManager_Run_MockDriver(t *testing.T) {

node := &structs.Node{
Attributes: make(map[string]string, 0),
Links: make(map[string]string, 0),
Resources: &structs.Resources{},
}

updateNode := func(r *cstructs.FingerprintResponse) *structs.Node {
for k, v := range r.Attributes {
node.Attributes[k] = v
}
return node
}
testConfig := config.Config{Node: node}
testClient := &Client{config: &testConfig}
conf := config.DefaultConfig()

getConfig := func() *config.Config {
return conf
}
Expand All @@ -36,7 +33,7 @@ func TestFingerprintManager_Run_MockDriver(t *testing.T) {
getConfig,
node,
make(chan struct{}),
updateNode,
testClient.updateNodeFromFingerprint,
testLogger(),
)

Expand All @@ -50,14 +47,14 @@ func TestFingerprintManager_Run_ResourcesFingerprint(t *testing.T) {
t.Parallel()
require := require.New(t)

node := &structs.Node{Resources: &structs.Resources{}}

updateNode := func(r *cstructs.FingerprintResponse) *structs.Node {
if r.Resources != nil {
node.Resources.Merge(r.Resources)
}
return node
node := &structs.Node{
Attributes: make(map[string]string, 0),
Links: make(map[string]string, 0),
Resources: &structs.Resources{},
}
testConfig := config.Config{Node: node}
testClient := &Client{config: &testConfig}

conf := config.DefaultConfig()
getConfig := func() *config.Config {
return conf
Expand All @@ -67,7 +64,7 @@ func TestFingerprintManager_Run_ResourcesFingerprint(t *testing.T) {
getConfig,
node,
make(chan struct{}),
updateNode,
testClient.updateNodeFromFingerprint,
testLogger(),
)

Expand All @@ -84,26 +81,23 @@ func TestFingerprintManager_Fingerprint_Run(t *testing.T) {

node := &structs.Node{
Attributes: make(map[string]string, 0),
Links: make(map[string]string, 0),
Resources: &structs.Resources{},
}
testConfig := config.Config{Node: node}
testClient := &Client{config: &testConfig}

conf := config.DefaultConfig()
conf.Options = map[string]string{"driver.raw_exec.enable": "true"}
getConfig := func() *config.Config {
return conf
}

updateNode := func(r *cstructs.FingerprintResponse) *structs.Node {
for k, v := range r.Attributes {
node.Attributes[k] = v
}
return node
}

fm := NewFingerprintManager(
getConfig,
node,
make(chan struct{}),
updateNode,
testClient.updateNodeFromFingerprint,
testLogger(),
)

Expand All @@ -119,13 +113,12 @@ func TestFingerprintManager_Fingerprint_Periodic(t *testing.T) {

node := &structs.Node{
Attributes: make(map[string]string, 0),
Links: make(map[string]string, 0),
Resources: &structs.Resources{},
}
updateNode := func(r *cstructs.FingerprintResponse) *structs.Node {
for k, v := range r.Attributes {
node.Attributes[k] = v
}
return node
}
testConfig := config.Config{Node: node}
testClient := &Client{config: &testConfig}

conf := config.DefaultConfig()
conf.Options = map[string]string{
"test.shutdown_periodic_after": "true",
Expand All @@ -144,7 +137,7 @@ func TestFingerprintManager_Fingerprint_Periodic(t *testing.T) {
getConfig,
node,
shutdownCh,
updateNode,
testClient.updateNodeFromFingerprint,
testLogger(),
)

Expand Down Expand Up @@ -180,13 +173,12 @@ func TestFimgerprintManager_Run_InWhitelist(t *testing.T) {

node := &structs.Node{
Attributes: make(map[string]string, 0),
Links: make(map[string]string, 0),
Resources: &structs.Resources{},
}
updateNode := func(r *cstructs.FingerprintResponse) *structs.Node {
for k, v := range r.Attributes {
node.Attributes[k] = v
}
return node
}
testConfig := config.Config{Node: node}
testClient := &Client{config: &testConfig}

conf := config.DefaultConfig()
conf.Options = map[string]string{"fingerprint.whitelist": " arch,cpu,memory,network,storage,foo,bar "}
getConfig := func() *config.Config {
Expand All @@ -202,7 +194,7 @@ func TestFimgerprintManager_Run_InWhitelist(t *testing.T) {
getConfig,
node,
shutdownCh,
updateNode,
testClient.updateNodeFromFingerprint,
testLogger(),
)

Expand All @@ -217,13 +209,12 @@ func TestFimgerprintManager_Run_InBlacklist(t *testing.T) {

node := &structs.Node{
Attributes: make(map[string]string, 0),
Links: make(map[string]string, 0),
Resources: &structs.Resources{},
}
updateNode := func(r *cstructs.FingerprintResponse) *structs.Node {
for k, v := range r.Attributes {
node.Attributes[k] = v
}
return node
}
testConfig := config.Config{Node: node}
testClient := &Client{config: &testConfig}

conf := config.DefaultConfig()
conf.Options = map[string]string{"fingerprint.whitelist": " arch,memory,foo,bar "}
conf.Options = map[string]string{"fingerprint.blacklist": " cpu "}
Expand All @@ -240,7 +231,7 @@ func TestFimgerprintManager_Run_InBlacklist(t *testing.T) {
getConfig,
node,
shutdownCh,
updateNode,
testClient.updateNodeFromFingerprint,
testLogger(),
)

Expand All @@ -256,13 +247,12 @@ func TestFimgerprintManager_Run_Combination(t *testing.T) {

node := &structs.Node{
Attributes: make(map[string]string, 0),
Links: make(map[string]string, 0),
Resources: &structs.Resources{},
}
updateNode := func(r *cstructs.FingerprintResponse) *structs.Node {
for k, v := range r.Attributes {
node.Attributes[k] = v
}
return node
}
testConfig := config.Config{Node: node}
testClient := &Client{config: &testConfig}

conf := config.DefaultConfig()
conf.Options = map[string]string{"fingerprint.whitelist": " arch,cpu,memory,foo,bar "}
conf.Options = map[string]string{"fingerprint.blacklist": " memory,nomad "}
Expand All @@ -279,7 +269,7 @@ func TestFimgerprintManager_Run_Combination(t *testing.T) {
getConfig,
node,
shutdownCh,
updateNode,
testClient.updateNodeFromFingerprint,
testLogger(),
)

Expand All @@ -297,13 +287,12 @@ func TestFimgerprintManager_Run_WhitelistDrivers(t *testing.T) {

node := &structs.Node{
Attributes: make(map[string]string, 0),
Links: make(map[string]string, 0),
Resources: &structs.Resources{},
}
updateNode := func(r *cstructs.FingerprintResponse) *structs.Node {
for k, v := range r.Attributes {
node.Attributes[k] = v
}
return node
}
testConfig := config.Config{Node: node}
testClient := &Client{config: &testConfig}

conf := config.DefaultConfig()
conf.Options = map[string]string{
"driver.raw_exec.enable": "1",
Expand All @@ -322,7 +311,7 @@ func TestFimgerprintManager_Run_WhitelistDrivers(t *testing.T) {
getConfig,
node,
shutdownCh,
updateNode,
testClient.updateNodeFromFingerprint,
testLogger(),
)

Expand All @@ -337,13 +326,12 @@ func TestFimgerprintManager_Run_AllDriversBlacklisted(t *testing.T) {

node := &structs.Node{
Attributes: make(map[string]string, 0),
Links: make(map[string]string, 0),
Resources: &structs.Resources{},
}
updateNode := func(r *cstructs.FingerprintResponse) *structs.Node {
for k, v := range r.Attributes {
node.Attributes[k] = v
}
return node
}
testConfig := config.Config{Node: node}
testClient := &Client{config: &testConfig}

conf := config.DefaultConfig()
conf.Options = map[string]string{
"driver.whitelist": " foo,bar,baz ",
Expand All @@ -361,7 +349,7 @@ func TestFimgerprintManager_Run_AllDriversBlacklisted(t *testing.T) {
getConfig,
node,
shutdownCh,
updateNode,
testClient.updateNodeFromFingerprint,
testLogger(),
)

Expand All @@ -378,13 +366,12 @@ func TestFimgerprintManager_Run_DriversWhiteListBlacklistCombination(t *testing.

node := &structs.Node{
Attributes: make(map[string]string, 0),
Links: make(map[string]string, 0),
Resources: &structs.Resources{},
}
updateNode := func(r *cstructs.FingerprintResponse) *structs.Node {
for k, v := range r.Attributes {
node.Attributes[k] = v
}
return node
}
testConfig := config.Config{Node: node}
testClient := &Client{config: &testConfig}

conf := config.DefaultConfig()
conf.Options = map[string]string{
"driver.raw_exec.enable": "1",
Expand All @@ -404,7 +391,7 @@ func TestFimgerprintManager_Run_DriversWhiteListBlacklistCombination(t *testing.
getConfig,
node,
shutdownCh,
updateNode,
testClient.updateNodeFromFingerprint,
testLogger(),
)

Expand All @@ -423,33 +410,29 @@ func TestFimgerprintManager_Run_DriversInBlacklist(t *testing.T) {

node := &structs.Node{
Attributes: make(map[string]string, 0),
}
updateNode := func(r *cstructs.FingerprintResponse) *structs.Node {
for k, v := range r.Attributes {
node.Attributes[k] = v
}
return node
Links: make(map[string]string, 0),
Resources: &structs.Resources{},
}
conf := config.DefaultConfig()
conf.Options = map[string]string{
"driver.raw_exec.enable": "1",
"driver.whitelist": " raw_exec,foo,bar,baz ",
"driver.blacklist": " exec,foo,bar,baz ",
}
getConfig := func() *config.Config {
return conf
}
conf.Node = node

testClient := &Client{config: conf}

shutdownCh := make(chan struct{})
defer (func() {
close(shutdownCh)
})()

fm := NewFingerprintManager(
getConfig,
testClient.GetConfig,
node,
shutdownCh,
updateNode,
testClient.updateNodeFromFingerprint,
testLogger(),
)

Expand Down

0 comments on commit ac91ee4

Please sign in to comment.