Skip to content

sanity: Add tests for NodeStageVolume/NodeUnstageVolume #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 9, 2018

Conversation

darkowlzz
Copy link
Contributor

Fixes #46

@lpabon lpabon requested a review from sbezverk April 17, 2018 14:54
if nodeStageSupported {
err := createMountTargetLocation(config.StagingPath)
Expect(err).NotTo(HaveOccurred())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If STAGE_UNSTAGE_VOLUME is not supported it should skip this test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -16,15 +16,84 @@ func (s *service) NodeStageVolume(
req *csi.NodeStageVolumeRequest) (
*csi.NodeStageVolumeResponse, error) {

return nil, status.Error(codes.Unimplemented, "")
device, ok := req.PublishInfo["device"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To support this, STAGE_UNSTAGE_VOLUME needs to be supported in https://github.com/kubernetes-csi/csi-test/blob/master/mock/service/node.go#L119 and the test should skip if not supported.

nodeStgPathKey := path.Join(s.nodeID, req.StagingTargetPath)

// Check to see if the volume has already been unstaged.
if v.Attributes[nodeStgPathKey] == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes that the key is there. It could panic. There needs to be a check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified that if a key doesn't exists in a map, it doesn't panic. The value would just be empty.

nodeStgPathKey := path.Join(s.nodeID, req.StagingTargetPath)

// Check to see if the volume has already been staged.
if v.Attributes[nodeStgPathKey] != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes the key is in the map and could panic. It needs to get the key by also checking to see if it is there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just verified that if a key doesn't exists in a map, it doesn't panic. The value would just be empty. And this is done in the same way for NodePublishVolume as well. So, it should be fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! That must be new since I started using golang (1.2): https://play.golang.org/p/OMC7Taio5h1

Copy link
Contributor

@davidz627 davidz627 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Really appreciate the work put into this 👍 Review is mostly just some nit's


// Check to see if the volume has already been staged.
if v.Attributes[nodeStgPathKey] != "" {
return &csi.NodeStageVolumeResponse{}, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should check whether the volume staged is compatible. See error "ALREADY_EXISTS" in spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried adding this, but this would require changes in service.go, in the Volume struct. I think it would be better to add separately, capability check for Controller functions as well. I'll add a TODO for now here.

delete(v.Attributes, nodeStgPathKey)
s.vols[i] = v

return &csi.NodeUnstageVolumeResponse{}, nil
}

func (s *service) NodePublishVolume(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to modify NodePublishVolume to do the right thing when a StagingTargetPath is provided.


_, err := c.NodeStageVolume(
context.Background(),
&csi.NodeStageVolumeRequest{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provide the rest of the required fields to isolate the error as just a volume id error

_, err := c.NodeStageVolume(
context.Background(),
&csi.NodeStageVolumeRequest{
VolumeId: "id",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provide the rest of the required fields.

Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

It("should return appropriate values (no optional values added)", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this similar enough to testFullWorkflowSuccess that we could reuse that - or make some minimal tweaks to that function and reuse it here?

Expect(serverError.Code()).To(Equal(codes.InvalidArgument))
})

It("should return appropriate values (no optional values added)", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this similar enough to testFullWorkflowSuccess that we could reuse that - or make some minimal tweaks to that function and reuse it here?

https://github.com/kubernetes-csi/csi-test/blob/master/pkg/sanity/node.go#L224

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's completely same. I failed to see that :)

controllerPublishSupported = isControllerCapabilitySupported(
s,
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME)
nodeStageSupported = isNodeCapabilitySupported(c, csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip test if nodeStage not supported


_, err := c.NodeUnstageVolume(
context.Background(),
&csi.NodeUnstageVolumeRequest{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: provide rest of the required args

_, err := c.NodeUnstageVolume(
context.Background(),
&csi.NodeUnstageVolumeRequest{
VolumeId: "id",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: provide rest of the required args

@darkowlzz darkowlzz force-pushed the 46-nodestagetest branch 2 times, most recently from dce0b55 to 2624233 Compare April 29, 2018 19:51
@@ -64,7 +140,7 @@ func (s *service) NodePublishVolume(
}

// Publish the volume.
v.Attributes[nodeMntPathKey] = device
v.Attributes[nodeMntPathKey] = req.GetStagingTargetPath()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this from device to the staging target path. I think staging path is bind mounted to the target path. Correct me if I'm wrong about that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. I'll ask.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should only be the staging target path if it is defined - if not, it would be device.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Thanks!

@darkowlzz darkowlzz force-pushed the 46-nodestagetest branch from 2624233 to f6f4d37 Compare May 6, 2018 09:25
@darkowlzz darkowlzz force-pushed the 46-nodestagetest branch from f6f4d37 to 0590ad0 Compare May 6, 2018 09:34
@darkowlzz
Copy link
Contributor Author

Made the changes. Hope it's ready.

@davidz627
Copy link
Contributor

/lgtm

nodeStgPathKey := path.Join(s.nodeID, req.StagingTargetPath)

// Check to see if the volume has already been staged.
if v.Attributes[nodeStgPathKey] != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! That must be new since I started using golang (1.2): https://play.golang.org/p/OMC7Taio5h1

@lpabon
Copy link
Member

lpabon commented May 9, 2018

Looks great

@lpabon lpabon merged commit ed74243 into kubernetes-csi:master May 9, 2018
suneeth51 pushed a commit to suneeth51/csi-test that referenced this pull request Sep 11, 2019
sanity: Add tests for NodeStageVolume/NodeUnstageVolume
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants