Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added querySystemLimits for CSI spec 1.6 #86

Merged
merged 18 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions inttests/system_limit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright © 2021 - 2023 Dell Inc. or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package inttests

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

// TestGetSystemLimits gets the list of system limits
func TestGetSystemLimits(t *testing.T) {
resp, err := C.GetSystemLimits()
fmt.Println("systemlimit", resp)
assert.NotNil(t, resp)
assert.Nil(t, err)
}

// TestGetMaxVol get the max volume
func TestGetMaxVol(t *testing.T) {
maxvolsize, err := C.GetMaxVol()
fmt.Println("max vol size", maxvolsize)
assert.NotNil(t, maxvolsize)
assert.Nil(t, err)

}
54 changes: 54 additions & 0 deletions system_limit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright © 2019 - 2023 Dell Inc. or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package goscaleio

import (
"errors"
"net/http"
"time"

types "github.com/dell/goscaleio/types/v1"
)

VamsiSiddu-7 marked this conversation as resolved.
Show resolved Hide resolved
// GetSystemLimits gets list of sytem limits
func (c *Client) GetSystemLimits() (systemLimits *types.QuerySystemLimitsResponse, err error) {
defer TimeSpent("GetSystemLimits", time.Now())
var body types.QuerySystemLimitsParam
path := "/api/instances/System/action/querySystemLimits"
err = c.getJSONWithRetry(
http.MethodPost, path, body, &systemLimits)
if err != nil {
return nil, err
}

return systemLimits, nil
}

// GetMaxVol returns max volume size in GB
func (c *Client) GetMaxVol() (MaxVolumeSize string, err error) {
defer TimeSpent("GetMaxVol", time.Now())
sysLimit, err := c.GetSystemLimits()

if err != nil {
return "", err
}

for _, systemLimit := range sysLimit.SystemLimitEntryList {

if systemLimit.Type == "volumeSizeGb" {
return systemLimit.MaxVal, nil
}

}
return "", errors.New("couldn't get max vol size")
}
145 changes: 145 additions & 0 deletions system_limit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright © 2021 - 2023 Dell Inc. or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package goscaleio

import (
"encoding/json"
"fmt"
"math"
"net/http"
"net/http/httptest"
"testing"

types "github.com/dell/goscaleio/types/v1"
"github.com/stretchr/testify/assert"
)

func TestGetSystemLimits(t *testing.T) {
type checkFn func(*testing.T, *types.QuerySystemLimitsResponse, error)
check := func(fns ...checkFn) []checkFn { return fns }

hasNoError := func(t *testing.T, syslimit *types.QuerySystemLimitsResponse, err error) {
if err != nil {
t.Fatalf("expected no error")
}
}

hasError := func(t *testing.T, syslimit *types.QuerySystemLimitsResponse, err error) {
if err == nil {
t.Fatalf("expected error")
}
}

checkLimitType := func(expectedType string) func(t *testing.T, syslimit *types.QuerySystemLimitsResponse, err error) {
return func(t *testing.T, syslimit *types.QuerySystemLimitsResponse, err error) {
if err == nil {
// Add your custom assertions here to check the syslimit.Type.
assert.Equal(t, expectedType, syslimit.SystemLimitEntryList[0].Type)
}
}
}

checkLimitDescription := func(expectedDescription string) func(t *testing.T, syslimit *types.QuerySystemLimitsResponse, err error) {
return func(t *testing.T, syslimit *types.QuerySystemLimitsResponse, err error) {
if err == nil {
// Add your custom assertions here to check the syslimit.Description.
assert.Equal(t, expectedDescription, syslimit.SystemLimitEntryList[0].Description)
}
}
}

checkLimitMaxVal := func(expectedMaxVal string) func(t *testing.T, syslimit *types.QuerySystemLimitsResponse, err error) {
return func(t *testing.T, syslimit *types.QuerySystemLimitsResponse, err error) {
if err == nil {
// Add your custom assertions here to check the syslimit.MaxVal.
assert.Equal(t, expectedMaxVal, syslimit.SystemLimitEntryList[0].MaxVal)
}
}
}

tests := map[string]func(t *testing.T) (*httptest.Server, []checkFn){
"success": func(t *testing.T) (*httptest.Server, []checkFn) {
href := "/api/instances/System/action/querySystemLimits"

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
t.Fatal(fmt.Errorf("wrong method. Expected %s; but got %s", http.MethodPost, r.Method))
}

if r.URL.Path != href {
t.Fatal(fmt.Errorf("wrong path. Expected %s; but got %s", href, r.URL.Path))
}

// Simulate a successful response for GetSystemLimits.
resp := types.QuerySystemLimitsResponse{
SystemLimitEntryList: []types.SystemLimits{
{
Type: "volumeSizeGb",
Description: "Maximum volume size in GB",
MaxVal: "1024",
},
},
}

respData, err := json.Marshal(resp)
if err != nil {
t.Fatal(err)
}
fmt.Fprintln(w, string(respData))
}))

return ts, check(hasNoError, checkLimitType("volumeSizeGb"), checkLimitDescription("Maximum volume size in GB"), checkLimitMaxVal("1024"))
},
"not found": func(t *testing.T) (*httptest.Server, []checkFn) {
href := "/api/instances/System/action/querySystemLimits"

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
t.Fatal(fmt.Errorf("wrong method. Expected %s; but got %s", http.MethodPost, r.Method))
}

if r.URL.Path != href {
t.Fatal(fmt.Errorf("wrong path. Expected %s; but got %s", href, r.URL.Path))
}

http.Error(w, "nas not found", http.StatusNotFound)
}))

return ts, check(hasError)
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
ts, checkFns := tc(t)
defer ts.Close()

// Create a test client and call GetSystemLimits.
//client := NewTestClient(ts.URL) // Replace with your own client creation logic.
client, err := NewClientWithArgs(ts.URL, "", math.MaxInt64, true, false)
client.configConnect.Version = "4.0"
if err != nil {
t.Fatal(err)
}

sys := System{
client: client,
}

resp, err := sys.client.GetSystemLimits()
for _, checkFn := range checkFns {
checkFn(t, resp, err)
}
})
}
}
15 changes: 15 additions & 0 deletions types/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1738,3 +1738,18 @@ type MDMQueueCommandDetails struct {
TargetEntityIdentifier string `json:"targetEntityIdentifier,omitempty"`
AllowedPhase string `json:"allowedPhase,omitempty"`
}

// SystemLimits defines struct for system limits
type SystemLimits struct {
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
MaxVal string `json:"maxVal,omitempty"`
}

// SystemLimitEntryList defines struct for system limit entryList
type QuerySystemLimitsResponse struct {
SystemLimitEntryList []SystemLimits `json:"systemLimitEntryList"`
}

type QuerySystemLimitsParam struct {
}
Loading