-
Notifications
You must be signed in to change notification settings - Fork 151
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
Conversation
pkg/sanity/node.go
Outdated
if nodeStageSupported { | ||
err := createMountTargetLocation(config.StagingPath) | ||
Expect(err).NotTo(HaveOccurred()) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
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] == "" { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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] != "" { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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
mock/service/node.go
Outdated
|
||
// Check to see if the volume has already been staged. | ||
if v.Attributes[nodeStgPathKey] != "" { | ||
return &csi.NodeStageVolumeResponse{}, nil |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
pkg/sanity/node.go
Outdated
|
||
_, err := c.NodeStageVolume( | ||
context.Background(), | ||
&csi.NodeStageVolumeRequest{}) |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
pkg/sanity/node.go
Outdated
|
||
_, err := c.NodeUnstageVolume( | ||
context.Background(), | ||
&csi.NodeUnstageVolumeRequest{}) |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
dce0b55
to
2624233
Compare
mock/service/node.go
Outdated
@@ -64,7 +140,7 @@ func (s *service) NodePublishVolume( | |||
} | |||
|
|||
// Publish the volume. | |||
v.Attributes[nodeMntPathKey] = device | |||
v.Attributes[nodeMntPathKey] = req.GetStagingTargetPath() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Thanks!
2624233
to
f6f4d37
Compare
Adds the missing volume ID, target path and capabilities validations as well.
f6f4d37
to
0590ad0
Compare
Made the changes. Hope it's ready. |
/lgtm |
nodeStgPathKey := path.Join(s.nodeID, req.StagingTargetPath) | ||
|
||
// Check to see if the volume has already been staged. | ||
if v.Attributes[nodeStgPathKey] != "" { |
There was a problem hiding this comment.
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
Looks great |
sanity: Add tests for NodeStageVolume/NodeUnstageVolume
Fixes #46