Skip to content

Commit

Permalink
add more unit-test.
Browse files Browse the repository at this point in the history
  • Loading branch information
VamsiSiddu-7 committed Jul 16, 2023
1 parent 72cc00f commit 5d9e846
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 2 deletions.
6 changes: 6 additions & 0 deletions service/features/delete_volume.feature
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ Feature: VxFlex OS CSI interface
And I call DeleteVolume with "single-writer"
Then a valid DeleteVolumeResponse is returned

Scenario: Delete Volume negative
Given a VxFlexOS service
When I call Probe
And I call DeleteVolume with Bad "single-writer"
Then the error contains "volume ID is required"

92 changes: 92 additions & 0 deletions service/features/node_publish_unpublish.feature
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,98 @@ Feature: VxFlex OS CSI interface
Then I call NodeUnpublishVolume ""
Then the error contains "none"

Scenario: a Basic NFS Node Publish Volume good
Given a VxFlexOS service
When I specify CreateVolumeMountRequest "nfs"
And I call CreateVolume "volume1"
Then a valid CreateVolumeResponse is returned
And I call NFS PublishVolume with "single-node-single-writer"
Then a valid PublishVolumeResponse is returned
And a capability with voltype "mount" access "single-node-single-writer" fstype "nfs"
Then I call NodePublishVolume NFS ""
Then the error contains "none"
Then I call NodeUnpublishVolume ""
Then the error contains "none"


Scenario: a Basic NFS Node Publish Volume good
Given a VxFlexOS service
When I specify CreateVolumeMountRequest "nfs"
And I call CreateVolume "volume1"
Then a valid CreateVolumeResponse is returned
And I call NFS PublishVolume with "single-node-single-writer"
Then a valid PublishVolumeResponse is returned
And a capability with voltype "mount" access "single-node-single-writer" fstype "nfs"
Then I call NodePublishVolume NFS ""
Then the error contains "none"
Then I call NodePublishVolume NFS ""
Then the error contains "none"
Then I call NodeUnpublishVolume ""
Then the error contains "none"


Scenario: a Basic NFS Node Publish Volume good
Given a VxFlexOS service
When I specify CreateVolumeMountRequest "nfs"
And I call CreateVolume "volume1"
Then a valid CreateVolumeResponse is returned
And I call NFS PublishVolume with "single-node-single-writer"
Then a valid PublishVolumeResponse is returned
And a capability with voltype "mount" access "single-node-single-writer" fstype "nfs"
And I induce error "NasNotFoundError"
Then I call NodePublishVolume NFS ""
Then the error contains "could not find NAS server by id"


Scenario: a Basic NFS Node Publish Volume good
Given a VxFlexOS service
When I specify CreateVolumeMountRequest "nfs"
And I call CreateVolume "volume1"
Then a valid CreateVolumeResponse is returned
And I call NFS PublishVolume with "single-node-single-writer"
Then a valid PublishVolumeResponse is returned
And a capability with voltype "mount" access "single-node-single-writer" fstype "nfs"
And I induce error "fileInterfaceNotFoundError"
Then I call NodePublishVolume NFS ""
Then the error contains "could not find the File interface using id"


Scenario: a Basic NFS Node Publish Volume good
Given a VxFlexOS service
When I specify CreateVolumeMountRequest "nfs"
And I call CreateVolume "volume1"
Then a valid CreateVolumeResponse is returned
And I call NFS PublishVolume with "single-reader"
Then the error contains "access mode cannot be UNKNOWN"


Scenario: a Basic NFS Node Publish Volume good
Given a VxFlexOS service
When I specify CreateVolumeMountRequest "nfs"
And I call CreateVolume "volume1"
Then a valid CreateVolumeResponse is returned
And I call NFS PublishVolume with "multiple-writer"
Then a valid PublishVolumeResponse is returned
And a capability with voltype "mount" access "multiple-writer" fstype "nfs"
Then I call NodePublishVolume NFS ""
Then the error contains "none"
Then I call NodeUnpublishVolume ""
Then the error contains "none"


Scenario: a Basic NFS Node Publish Volume good
Given a VxFlexOS service
When I specify CreateVolumeMountRequest "nfs"
And I call CreateVolume "volume1"
Then a valid CreateVolumeResponse is returned
And I call NFS PublishVolume with "single-node-multi-writer"
Then a valid PublishVolumeResponse is returned
And a capability with voltype "mount" access "single-node-multi-writer" fstype "nfs"
Then I call NodePublishVolume NFS ""
Then the error contains "none"
Then I call NodeUnpublishVolume ""
Then the error contains "none"

Scenario Outline: Node publish mount volumes various induced error use cases from examples
Given a VxFlexOS service
And a controller published volume
Expand Down
38 changes: 38 additions & 0 deletions service/features/service.feature
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,44 @@ Feature: VxFlex OS CSI interface
| sysID |
| "f.service.opt.SystemName" |


Scenario Outline: Create volume with Accessibility Requirements nfs
Given a VxFlexOS service
When I call Probe
And I specify NFS AccessibilityRequirements with a SystemID of <sysID>
And I call CreateVolume "volume1"
Then a valid CreateVolumeResponse with topology is returned
Examples:
| sysID |
| "f.service.opt.SystemName" |


Scenario Outline: Create volume with Accessiblity Requirements nfs
Given a VxFlexOS service
When I call Probe
And I specify bad NFS AccessibilityRequirements with a SystemID of <sysID>
And I call CreateVolume "volume1"
Then the error contains "Invalid topology requested for NFS Volume"
Examples:
| sysID |
| "f.service.opt.SystemName" |



Scenario Outline: Create volume with Accessibility Requirements
Given a VxFlexOS service
When I call Probe
And I specify NFS AccessibilityRequirements with a SystemID of <sysID>
And I call CreateVolume "volume1"
Then the error contains <errormsg>

Examples:
| sysID | errormsg |
| "f.service.opt.SystemName" | "none" |
| "" | "is not accessible based on Preferred" |
| "Unknown" | "is not accessible based on Preferred" |
| "badSystem" | "is not accessible based on Preferred" |

Scenario: Create volume with AccessMode_MULTINODE_WRITER
Given a VxFlexOS service
When I call Probe
Expand Down
161 changes: 161 additions & 0 deletions service/step_defs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,97 @@ func (f *feature) iSpecifyAccessibilityRequirementsWithASystemIDOf(requestedSyst
return nil
}

func (f *feature) iSpecifyAccessibilityRequirementsNFSWithASystemIDOf(requestedSystem string) error {
if requestedSystem == "f.service.opt.SystemName" {
requestedSystem = f.service.opts.defaultSystemID
}
req := new(csi.CreateVolumeRequest)
params := make(map[string]string)
params["storagepool"] = "viki_pool_HDD_20181031"
req.Parameters = params
req.Name = "accessability"
capacityRange := new(csi.CapacityRange)
capacityRange.RequiredBytes = 32 * 1024 * 1024 * 1024
req.CapacityRange = capacityRange
req.AccessibilityRequirements = new(csi.TopologyRequirement)
top := new(csi.Topology)
top.Segments = map[string]string{
"csi-vxflexos.dellemc.com/" + requestedSystem + "-nfs": "powerflex.dellemc.com",
}
req.AccessibilityRequirements.Preferred = append(req.AccessibilityRequirements.Preferred, top)
req.AccessibilityRequirements.Preferred = append(req.AccessibilityRequirements.Preferred, top)
capability := new(csi.VolumeCapability)
mountVolume := new(csi.VolumeCapability_MountVolume)
mountVolume.FsType = "nfs"
if mountVolume.FsType == "nfs" {
req.Parameters["nasName"] = "dummy-nas-server"
}
mountVolume.MountFlags = make([]string, 0)
mount := new(csi.VolumeCapability_Mount)
mount.Mount = mountVolume
capability.AccessType = mount
accessMode := new(csi.VolumeCapability_AccessMode)
accessMode.Mode = csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER
capability.AccessMode = accessMode
capabilities := make([]*csi.VolumeCapability, 0)
capabilities = append(capabilities, capability)
req.VolumeCapabilities = capabilities
f.createVolumeRequest = req
return nil
}

