Skip to content

Commit

Permalink
Add UT for vsphere in node.go
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshaySainiDell committed Nov 26, 2024
1 parent 28c7e47 commit b20277b
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
31 changes: 31 additions & 0 deletions service/features/node_publish_unpublish.feature
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,37 @@ Feature: PowerMax CSI interface
| "NVME" | "NodePublishNoTargetPath" | "Target Path is required" |
| "NVME" | "GobrickConnectError" | "induced ConnectVolumeError" |

@nodePublish
@v1.0.0
Scenario Outline: Node stage volume with vSphere enabled
Given a PowerMax service
And I call set attribute IsVsphereEnabled "true"
And I set transport protocol to <transport>
And I have a Node "node1" with MaskingView
And a controller published volume
When I call NodeStageVolume with simulator
Then the error contains <errormsg>

Examples:
| transport | errormsg |
| "NVME" | "could not attach RDM" |

@nodePublish
@v1.0.0
Scenario Outline: Node unstage volume with vSphere enabled
Given a PowerMax service
And I call set attribute IsVsphereEnabled "true"
And I set transport protocol to <transport>
And I have a Node "node1" with MaskingView
And a controller published volume
When I call NodeStageVolume with simulator
And I call NodeUnstageVolume with simulator
And there are no remaining mounts
Then the error contains <errormsg>

Examples:
| transport | errormsg |
| "NVME" | "none" |

@nodePublish
@v1.0.0
Expand Down
58 changes: 58 additions & 0 deletions service/step_defs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import (
"time"

"github.com/dell/gonvme"
"github.com/vmware/govmomi"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/simulator"
"github.com/vmware/govmomi/vim25"

"github.com/dell/csi-powermax/v2/k8smock"

Expand Down Expand Up @@ -2679,6 +2683,34 @@ func (f *feature) iCallNodeStageVolume() error {
return nil
}

func (f *feature) iCallNodeStageVolumeWithSimulator() error {
simulator.Test(func(ctx context.Context, c *vim25.Client) {
mockVMHost := &VMHost{
client: &govmomi.Client{
Client: c,
},
Ctx: context.Background(),
VM: object.NewVirtualMachine(c, simulator.Map.Any("VirtualMachine").Reference()),
}
vmHost = mockVMHost
_ = f.getNodePublishVolumeRequest()
header := metadata.New(map[string]string{"csi.requestid": "1"})
ctx = metadata.NewIncomingContext(ctx, header)
req := new(csi.NodeStageVolumeRequest)
req.VolumeId = f.nodePublishVolumeRequest.VolumeId
req.PublishContext = f.nodePublishVolumeRequest.PublishContext
req.StagingTargetPath = f.nodePublishVolumeRequest.StagingTargetPath
req.VolumeCapability = f.nodePublishVolumeRequest.VolumeCapability
req.VolumeContext = f.nodePublishVolumeRequest.VolumeContext
if inducedErrors.badVolumeIdentifier {
req.VolumeId = "bad volume identifier"
}
fmt.Printf("calling NodeStageVolume %#v\n", req)
_, f.err = f.service.NodeStageVolume(ctx, req)
})
return nil
}

func (f *feature) iCallControllerExpandVolume(nCYL int64) error {
var req *csi.ControllerExpandVolumeRequest
header := metadata.New(map[string]string{"csi.requestid": "1"})
Expand Down Expand Up @@ -2733,6 +2765,30 @@ func (f *feature) iCallNodeUnstageVolume() error {
return nil
}

func (f *feature) iCallNodeUnstageVolumeWithSimulator() error {
simulator.Test(func(ctx context.Context, c *vim25.Client) {
mockVMHost := &VMHost{
client: &govmomi.Client{
Client: c,
},
Ctx: context.Background(),
VM: object.NewVirtualMachine(c, simulator.Map.Any("VirtualMachine").Reference()),
}
vmHost = mockVMHost
header := metadata.New(map[string]string{"csi.requestid": "1"})
ctx = metadata.NewIncomingContext(ctx, header)
req := new(csi.NodeUnstageVolumeRequest)
req.VolumeId = f.nodePublishVolumeRequest.VolumeId
if inducedErrors.invalidVolumeID {
req.VolumeId = "badVolumeID"
}
req.StagingTargetPath = f.nodePublishVolumeRequest.StagingTargetPath
log.Printf("iCallNodeUnstageVolume %s %s", req.VolumeId, req.StagingTargetPath)
_, f.err = f.service.NodeUnstageVolume(ctx, req)
})
return nil
}

func (f *feature) iCallNodeGetCapabilities() error {
header := metadata.New(map[string]string{"csi.requestid": "1"})
ctx := metadata.NewIncomingContext(context.Background(), header)
Expand Down Expand Up @@ -4920,6 +4976,8 @@ func FeatureContext(s *godog.ScenarioContext) {
s.Step(`^I call BeforeServe with an invalid ClusterPrefix$`, f.iCallBeforeServeWithAnInvalidClusterPrefix)
s.Step(`^I call NodeStageVolume$`, f.iCallNodeStageVolume)
s.Step(`^I call NodeUnstageVolume$`, f.iCallNodeUnstageVolume)
s.Step(`^I call NodeStageVolume with simulator$`, f.iCallNodeStageVolumeWithSimulator)
s.Step(`^I call NodeUnstageVolume with simulator$`, f.iCallNodeUnstageVolumeWithSimulator)
s.Step(`^I call NodeGetCapabilities$`, f.iCallNodeGetCapabilities)
s.Step(`^a valid NodeGetCapabilitiesResponse is returned$`, f.aValidNodeGetCapabilitiesResponseIsReturned)
s.Step(`^I call CreateSnapshot$`, f.iCallCreateSnapshot)
Expand Down

0 comments on commit b20277b

Please sign in to comment.