@@ -643,6 +643,134 @@ func TestAzureMachineType(t *testing.T) {
643643 require .Error (t , err2 )
644644}
645645
646+ func TestIBMMachineType (t * testing.T ) {
647+ testCases := []struct {
648+ name string
649+ cpus int
650+ mem spec.MemPerCPU
651+ arch vm.CPUArch
652+ expectedMachine string
653+ expectedArch vm.CPUArch
654+ expectedError string
655+ }{}
656+
657+ // Helper function to generate the expected machine type string
658+ ibmMachineType := func (series string , cpus int , ramRatio int ) string {
659+ return fmt .Sprintf ("%s-%dx%d" , series , cpus , cpus * ramRatio )
660+ }
661+
662+ // IBM Z only supports s390x architecture
663+ arch := vm .ArchS390x
664+
665+ // Add test cases for each memory configuration
666+ addTestCases := func (mem spec.MemPerCPU ) {
667+ var series string
668+ var ramRatio int
669+
670+ switch mem {
671+ case spec .Auto , spec .Standard :
672+ series = "bz2" // balanced
673+ ramRatio = 4
674+ case spec .High :
675+ series = "mz2" // memory optimized
676+ ramRatio = 8
677+ case spec .Low :
678+ series = "cz2" // compute optimized
679+ ramRatio = 2
680+ }
681+
682+ // IBM Z only supports 2, 4, 8, or 16 CPUs
683+ for _ , cpus := range []int {2 , 4 , 8 , 16 } {
684+ testName := fmt .Sprintf ("valid_%dcpu_%s" , cpus , mem )
685+ testCases = append (testCases , struct {
686+ name string
687+ cpus int
688+ mem spec.MemPerCPU
689+ arch vm.CPUArch
690+ expectedMachine string
691+ expectedArch vm.CPUArch
692+ expectedError string
693+ }{
694+ name : testName ,
695+ cpus : cpus ,
696+ mem : mem ,
697+ arch : arch ,
698+ expectedMachine : ibmMachineType (series , cpus , ramRatio ),
699+ expectedArch : arch ,
700+ expectedError : "" ,
701+ })
702+ }
703+
704+ // Add test cases for unsupported CPU counts
705+ invalidCPUs := []int {1 , 6 , 10 , 32 , 96 , 128 }
706+ for _ , cpus := range invalidCPUs {
707+ testName := fmt .Sprintf ("invalid_%dcpu_%s" , cpus , mem )
708+ testCases = append (testCases , struct {
709+ name string
710+ cpus int
711+ mem spec.MemPerCPU
712+ arch vm.CPUArch
713+ expectedMachine string
714+ expectedArch vm.CPUArch
715+ expectedError string
716+ }{
717+ name : testName ,
718+ cpus : cpus ,
719+ mem : mem ,
720+ arch : arch ,
721+ expectedMachine : "" ,
722+ expectedArch : arch ,
723+ expectedError : fmt .Sprintf ("invalid number of cpus %d for IBM" , cpus ),
724+ })
725+ }
726+ }
727+
728+ // Add test cases for each memory configuration
729+ for _ , mem := range []spec.MemPerCPU {spec .Auto , spec .Standard , spec .High , spec .Low } {
730+ addTestCases (mem )
731+ }
732+
733+ // Add test cases for unsupported architectures
734+ for _ , invalidArch := range []vm.CPUArch {vm .ArchAMD64 , vm .ArchARM64 , vm .ArchFIPS } {
735+ testName := fmt .Sprintf ("invalid_arch_%s" , invalidArch )
736+ testCases = append (testCases , struct {
737+ name string
738+ cpus int
739+ mem spec.MemPerCPU
740+ arch vm.CPUArch
741+ expectedMachine string
742+ expectedArch vm.CPUArch
743+ expectedError string
744+ }{
745+ name : testName ,
746+ cpus : 4 ,
747+ mem : spec .Auto ,
748+ arch : invalidArch ,
749+ expectedMachine : "" ,
750+ expectedArch : invalidArch ,
751+ expectedError : fmt .Sprintf ("invalid architecture %q for IBM" , invalidArch ),
752+ })
753+ }
754+
755+ for _ , tc := range testCases {
756+ t .Run (tc .name , func (t * testing.T ) {
757+ machineType , selectedArch , err := spec .SelectIBMMachineType (tc .cpus , tc .mem , tc .arch )
758+
759+ if tc .expectedError != "" {
760+ // We expect a specific error
761+ require .Error (t , err )
762+ require .Equal (t , tc .expectedError , err .Error ())
763+ require .Equal (t , tc .expectedMachine , machineType )
764+ require .Equal (t , tc .expectedArch , selectedArch )
765+ } else {
766+ require .NoError (t , err )
767+ require .Equal (t , tc .expectedMachine , machineType )
768+ require .Equal (t , tc .expectedArch , selectedArch )
769+ }
770+ })
771+ }
772+ }
773+
646774func TestMachineTypes (t * testing.T ) {
647775 datadriven .Walk (t , datapathutils .TestDataPath (t , "cluster_test" ), func (t * testing.T , path string ) {
648776 datadriven .RunTest (t , path , func (t * testing.T , d * datadriven.TestData ) string {
0 commit comments