From ce5b795dc6d1b6ca309ec8c2063958a27c7fa28d Mon Sep 17 00:00:00 2001 From: Harshita Pandey <88329939+harshitap26@users.noreply.github.com> Date: Fri, 29 Nov 2024 19:54:07 +0530 Subject: [PATCH] Unit tests for Node Topologies (#358) * Adding Unit tests * fixing formatting issues --- 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 76894ef9..922ec8d8 100644 --- a/service/features/service.feature +++ b/service/features/service.feature @@ -1567,8 +1567,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 2008469f..713878d2 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 } @@ -4727,7 +4728,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 } @@ -4750,6 +4751,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) @@ -4977,6 +4999,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 {