func (f *feature) iSpecifyBadAccessibilityRequirementsNFSWithASystemIDOf(requestedSystem string) error {
if requestedSystem == "f.service.opt.SystemName" {
requestedSystem = f.service.opts.defaultSystemID
}
req := new(csi.CreateVolumeRequest)
params := make(map[string]string)
params["storagepool"] = "viki_pool_HDD_20181031"
req.Parameters = params
req.Name = "accessability"
capacityRange := new(csi.CapacityRange)
capacityRange.RequiredBytes = 32 * 1024 * 1024 * 1024
req.CapacityRange = capacityRange
req.AccessibilityRequirements = new(csi.TopologyRequirement)
top := new(csi.Topology)
top.Segments = map[string]string{
"csi-vxflexos.dellemc.com/" + requestedSystem + "-abc": "powerflex.dellemc.com",
}
req.AccessibilityRequirements.Preferred = append(req.AccessibilityRequirements.Preferred, top)
capability := new(csi.VolumeCapability)
mountVolume := new(csi.VolumeCapability_MountVolume)
mountVolume.FsType = "nfs"
if mountVolume.FsType == "nfs" {
req.Parameters["nasName"] = "dummy-nas-server"
}
mountVolume.MountFlags = make([]string, 0)
mount := new(csi.VolumeCapability_Mount)
mount.Mount = mountVolume
capability.AccessType = mount
accessMode := new(csi.VolumeCapability_AccessMode)
accessMode.Mode = csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER
capability.AccessMode = accessMode
capabilities := make([]*csi.VolumeCapability, 0)
capabilities = append(capabilities, capability)
req.VolumeCapabilities = capabilities
f.createVolumeRequest = req
return nil
}

