From 0644cbd78f1963412f884b96c4b26c134bac8068 Mon Sep 17 00:00:00 2001 From: Garg Date: Thu, 14 Nov 2024 16:33:14 +0530 Subject: [PATCH 1/6] Fixing multi-driver-capacity-tracking and adding UT --- pkg/testcore/suites/functional-suites.go | 43 +++++++++--- pkg/testcore/suites/functional-suites_test.go | 69 +++++++++++++++++++ pkg/testcore/suites/perf-suites.go | 2 +- 3 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 pkg/testcore/suites/functional-suites_test.go diff --git a/pkg/testcore/suites/functional-suites.go b/pkg/testcore/suites/functional-suites.go index 0a00150..b2ff5b4 100644 --- a/pkg/testcore/suites/functional-suites.go +++ b/pkg/testcore/suites/functional-suites.go @@ -840,18 +840,28 @@ type CapacityTrackingSuite struct { // Run runs storage capacity tracking test suite func (cts *CapacityTrackingSuite) Run(ctx context.Context, storageClass string, clients *k8sclient.Clients) (delFunc func() error, e error) { - // Get unique topology count from csinode - topologiesCount, err := getTopologyCount() - if err != nil { - return delFunc, err - } - log.Infof("Found %s topology segment(s) in csinode", color.HiYellowString(strconv.Itoa(topologiesCount))) storageClass = cts.StorageClass sc := clients.SCClient.Get(ctx, storageClass) if sc.HasError() { return delFunc, sc.GetError() } + // Get unique topology count from csinode + // Get topology keys to filter for when retrieving topology count + topologyKeys := []string{} + + if len(sc.Object.AllowedTopologies) > 0 { + matchLabelExpressions := sc.Object.AllowedTopologies[0].MatchLabelExpressions + for _, exp := range matchLabelExpressions { + topologyKeys = append(topologyKeys, exp.Key) + } + } + topologiesCount, err := getTopologyCount(topologyKeys) + if err != nil { + return delFunc, err + } + log.Infof("Found %s topology segment(s) in csinode", color.HiYellowString(strconv.Itoa(topologiesCount))) + if cts.Image == "" { cts.Image = "quay.io/centos/centos:latest" log.Infof("Using default image: %s", cts.Image) @@ -939,14 +949,17 @@ func (cts *CapacityTrackingSuite) Run(ctx context.Context, storageClass string, return delFunc, nil } -func getTopologyCount() (int, error) { +func getTopologyCount(topologyKeys []string) (int, error) { exe := []string{"bash", "-c", "kubectl describe csinode | grep 'Topology Keys'"} str, err := FindDriverLogs(exe) - if err != nil { + if len(str) == 0 || err != nil { return 0, err } topologies := strings.Split(strings.TrimSpace(strings.ReplaceAll(str, "Topology Keys:", "")), "\n") topologies = removeDuplicates(topologies) + if len(topologyKeys) > 0 { + topologies = filterArrayForMatches(topologies, topologyKeys) + } topologiesCount := len(topologies) return topologiesCount, nil } @@ -981,6 +994,20 @@ func removeDuplicates(strSlice []string) []string { return list } +func filterArrayForMatches(listToFilter []string, filterValues []string) []string { + filteredList := []string{} + for _, value := range listToFilter { + for _, key := range filterValues { + if strings.Contains(value, key) { + filteredList = append(filteredList, value) + break + } + } + } + + return filteredList +} + // GetName returns storage capacity tracking suite name func (cts *CapacityTrackingSuite) GetName() string { return "CapacityTrackingSuite" diff --git a/pkg/testcore/suites/functional-suites_test.go b/pkg/testcore/suites/functional-suites_test.go new file mode 100644 index 0000000..93ecffc --- /dev/null +++ b/pkg/testcore/suites/functional-suites_test.go @@ -0,0 +1,69 @@ +/* + * + * Copyright © 2022-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. + * + */ + +/* + * + * Copyright © 2022-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 suites + + import ( + "errors" + "testing" + + "github.com/stretchr/testify/assert" + ) + + func TestGetTopologyCount(t *testing.T) { + // Test case: Empty topology keys + FindDriverLogs = func(exe []string) (string, error) { + return "", nil + } + topologyCount, err := getTopologyCount([]string{}) + assert.NoError(t, err) + assert.Equal(t, 0, topologyCount) + + // Test case: Non-empty topology keys + + FindDriverLogs = func(exe []string) (string, error) { + var keys = "Topology Keys: [csi-powerstore.dellemc.com/10.230.24.67-iscsi csi-powerstore.dellemc.com/10.230.24.67-nfs]" + return keys, nil + } + topologyCount, err = getTopologyCount([]string{"csi-powerstore.dellemc.com/10.230.24.67-iscsi"}) + assert.NoError(t, err) + assert.Equal(t, 1, topologyCount) + + // Test case: Error in FindDriverLogs + FindDriverLogs = func(exe []string) (string, error) { + return "", errors.New("error in FindDriverLogs") + } + type FindDriverLogs func(url string) string + topologyCount, err = getTopologyCount([]string{}) + assert.Error(t, err) + assert.Equal(t, 0, topologyCount) + } + \ No newline at end of file diff --git a/pkg/testcore/suites/perf-suites.go b/pkg/testcore/suites/perf-suites.go index 8dafd19..96a3909 100644 --- a/pkg/testcore/suites/perf-suites.go +++ b/pkg/testcore/suites/perf-suites.go @@ -2240,7 +2240,7 @@ type VolumeHealthMetricsSuite struct { } // FindDriverLogs executes command and returns the output -func FindDriverLogs(command []string) (string, error) { +var FindDriverLogs = func(command []string) (string, error) { cmd := exec.Command(command[0], command[1:]...) // #nosec G204 output, err := cmd.Output() if err != nil { From 6eaae37fc03143352b01d80d58d1ed81e27f88f3 Mon Sep 17 00:00:00 2001 From: sakshi-garg1 <74704849+sakshi-garg1@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:57:13 +0530 Subject: [PATCH 2/6] Updated year in copyright section --- pkg/testcore/suites/functional-suites_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/testcore/suites/functional-suites_test.go b/pkg/testcore/suites/functional-suites_test.go index 93ecffc..abb4444 100644 --- a/pkg/testcore/suites/functional-suites_test.go +++ b/pkg/testcore/suites/functional-suites_test.go @@ -1,6 +1,6 @@ /* * - * Copyright © 2022-2023 Dell Inc. or its subsidiaries. All Rights Reserved. + * Copyright © 2024 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. @@ -66,4 +66,4 @@ assert.Error(t, err) assert.Equal(t, 0, topologyCount) } - \ No newline at end of file + From fb3ac1e873d8fdd4092bd9d78c3345596ab0e591 Mon Sep 17 00:00:00 2001 From: sakshi-garg1 <74704849+sakshi-garg1@users.noreply.github.com> Date: Thu, 14 Nov 2024 17:07:26 +0530 Subject: [PATCH 3/6] Update to fix lint warnings --- pkg/testcore/suites/functional-suites_test.go | 87 ++++++++----------- 1 file changed, 35 insertions(+), 52 deletions(-) diff --git a/pkg/testcore/suites/functional-suites_test.go b/pkg/testcore/suites/functional-suites_test.go index abb4444..9d4abfb 100644 --- a/pkg/testcore/suites/functional-suites_test.go +++ b/pkg/testcore/suites/functional-suites_test.go @@ -13,57 +13,40 @@ * limitations under the License. * */ +package suites -/* - * - * Copyright © 2022-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 suites +import ( + "errors" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetTopologyCount(t *testing.T) { + // Test case: Empty topology keys + FindDriverLogs = func(_ []string) (string, error) { + return "", nil + } + topologyCount, err := getTopologyCount([]string{}) + assert.NoError(t, err) + assert.Equal(t, 0, topologyCount) + + // Test case: Non-empty topology keys + + FindDriverLogs = func(_ []string) (string, error) { + var keys = "Topology Keys: [csi-powerstore.dellemc.com/10.230.24.67-iscsi csi-powerstore.dellemc.com/10.230.24.67-nfs]" + return keys, nil + } + topologyCount, err = getTopologyCount([]string{"csi-powerstore.dellemc.com/10.230.24.67-iscsi"}) + assert.NoError(t, err) + assert.Equal(t, 1, topologyCount) - import ( - "errors" - "testing" - - "github.com/stretchr/testify/assert" - ) - - func TestGetTopologyCount(t *testing.T) { - // Test case: Empty topology keys - FindDriverLogs = func(exe []string) (string, error) { - return "", nil - } - topologyCount, err := getTopologyCount([]string{}) - assert.NoError(t, err) - assert.Equal(t, 0, topologyCount) - - // Test case: Non-empty topology keys - - FindDriverLogs = func(exe []string) (string, error) { - var keys = "Topology Keys: [csi-powerstore.dellemc.com/10.230.24.67-iscsi csi-powerstore.dellemc.com/10.230.24.67-nfs]" - return keys, nil - } - topologyCount, err = getTopologyCount([]string{"csi-powerstore.dellemc.com/10.230.24.67-iscsi"}) - assert.NoError(t, err) - assert.Equal(t, 1, topologyCount) - - // Test case: Error in FindDriverLogs - FindDriverLogs = func(exe []string) (string, error) { - return "", errors.New("error in FindDriverLogs") - } - type FindDriverLogs func(url string) string - topologyCount, err = getTopologyCount([]string{}) - assert.Error(t, err) - assert.Equal(t, 0, topologyCount) - } - + // Test case: Error in FindDriverLogs + FindDriverLogs = func(_ []string) (string, error) { + return "", errors.New("error in FindDriverLogs") + } + type FindDriverLogs func(url string) string + topologyCount, err = getTopologyCount([]string{}) + assert.Error(t, err) + assert.Equal(t, 0, topologyCount) +} From fac7c04e42aa20db33dd633f9e19c99ee50ea7a2 Mon Sep 17 00:00:00 2001 From: aqu-dell Date: Thu, 14 Nov 2024 16:55:10 +0000 Subject: [PATCH 4/6] gofumpt lint fix --- pkg/testcore/suites/functional-suites_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/testcore/suites/functional-suites_test.go b/pkg/testcore/suites/functional-suites_test.go index 9d4abfb..a0993e9 100644 --- a/pkg/testcore/suites/functional-suites_test.go +++ b/pkg/testcore/suites/functional-suites_test.go @@ -34,7 +34,7 @@ func TestGetTopologyCount(t *testing.T) { // Test case: Non-empty topology keys FindDriverLogs = func(_ []string) (string, error) { - var keys = "Topology Keys: [csi-powerstore.dellemc.com/10.230.24.67-iscsi csi-powerstore.dellemc.com/10.230.24.67-nfs]" + keys := "Topology Keys: [csi-powerstore.dellemc.com/10.230.24.67-iscsi csi-powerstore.dellemc.com/10.230.24.67-nfs]" return keys, nil } topologyCount, err = getTopologyCount([]string{"csi-powerstore.dellemc.com/10.230.24.67-iscsi"}) @@ -45,7 +45,6 @@ func TestGetTopologyCount(t *testing.T) { FindDriverLogs = func(_ []string) (string, error) { return "", errors.New("error in FindDriverLogs") } - type FindDriverLogs func(url string) string topologyCount, err = getTopologyCount([]string{}) assert.Error(t, err) assert.Equal(t, 0, topologyCount) From 8b93653c581d5674fbf7d6f99dbe8d1f3e756696 Mon Sep 17 00:00:00 2001 From: Jooseppi Luna Date: Fri, 10 Jan 2025 18:26:28 -0500 Subject: [PATCH 5/6] adjust test --- pkg/testcore/suites/functional-suites_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/testcore/suites/functional-suites_test.go b/pkg/testcore/suites/functional-suites_test.go index a0993e9..0d1fc6d 100644 --- a/pkg/testcore/suites/functional-suites_test.go +++ b/pkg/testcore/suites/functional-suites_test.go @@ -34,10 +34,10 @@ func TestGetTopologyCount(t *testing.T) { // Test case: Non-empty topology keys FindDriverLogs = func(_ []string) (string, error) { - keys := "Topology Keys: [csi-powerstore.dellemc.com/10.230.24.67-iscsi csi-powerstore.dellemc.com/10.230.24.67-nfs]" + keys := "Topology Keys: [csi-powerstore.dellemc.com/1.2.3.4-iscsi csi-powerstore.dellemc.com/1.2.3.4-nfs]" return keys, nil } - topologyCount, err = getTopologyCount([]string{"csi-powerstore.dellemc.com/10.230.24.67-iscsi"}) + topologyCount, err = getTopologyCount([]string{"csi-powerstore.dellemc.com/1.2.3.4-iscsi"}) assert.NoError(t, err) assert.Equal(t, 1, topologyCount) From 9d7e8bdf47bff7d70d2612a5cf43e35201b8db7d Mon Sep 17 00:00:00 2001 From: aqu-dell Date: Mon, 13 Jan 2025 19:18:46 +0000 Subject: [PATCH 6/6] updating 2024 to 2025 copyright --- pkg/testcore/suites/functional-suites_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/testcore/suites/functional-suites_test.go b/pkg/testcore/suites/functional-suites_test.go index 0d1fc6d..28801ae 100644 --- a/pkg/testcore/suites/functional-suites_test.go +++ b/pkg/testcore/suites/functional-suites_test.go @@ -1,6 +1,6 @@ /* * - * Copyright © 2024 Dell Inc. or its subsidiaries. All Rights Reserved. + * Copyright © 2025 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.