2015-08-27 00:07:31 +00:00
|
|
|
package fingerprint
|
|
|
|
|
|
|
|
import (
|
2015-08-27 00:16:34 +00:00
|
|
|
"strconv"
|
2015-08-27 00:07:31 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"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
|
|
|
}
|
|
|
|
|
2018-01-24 14:09:53 +00:00
|
|
|
response := assertFingerprintOK(t, fp, node)
|
2015-08-27 00:07:31 +00:00
|
|
|
|
2018-01-31 22:03:55 +00:00
|
|
|
if !response.Detected {
|
2018-01-30 17:57:37 +00:00
|
|
|
t.Fatalf("expected response to be applicable")
|
|
|
|
}
|
2015-08-27 00:16:34 +00:00
|
|
|
|
2018-01-30 17:57:37 +00:00
|
|
|
assertNodeAttributeContains(t, response.Attributes, "unique.storage.volume")
|
|
|
|
assertNodeAttributeContains(t, response.Attributes, "unique.storage.bytestotal")
|
|
|
|
assertNodeAttributeContains(t, response.Attributes, "unique.storage.bytesfree")
|
2018-01-26 16:21:07 +00:00
|
|
|
|
2018-01-30 17:57:37 +00:00
|
|
|
total, err := strconv.ParseInt(response.Attributes["unique.storage.bytestotal"], 10, 64)
|
2015-08-27 00:16:34 +00:00
|
|
|
if err != nil {
|
2016-01-23 02:12:16 +00:00
|
|
|
t.Fatalf("Failed to parse unique.storage.bytestotal: %s", err)
|
2015-08-27 00:16:34 +00:00
|
|
|
}
|
2018-01-30 17:57:37 +00:00
|
|
|
free, err := strconv.ParseInt(response.Attributes["unique.storage.bytesfree"], 10, 64)
|
2015-08-27 00:16:34 +00:00
|
|
|
if err != nil {
|
2016-01-23 02:12:16 +00:00
|
|
|
t.Fatalf("Failed to parse unique.storage.bytesfree: %s", err)
|
2015-08-27 00:16:34 +00:00
|
|
|
}
|
|
|
|
|
2015-08-27 19:37:05 +00:00
|
|
|
if free > total {
|
2016-01-23 02:12:16 +00:00
|
|
|
t.Fatalf("unique.storage.bytesfree %d is larger than unique.storage.bytestotal %d", free, total)
|
2015-08-27 00:16:34 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 17:57:37 +00:00
|
|
|
if response.Resources == nil {
|
2015-11-07 14:14:25 +00:00
|
|
|
t.Fatalf("Node Resources was nil")
|
|
|
|
}
|
2018-01-30 17:57:37 +00:00
|
|
|
if response.Resources.DiskMB == 0 {
|
2015-08-27 00:16:34 +00:00
|
|
|
t.Errorf("Expected node.Resources.DiskMB to be non-zero")
|
|
|
|
}
|
2015-08-27 00:07:31 +00:00
|
|
|
}
|