diff --git a/pkg/tool/gen-disk-skus-map.go b/pkg/tool/gen-disk-skus-map.go index 460f80aeaf..8dfca198d1 100644 --- a/pkg/tool/gen-disk-skus-map.go +++ b/pkg/tool/gen-disk-skus-map.go @@ -43,6 +43,7 @@ var ( UncachedDiskBytesPerSecondCapability = "uncacheddiskbytespersecond" MaxDataDiskCountCapability = "maxdatadiskcount" VCPUsCapability = "vcpus" + SkusFullfilePath = "skus-full.json" ) func init() { @@ -87,21 +88,20 @@ import ( nodeInfo := ` "%s": NodeInfo{SkuName: "%s", MaxDataDiskCount: %s, VCpus: %s, MaxBurstIops: %s, MaxIops: %s, MaxBwMbps: %s, MaxBurstBwMbps: %s},` nodeMapEnd := " }" - skusFullfilePath := "skus-full.json" - defer os.Remove(skusFullfilePath) + defer os.Remove(SkusFullfilePath) skusFilePath := "pkg/azuredisk/azure_skus_map.go" skuMap := map[string]bool{} var resources []*armcompute.ResourceSKU - if err := getAllSkus(skusFullfilePath); err != nil { + if err := getAllSkus(); err != nil { klog.Errorf("Could not get skus. Error: %v", err) } - diskSkusFullJSON, err := os.Open(skusFullfilePath) + diskSkusFullJSON, err := os.Open(SkusFullfilePath) if err != nil { - klog.Errorf("Could not read file. Error: %v, FilePath: %s", err, skusFullfilePath) + klog.Errorf("Could not read file. Error: %v, FilePath: %s", err, SkusFullfilePath) return } defer diskSkusFullJSON.Close() @@ -110,7 +110,7 @@ import ( err = json.Unmarshal([]byte(byteValue), &resources) if err != nil { - klog.Errorf("Could not parse json file file. Error: %v, FilePath: %s", err, skusFullfilePath) + klog.Errorf("Could not parse json file file. Error: %v, FilePath: %s", err, SkusFullfilePath) return } @@ -145,7 +145,6 @@ import ( exit(1) } } else if resType == "virtualmachines" { - nodeInfo := optimization.NodeInfo{} nodeInfo.SkuName = *sku.Name err = populateNodeCapabilities(sku, &nodeInfo) @@ -215,13 +214,19 @@ func formatInt(value int) string { return strconv.Itoa(value) } -func getAllSkus(filePath string) (err error) { - klog.V(2).Infof("Getting skus and writing to %s", filePath) +func getAllSkus() (err error) { + if os.Getenv("TEST_SCENARIO") == "true" { + if _, err := os.Stat("skus-sample.json"); err == nil { + SkusFullfilePath = "skus-sample.json" + return nil + } + } + klog.V(2).Infof("Getting skus and writing to %s", SkusFullfilePath) cmd := exec.Command("az", "vm", "list-skus") - outfile, err := os.Create(filePath) + outfile, err := os.Create(SkusFullfilePath) var errorBuf bytes.Buffer if err != nil { - klog.Errorf("Could dnot create file. Error: %v File: %s", err, filePath) + klog.Errorf("Could not create file. Error: %v File: %s", err, SkusFullfilePath) return err } defer outfile.Close() diff --git a/pkg/tool/gen-disk-skus-map_test.go b/pkg/tool/gen-disk-skus-map_test.go index 96030558dd..3b2e5d29f2 100644 --- a/pkg/tool/gen-disk-skus-map_test.go +++ b/pkg/tool/gen-disk-skus-map_test.go @@ -22,6 +22,10 @@ import ( ) func TestMain(t *testing.T) { + // Set environment variable for test scenario + os.Setenv("TEST_SCENARIO", "true") + defer os.Unsetenv("TEST_SCENARIO") + // Capture stdout old := os.Stdout _, w, _ := os.Pipe() diff --git a/pkg/tool/skus-sample.json b/pkg/tool/skus-sample.json new file mode 100644 index 0000000000..88a0f6af47 --- /dev/null +++ b/pkg/tool/skus-sample.json @@ -0,0 +1,366 @@ +[ + { + "apiVersions": null, + "capabilities": [ + { + "name": "MaximumPlatformFaultDomainCount", + "value": "2" + } + ], + "capacity": null, + "costs": null, + "family": null, + "kind": null, + "locationInfo": [ + { + "location": "AustraliaCentral", + "zoneDetails": [], + "zones": [] + } + ], + "locations": [ + "AustraliaCentral" + ], + "name": "Aligned", + "resourceType": "availabilitySets", + "restrictions": [], + "size": null, + "tier": null + }, + { + "apiVersions": null, + "capabilities": [ + { + "name": "MaxResourceVolumeMB", + "value": "10240" + }, + { + "name": "OSVhdSizeMB", + "value": "1047552" + }, + { + "name": "vCPUs", + "value": "1" + }, + { + "name": "MemoryPreservingMaintenanceSupported", + "value": "True" + }, + { + "name": "HyperVGenerations", + "value": "V1" + }, + { + "name": "MemoryGB", + "value": "2" + }, + { + "name": "MaxDataDiskCount", + "value": "2" + }, + { + "name": "CpuArchitectureType", + "value": "x64" + }, + { + "name": "LowPriorityCapable", + "value": "True" + }, + { + "name": "PremiumIO", + "value": "False" + }, + { + "name": "VMDeploymentTypes", + "value": "PaaS,IaaS" + }, + { + "name": "vCPUsAvailable", + "value": "1" + }, + { + "name": "ACUs", + "value": "100" + }, + { + "name": "vCPUsPerCore", + "value": "1" + }, + { + "name": "CombinedTempDiskAndCachedIOPS", + "value": "1000" + }, + { + "name": "CombinedTempDiskAndCachedReadBytesPerSecond", + "value": "20971520" + }, + { + "name": "CombinedTempDiskAndCachedWriteBytesPerSecond", + "value": "10485760" + }, + { + "name": "UncachedDiskIOPS", + "value": "1600" + }, + { + "name": "UncachedDiskBytesPerSecond", + "value": "24000000" + }, + { + "name": "EphemeralOSDiskSupported", + "value": "False" + }, + { + "name": "EncryptionAtHostSupported", + "value": "False" + }, + { + "name": "CapacityReservationSupported", + "value": "False" + }, + { + "name": "AcceleratedNetworkingEnabled", + "value": "False" + }, + { + "name": "RdmaEnabled", + "value": "False" + }, + { + "name": "MaxNetworkInterfaces", + "value": "2" + } + ], + "capacity": null, + "costs": null, + "family": "standardAv2Family", + "kind": null, + "locationInfo": [ + { + "location": "australiaeast", + "zoneDetails": [], + "zones": [ + "1", + "2", + "3" + ] + } + ], + "locations": [ + "australiaeast" + ], + "name": "Standard_A1_v2", + "resourceType": "virtualMachines", + "restrictions": [], + "size": "A1_v2", + "tier": "Standard" + }, + { + "apiVersions": null, + "capabilities": [ + { + "name": "MaxSizeGiB", + "value": "65536" + }, + { + "name": "MinSizeGiB", + "value": "1" + }, + { + "name": "MaxIOpsReadWrite", + "value": "80000" + }, + { + "name": "MinIOpsReadWrite", + "value": "3000" + }, + { + "name": "MaxBandwidthMBpsReadWrite", + "value": "1200" + }, + { + "name": "MinBandwidthMBpsReadWrite", + "value": "125" + }, + { + "name": "MaxValueOfMaxShares", + "value": "15" + }, + { + "name": "MinIOSizeKiBps", + "value": "4" + }, + { + "name": "MaxIOSizeKiBps", + "value": "256" + }, + { + "name": "MinIopsReadOnly", + "value": "3000" + }, + { + "name": "MaxIopsReadOnly", + "value": "80000" + }, + { + "name": "MinBandwidthMBpsReadOnly", + "value": "125" + }, + { + "name": "MaxBandwidthMBpsReadOnly", + "value": "1200" + }, + { + "name": "MaxIopsPerGiBReadWrite", + "value": "500" + }, + { + "name": "MaxIopsPerGiBReadOnly", + "value": "500" + }, + { + "name": "MinIopsPerGiBReadWrite", + "value": "1" + }, + { + "name": "MinIopsPerGiBReadOnly", + "value": "1" + }, + { + "name": "BillingPartitionSizes", + "value": "1, 2, 3, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 13312, 14336, 15360, 16384, 17408, 18432, 19456, 20480, 21504, 22528, 23552,24576,25600,26624,27648,28672,29696,30720,31744,32768,33792,34816,35840,36864,37888,38912,39936,40960,41984,43008,44032,45056,46080,47104,48128,49152,50176,51200,52224,53248,54272,55296,56320,57344,58368,59392,60416,61440,62464,63488,64512,65536" + }, + { + "name": "PlatformFaultDomainCount", + "value": "2" + } + ], + "capacity": null, + "costs": null, + "family": null, + "kind": null, + "locationInfo": [ + { + "location": "australiaeast", + "zoneDetails": [], + "zones": [ + "3", + "1", + "2" + ] + } + ], + "locations": [ + "australiaeast" + ], + "name": "PremiumV2_LRS", + "resourceType": "disks", + "restrictions": [], + "size": "P", + "tier": "Premium" + }, + { + "apiVersions": null, + "capabilities": [ + { + "name": "MaxSizeGiB", + "value": "65536" + }, + { + "name": "MinSizeGiB", + "value": "1" + }, + { + "name": "MaxIOpsReadWrite", + "value": "80000" + }, + { + "name": "MinIOpsReadWrite", + "value": "3000" + }, + { + "name": "MaxBandwidthMBpsReadWrite", + "value": "1200" + }, + { + "name": "MinBandwidthMBpsReadWrite", + "value": "125" + }, + { + "name": "MaxValueOfMaxShares", + "value": "15" + }, + { + "name": "MinIOSizeKiBps", + "value": "4" + }, + { + "name": "MaxIOSizeKiBps", + "value": "256" + }, + { + "name": "MinIopsReadOnly", + "value": "3000" + }, + { + "name": "MaxIopsReadOnly", + "value": "80000" + }, + { + "name": "MinBandwidthMBpsReadOnly", + "value": "125" + }, + { + "name": "MaxBandwidthMBpsReadOnly", + "value": "1200" + }, + { + "name": "MaxIopsPerGiBReadWrite", + "value": "500" + }, + { + "name": "MaxIopsPerGiBReadOnly", + "value": "500" + }, + { + "name": "MinIopsPerGiBReadWrite", + "value": "1" + }, + { + "name": "MinIopsPerGiBReadOnly", + "value": "1" + }, + { + "name": "BillingPartitionSizes", + "value": "1, 2, 3, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, 9216, 10240, 11264, 12288, 13312, 14336, 15360, 16384, 17408, 18432, 19456, 20480, 21504, 22528, 23552,24576,25600,26624,27648,28672,29696,30720,31744,32768,33792,34816,35840,36864,37888,38912,39936,40960,41984,43008,44032,45056,46080,47104,48128,49152,50176,51200,52224,53248,54272,55296,56320,57344,58368,59392,60416,61440,62464,63488,64512,65536" + }, + { + "name": "PlatformFaultDomainCount", + "value": "2" + } + ], + "capacity": null, + "costs": null, + "family": null, + "kind": null, + "locationInfo": [ + { + "location": "australiaeast", + "zoneDetails": [], + "zones": [ + "3", + "1", + "2" + ] + } + ], + "locations": [ + "australiaeast" + ], + "name": "PremiumV2_LRS", + "resourceType": "disks", + "restrictions": [], + "size": "P", + "tier": "Premium" + } +] \ No newline at end of file