This is an automated email from the ASF dual-hosted git repository. ccondit pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
The following commit(s) were added to refs/heads/master by this push:
new 96553dd7 [YUNIKORN-1871] Add limits and ugm validation test cases
(#595)
96553dd7 is described below
commit 96553dd7b5a402d6dc353b8ed556156e556483b5
Author: Frank Yang <[email protected]>
AuthorDate: Thu Aug 24 13:29:00 2023 -0500
[YUNIKORN-1871] Add limits and ugm validation test cases (#595)
Closes: #595
Signed-off-by: Craig Condit <[email protected]>
---
pkg/common/configs/configvalidator_test.go | 559 +++++++++++++++++++++++++++++
pkg/scheduler/ugm/manager_test.go | 292 +++++++++++++++
2 files changed, 851 insertions(+)
diff --git a/pkg/common/configs/configvalidator_test.go
b/pkg/common/configs/configvalidator_test.go
index 84923ad5..893bd7e3 100644
--- a/pkg/common/configs/configvalidator_test.go
+++ b/pkg/common/configs/configvalidator_test.go
@@ -23,6 +23,8 @@ import (
"testing"
"gotest.tools/v3/assert"
+
+ "github.com/apache/yunikorn-core/pkg/common/resources"
)
func TestCheckResourceConfigurationsForQueue(t *testing.T) {
@@ -734,3 +736,560 @@ func TestServiceAccountGroupName(t *testing.T) {
})
}
}
+
+func TestCheckLimitResource(t *testing.T) { //nolint:funlen
+ testCases := []struct {
+ name string
+ config QueueConfig
+ hasError bool
+ }{
+ {
+ name: "leaf queue user group maxresoruces are within
parent queue user group maxresources",
+ config: QueueConfig{
+ Name: "parent",
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxResources:
map[string]string{"memory": "100"},
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxResources:
map[string]string{"memory": "100"},
+ },
+ },
+ Queues: []QueueConfig{
+ {
+ Name: "child1",
+ Limits: []Limit{
+ {
+ Limit:
"user-limit",
+ Users:
[]string{"test-user"},
+ MaxResources:
map[string]string{"memory": "50"},
+ },
+ {
+ Limit:
"group-limit",
+ Groups:
[]string{"test-group"},
+ MaxResources:
map[string]string{"memory": "50"},
+ },
+ },
+ Queues: []QueueConfig{
+ {
+ Name: "child2",
+ Limits: []Limit{
+ {
+
Limit: "user-limit",
+
Users: []string{"test-user"},
+
MaxResources: map[string]string{"memory": "10"},
+ },
+ {
+
Limit: "group-limit",
+
Groups: []string{"test-group"},
+
MaxResources: map[string]string{"memory": "10"},
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ hasError: false,
+ },
+ {
+ name: "leaf queue user maxresources exceed parent queue
user maxresources",
+ config: QueueConfig{
+ Name: "parent",
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxResources:
map[string]string{"memory": "100"},
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxResources:
map[string]string{"memory": "100"},
+ },
+ },
+ Queues: []QueueConfig{
+ {
+ Name: "child1",
+ Limits: []Limit{
+ {
+ Limit:
"user-limit",
+ Users:
[]string{"test-user"},
+ MaxResources:
map[string]string{"memory": "200"},
+ },
+ {
+ Limit:
"group-limit",
+ Groups:
[]string{"test-group"},
+ MaxResources:
map[string]string{"memory": "50"},
+ },
+ },
+ },
+ },
+ },
+ hasError: true,
+ },
+ {
+ name: "leaf queue group maxresources exceed parent
queue group maxresources",
+ config: QueueConfig{
+ Name: "parent",
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxResources:
map[string]string{"memory": "100"},
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxResources:
map[string]string{"memory": "100"},
+ },
+ },
+ Queues: []QueueConfig{
+ {
+ Name: "child1",
+ Limits: []Limit{
+ {
+ Limit:
"user-limit",
+ Users:
[]string{"test-user"},
+ MaxResources:
map[string]string{"memory": "50"},
+ },
+ {
+ Limit:
"group-limit",
+ Groups:
[]string{"test-group"},
+ MaxResources:
map[string]string{"memory": "200"},
+ },
+ },
+ },
+ },
+ },
+ hasError: true,
+ },
+ }
+
+ for _, testCase := range testCases {
+ t.Run(testCase.name, func(t *testing.T) {
+ err := checkLimitResource(testCase.config, nil,
make(map[string]*resources.Resource), make(map[string]*resources.Resource))
+ if testCase.hasError {
+ assert.ErrorContains(t, err, "is greater than
immediate or ancestor parent maximum resource")
+ } else {
+ assert.NilError(t, err)
+ }
+ })
+ }
+}
+
+func TestCheckLimitMaxApplications(t *testing.T) { //nolint:funlen
+ testCases := []struct {
+ name string
+ config QueueConfig
+ hasError bool
+ }{
+ {
+ name: "leaf queue user group maxapplications are within
parent queue user group maxapplications",
+ config: QueueConfig{
+ Name: "parent",
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxApplications: 100,
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxApplications: 100,
+ },
+ },
+ Queues: []QueueConfig{
+ {
+ Name: "child1",
+ Limits: []Limit{
+ {
+ Limit:
"user-limit",
+ Users:
[]string{"test-user"},
+
MaxApplications: 100,
+ },
+ {
+ Limit:
"group-limit",
+ Groups:
[]string{"test-group"},
+
MaxApplications: 100,
+ },
+ },
+ Queues: []QueueConfig{
+ {
+ Name: "child2",
+ Limits: []Limit{
+ {
+
Limit: "user-limit",
+
Users: []string{"test-user"},
+
MaxApplications: 100,
+ },
+ {
+
Limit: "group-limit",
+
Groups: []string{"test-group"},
+
MaxApplications: 100,
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ hasError: false,
+ },
+ {
+ name: "leaf queue user maxapplications exceed parent
queue user maxapplications",
+ config: QueueConfig{
+ Name: "parent",
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxApplications: 100,
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxApplications: 100,
+ },
+ },
+ Queues: []QueueConfig{
+ {
+ Name: "child1",
+ Limits: []Limit{
+ {
+ Limit:
"user-limit",
+ Users:
[]string{"test-user"},
+
MaxApplications: 200,
+ },
+ {
+ Limit:
"group-limit",
+ Groups:
[]string{"test-group"},
+
MaxApplications: 50,
+ },
+ },
+ },
+ },
+ },
+ hasError: true,
+ },
+ {
+ name: "leaf queue group maxapplications exceed parent
queue group maxapplications",
+ config: QueueConfig{
+ Name: "parent",
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxApplications: 100,
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxApplications: 100,
+ },
+ },
+ Queues: []QueueConfig{
+ {
+ Name: "child1",
+ Limits: []Limit{
+ {
+ Limit:
"user-limit",
+ Users:
[]string{"test-user"},
+
MaxApplications: 50,
+ },
+ {
+ Limit:
"group-limit",
+ Groups:
[]string{"test-group"},
+
MaxApplications: 200,
+ },
+ },
+ },
+ },
+ },
+ hasError: true,
+ },
+ }
+
+ for _, testCase := range testCases {
+ t.Run(testCase.name, func(t *testing.T) {
+ err := checkLimitMaxApplications(testCase.config, nil,
make(map[string]uint64), make(map[string]uint64))
+ if testCase.hasError {
+ assert.ErrorContains(t, err, "is greater than
immediate or ancestor parent max applications")
+ } else {
+ assert.NilError(t, err)
+ }
+ })
+ }
+}
+
+func TestCheckLimits(t *testing.T) { //nolint:funlen
+ testCases := []struct {
+ name string
+ config QueueConfig
+ errMsg string
+ }{
+ {
+ name: "user group maxresources and maxapplications are
within queue limits",
+ config: QueueConfig{
+ Name: "parent",
+ Resources: Resources{
+ Max: map[string]string{"memory": "100"},
+ },
+ MaxApplications: 100,
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user", "*"},
+ MaxResources:
map[string]string{"memory": "100"},
+ MaxApplications: 100,
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group", "*"},
+ MaxResources:
map[string]string{"memory": "100"},
+ MaxApplications: 100,
+ },
+ },
+ },
+ errMsg: "",
+ },
+ {
+ name: "default queue maxapplications",
+ config: QueueConfig{
+ Name: "parent",
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxApplications: 100,
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxApplications: 100,
+ },
+ },
+ },
+ errMsg: "",
+ },
+ {
+ name: "user maxresources exceed queue limits",
+ config: QueueConfig{
+ Name: "parent",
+ Resources: Resources{
+ Max: map[string]string{"memory": "100"},
+ },
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxResources:
map[string]string{"memory": "200"},
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxResources:
map[string]string{"memory": "100"},
+ },
+ },
+ },
+ errMsg: "invalid MaxResources settings",
+ },
+ {
+ name: "group maxresources exceed queue limits",
+ config: QueueConfig{
+ Name: "parent",
+ Resources: Resources{
+ Max: map[string]string{"memory": "100"},
+ },
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxResources:
map[string]string{"memory": "100"},
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxResources:
map[string]string{"memory": "200"},
+ },
+ },
+ },
+ errMsg: "invalid MaxResources settings",
+ },
+ {
+ name: "user maxapplications exceed queue limits",
+ config: QueueConfig{
+ Name: "parent",
+ MaxApplications: 100,
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxApplications: 200,
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxApplications: 100,
+ },
+ },
+ },
+ errMsg: "invalid MaxApplications settings",
+ },
+ {
+ name: "group maxapplications exceed queue limits",
+ config: QueueConfig{
+ Name: "parent",
+ MaxApplications: 100,
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxApplications: 100,
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxApplications: 200,
+ },
+ },
+ },
+ errMsg: "invalid MaxApplications settings",
+ },
+ {
+ name: "user maxapplications is 0",
+ config: QueueConfig{
+ Name: "parent",
+ Resources: Resources{
+ Max: map[string]string{"memory": "100"},
+ },
+ MaxApplications: 100,
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxApplications: 0,
+ MaxResources:
map[string]string{"memory": "100"},
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxApplications: 100,
+ MaxResources:
map[string]string{"memory": "100"},
+ },
+ },
+ },
+ errMsg: "MaxApplications is 0",
+ },
+ {
+ name: "group maxapplications is 0",
+ config: QueueConfig{
+ Name: "parent",
+ Resources: Resources{
+ Max: map[string]string{"memory": "100"},
+ },
+ MaxApplications: 100,
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user"},
+ MaxApplications: 100,
+ MaxResources:
map[string]string{"memory": "100"},
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group"},
+ MaxApplications: 0,
+ MaxResources:
map[string]string{"memory": "100"},
+ },
+ },
+ },
+ errMsg: "MaxApplications is 0",
+ },
+ {
+ name: "user wildcard is not last entry",
+ config: QueueConfig{
+ Name: "parent",
+ Resources: Resources{
+ Max: map[string]string{"memory": "100"},
+ },
+ MaxApplications: 100,
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users: []string{"*",
"test-user"},
+ MaxResources:
map[string]string{"memory": "100"},
+ MaxApplications: 100,
+ },
+ {
+ Limit: "group-limit",
+ Groups:
[]string{"test-group", "*"},
+ MaxResources:
map[string]string{"memory": "100"},
+ MaxApplications: 100,
+ },
+ },
+ },
+ errMsg: "should not set no wildcard user test-user
after wildcard user limit",
+ },
+ {
+ name: "group wildcard is not last entry",
+ config: QueueConfig{
+ Name: "parent",
+ Resources: Resources{
+ Max: map[string]string{"memory": "100"},
+ },
+ MaxApplications: 100,
+ Limits: []Limit{
+ {
+ Limit: "user-limit",
+ Users:
[]string{"test-user", "*"},
+ MaxResources:
map[string]string{"memory": "100"},
+ MaxApplications: 100,
+ },
+ {
+ Limit: "group-limit",
+ Groups: []string{"*",
"test-group"},
+ MaxResources:
map[string]string{"memory": "100"},
+ MaxApplications: 100,
+ },
+ },
+ },
+ errMsg: "should not set no wildcard group test-group
after wildcard group limit",
+ },
+ {
+ name: "group wildcard is only entry",
+ config: QueueConfig{
+ Name: "parent",
+ Resources: Resources{
+ Max: map[string]string{"memory": "100"},
+ },
+ MaxApplications: 100,
+ Limits: []Limit{
+ {
+ Limit: "group-limit",
+ Groups: []string{"*"},
+ MaxResources:
map[string]string{"memory": "100"},
+ MaxApplications: 100,
+ },
+ },
+ },
+ errMsg: "should not specify only one group limit that
is using the wildcard.",
+ },
+ }
+
+ for _, testCase := range testCases {
+ t.Run(testCase.name, func(t *testing.T) {
+ err := checkLimits(testCase.config.Limits,
testCase.config.Name, &testCase.config)
+ if testCase.errMsg != "" {
+ assert.ErrorContains(t, err, testCase.errMsg)
+ } else {
+ assert.NilError(t, err)
+ }
+ })
+ }
+}
diff --git a/pkg/scheduler/ugm/manager_test.go
b/pkg/scheduler/ugm/manager_test.go
index 7d54195c..a1275b8b 100644
--- a/pkg/scheduler/ugm/manager_test.go
+++ b/pkg/scheduler/ugm/manager_test.go
@@ -30,6 +30,26 @@ import (
"github.com/apache/yunikorn-core/pkg/common/security"
)
+const (
+ queuePathParent = "root.parent"
+ queuePathLeaf = "root.parent.leaf"
+)
+
+var (
+ largeResource = map[string]string{
+ "memory": "100",
+ "vcores": "100",
+ }
+ mediumResource = map[string]string{
+ "memory": "50",
+ "vcores": "50",
+ }
+ tinyResource = map[string]string{
+ "memory": "25",
+ "vcores": "25",
+ }
+)
+
func TestUserManagerOnceInitialization(t *testing.T) {
manager := GetUserManager()
assert.Equal(t, manager, manager)
@@ -802,6 +822,278 @@ func TestCanRunApp(t *testing.T) {
}
}
+func TestSeparateUserGroupHeadroom(t *testing.T) {
+ testCases := []struct {
+ name string
+ user security.UserGroup
+ conf configs.PartitionConfig
+ }{
+ {
+ name: "headroom with only user limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
mediumResource, 2),
+ }),
+ },
+ {
+ name: "headroom with only group limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit(nil, []string{"group1"},
mediumResource, 2),
+ }),
+ },
+ {
+ name: "headroom with user limit lower than group limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
mediumResource, 2),
+ createLimit(nil, []string{"group1"},
largeResource, 2),
+ }),
+ },
+ {
+ name: "headroom with group limit lower than user limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
largeResource, 2),
+ createLimit(nil, []string{"group1"},
mediumResource, 2),
+ }),
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ setupUGM()
+
+ manager := GetUserManager()
+ assert.NilError(t,
manager.UpdateConfig(tc.conf.Queues[0], "root"))
+
+ usage, err :=
resources.NewResourceFromConf(tinyResource)
+ if err != nil {
+ t.Errorf("new resource create returned error or
wrong resource: error %t, res %v", err, usage)
+ }
+
+ increased :=
manager.IncreaseTrackedResource(queuePathParent, TestApp1, usage, tc.user)
+ assert.Equal(t, increased, true, "unable to increase
tracked resource: queuepath "+queuePathParent+", app "+TestApp1+", res
"+usage.String())
+
+ headroom := manager.Headroom(queuePathParent, TestApp1,
tc.user)
+ expectedHeadroom, err :=
resources.NewResourceFromConf(tinyResource)
+ if err != nil {
+ t.Errorf("new resource create returned error or
wrong resource: error %t, res %v", err, usage)
+ }
+
+ assert.Equal(t, resources.Equals(headroom,
expectedHeadroom), true)
+ })
+ }
+}
+
+func TestUserGroupLimit(t *testing.T) { //nolint:funlen
+ testCases := []struct {
+ name string
+ user security.UserGroup
+ conf configs.PartitionConfig
+ }{
+ // unmixed user and group limit
+ {
+ name: "maxresources with a specific user limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
mediumResource, 2),
+ }),
+ },
+ {
+ name: "maxapplications with a specific user limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
largeResource, 1),
+ }),
+ },
+ {
+ name: "maxresources with a specific user limit and a
wildcard user limit for a not specific user",
+ user: security.UserGroup{User: "user2", Groups:
[]string{"group2"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
largeResource, 2),
+ createLimit([]string{"*"}, nil, mediumResource,
2),
+ }),
+ },
+ {
+ name: "maxapplications with a specific user limit and a
wildcard user limit for a not specific user",
+ user: security.UserGroup{User: "user2", Groups:
[]string{"group2"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
largeResource, 2),
+ createLimit([]string{"*"}, nil, largeResource,
1),
+ }),
+ },
+ {
+ name: "maxresources with a specific user limit and a
wildcard user limit for a specific user",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
mediumResource, 2),
+ createLimit([]string{"*"}, nil, largeResource,
2),
+ }),
+ },
+ {
+ name: "maxapplications with a specific user limit and a
wildcard user limit for a specific user",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
largeResource, 1),
+ createLimit([]string{"*"}, nil, largeResource,
2),
+ }),
+ },
+ {
+ name: "maxresources with a wildcard user limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit(nil, []string{"*"}, mediumResource,
2),
+ }),
+ },
+ {
+ name: "maxapplications with a wildcard user limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit(nil, []string{"*"}, largeResource,
1),
+ }),
+ },
+ {
+ name: "maxresources with a specific group limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit(nil, []string{"group1"},
mediumResource, 2),
+ }),
+ },
+ {
+ name: "maxapplications with a specific group limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit(nil, []string{"group1"},
largeResource, 1),
+ }),
+ },
+ {
+ name: "maxresources with a specific group limit and a
wildcard group limit for a not specific group user",
+ user: security.UserGroup{User: "user2", Groups:
[]string{"group2"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit(nil, []string{"group1"},
largeResource, 2),
+ createLimit(nil, []string{"*"}, mediumResource,
2),
+ }),
+ },
+ {
+ name: "maxapplications with a specific group limit and
a wildcard group limit for a not specific group user",
+ user: security.UserGroup{User: "user2", Groups:
[]string{"group2"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit(nil, []string{"group1"},
largeResource, 2),
+ createLimit(nil, []string{"*"}, largeResource,
1),
+ }),
+ },
+ {
+ name: "maxresources with a specific group limit and a
wildcard group limit for a specific group user",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit(nil, []string{"group1"},
mediumResource, 2),
+ createLimit(nil, []string{"*"}, largeResource,
2),
+ }),
+ },
+ {
+ name: "maxapplications with a specific group limit and
a wildcard group limit for a specific group user",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit(nil, []string{"group1"},
largeResource, 1),
+ createLimit(nil, []string{"*"}, largeResource,
2),
+ }),
+ },
+ // mixed user and group limit
+ {
+ name: "maxresources with user limit lower than group
limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
mediumResource, 2),
+ createLimit(nil, []string{"group1"},
largeResource, 2),
+ }),
+ },
+ {
+ name: "maxapplications with user limit lower than group
limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
largeResource, 1),
+ createLimit(nil, []string{"group1"},
largeResource, 2),
+ }),
+ },
+ {
+ name: "maxresources with gorup limit lower than user
limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
largeResource, 2),
+ createLimit(nil, []string{"group1"},
mediumResource, 2),
+ }),
+ },
+ {
+ name: "maxapplications with group limit lower than user
limit",
+ user: security.UserGroup{User: "user1", Groups:
[]string{"group1"}},
+ conf: createConfigWithLimits([]configs.Limit{
+ createLimit([]string{"user1"}, nil,
largeResource, 2),
+ createLimit(nil, []string{"group1"},
largeResource, 1),
+ }),
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ // clear tracked resource
+ setupUGM()
+
+ manager := GetUserManager()
+ assert.NilError(t,
manager.UpdateConfig(tc.conf.Queues[0], "root"))
+
+ usage, err :=
resources.NewResourceFromConf(mediumResource)
+ if err != nil {
+ t.Errorf("new resource create returned error or
wrong resource: error %t, res %v", err, usage)
+ }
+
+ increased :=
manager.IncreaseTrackedResource(queuePathParent, TestApp1, usage, tc.user)
+ assert.Equal(t, increased, true, "unable to increase
tracked resource: queuepath "+queuePathParent+", app "+TestApp1+", res
"+usage.String())
+ userTracker := manager.GetUserTracker(tc.user.User)
+ assert.Equal(t, userTracker != nil, true,
fmt.Sprintf("can't get user tracker: %s", tc.user.User))
+ assert.Equal(t,
resources.Equals(userTracker.queueTracker.resourceUsage, usage), true, "user
tracker resource usage is not expected at root level")
+ assert.Equal(t,
userTracker.queueTracker.runningApplications[TestApp1], true, fmt.Sprintf("%s
is not in runningApplications for user tracker %s at root level", TestApp1,
tc.user.User))
+ assert.Equal(t,
userTracker.queueTracker.childQueueTrackers["parent"] != nil, true,
fmt.Sprintf("can't get root.parent queue tracker in user tracker: %s",
tc.user.User))
+ assert.Equal(t,
resources.Equals(userTracker.queueTracker.childQueueTrackers["parent"].resourceUsage,
usage), true, "user tracker resource usage is not expected at root.parent
level")
+ assert.Equal(t,
userTracker.queueTracker.childQueueTrackers["parent"].runningApplications[TestApp1],
true, fmt.Sprintf("%s is not in runningApplications for user tracker %s at
root.parent level", TestApp1, tc.user.User))
+
+ increased =
manager.IncreaseTrackedResource(queuePathParent, TestApp2, usage, tc.user)
+ assert.Equal(t, increased, false, "should not increase
tracked resource: queuepath "+queuePathParent+", app "+TestApp2+", res
"+usage.String())
+ })
+ }
+}
+
+func createLimit(users, groups []string, maxResources map[string]string,
maxApps uint64) configs.Limit {
+ return configs.Limit{
+ Users: users,
+ Groups: groups,
+ MaxResources: maxResources,
+ MaxApplications: maxApps,
+ }
+}
+
+func createConfigWithLimits(limits []configs.Limit) configs.PartitionConfig {
+ return configs.PartitionConfig{
+ Name: "test",
+ Queues: []configs.QueueConfig{
+ {
+ Name: "root",
+ Parent: true,
+ SubmitACL: "*",
+ Queues: []configs.QueueConfig{
+ {
+ Name: "parent",
+ Parent: true,
+ SubmitACL: "*",
+ Queues: nil,
+ Limits: limits,
+ },
+ },
+ },
+ },
+ }
+}
+
func createUpdateConfigWithWildCardUsersAndGroups(user string, group string,
wildUser string, wildGroup string, memory string, vcores string)
configs.PartitionConfig {
conf := configs.PartitionConfig{
Name: "test",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
