Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #100 from vjuranek/BZ1882983
Browse files Browse the repository at this point in the history
Bug 1882983: check PV access mode
  • Loading branch information
openshift-merge-robot committed Jan 10, 2022
2 parents 75d5266 + d0360a5 commit 675c165
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/service/controller.go
Expand Up @@ -51,6 +51,13 @@ func (c *ControllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
"failed to parse storage class field %s, expected 'true' or 'false' but got %s",
ParameterThinProvisioning, req.Parameters[ParameterThinProvisioning])
}
// Check access mode
for _, cap := range req.GetVolumeCapabilities() {
if cap.AccessMode.Mode != csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY &&
cap.AccessMode.Mode != csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER {
return nil, fmt.Errorf("unsupported access mode %s, currently only RWO is supported", cap.AccessMode.Mode)
}
}
requiredSize := req.CapacityRange.GetRequiredBytes()
// Check if a disk with the same name already exist
disks, err := c.ovirtClient.ListDisksByAlias(diskName, ovirtclient.ContextStrategy(ctx))
Expand Down
33 changes: 33 additions & 0 deletions pkg/service/controller_test.go
Expand Up @@ -33,6 +33,39 @@ func TestVolumeCreation(t *testing.T) {
}
}

func TestCreateRWXVolumeFails(t *testing.T) {
helper := getMockHelper(t)
controller := service.NewOvirtCSIDriver(helper.GetClient(), "test")
testStorageDomain, err := helper.GetClient().GetStorageDomain(helper.GetStorageDomainID())
if err != nil {
t.Fatalf("failed to get stoarge domain %s", helper.GetStorageDomainID())
}

_, err = controller.CreateVolume(context.Background(), &csi.CreateVolumeRequest{
Name: "test",
CapacityRange: &csi.CapacityRange{
RequiredBytes: 4096,
LimitBytes: 4096,
},
Parameters: map[string]string{
"storageClass": "ovirt-test-domain",
"storageDomainName": testStorageDomain.Name(),
"thinProvisioning": "true",
},
VolumeCapabilities: []*csi.VolumeCapability{
{
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
},
},
},
})

if err == nil {
t.Fatalf("publishing RWX volume which shouldn't be possible")
}
}

func TestDeleteVolume(t *testing.T) {
helper := getMockHelper(t)
controller := service.NewOvirtCSIDriver(helper.GetClient(), "test")
Expand Down

0 comments on commit 675c165

Please sign in to comment.