func (f *feature) aValidCreateVolumeResponseWithTopologyIsReturned() error {
if f.err != nil {
return f.err
}

isNFS := false
var fsType string
if len(f.createVolumeRequest.VolumeCapabilities) != 0 {
fsType = f.createVolumeRequest.VolumeCapabilities[0].GetMount().GetFsType()
if fsType == "nfs" {
isNFS = true
}
}

f.volumeIDList = append(f.volumeIDList, f.createVolumeResponse.Volume.VolumeId)
topology := f.createVolumeResponse.Volume.AccessibleTopology
if len(topology) != 1 {
Expand All @@ -851,7 +938,20 @@ func (f *feature) aValidCreateVolumeResponseWithTopologyIsReturned() error {
if len(tokens) > 1 {
constraint = tokens[1]
}

log.Printf("Found topology constraint: VxFlex OS system: %s", constraint)
if isNFS {
nfsTokens := strings.Split(constraint, "-")
nfsLabel := ""
if len(nfsTokens) > 1 {
constraint = nfsTokens[0]
nfsLabel = nfsTokens[1]
if nfsLabel != "nfs" {
return status.Errorf(codes.InvalidArgument,
"Invalid topology requested for NFS Volume. Please validate your storage class has nfs topology.")
}
}
}
if constraint != requestedSystem {
fmt.Printf("Volume topology segement should have system %s. Found %s.", requestedSystem, constraint)
return errors.New("wrong systemID in AccessibleTopology")
Expand Down Expand Up @@ -1084,6 +1184,8 @@ func (f *feature) iInduceError(errtype string) error {
stepHandlersErrors.FileSystemInstancesError = true
case "NasNotFoundError":
stepHandlersErrors.NasServerNotFoundError = true
case "fileInterfaceNotFoundError":
stepHandlersErrors.FileInterfaceNotFoundError = true
case "NoVolumeIDError":
stepHandlersErrors.NoVolumeIDError = true
case "BadVolIDJSON":
Expand Down Expand Up @@ -1404,6 +1506,47 @@ func (f *feature) getControllerDeleteVolumeRequest(accessType string) *csi.Delet
return req
}

func (f *feature) getControllerDeleteVolumeRequestBad(accessType string) *csi.DeleteVolumeRequest {
capability := new(csi.VolumeCapability)
block := new(csi.VolumeCapability_Block)
block.Block = new(csi.VolumeCapability_BlockVolume)
if f.useAccessTypeMount {
mountVolume := new(csi.VolumeCapability_MountVolume)
mountVolume.FsType = "xfs"
mountVolume.MountFlags = make([]string, 0)
mount := new(csi.VolumeCapability_Mount)
mount.Mount = mountVolume
capability.AccessType = mount
} else {
capability.AccessType = block
}
accessMode := new(csi.VolumeCapability_AccessMode)
switch accessType {
case "single-writer":
accessMode.Mode = csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER
case "multiple-reader":
accessMode.Mode = csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY
case "multiple-writer":
accessMode.Mode = csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER
case "unknown":
accessMode.Mode = csi.VolumeCapability_AccessMode_UNKNOWN
}
if !f.omitAccessMode {
capability.AccessMode = accessMode
}
fmt.Printf("capability.AccessType %v\n", capability.AccessType)
fmt.Printf("capability.AccessMode %v\n", capability.AccessMode)
req := new(csi.DeleteVolumeRequest)
if !f.noVolumeID {
if f.invalidVolumeID {
req.VolumeId = badVolumeID2
} else {
req.VolumeId = ""
}
}
return req
}

func (f *feature) getControllerDeleteVolumeRequestNFS(accessType string) *csi.DeleteVolumeRequest {
capability := new(csi.VolumeCapability)

Expand Down Expand Up @@ -1673,6 +1816,21 @@ func (f *feature) iCallDeleteVolumeWith(arg1 string) error {
return nil
}

func (f *feature) iCallDeleteVolumeWithBad(arg1 string) error {
ctx := new(context.Context)
req := f.deleteVolumeRequest
if f.deleteVolumeRequest == nil {
req = f.getControllerDeleteVolumeRequestBad(arg1)
f.deleteVolumeRequest = req
}
log.Printf("Calling DeleteVolume")
f.deleteVolumeResponse, f.err = f.service.DeleteVolume(*ctx, req)
if f.err != nil {
log.Printf("DeleteVolume called failed: %s\n", f.err.Error())
}
return nil
}

func (f *feature) iCallDeleteVolumeNFSWith(arg1 string) error {
ctx := new(context.Context)
req := f.deleteVolumeRequest
Expand Down Expand Up @@ -4003,6 +4161,8 @@ func FeatureContext(s *godog.ScenarioContext) {
s.Step(`^I call ValidateConnectivity$`, f.iCallValidateVolumeHostConnectivity)
s.Step(`^a valid CreateVolumeResponse is returned$`, f.aValidCreateVolumeResponseIsReturned)
s.Step(`^I specify AccessibilityRequirements with a SystemID of "([^"]*)"$`, f.iSpecifyAccessibilityRequirementsWithASystemIDOf)
s.Step(`^I specify NFS AccessibilityRequirements with a SystemID of "([^"]*)"$`, f.iSpecifyAccessibilityRequirementsNFSWithASystemIDOf)
s.Step(`^I specify bad NFS AccessibilityRequirements with a SystemID of "([^"]*)"$`, f.iSpecifyBadAccessibilityRequirementsNFSWithASystemIDOf)
s.Step(`^a valid CreateVolumeResponse with topology is returned$`, f.aValidCreateVolumeResponseWithTopologyIsReturned)
s.Step(`^I specify MULTINODE_WRITER$`, f.iSpecifyMULTINODEWRITER)
s.Step(`^I specify a BadCapacity$`, f.iSpecifyABadCapacity)
Expand Down Expand Up @@ -4035,6 +4195,7 @@ func FeatureContext(s *godog.ScenarioContext) {
s.Step(`^I call Node Probe$`, f.iCallNodeProbe)
s.Step(`^a valid NodeGetInfoResponse is returned$`, f.aValidNodeGetInfoResponseIsReturned)
s.Step(`^I call DeleteVolume with "([^"]*)"$`, f.iCallDeleteVolumeWith)
s.Step(`^I call DeleteVolume with Bad "([^"]*)"$`, f.iCallDeleteVolumeWithBad)
s.Step(`^I call DeleteVolume nfs with "([^"]*)"$`, f.iCallDeleteVolumeNFSWith)
s.Step(`^a valid DeleteVolumeResponse is returned$`, f.aValidDeleteVolumeResponseIsReturned)
s.Step(`^the volume is already mapped to an SDC$`, f.theVolumeIsAlreadyMappedToAnSDC)
Expand Down
6 changes: 4 additions & 2 deletions service/step_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var (
FileSystemInstancesError bool
NFSExportInstancesError bool
NasServerNotFoundError bool
FileInterfaceNotFoundError bool
BadVolIDError bool
NoCsiVolIDError bool
WrongVolIDError bool
Expand Down Expand Up @@ -163,6 +164,7 @@ func getHandler() http.Handler {
stepHandlersErrors.RemoveVolumeError = false
stepHandlersErrors.VolumeInstancesError = false
stepHandlersErrors.NasServerNotFoundError = false
stepHandlersErrors.FileInterfaceNotFoundError = false
stepHandlersErrors.FileSystemInstancesError = false
stepHandlersErrors.NFSExportInstancesError = false
stepHandlersErrors.NasServerNotFoundError = false
Expand Down Expand Up @@ -325,8 +327,8 @@ func handleGetNasInstances(w http.ResponseWriter, r *http.Request) {

func handleGetFileInterface(w http.ResponseWriter, r *http.Request) {

if stepHandlersErrors.NasServerNotFoundError {
writeError(w, "nas server not found", http.StatusNotFound, codes.NotFound)
if stepHandlersErrors.FileInterfaceNotFoundError {
writeError(w, "file interace not found", http.StatusNotFound, codes.NotFound)
return
}

Expand Down

0 comments on commit 5d9e846

Please sign in to comment.