From 98247d27212edd77360e2172f6330b4bee0f74bc Mon Sep 17 00:00:00 2001 From: Kshitija Kakde Date: Thu, 12 Oct 2023 10:02:25 +0530 Subject: [PATCH 01/18] changes added --- system_limit.go | 33 +++++++++++++++++++++++++++++++++ types/v1/types.go | 7 +++++++ 2 files changed, 40 insertions(+) create mode 100644 system_limit.go diff --git a/system_limit.go b/system_limit.go new file mode 100644 index 0000000..3bff6cc --- /dev/null +++ b/system_limit.go @@ -0,0 +1,33 @@ +// 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 ( + "net/http" + "time" + + types "github.com/dell/goscaleio/types/v1" +) + +func (c *Client) GetSystemLimits() (syslimit []types.QuerySystemLimits, err error) { + defer TimeSpent("GetSystemLimits", time.Now()) + path := "/api/instances/System/action/querySystemLimits" + + err = c.getJSONWithRetry( + http.MethodPost, path, nil, &syslimit) + if err != nil { + return nil, err + } + + return syslimit, nil +} diff --git a/types/v1/types.go b/types/v1/types.go index 659c5f7..fbccd64 100644 --- a/types/v1/types.go +++ b/types/v1/types.go @@ -1738,3 +1738,10 @@ type MDMQueueCommandDetails struct { TargetEntityIdentifier string `json:"targetEntityIdentifier,omitempty"` AllowedPhase string `json:"allowedPhase,omitempty"` } + +type QuerySystemLimits struct { + Type string `json:"type,omitempty"` + Description string `json:"description,omitempty"` + MinVal string `json:"min_val,omitempty"` + MaxVal string `json:"max_val,omitempty"` +} From a04e73c30c9efb1e9705c60f3603e8e63624d346 Mon Sep 17 00:00:00 2001 From: Vamsikrishna_Siddu Date: Thu, 12 Oct 2023 07:06:15 -0400 Subject: [PATCH 02/18] update GetSystemLimits. --- system_limit.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/system_limit.go b/system_limit.go index 3bff6cc..b8b0056 100644 --- a/system_limit.go +++ b/system_limit.go @@ -22,9 +22,8 @@ import ( func (c *Client) GetSystemLimits() (syslimit []types.QuerySystemLimits, err error) { defer TimeSpent("GetSystemLimits", time.Now()) path := "/api/instances/System/action/querySystemLimits" - err = c.getJSONWithRetry( - http.MethodPost, path, nil, &syslimit) + http.MethodPost, path, nil, syslimit) if err != nil { return nil, err } From 354abb6a019a66a859fa01d0016813217b6594e7 Mon Sep 17 00:00:00 2001 From: Vamsikrishna_Siddu Date: Thu, 12 Oct 2023 07:10:52 -0400 Subject: [PATCH 03/18] update GetSystemLimits. --- api.go | 2 ++ system_limit.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index 1bc98bb..168cdaf 100644 --- a/api.go +++ b/api.go @@ -200,6 +200,8 @@ func (c *Client) getJSONWithRetry( return nil } + fmt.Printf("err: %#v\n", err) + // check if we need to authenticate if e, ok := err.(*types.Error); ok { doLog(log.WithError(err).Debug, fmt.Sprintf("Got JSON error: %+v", e)) diff --git a/system_limit.go b/system_limit.go index b8b0056..453c20e 100644 --- a/system_limit.go +++ b/system_limit.go @@ -23,7 +23,7 @@ func (c *Client) GetSystemLimits() (syslimit []types.QuerySystemLimits, err erro defer TimeSpent("GetSystemLimits", time.Now()) path := "/api/instances/System/action/querySystemLimits" err = c.getJSONWithRetry( - http.MethodPost, path, nil, syslimit) + http.MethodPost, path, nil, &syslimit) if err != nil { return nil, err } From 08d909a08ae9b36d552e6d2fe7cfb76ed674c8f6 Mon Sep 17 00:00:00 2001 From: Vamsikrishna_Siddu Date: Thu, 12 Oct 2023 07:20:32 -0400 Subject: [PATCH 04/18] update GetSystemLimits. --- api.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/api.go b/api.go index 168cdaf..d87cda7 100644 --- a/api.go +++ b/api.go @@ -23,7 +23,6 @@ import ( "net/http" "os" "regexp" - "strconv" "strings" "sync" "time" @@ -42,8 +41,8 @@ var ( errBodyRead = errors.New("error reading body") errNoLink = errors.New("Error: problem finding link") - debug, _ = strconv.ParseBool(os.Getenv("GOSCALEIO_DEBUG")) - showHTTP, _ = strconv.ParseBool(os.Getenv("GOSCALEIO_SHOWHTTP")) + debug = true + showHTTP = true ) // Client defines struct for Client From 2dc5aabc24ed42abe42a3338449ed65ca999b5ed Mon Sep 17 00:00:00 2001 From: Vamsikrishna_Siddu Date: Thu, 12 Oct 2023 07:55:05 -0400 Subject: [PATCH 05/18] update GetSystemLimits. --- api/api.go | 2 ++ system_limit.go | 2 +- types/v1/types.go | 7 +++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/api/api.go b/api/api.go index 87a2437..fd448d7 100644 --- a/api/api.go +++ b/api/api.go @@ -326,6 +326,8 @@ func (c *client) DoAndGetResponseBody( if r, ok := body.(io.ReadCloser); ok { req, err = http.NewRequest(method, u.String(), r) + fmt.Printf("req: %#v\n", req) + defer func() { if err := r.Close(); err != nil { c.doLog(log.WithError(err).Error, "") diff --git a/system_limit.go b/system_limit.go index 453c20e..ed81260 100644 --- a/system_limit.go +++ b/system_limit.go @@ -19,7 +19,7 @@ import ( types "github.com/dell/goscaleio/types/v1" ) -func (c *Client) GetSystemLimits() (syslimit []types.QuerySystemLimits, err error) { +func (c *Client) GetSystemLimits() (syslimit *types.Limit, err error) { defer TimeSpent("GetSystemLimits", time.Now()) path := "/api/instances/System/action/querySystemLimits" err = c.getJSONWithRetry( diff --git a/types/v1/types.go b/types/v1/types.go index fbccd64..30978c3 100644 --- a/types/v1/types.go +++ b/types/v1/types.go @@ -1742,6 +1742,9 @@ type MDMQueueCommandDetails struct { type QuerySystemLimits struct { Type string `json:"type,omitempty"` Description string `json:"description,omitempty"` - MinVal string `json:"min_val,omitempty"` - MaxVal string `json:"max_val,omitempty"` + MaxVal string `json:"maxVal,omitempty"` +} + +type Limit struct { + SystemLimitEntryList []QuerySystemLimits `json:"systemLimitEntryList"` } From fcec27866fbf1f333951de729ac4989d6b0a61e8 Mon Sep 17 00:00:00 2001 From: Vamsikrishna_Siddu Date: Thu, 12 Oct 2023 08:11:41 -0400 Subject: [PATCH 06/18] update GetSystemLimits. --- api/api.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/api.go b/api/api.go index fd448d7..67a440e 100644 --- a/api/api.go +++ b/api/api.go @@ -342,6 +342,7 @@ func (c *client) DoAndGetResponseBody( } isContentTypeSet = true } else if body != nil { + fmt.Printf("req1: %#v\n", req) buf := &bytes.Buffer{} enc := json.NewEncoder(buf) if err = enc.Encode(body); err != nil { @@ -355,6 +356,7 @@ func (c *client) DoAndGetResponseBody( } isContentTypeSet = true } else { + fmt.Printf("req3: %#v\n", req) req, err = http.NewRequest(method, u.String(), nil) } @@ -406,8 +408,10 @@ func (c *client) DoAndGetResponseBody( // send the request req = req.WithContext(ctx) if res, err = c.http.Do(req); err != nil { + fmt.Printf("err:%#v\n", err) return nil, err } + fmt.Printf("err:%#v", err) if c.showHTTP { logResponse(ctx, res, c.doLog) From 3babd9983c970254fa5fcfca5eafc8d238f0d8ea Mon Sep 17 00:00:00 2001 From: Vamsikrishna_Siddu Date: Thu, 12 Oct 2023 08:15:57 -0400 Subject: [PATCH 07/18] update GetSystemLimits. --- api/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/api.go b/api/api.go index 67a440e..f952f37 100644 --- a/api/api.go +++ b/api/api.go @@ -411,7 +411,7 @@ func (c *client) DoAndGetResponseBody( fmt.Printf("err:%#v\n", err) return nil, err } - fmt.Printf("err:%#v", err) + fmt.Printf("res:%#v", res) if c.showHTTP { logResponse(ctx, res, c.doLog) From 0ba81004f2939327c26187715d39ffc54bdd71f7 Mon Sep 17 00:00:00 2001 From: Vamsikrishna_Siddu Date: Thu, 12 Oct 2023 08:23:48 -0400 Subject: [PATCH 08/18] update GetSystemLimits. --- api/api.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/api.go b/api/api.go index f952f37..4509562 100644 --- a/api/api.go +++ b/api/api.go @@ -447,6 +447,7 @@ func (c *client) ParseJSONError(r *http.Response) error { if jsonError.Message == "" { jsonError.Message = r.Status } + fmt.Println("jsonError", jsonError) return jsonError } From 28584574a0c1f50d252cb916d49fbb4190ee5402 Mon Sep 17 00:00:00 2001 From: Vamsikrishna_Siddu Date: Thu, 12 Oct 2023 08:27:15 -0400 Subject: [PATCH 09/18] update GetSystemLimits. --- api/api.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/api.go b/api/api.go index 4509562..f37e79f 100644 --- a/api/api.go +++ b/api/api.go @@ -356,8 +356,9 @@ func (c *client) DoAndGetResponseBody( } isContentTypeSet = true } else { - fmt.Printf("req3: %#v\n", req) + req, err = http.NewRequest(method, u.String(), nil) + fmt.Printf("req3: %#v\n", req) } if err != nil { From bd4049ecf891ca29c338e261871243839aa43729 Mon Sep 17 00:00:00 2001 From: Kshitija Kakde Date: Mon, 16 Oct 2023 17:56:34 +0530 Subject: [PATCH 10/18] changes added --- inttests/system_limit_test.go | 35 +++++++++++++++++++++++++++++++++++ system_limit.go | 25 ++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 inttests/system_limit_test.go diff --git a/inttests/system_limit_test.go b/inttests/system_limit_test.go new file mode 100644 index 0000000..f773461 --- /dev/null +++ b/inttests/system_limit_test.go @@ -0,0 +1,35 @@ +// 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" +) + +func TestGetSystemLimits(t *testing.T) { + resp, err := C.GetSystemLimits() + fmt.Println("systemlimit", resp) + assert.NotNil(t, resp) + assert.Nil(t, err) +} + +func TestGetMaxVol(t *testing.T) { + maxvolsize, err := C.GetMaxVol() + fmt.Println("max vol size", maxvolsize) + assert.NotNil(t, maxvolsize) + assert.Nil(t, err) + +} diff --git a/system_limit.go b/system_limit.go index ed81260..f166d37 100644 --- a/system_limit.go +++ b/system_limit.go @@ -13,20 +13,43 @@ package goscaleio import ( + "errors" "net/http" "time" types "github.com/dell/goscaleio/types/v1" ) +type emptyBody struct { +} + func (c *Client) GetSystemLimits() (syslimit *types.Limit, err error) { defer TimeSpent("GetSystemLimits", time.Now()) + var e emptyBody path := "/api/instances/System/action/querySystemLimits" err = c.getJSONWithRetry( - http.MethodPost, path, nil, &syslimit) + http.MethodPost, path, e, &syslimit) if err != nil { return nil, err } return syslimit, nil } + +func (c *Client) GetMaxVol() (sys string, err error) { + defer TimeSpent("GetMaxVol", time.Now()) + maxlimitType, err := c.GetSystemLimits() + + if err != nil { + return "", err + } + + for _, systype := range maxlimitType.SystemLimitEntryList { + + if systype.Type == "volumeSizeGb" { + return systype.MaxVal, nil + } + + } + return "", errors.New("couldn't get max vol size") +} From 746b6ae014f8be8024da044a5dec3afe1850dc39 Mon Sep 17 00:00:00 2001 From: Kshitija Kakde Date: Tue, 17 Oct 2023 07:20:31 +0530 Subject: [PATCH 11/18] unit test added --- api.go | 7 +-- system_limit_test.go | 145 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 system_limit_test.go diff --git a/api.go b/api.go index d87cda7..1bc98bb 100644 --- a/api.go +++ b/api.go @@ -23,6 +23,7 @@ import ( "net/http" "os" "regexp" + "strconv" "strings" "sync" "time" @@ -41,8 +42,8 @@ var ( errBodyRead = errors.New("error reading body") errNoLink = errors.New("Error: problem finding link") - debug = true - showHTTP = true + debug, _ = strconv.ParseBool(os.Getenv("GOSCALEIO_DEBUG")) + showHTTP, _ = strconv.ParseBool(os.Getenv("GOSCALEIO_SHOWHTTP")) ) // Client defines struct for Client @@ -199,8 +200,6 @@ func (c *Client) getJSONWithRetry( return nil } - fmt.Printf("err: %#v\n", err) - // check if we need to authenticate if e, ok := err.(*types.Error); ok { doLog(log.WithError(err).Debug, fmt.Sprintf("Got JSON error: %+v", e)) diff --git a/system_limit_test.go b/system_limit_test.go new file mode 100644 index 0000000..5438cab --- /dev/null +++ b/system_limit_test.go @@ -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.Limit, error) + check := func(fns ...checkFn) []checkFn { return fns } + + hasNoError := func(t *testing.T, syslimit *types.Limit, err error) { + if err != nil { + t.Fatalf("expected no error") + } + } + + hasError := func(t *testing.T, syslimit *types.Limit, err error) { + if err == nil { + t.Fatalf("expected error") + } + } + + checkLimitType := func(expectedType string) func(t *testing.T, syslimit *types.Limit, err error) { + return func(t *testing.T, syslimit *types.Limit, 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.Limit, err error) { + return func(t *testing.T, syslimit *types.Limit, 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.Limit, err error) { + return func(t *testing.T, syslimit *types.Limit, 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.Limit{ + SystemLimitEntryList: []types.QuerySystemLimits{ + { + 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) + } + }) + } +} From e38ed0ed7b6fec4f36343c72c29176743f7a1026 Mon Sep 17 00:00:00 2001 From: Kshitija Kakde Date: Tue, 17 Oct 2023 07:24:13 +0530 Subject: [PATCH 12/18] unit test added --- api/api.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/api/api.go b/api/api.go index f37e79f..87a2437 100644 --- a/api/api.go +++ b/api/api.go @@ -326,8 +326,6 @@ func (c *client) DoAndGetResponseBody( if r, ok := body.(io.ReadCloser); ok { req, err = http.NewRequest(method, u.String(), r) - fmt.Printf("req: %#v\n", req) - defer func() { if err := r.Close(); err != nil { c.doLog(log.WithError(err).Error, "") @@ -342,7 +340,6 @@ func (c *client) DoAndGetResponseBody( } isContentTypeSet = true } else if body != nil { - fmt.Printf("req1: %#v\n", req) buf := &bytes.Buffer{} enc := json.NewEncoder(buf) if err = enc.Encode(body); err != nil { @@ -356,9 +353,7 @@ func (c *client) DoAndGetResponseBody( } isContentTypeSet = true } else { - req, err = http.NewRequest(method, u.String(), nil) - fmt.Printf("req3: %#v\n", req) } if err != nil { @@ -409,10 +404,8 @@ func (c *client) DoAndGetResponseBody( // send the request req = req.WithContext(ctx) if res, err = c.http.Do(req); err != nil { - fmt.Printf("err:%#v\n", err) return nil, err } - fmt.Printf("res:%#v", res) if c.showHTTP { logResponse(ctx, res, c.doLog) @@ -448,7 +441,6 @@ func (c *client) ParseJSONError(r *http.Response) error { if jsonError.Message == "" { jsonError.Message = r.Status } - fmt.Println("jsonError", jsonError) return jsonError } From b84ad34b5f6be451dfd6ff7a687352716bcd28fb Mon Sep 17 00:00:00 2001 From: Kshitija Kakde Date: Tue, 17 Oct 2023 09:28:11 +0530 Subject: [PATCH 13/18] comments added --- inttests/system_limit_test.go | 2 ++ system_limit.go | 3 +++ types/v1/types.go | 2 ++ 3 files changed, 7 insertions(+) diff --git a/inttests/system_limit_test.go b/inttests/system_limit_test.go index f773461..5759d32 100644 --- a/inttests/system_limit_test.go +++ b/inttests/system_limit_test.go @@ -19,6 +19,7 @@ import ( "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) @@ -26,6 +27,7 @@ func TestGetSystemLimits(t *testing.T) { assert.Nil(t, err) } +// TestGetMaxVol get the max volume func TestGetMaxVol(t *testing.T) { maxvolsize, err := C.GetMaxVol() fmt.Println("max vol size", maxvolsize) diff --git a/system_limit.go b/system_limit.go index f166d37..cc52e83 100644 --- a/system_limit.go +++ b/system_limit.go @@ -23,6 +23,8 @@ import ( type emptyBody struct { } +// GetSystemLimits gets list of sytem limits + func (c *Client) GetSystemLimits() (syslimit *types.Limit, err error) { defer TimeSpent("GetSystemLimits", time.Now()) var e emptyBody @@ -36,6 +38,7 @@ func (c *Client) GetSystemLimits() (syslimit *types.Limit, err error) { return syslimit, nil } +// GetMaxVol returns max volume size in GB func (c *Client) GetMaxVol() (sys string, err error) { defer TimeSpent("GetMaxVol", time.Now()) maxlimitType, err := c.GetSystemLimits() diff --git a/types/v1/types.go b/types/v1/types.go index 30978c3..fe8ca86 100644 --- a/types/v1/types.go +++ b/types/v1/types.go @@ -1739,12 +1739,14 @@ type MDMQueueCommandDetails struct { AllowedPhase string `json:"allowedPhase,omitempty"` } +// QuerySystemLimits defines struct for query system limits type QuerySystemLimits struct { Type string `json:"type,omitempty"` Description string `json:"description,omitempty"` MaxVal string `json:"maxVal,omitempty"` } +// SystemLimitEntryList defines struct for system limit entryList type Limit struct { SystemLimitEntryList []QuerySystemLimits `json:"systemLimitEntryList"` } From 9ae3b7dd3b48a8670553243a6ba2b6f6f077aae7 Mon Sep 17 00:00:00 2001 From: Kshitija Kakde Date: Tue, 17 Oct 2023 10:23:31 +0530 Subject: [PATCH 14/18] review comments added --- system_limit.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/system_limit.go b/system_limit.go index cc52e83..15d82b4 100644 --- a/system_limit.go +++ b/system_limit.go @@ -20,22 +20,22 @@ import ( types "github.com/dell/goscaleio/types/v1" ) -type emptyBody struct { +type QuerySystemLimitsParam struct { } // GetSystemLimits gets list of sytem limits -func (c *Client) GetSystemLimits() (syslimit *types.Limit, err error) { +func (c *Client) GetSystemLimits() (systemLimits *types.Limit, err error) { defer TimeSpent("GetSystemLimits", time.Now()) - var e emptyBody + var body QuerySystemLimitsParam path := "/api/instances/System/action/querySystemLimits" err = c.getJSONWithRetry( - http.MethodPost, path, e, &syslimit) + http.MethodPost, path, body, &systemLimits) if err != nil { return nil, err } - return syslimit, nil + return systemLimits, nil } // GetMaxVol returns max volume size in GB From 4d6fc0d72f0d930dc36fa42e2fd9da2e4e15f25d Mon Sep 17 00:00:00 2001 From: Kshitija Kakde Date: Tue, 17 Oct 2023 10:27:31 +0530 Subject: [PATCH 15/18] review comments addressed --- system_limit.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/system_limit.go b/system_limit.go index 15d82b4..5080943 100644 --- a/system_limit.go +++ b/system_limit.go @@ -39,18 +39,18 @@ func (c *Client) GetSystemLimits() (systemLimits *types.Limit, err error) { } // GetMaxVol returns max volume size in GB -func (c *Client) GetMaxVol() (sys string, err error) { +func (c *Client) GetMaxVol() (systemLimits string, err error) { defer TimeSpent("GetMaxVol", time.Now()) - maxlimitType, err := c.GetSystemLimits() + maxLimitType, err := c.GetSystemLimits() if err != nil { return "", err } - for _, systype := range maxlimitType.SystemLimitEntryList { + for _, systemType := range maxLimitType.SystemLimitEntryList { - if systype.Type == "volumeSizeGb" { - return systype.MaxVal, nil + if systemType.Type == "volumeSizeGb" { + return systemType.MaxVal, nil } } From 893a09fcd0fe163ad27f910ff05597a05372d5c0 Mon Sep 17 00:00:00 2001 From: Kshitija Kakde Date: Tue, 17 Oct 2023 11:03:04 +0530 Subject: [PATCH 16/18] review comments addressed --- system_limit.go | 16 ++++++---------- system_limit_test.go | 22 +++++++++++----------- types/v1/types.go | 11 +++++++---- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/system_limit.go b/system_limit.go index 5080943..e58ca7e 100644 --- a/system_limit.go +++ b/system_limit.go @@ -20,14 +20,10 @@ import ( types "github.com/dell/goscaleio/types/v1" ) -type QuerySystemLimitsParam struct { -} - // GetSystemLimits gets list of sytem limits - -func (c *Client) GetSystemLimits() (systemLimits *types.Limit, err error) { +func (c *Client) GetSystemLimits() (systemLimits *types.QuerySystemLimitsResponse, err error) { defer TimeSpent("GetSystemLimits", time.Now()) - var body QuerySystemLimitsParam + var body *types.QuerySystemLimitsParam path := "/api/instances/System/action/querySystemLimits" err = c.getJSONWithRetry( http.MethodPost, path, body, &systemLimits) @@ -41,16 +37,16 @@ func (c *Client) GetSystemLimits() (systemLimits *types.Limit, err error) { // GetMaxVol returns max volume size in GB func (c *Client) GetMaxVol() (systemLimits string, err error) { defer TimeSpent("GetMaxVol", time.Now()) - maxLimitType, err := c.GetSystemLimits() + sysLimit, err := c.GetSystemLimits() if err != nil { return "", err } - for _, systemType := range maxLimitType.SystemLimitEntryList { + for _, systemLimit := range sysLimit.SystemLimitEntryList { - if systemType.Type == "volumeSizeGb" { - return systemType.MaxVal, nil + if systemLimit.Type == "volumeSizeGb" { + return systemLimit.MaxVal, nil } } diff --git a/system_limit_test.go b/system_limit_test.go index 5438cab..1ecc384 100644 --- a/system_limit_test.go +++ b/system_limit_test.go @@ -25,23 +25,23 @@ import ( ) func TestGetSystemLimits(t *testing.T) { - type checkFn func(*testing.T, *types.Limit, error) + type checkFn func(*testing.T, *types.QuerySystemLimitsResponse, error) check := func(fns ...checkFn) []checkFn { return fns } - hasNoError := func(t *testing.T, syslimit *types.Limit, err error) { + 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.Limit, err 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.Limit, err error) { - return func(t *testing.T, syslimit *types.Limit, err 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) @@ -49,8 +49,8 @@ func TestGetSystemLimits(t *testing.T) { } } - checkLimitDescription := func(expectedDescription string) func(t *testing.T, syslimit *types.Limit, err error) { - return func(t *testing.T, syslimit *types.Limit, err error) { + 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) @@ -58,8 +58,8 @@ func TestGetSystemLimits(t *testing.T) { } } - checkLimitMaxVal := func(expectedMaxVal string) func(t *testing.T, syslimit *types.Limit, err error) { - return func(t *testing.T, syslimit *types.Limit, err error) { + 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) @@ -81,8 +81,8 @@ func TestGetSystemLimits(t *testing.T) { } // Simulate a successful response for GetSystemLimits. - resp := types.Limit{ - SystemLimitEntryList: []types.QuerySystemLimits{ + resp := types.QuerySystemLimitsResponse{ + SystemLimitEntryList: []types.SystemLimits{ { Type: "volumeSizeGb", Description: "Maximum volume size in GB", diff --git a/types/v1/types.go b/types/v1/types.go index fe8ca86..6ec8a3b 100644 --- a/types/v1/types.go +++ b/types/v1/types.go @@ -1739,14 +1739,17 @@ type MDMQueueCommandDetails struct { AllowedPhase string `json:"allowedPhase,omitempty"` } -// QuerySystemLimits defines struct for query system limits -type QuerySystemLimits struct { +// 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 Limit struct { - SystemLimitEntryList []QuerySystemLimits `json:"systemLimitEntryList"` +type QuerySystemLimitsResponse struct { + SystemLimitEntryList []SystemLimits `json:"systemLimitEntryList"` +} + +type QuerySystemLimitsParam struct { } From 48e64b15bd18e7ba54d055fe5f7835fee67aa696 Mon Sep 17 00:00:00 2001 From: Kshitija Kakde Date: Tue, 17 Oct 2023 11:14:47 +0530 Subject: [PATCH 17/18] review comments addressed --- system_limit.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system_limit.go b/system_limit.go index e58ca7e..116719d 100644 --- a/system_limit.go +++ b/system_limit.go @@ -35,7 +35,7 @@ func (c *Client) GetSystemLimits() (systemLimits *types.QuerySystemLimitsRespons } // GetMaxVol returns max volume size in GB -func (c *Client) GetMaxVol() (systemLimits string, err error) { +func (c *Client) GetMaxVol() (MaxVolumeSize string, err error) { defer TimeSpent("GetMaxVol", time.Now()) sysLimit, err := c.GetSystemLimits() From 8daf1cba4b9a603cf3f61e41f633664f8df81d06 Mon Sep 17 00:00:00 2001 From: Kshitija Kakde Date: Tue, 17 Oct 2023 13:10:48 +0530 Subject: [PATCH 18/18] review comments addressed --- system_limit.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system_limit.go b/system_limit.go index 116719d..b83f2ee 100644 --- a/system_limit.go +++ b/system_limit.go @@ -23,7 +23,7 @@ import ( // GetSystemLimits gets list of sytem limits func (c *Client) GetSystemLimits() (systemLimits *types.QuerySystemLimitsResponse, err error) { defer TimeSpent("GetSystemLimits", time.Now()) - var body *types.QuerySystemLimitsParam + var body types.QuerySystemLimitsParam path := "/api/instances/System/action/querySystemLimits" err = c.getJSONWithRetry( http.MethodPost, path, body, &systemLimits)