github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/client/fingerprint/cpu_test.go (about) 1 package fingerprint 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/nomad/client/config" 7 "github.com/hashicorp/nomad/nomad/structs" 8 ) 9 10 func TestCPUFingerprint(t *testing.T) { 11 f := NewCPUFingerprint(testLogger()) 12 node := &structs.Node{ 13 Attributes: make(map[string]string), 14 } 15 ok, err := f.Fingerprint(&config.Config{}, node) 16 if err != nil { 17 t.Fatalf("err: %v", err) 18 } 19 if !ok { 20 t.Fatalf("should apply") 21 } 22 23 // CPU info 24 if node.Attributes["cpu.numcores"] == "" { 25 t.Fatalf("Missing Num Cores") 26 } 27 if node.Attributes["cpu.modelname"] == "" { 28 t.Fatalf("Missing Model Name") 29 } 30 31 if node.Attributes["cpu.frequency"] == "" { 32 t.Fatalf("Missing CPU Frequency") 33 } 34 if node.Attributes["cpu.totalcompute"] == "" { 35 t.Fatalf("Missing CPU Total Compute") 36 } 37 38 if node.Resources == nil || node.Resources.CPU == 0 { 39 t.Fatalf("Expected to find CPU Resources") 40 } 41 42 } 43 44 // TestCPUFingerprint_OverrideCompute asserts that setting cpu_total_compute in 45 // the client config overrides the detected CPU freq (if any). 46 func TestCPUFingerprint_OverrideCompute(t *testing.T) { 47 f := NewCPUFingerprint(testLogger()) 48 node := &structs.Node{ 49 Attributes: make(map[string]string), 50 } 51 cfg := &config.Config{} 52 ok, err := f.Fingerprint(cfg, node) 53 if err != nil { 54 t.Fatalf("err: %v", err) 55 } 56 if !ok { 57 t.Fatalf("should apply") 58 } 59 60 // Get actual system CPU 61 origCPU := node.Resources.CPU 62 63 // Override it with a setting 64 cfg.CpuCompute = origCPU + 123 65 66 // Make sure the Fingerprinter applies the override 67 ok, err = f.Fingerprint(cfg, node) 68 if err != nil { 69 t.Fatalf("err: %v", err) 70 } 71 if !ok { 72 t.Fatalf("should apply") 73 } 74 75 if node.Resources.CPU != cfg.CpuCompute { 76 t.Fatalf("expected override cpu of %d but found %d", cfg.CpuCompute, node.Resources.CPU) 77 } 78 }