|
|
@@ -4,6 +4,7 @@ import (
|
|
|
"fmt"
|
|
|
"math"
|
|
|
"os"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"testing"
|
|
|
"time"
|
|
|
@@ -118,8 +119,10 @@ func TestPVPriceFromCSV(t *testing.T) {
|
|
|
t.Errorf("Error in NodePricing: %s", err.Error())
|
|
|
} else {
|
|
|
gotPrice := resPV.Cost
|
|
|
- if gotPrice != wantPrice {
|
|
|
- t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
|
|
|
+ wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
|
|
|
+ gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
|
|
|
+ if gotPriceFloat != wantPriceFloat {
|
|
|
+ t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -150,8 +153,10 @@ func TestPVPriceFromCSVStorageClass(t *testing.T) {
|
|
|
t.Errorf("Error in NodePricing: %s", err.Error())
|
|
|
} else {
|
|
|
gotPrice := resPV.Cost
|
|
|
- if gotPrice != wantPrice {
|
|
|
- t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
|
|
|
+ wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
|
|
|
+ gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
|
|
|
+ if gotPriceFloat != wantPriceFloat {
|
|
|
+ t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -203,8 +208,10 @@ func TestNodePriceFromCSVWithGPU(t *testing.T) {
|
|
|
if gotGPU != wantGPU {
|
|
|
t.Errorf("Wanted gpu count '%s' got gpu count '%s'", wantGPU, gotGPU)
|
|
|
}
|
|
|
- if gotPrice != wantPrice {
|
|
|
- t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
|
|
|
+ wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
|
|
|
+ gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
|
|
|
+ if gotPriceFloat != wantPriceFloat {
|
|
|
+ t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -219,8 +226,10 @@ func TestNodePriceFromCSVWithGPU(t *testing.T) {
|
|
|
if gotGPU != wantGPU {
|
|
|
t.Errorf("Wanted gpu count '%s' got gpu count '%s'", wantGPU, gotGPU)
|
|
|
}
|
|
|
- if gotPrice != wantPrice2 {
|
|
|
- t.Errorf("Wanted price '%s' got price '%s'", wantPrice2, gotPrice)
|
|
|
+ wantPriceFloat, _ := strconv.ParseFloat(wantPrice2, 64)
|
|
|
+ gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
|
|
|
+ if gotPriceFloat != wantPriceFloat {
|
|
|
+ t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -254,8 +263,10 @@ func TestNodePriceFromCSVSpecialChar(t *testing.T) {
|
|
|
t.Errorf("Error in NodePricing: %s", err.Error())
|
|
|
} else {
|
|
|
gotPrice := resN.Cost
|
|
|
- if gotPrice != wantPrice {
|
|
|
- t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
|
|
|
+ wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
|
|
|
+ gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
|
|
|
+ if gotPriceFloat != wantPriceFloat {
|
|
|
+ t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -290,8 +301,10 @@ func TestNodePriceFromCSV(t *testing.T) {
|
|
|
t.Errorf("Error in NodePricing: %s", err.Error())
|
|
|
} else {
|
|
|
gotPrice := resN.Cost
|
|
|
- if gotPrice != wantPrice {
|
|
|
- t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
|
|
|
+ wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
|
|
|
+ gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
|
|
|
+ if gotPriceFloat != wantPriceFloat {
|
|
|
+ t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -366,8 +379,10 @@ func TestNodePriceFromCSVWithRegion(t *testing.T) {
|
|
|
t.Errorf("Error in NodePricing: %s", err.Error())
|
|
|
} else {
|
|
|
gotPrice := resN.Cost
|
|
|
- if gotPrice != wantPrice {
|
|
|
- t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
|
|
|
+ wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
|
|
|
+ gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
|
|
|
+ if gotPriceFloat != wantPriceFloat {
|
|
|
+ t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
|
|
|
}
|
|
|
}
|
|
|
k2 := c.GetKey(n2.Labels, n2)
|
|
|
@@ -376,8 +391,10 @@ func TestNodePriceFromCSVWithRegion(t *testing.T) {
|
|
|
t.Errorf("Error in NodePricing: %s", err.Error())
|
|
|
} else {
|
|
|
gotPrice := resN2.Cost
|
|
|
- if gotPrice != wantPrice2 {
|
|
|
- t.Errorf("Wanted price '%s' got price '%s'", wantPrice2, gotPrice)
|
|
|
+ wantPriceFloat, _ := strconv.ParseFloat(wantPrice2, 64)
|
|
|
+ gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
|
|
|
+ if gotPriceFloat != wantPriceFloat {
|
|
|
+ t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
|
|
|
}
|
|
|
}
|
|
|
k3 := c.GetKey(n3.Labels, n3)
|
|
|
@@ -386,8 +403,10 @@ func TestNodePriceFromCSVWithRegion(t *testing.T) {
|
|
|
t.Errorf("Error in NodePricing: %s", err.Error())
|
|
|
} else {
|
|
|
gotPrice := resN3.Cost
|
|
|
- if gotPrice != wantPrice3 {
|
|
|
- t.Errorf("Wanted price '%s' got price '%s'", wantPrice3, gotPrice)
|
|
|
+ wantPriceFloat, _ := strconv.ParseFloat(wantPrice3, 64)
|
|
|
+ gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
|
|
|
+ if gotPriceFloat != wantPriceFloat {
|
|
|
+ t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -572,8 +591,67 @@ func TestNodePriceFromCSVWithCase(t *testing.T) {
|
|
|
t.Errorf("Error in NodePricing: %s", err.Error())
|
|
|
} else {
|
|
|
gotPrice := resN.Cost
|
|
|
- if gotPrice != wantPrice {
|
|
|
- t.Errorf("Wanted price '%s' got price '%s'", wantPrice, gotPrice)
|
|
|
+ wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
|
|
|
+ gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
|
|
|
+ if gotPriceFloat != wantPriceFloat {
|
|
|
+ t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func TestNodePriceFromCSVMixed(t *testing.T) {
|
|
|
+ labelFooWant := "OnDemand"
|
|
|
+
|
|
|
+ confMan := config.NewConfigFileManager(&config.ConfigFileManagerOpts{
|
|
|
+ LocalConfigPath: "./",
|
|
|
+ })
|
|
|
+
|
|
|
+ n := &v1.Node{}
|
|
|
+ n.Labels = make(map[string]string)
|
|
|
+ n.Labels["TestClusterUsage"] = labelFooWant
|
|
|
+ n.Labels["nvidia.com/gpu_type"] = "a100-ondemand"
|
|
|
+ n.Status.Capacity = v1.ResourceList{"nvidia.com/gpu": *resource.NewScaledQuantity(2, 0)}
|
|
|
+ wantPrice := "1.904110"
|
|
|
+
|
|
|
+ labelFooWant2 := "Reserved"
|
|
|
+ n2 := &v1.Node{}
|
|
|
+ n2.Labels = make(map[string]string)
|
|
|
+ n2.Labels["TestClusterUsage"] = labelFooWant2
|
|
|
+ n2.Labels["nvidia.com/gpu_type"] = "a100-reserved"
|
|
|
+ n2.Status.Capacity = v1.ResourceList{"nvidia.com/gpu": *resource.NewScaledQuantity(1, 0)}
|
|
|
+
|
|
|
+ wantPrice2 := "1.654795"
|
|
|
+
|
|
|
+ c := &provider.CSVProvider{
|
|
|
+ CSVLocation: "../configs/pricing_schema_mixed_gpu_ondemand.csv",
|
|
|
+ CustomProvider: &provider.CustomProvider{
|
|
|
+ Config: provider.NewProviderConfig(confMan, "../configs/default.json"),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ c.DownloadPricingData()
|
|
|
+ k := c.GetKey(n.Labels, n)
|
|
|
+ resN, _, err := c.NodePricing(k)
|
|
|
+ if err != nil {
|
|
|
+ t.Errorf("Error in NodePricing: %s", err.Error())
|
|
|
+ } else {
|
|
|
+ gotPrice := resN.Cost
|
|
|
+ wantPriceFloat, _ := strconv.ParseFloat(wantPrice, 64)
|
|
|
+ gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
|
|
|
+ if gotPriceFloat != wantPriceFloat {
|
|
|
+ t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ k2 := c.GetKey(n2.Labels, n2)
|
|
|
+ resN2, _, err2 := c.NodePricing(k2)
|
|
|
+ if err2 != nil {
|
|
|
+ t.Errorf("Error in NodePricing: %s", err.Error())
|
|
|
+ } else {
|
|
|
+ gotPrice := resN2.Cost
|
|
|
+ wantPriceFloat, _ := strconv.ParseFloat(wantPrice2, 64)
|
|
|
+ gotPriceFloat, _ := strconv.ParseFloat(gotPrice, 64)
|
|
|
+ if gotPriceFloat != wantPriceFloat {
|
|
|
+ t.Errorf("Wanted price '%f' got price '%f'", wantPriceFloat, gotPriceFloat)
|
|
|
}
|
|
|
}
|
|
|
|