Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#646 from andyzhangx/check-vol-cap
Browse files Browse the repository at this point in the history
fix: should return error for block volumeMode
  • Loading branch information
andyzhangx authored Apr 8, 2022
2 parents 0fb2adf + f7ae08f commit 9663a8b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
16 changes: 14 additions & 2 deletions pkg/blob/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
return nil, err
}

volumeCapabilities := req.GetVolumeCapabilities()
volName := req.GetName()
if len(volName) == 0 {
return nil, status.Error(codes.InvalidArgument, "CreateVolume Name must be provided")
}

volumeCapabilities := req.GetVolumeCapabilities()
if len(volumeCapabilities) == 0 {
return nil, status.Error(codes.InvalidArgument, "CreateVolume Volume capabilities must be provided")
}
for _, c := range volumeCapabilities {
if c.GetBlock() != nil {
return nil, status.Error(codes.InvalidArgument, "Block volume capability not supported")
}
}

if acquired := d.volumeLocks.TryAcquire(volName); !acquired {
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, volName)
Expand Down Expand Up @@ -402,9 +408,15 @@ func (d *Driver) ValidateVolumeCapabilities(ctx context.Context, req *csi.Valida
if len(volumeID) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
}
if req.GetVolumeCapabilities() == nil {
volumeCapabilities := req.GetVolumeCapabilities()
if len(volumeCapabilities) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume capabilities missing in request")
}
for _, c := range volumeCapabilities {
if c.GetBlock() != nil {
return nil, status.Error(codes.InvalidArgument, "Block volume capability not supported")
}
}

resourceGroupName, accountName, containerName, err := GetContainerInfo(volumeID)
if err != nil {
Expand Down
49 changes: 49 additions & 0 deletions pkg/blob/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ func TestCreateVolume(t *testing.T) {
stdVolumeCapabilities := []*csi.VolumeCapability{
stdVolumeCapability,
}
blockVolumeCapability := &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Block{
Block: &csi.VolumeCapability_BlockVolume{},
},
}
blockVolumeCapabilities := []*csi.VolumeCapability{
blockVolumeCapability,
}
controllerservicecapabilityRPC := &csi.ControllerServiceCapability_RPC{
Type: csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
}
Expand Down Expand Up @@ -116,6 +124,24 @@ func TestCreateVolume(t *testing.T) {
}
},
},
{
name: "block volume capability not supported",
testFunc: func(t *testing.T) {
d := NewFakeDriver()
req := &csi.CreateVolumeRequest{
Name: "unit-test",
VolumeCapabilities: blockVolumeCapabilities,
}
d.Cap = []*csi.ControllerServiceCapability{
controllerServiceCapability,
}
_, err := d.CreateVolume(context.Background(), req)
expectedErr := status.Error(codes.InvalidArgument, "Block volume capability not supported")
if !reflect.DeepEqual(err, expectedErr) {
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
}
},
},
{
name: "invalid protocol",
testFunc: func(t *testing.T) {
Expand Down Expand Up @@ -393,6 +419,14 @@ func TestValidateVolumeCapabilities(t *testing.T) {
stdVolumeCapabilities := []*csi.VolumeCapability{
stdVolumeCapability,
}
blockVolumeCapability := &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Block{
Block: &csi.VolumeCapability_BlockVolume{},
},
}
blockVolumeCapabilities := []*csi.VolumeCapability{
blockVolumeCapability,
}
controllerservicecapabilityRPC := &csi.ControllerServiceCapability_RPC{
Type: csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
}
Expand Down Expand Up @@ -431,6 +465,21 @@ func TestValidateVolumeCapabilities(t *testing.T) {
}
},
},
{
name: "block volume capability not supported",
testFunc: func(t *testing.T) {
d := NewFakeDriver()
req := &csi.ValidateVolumeCapabilitiesRequest{
VolumeId: "unit-test",
VolumeCapabilities: blockVolumeCapabilities,
}
_, err := d.ValidateVolumeCapabilities(context.Background(), req)
expectedErr := status.Error(codes.InvalidArgument, "Block volume capability not supported")
if !reflect.DeepEqual(err, expectedErr) {
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
}
},
},
{
name: "invalid volume Id",
testFunc: func(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions test/integration/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ fi

# Begin to run CSI functions one by one
echo "Create volume test:"
value="$(csc controller new --endpoint "$endpoint" --cap 1,block "$volname" --req-bytes "$volsize" --params skuname=Standard_LRS)"
value="$(csc controller new --endpoint "$endpoint" --cap MULTI_NODE_MULTI_WRITER,mount,xfs "$volname" --req-bytes "$volsize" --params skuname=Standard_LRS)"
sleep 15

volumeid="$(echo "$value" | awk '{print $1}' | sed 's/"//g')"
echo "Got volume id: $volumeid"
storage_account_name="$(echo "$volumeid" | awk -F# '{print $2}')"

csc controller validate-volume-capabilities --endpoint "$endpoint" --cap 1,block "$volumeid"
csc controller validate-volume-capabilities --endpoint "$endpoint" --cap MULTI_NODE_MULTI_WRITER,mount,xfs "$volumeid"

if [[ "$cloud" != "AzureChinaCloud" ]]; then
echo "stage volume test:"
csc node stage --endpoint "$endpoint" --cap 1,block --staging-target-path "$staging_target_path" "$volumeid"
csc node stage --endpoint "$endpoint" --cap MULTI_NODE_MULTI_WRITER,mount,xfs --staging-target-path "$staging_target_path" "$volumeid"

echo "publish volume test:"
csc node publish --endpoint "$endpoint" --cap 1,block --staging-target-path "$staging_target_path" --target-path "$target_path" "$volumeid"
csc node publish --endpoint "$endpoint" --cap MULTI_NODE_MULTI_WRITER,mount,xfs --staging-target-path "$staging_target_path" --target-path "$target_path" "$volumeid"
sleep 2

echo "node stats test:"
Expand All @@ -84,7 +84,7 @@ csc controller del --endpoint "$endpoint" "$volumeid"
sleep 15

echo "Create volume in storage account($storage_account_name) under resource group($resource_group):"
value="$(csc controller new --endpoint "$endpoint" --cap 1,block "$volname" --req-bytes "$volsize" --params skuname=Standard_LRS,storageAccount=$storage_account_name,resourceGroup=$resource_group)"
value="$(csc controller new --endpoint "$endpoint" --cap MULTI_NODE_MULTI_WRITER,mount,xfs "$volname" --req-bytes "$volsize" --params skuname=Standard_LRS,storageAccount=$storage_account_name,resourceGroup=$resource_group)"
sleep 15

volumeid="$(echo "$value" | awk '{print $1}' | sed 's/"//g')"
Expand Down

0 comments on commit 9663a8b

Please sign in to comment.