@@ -1070,6 +1070,103 @@ func TestUserGroupLimit(t *testing.T) { //nolint:funlen
1070
1070
}
1071
1071
}
1072
1072
1073
+ func TestUserGroupLimitChange (t * testing.T ) { //nolint:funlen
1074
+ testCases := []struct {
1075
+ name string
1076
+ user security.UserGroup
1077
+ limits []configs.Limit
1078
+ newLimits []configs.Limit
1079
+ }{
1080
+ {
1081
+ name : "maxresources with an updated specific group limit" ,
1082
+ user : security.UserGroup {User : "user1" , Groups : []string {"group1" }},
1083
+ limits : []configs.Limit {
1084
+ createLimit (nil , []string {"group1" }, largeResource , 2 ),
1085
+ },
1086
+ newLimits : []configs.Limit {
1087
+ createLimit (nil , []string {"group1" }, mediumResource , 2 ),
1088
+ },
1089
+ },
1090
+ }
1091
+
1092
+ for _ , tc := range testCases {
1093
+ t .Run (tc .name , func (t * testing.T ) {
1094
+ setupUGM ()
1095
+
1096
+ manager := GetUserManager ()
1097
+ conf := createConfigWithLimits (tc .limits )
1098
+
1099
+ assert .NilError (t , manager .UpdateConfig (conf .Queues [0 ], "root" ))
1100
+
1101
+ usage , err := resources .NewResourceFromConf (mediumResource )
1102
+ if err != nil {
1103
+ t .Errorf ("new resource create returned error or wrong resource: error %t, res %v" , err , usage )
1104
+ }
1105
+
1106
+ increased := manager .IncreaseTrackedResource (queuePathParent , TestApp1 , usage , tc .user )
1107
+ assert .Equal (t , increased , true , "unable to increase tracked resource: queuepath " + queuePathParent + ", app " + TestApp1 + ", res " + usage .String ())
1108
+
1109
+ increased = manager .IncreaseTrackedResource (queuePathParent , TestApp2 , usage , tc .user )
1110
+ assert .Equal (t , increased , true , "unable to increase tracked resource: queuepath " + queuePathParent + ", app " + TestApp2 + ", res " + usage .String ())
1111
+
1112
+ decreased := manager .DecreaseTrackedResource (queuePathParent , TestApp2 , usage , tc .user , true )
1113
+ assert .Equal (t , decreased , true , "unable to decreased tracked resource: queuepath " + queuePathParent + ", app " + TestApp2 + ", res " + usage .String ())
1114
+
1115
+ conf .Queues [0 ].Queues [0 ].Limits = tc .newLimits
1116
+ assert .NilError (t , manager .UpdateConfig (conf .Queues [0 ], "root" ))
1117
+
1118
+ increased = manager .IncreaseTrackedResource (queuePathParent , TestApp2 , usage , tc .user )
1119
+ assert .Equal (t , increased , false , "should not increase tracked resource: queuepath " + queuePathParent + ", app " + TestApp2 + ", res " + usage .String ())
1120
+ })
1121
+ }
1122
+ }
1123
+
1124
+ func TestMultipleGroupLimitChange (t * testing.T ) {
1125
+ setupUGM ()
1126
+
1127
+ manager := GetUserManager ()
1128
+ conf := createConfigWithLimits ([]configs.Limit {
1129
+ createLimit (nil , []string {"group1" , "group2" }, largeResource , 2 ),
1130
+ createLimit (nil , []string {"*" }, mediumResource , 1 ),
1131
+ })
1132
+ assert .NilError (t , manager .UpdateConfig (conf .Queues [0 ], "root" ))
1133
+
1134
+ user1 := security.UserGroup {User : "user1" , Groups : []string {"group1" }}
1135
+ user2 := security.UserGroup {User : "user2" , Groups : []string {"group2" }}
1136
+ user3 := security.UserGroup {User : "user3" , Groups : []string {"group3" }}
1137
+
1138
+ usage , err := resources .NewResourceFromConf (mediumResource )
1139
+ if err != nil {
1140
+ t .Errorf ("new resource create returned error or wrong resource: error %t, res %v" , err , usage )
1141
+ }
1142
+
1143
+ // all users can increate usage within the quota
1144
+ increased := manager .IncreaseTrackedResource (queuePathParent , "test-app-1-1" , usage , user1 )
1145
+ assert .Equal (t , increased , true , "unable to increase tracked resource: queuepath " + queuePathParent + ", app test-app-1-1, res " + usage .String ())
1146
+
1147
+ increased = manager .IncreaseTrackedResource (queuePathParent , "test-app-2-1" , usage , user2 )
1148
+ assert .Equal (t , increased , true , "unable to increase tracked resource: queuepath " + queuePathParent + ", app test-app-2-1, res " + usage .String ())
1149
+
1150
+ increased = manager .IncreaseTrackedResource (queuePathParent , "test-app-3-1" , usage , user3 )
1151
+ assert .Equal (t , increased , true , "unable to increase tracked resource: queuepath " + queuePathParent + ", app test-app-3-1, res " + usage .String ())
1152
+
1153
+ // remove group2 from the specific group
1154
+ conf .Queues [0 ].Queues [0 ].Limits [0 ].Groups = []string {"group1" }
1155
+ assert .NilError (t , manager .UpdateConfig (conf .Queues [0 ], "root" ))
1156
+
1157
+ // user1 still can increase usage within the quota
1158
+ increased = manager .IncreaseTrackedResource (queuePathParent , "test-app-1-2" , usage , user1 )
1159
+ assert .Equal (t , increased , true , "unable to increase tracked resource: queuepath " + queuePathParent + ", app test-app-1-2, res " + usage .String ())
1160
+
1161
+ // user2 can't increase usage more than wildcard limit
1162
+ increased = manager .IncreaseTrackedResource (queuePathParent , "test-app-2-2" , usage , user2 )
1163
+ assert .Equal (t , increased , false , "should not increase tracked resource: queuepath " + queuePathParent + ", app test-app-2-2, res " + usage .String ())
1164
+
1165
+ // user3 can't increase usage more than wildcard limit
1166
+ increased = manager .IncreaseTrackedResource (queuePathParent , "test-app-3-2" , usage , user3 )
1167
+ assert .Equal (t , increased , false , "should not increase tracked resource: queuepath " + queuePathParent + ", app test-app-3-2, res " + usage .String ())
1168
+ }
1169
+
1073
1170
func createLimit (users , groups []string , maxResources map [string ]string , maxApps uint64 ) configs.Limit {
1074
1171
return configs.Limit {
1075
1172
Users : users ,
0 commit comments