2015-08-27 00:07:31 +00:00
|
|
|
package fingerprint
|
|
|
|
|
|
|
|
import (
|
2015-08-27 00:16:34 +00:00
|
|
|
"os"
|
|
|
|
"strconv"
|
2015-08-27 00:07:31 +00:00
|
|
|
"testing"
|
|
|
|
|
2015-08-27 00:16:34 +00:00
|
|
|
"github.com/hashicorp/nomad/client/config"
|
2015-08-27 00:07:31 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStorageFingerprint(t *testing.T) {
|
2015-08-27 00:16:34 +00:00
|
|
|
fp := NewStorageFingerprint(testLogger())
|
2015-08-27 00:07:31 +00:00
|
|
|
node := &structs.Node{
|
|
|
|
Attributes: make(map[string]string),
|
2015-08-27 00:16:34 +00:00
|
|
|
Resources: &structs.Resources{},
|
|
|
|
}
|
|
|
|
|
|
|
|
cwd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to get test working directory: %s", err)
|
|
|
|
}
|
|
|
|
cfg := &config.Config{
|
|
|
|
AllocDir: cwd,
|
|
|
|
}
|
|
|
|
|
|
|
|
ok, err := fp.Fingerprint(cfg, node)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to fingerprint: `%s`", err)
|
|
|
|
}
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("Failed to apply node attributes")
|
2015-08-27 00:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assertNodeAttributeContains(t, node, "storage.volume")
|
|
|
|
assertNodeAttributeContains(t, node, "storage.bytestotal")
|
|
|
|
assertNodeAttributeContains(t, node, "storage.bytesavailable")
|
2015-08-27 00:16:34 +00:00
|
|
|
|
|
|
|
total, err := strconv.ParseInt(node.Attributes["storage.bytestotal"], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to parse storage.bytestotal: %s", err)
|
|
|
|
}
|
|
|
|
available, err := strconv.ParseInt(node.Attributes["storage.bytesavailable"], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to parse storage.bytesavailable: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if available > total {
|
|
|
|
t.Errorf("storage.bytesavailable %d is larger than storage.bytestotal %d", available, total)
|
|
|
|
}
|
|
|
|
|
|
|
|
if node.Resources.DiskMB == 0 {
|
|
|
|
t.Errorf("Expected node.Resources.DiskMB to be non-zero")
|
|
|
|
}
|
2015-08-27 00:07:31 +00:00
|
|
|
}
|