@@ -19,6 +19,7 @@ import (
19
19
20
20
sdk "github.com/cosmos/cosmos-sdk/types"
21
21
"github.com/shopspring/decimal"
22
+ "github.com/stretchr/testify/assert"
22
23
"github.com/stretchr/testify/require"
23
24
24
25
dtypes "github.com/akash-network/akash-api/go/node/deployment/v1beta3"
@@ -731,3 +732,235 @@ func TestRationalToIntConversion(t *testing.T) {
731
732
a := ceilBigRatToBigInt (big .NewRat (3 , 2 ))
732
733
require .Equal (t , big .NewInt (2 ), a )
733
734
}
735
+
736
+ func Test_parseGPU_LastAttribute (t * testing.T ) {
737
+ gpu := atypes.GPU {
738
+ Units : atypes.ResourceValue {
739
+ Val : sdk .NewInt (111 ),
740
+ },
741
+ Attributes : atypes.Attributes {
742
+ {
743
+ Key : "vendor/nvidia/model/a100" ,
744
+ Value : "true" ,
745
+ },
746
+ {
747
+ Key : "vendor/nvidia/model/v100" ,
748
+ Value : "true" ,
749
+ },
750
+ {
751
+ Key : "vendor/nvidia/model/h100" ,
752
+ Value : "true" ,
753
+ },
754
+ },
755
+ }
756
+
757
+ e := parseGPU (& gpu )
758
+
759
+ v , ok := e .Attributes .Vendor ["nvidia" ]
760
+ require .True (t , ok )
761
+
762
+ assert .Equal (t , "h100" , v .Model )
763
+ }
764
+
765
+ func Test_newDataForScript_GPUWildcard (t * testing.T ) {
766
+ cases := []struct {
767
+ desc string
768
+ r Request
769
+ gpu gpuElement
770
+ }{
771
+ {
772
+ desc : "wildcard and allocated resources" ,
773
+ r : Request {
774
+ GSpec : & dtypes.GroupSpec {
775
+ Resources : dtypes.ResourceUnits {
776
+ {
777
+ Price : sdk .NewDecCoin ("denom" , sdk .NewInt (111 )),
778
+ Resources : atypes.Resources {
779
+ CPU : & atypes.CPU {
780
+ Units : atypes.ResourceValue {
781
+ Val : sdk .NewInt (111 ),
782
+ },
783
+ },
784
+ Memory : & atypes.Memory {
785
+ Quantity : atypes.ResourceValue {
786
+ Val : sdk .NewInt (111 ),
787
+ },
788
+ },
789
+ GPU : & atypes.GPU {
790
+ Units : atypes.ResourceValue {
791
+ Val : sdk .NewInt (111 ),
792
+ },
793
+ Attributes : atypes.Attributes {
794
+ {
795
+ Key : "vendor/nvidia/model/*" ,
796
+ Value : "true" ,
797
+ },
798
+ },
799
+ },
800
+ },
801
+ },
802
+ },
803
+ },
804
+ AllocatedResources : dtypes.ResourceUnits {
805
+ {
806
+ Resources : atypes.Resources {
807
+ ID : 111 ,
808
+ CPU : & atypes.CPU {
809
+ Units : atypes.ResourceValue {
810
+ Val : sdk .NewInt (111 ),
811
+ },
812
+ },
813
+ Memory : & atypes.Memory {
814
+ Quantity : atypes.ResourceValue {
815
+ Val : sdk .NewInt (111 ),
816
+ },
817
+ },
818
+ GPU : & atypes.GPU {
819
+ Units : atypes.ResourceValue {
820
+ Val : sdk .NewInt (111 ),
821
+ },
822
+ Attributes : atypes.Attributes {
823
+ {
824
+ Key : "vendor/nvidia/model/a100" ,
825
+ Value : "true" ,
826
+ },
827
+ },
828
+ },
829
+ },
830
+ },
831
+ },
832
+ },
833
+ gpu : gpuElement {
834
+ Units : 111 ,
835
+ Attributes : gpuAttributes {
836
+ Vendor : map [string ]gpuVendorAttributes {
837
+ "nvidia" : {Model : "a100" },
838
+ },
839
+ },
840
+ },
841
+ },
842
+ {
843
+ desc : "wildcard and no reservation value" ,
844
+ r : Request {
845
+ GSpec : & dtypes.GroupSpec {
846
+ Resources : dtypes.ResourceUnits {
847
+ {
848
+ Price : sdk .NewDecCoin ("denom" , sdk .NewInt (111 )),
849
+ Resources : atypes.Resources {
850
+ CPU : & atypes.CPU {
851
+ Units : atypes.ResourceValue {
852
+ Val : sdk .NewInt (111 ),
853
+ },
854
+ },
855
+ Memory : & atypes.Memory {
856
+ Quantity : atypes.ResourceValue {
857
+ Val : sdk .NewInt (111 ),
858
+ },
859
+ },
860
+ GPU : & atypes.GPU {
861
+ Units : atypes.ResourceValue {
862
+ Val : sdk .NewInt (111 ),
863
+ },
864
+ Attributes : atypes.Attributes {
865
+ {
866
+ Key : "vendor/nvidia/model/*" ,
867
+ Value : "true" ,
868
+ },
869
+ },
870
+ },
871
+ },
872
+ },
873
+ },
874
+ },
875
+ },
876
+ gpu : gpuElement {
877
+ Units : 111 ,
878
+ Attributes : gpuAttributes {
879
+ Vendor : map [string ]gpuVendorAttributes {
880
+ "nvidia" : {Model : "*" },
881
+ },
882
+ },
883
+ },
884
+ },
885
+ {
886
+ desc : "no wildcard and reservation value" ,
887
+ r : Request {
888
+ GSpec : & dtypes.GroupSpec {
889
+ Resources : dtypes.ResourceUnits {
890
+ {
891
+ Price : sdk .NewDecCoin ("denom" , sdk .NewInt (111 )),
892
+ Resources : atypes.Resources {
893
+ CPU : & atypes.CPU {
894
+ Units : atypes.ResourceValue {
895
+ Val : sdk .NewInt (111 ),
896
+ },
897
+ },
898
+ Memory : & atypes.Memory {
899
+ Quantity : atypes.ResourceValue {
900
+ Val : sdk .NewInt (111 ),
901
+ },
902
+ },
903
+ GPU : & atypes.GPU {
904
+ Units : atypes.ResourceValue {
905
+ Val : sdk .NewInt (111 ),
906
+ },
907
+ Attributes : atypes.Attributes {
908
+ {
909
+ Key : "vendor/nvidia/model/h100" ,
910
+ Value : "true" ,
911
+ },
912
+ },
913
+ },
914
+ },
915
+ },
916
+ },
917
+ },
918
+ AllocatedResources : dtypes.ResourceUnits {
919
+ {
920
+ Resources : atypes.Resources {
921
+ ID : 111 ,
922
+ CPU : & atypes.CPU {
923
+ Units : atypes.ResourceValue {
924
+ Val : sdk .NewInt (111 ),
925
+ },
926
+ },
927
+ Memory : & atypes.Memory {
928
+ Quantity : atypes.ResourceValue {
929
+ Val : sdk .NewInt (111 ),
930
+ },
931
+ },
932
+ GPU : & atypes.GPU {
933
+ Units : atypes.ResourceValue {
934
+ Val : sdk .NewInt (111 ),
935
+ },
936
+ Attributes : atypes.Attributes {
937
+ {
938
+ Key : "vendor/nvidia/model/a100" ,
939
+ Value : "true" ,
940
+ },
941
+ },
942
+ },
943
+ },
944
+ },
945
+ },
946
+ },
947
+ gpu : gpuElement {
948
+ Units : 111 ,
949
+ Attributes : gpuAttributes {
950
+ Vendor : map [string ]gpuVendorAttributes {
951
+ "nvidia" : {Model : "h100" },
952
+ },
953
+ },
954
+ },
955
+ },
956
+ }
957
+
958
+ for _ , c := range cases {
959
+ c := c
960
+
961
+ t .Run (c .desc , func (t * testing.T ) {
962
+ d := newDataForScript (c .r )
963
+ assert .NotEmpty (t , d )
964
+ })
965
+ }
966
+ }
0 commit comments