Skip to content

Commit

Permalink
sriov: Add WithRdmaMode method
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaggapa committed Nov 20, 2024
1 parent 0bf6f2b commit 3bd4056
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/sriov/poolconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,33 @@ func (builder *PoolConfigBuilder) WithMaxUnavailable(maxUnavailable intstrutil.I
return builder
}

// WithRdmaMode method sets rdmaMode to shared/exclusive.
func (builder *PoolConfigBuilder) WithRdmaMode(mode string) *PoolConfigBuilder {
if valid, _ := builder.validate(); !valid {
return builder
}

if mode == "" {
glog.V(100).Info("PoolConfig RdmaMode cannot be empty")

builder.errorMsg = "rdmaMode cannot be empty"

return builder
}

if mode != "shared" && mode != "exclusive" {
glog.V(100).Info("Invalid RdmaMode. Acceptable values: shared or exclusive")

builder.errorMsg = "invalid value for rdmaMode. It should be 'shared' or 'exclusive'"

return builder
}

builder.Definition.Spec.RdmaMode = mode

return builder
}

// PullPoolConfig pulls existing SriovNetworkPoolConfig from cluster.
func PullPoolConfig(apiClient *clients.Settings, name, nsname string) (*PoolConfigBuilder, error) {
glog.V(100).Infof("Pulling existing SriovNetworkPoolConfig name %s under namespace %s from cluster", name, nsname)
Expand Down
34 changes: 34 additions & 0 deletions pkg/sriov/poolconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,40 @@ func TestWithMaxUnavailable(t *testing.T) {
}
}

func TestWithRdmaMode(t *testing.T) {
testCases := []struct {
RdmaMode string
ExpectedError string
}{
{
RdmaMode: "shared",
ExpectedError: "",
},
{
RdmaMode: "exclusive",
ExpectedError: "",
},
{
RdmaMode: "",
ExpectedError: "RdmaMode cannot be empty",
},
{
RdmaMode: "none",
ExpectedError: "Invalid value for rdmaMode. It should be 'shared' or 'exclusive'",
},
}

for _, testCase := range testCases {
testSettings := buildTestPoolConfigClientWithDummyObject()
testBuilder := buildValidPoolConfigTestBuilder(testSettings).WithRdmaMode(testCase.RdmaMode)
assert.Equal(t, testCase.ExpectedError, testBuilder.errorMsg)

if testCase.ExpectedError == "" {
assert.Equal(t, testBuilder.Definition.Spec.RdmaMode, testCase.RdmaMode)
}
}
}

func TestPullPoolConfig(t *testing.T) {
testCases := []struct {
poolConfigName string
Expand Down

0 comments on commit 3bd4056

Please sign in to comment.