From 0bc3cfbb32c0e9dbdd72687c43b0936a7c828b91 Mon Sep 17 00:00:00 2001 From: Harshita Pandey Date: Fri, 29 Nov 2024 14:44:57 +0530 Subject: [PATCH 1/2] Adding Unit tests --- service/features/service.feature | 14 +++++++++++++- service/step_defs_test.go | 26 +++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/service/features/service.feature b/service/features/service.feature index 35438de4..c83acb83 100644 --- a/service/features/service.feature +++ b/service/features/service.feature @@ -1564,8 +1564,20 @@ Feature: VxFlex OS CSI interface | "volume1" | "multi_az" | "none" | | "volume1" | "invalid_multi_az" | "no zone topology found in accessibility requirements" | + Scenario: Call NodeGetInfo without zone label + Given a VxFlexOS service + And I use config "config" + When I call NodeGetInfo + Then a NodeGetInfo is returned without zone topology + Scenario: Call NodeGetInfo with zone label Given a VxFlexOS service And I use config "multi_az" When I call NodeGetInfo with zone labels - Then a valid NodeGetInfo is returned with node topology + Then a valid NodeGetInfo is returned with node topology + + Scenario: Call NodeGetInfo with zone label with invalid config + Given a VxFlexOS service + And I use config "invalid_multi_az" + When I call NodeGetInfo with zone labels + Then a NodeGetInfo is returned without zone system topology diff --git a/service/step_defs_test.go b/service/step_defs_test.go index fd48055a..15b1f548 100644 --- a/service/step_defs_test.go +++ b/service/step_defs_test.go @@ -1881,6 +1881,7 @@ func (f *feature) iCallNodeGetInfo() error { req := new(csi.NodeGetInfoRequest) f.service.opts.SdcGUID = "9E56672F-2F4B-4A42-BFF4-88B6846FBFDA" GetNodeLabels = mockGetNodeLabels + GetNodeUID = mockGetNodeUID f.nodeGetInfoResponse, f.err = f.service.NodeGetInfo(*ctx, req) return nil } @@ -4724,7 +4725,7 @@ func (f *feature) iCallCreateVolumeWithZones(name string) error { } func mockGetNodeLabelsWithZone(_ context.Context, _ *service) (map[string]string, error) { - labels := map[string]string{"zone.csi-vxflexos.dellemc.com": "zoneA"} + labels := map[string]string{"zone." + Name: "zoneA"} return labels, nil } @@ -4747,6 +4748,27 @@ func (f *feature) aValidNodeGetInfoIsReturnedWithNodeTopology() error { return nil } +func (f *feature) aNodeGetInfoIsReturnedWithoutZoneTopology() error { + accessibility := f.nodeGetInfoResponse.GetAccessibleTopology() + Log.Printf("Node Accessibility %+v", accessibility) + if _, ok := accessibility.Segments["zone."+Name]; ok { + return fmt.Errorf("zone found") + } + return nil +} + +func ( f *feature) aNodeGetInfoIsReturnedWithoutZoneSystemTopology() error { + accessibility := f.nodeGetInfoResponse.GetAccessibleTopology() + Log.Printf("Node Accessibility %+v", accessibility) + + for _, array := range f.service.opts.arrays { + if _, ok := accessibility.Segments[Name+"/"+array.SystemID]; ok { + return fmt.Errorf("zone found") + } + } + return nil +} + func FeatureContext(s *godog.ScenarioContext) { f := &feature{} s.Step(`^a VxFlexOS service$`, f.aVxFlexOSService) @@ -4974,6 +4996,8 @@ func FeatureContext(s *godog.ScenarioContext) { s.Step(`^I call CreateVolume "([^"]*)" with zones$`, f.iCallCreateVolumeWithZones) s.Step(`^I call NodeGetInfo with zone labels$`, f.iCallNodeGetInfoWithZoneLabels) s.Step(`^a valid NodeGetInfo is returned with node topology$`, f.aValidNodeGetInfoIsReturnedWithNodeTopology) + s.Step(`^a NodeGetInfo is returned without zone topology$`, f.aNodeGetInfoIsReturnedWithoutZoneTopology) + s.Step(`^a NodeGetInfo is returned without zone system topology$`, f.aNodeGetInfoIsReturnedWithoutZoneSystemTopology) s.After(func(ctx context.Context, _ *godog.Scenario, _ error) (context.Context, error) { if f.server != nil { From 6ab94081fbf17e869c3bea2aa7ee325d636c145a Mon Sep 17 00:00:00 2001 From: Harshita Pandey Date: Fri, 29 Nov 2024 15:05:22 +0530 Subject: [PATCH 2/2] fixing formatting issues --- service/step_defs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/step_defs_test.go b/service/step_defs_test.go index 15b1f548..c485c60c 100644 --- a/service/step_defs_test.go +++ b/service/step_defs_test.go @@ -4757,7 +4757,7 @@ func (f *feature) aNodeGetInfoIsReturnedWithoutZoneTopology() error { return nil } -func ( f *feature) aNodeGetInfoIsReturnedWithoutZoneSystemTopology() error { +func (f *feature) aNodeGetInfoIsReturnedWithoutZoneSystemTopology() error { accessibility := f.nodeGetInfoResponse.GetAccessibleTopology() Log.Printf("Node Accessibility %+v", accessibility)