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"
|
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2018-06-13 22:33:25 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/testlog"
|
2015-08-27 00:07:31 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStorageFingerprint(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2018-09-16 00:48:59 +00:00
|
|
|
fp := NewStorageFingerprint(testlog.HCLogger(t))
|
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-09-30 00:23:41 +00:00
|
|
|
// COMPAT(0.10): Remove in 0.10
|
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")
|
|
|
|
}
|
2018-09-30 00:23:41 +00:00
|
|
|
|
|
|
|
if response.NodeResources == nil || response.NodeResources.Disk.DiskMB == 0 {
|
|
|
|
t.Errorf("Expected node.Resources.DiskMB to be non-zero")
|
|
|
|
}
|
2015-08-27 00:07:31 +00:00
|
|
|
}
|