2015-09-18 21:56:27 +00:00
|
|
|
package fingerprint
|
|
|
|
|
|
|
|
import (
|
2015-09-23 03:56:31 +00:00
|
|
|
"net"
|
2015-09-18 21:56:27 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/client/config"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNetworkFingerprint_basic(t *testing.T) {
|
2015-09-23 15:12:56 +00:00
|
|
|
f := NewNetworkFingerprinter(testLogger())
|
2015-09-18 21:56:27 +00:00
|
|
|
node := &structs.Node{
|
|
|
|
Attributes: make(map[string]string),
|
|
|
|
}
|
2015-10-03 00:32:11 +00:00
|
|
|
cfg := &config.Config{NetworkSpeed: 100}
|
2015-09-18 21:56:27 +00:00
|
|
|
|
2015-10-03 00:32:11 +00:00
|
|
|
ok, err := f.Fingerprint(cfg, node)
|
2015-09-18 21:56:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("should apply")
|
|
|
|
}
|
|
|
|
|
2015-09-23 03:56:31 +00:00
|
|
|
assertNodeAttributeContains(t, node, "network.ip-address")
|
|
|
|
|
|
|
|
ip := node.Attributes["network.ip-address"]
|
|
|
|
match := net.ParseIP(ip)
|
|
|
|
if match == nil {
|
|
|
|
t.Fatalf("Bad IP match: %s", ip)
|
2015-09-18 21:56:27 +00:00
|
|
|
}
|
2015-09-23 04:22:23 +00:00
|
|
|
|
|
|
|
if node.Resources == nil || len(node.Resources.Networks) == 0 {
|
|
|
|
t.Fatal("Expected to find Network Resources")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test at least the first Network Resource
|
|
|
|
net := node.Resources.Networks[0]
|
|
|
|
if net.IP == "" {
|
|
|
|
t.Fatal("Expected Network Resource to not be empty")
|
|
|
|
}
|
2015-09-23 04:51:56 +00:00
|
|
|
if net.CIDR == "" {
|
|
|
|
t.Fatal("Expected Network Resource to have a CIDR")
|
|
|
|
}
|
|
|
|
if net.Device == "" {
|
|
|
|
t.Fatal("Expected Network Resource to have a Device Name")
|
|
|
|
}
|
2015-10-03 00:32:11 +00:00
|
|
|
if net.MBits == 0 {
|
|
|
|
t.Fatal("Expected Network Resource to have a non-zero bandwith")
|
|
|
|
}
|
2015-09-18 21:56:27 +00:00
|
|
|
}
|