From 2ee6937714a1c6a8d88e29e1e6a0eb6dc4b8cb59 Mon Sep 17 00:00:00 2001 From: JeffYang Date: Tue, 13 Sep 2022 15:15:25 +0800 Subject: [PATCH] Fix some bugs that encounter when write e2e test --- pkg/driver/controllerserver.go | 2 +- pkg/openstack/openstack_volume.go | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pkg/driver/controllerserver.go b/pkg/driver/controllerserver.go index 1546e0a..b4ba44b 100644 --- a/pkg/driver/controllerserver.go +++ b/pkg/driver/controllerserver.go @@ -37,7 +37,7 @@ func (c *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu } size := RoundOffBytes(req.GetCapacityRange().GetRequiredBytes()) if size < 1 { - return nil, status.Error(codes.InvalidArgument, "CreateVolume: The cinder volume size not less than 1") + return nil, status.Error(codes.InvalidArgument, "CreateVolume: The cinder volume size require more than 1Gi") } volumeType := req.GetParameters()[cinderVolumeType] if volumeType == "" { diff --git a/pkg/openstack/openstack_volume.go b/pkg/openstack/openstack_volume.go index cb02132..3c15bae 100644 --- a/pkg/openstack/openstack_volume.go +++ b/pkg/openstack/openstack_volume.go @@ -51,6 +51,10 @@ func (op *Openstack) CreateVolume(name, zone, volType, snapshotID, sourceVolID s func (op *Openstack) DeleteVolume(volumeID string) error { err := volumes.Delete(op.BlockStorageClient, volumeID, volumes.DeleteOpts{}).ExtractErr() if err != nil { + vol404Msg := fmt.Sprintf("Volume %s could not be found", volumeID) + if strings.Contains(err.Error(), vol404Msg) { + return nil + } return err } return nil @@ -71,6 +75,10 @@ func (op *Openstack) AttachVolume(volumeID, mountPoint, hostName string) error { func (op *Openstack) DetachVolume(volumeID string) error { err := volumeactions.Detach(op.BlockStorageClient, volumeID, volumeactions.DetachOpts{}).ExtractErr() if err != nil { + vol404Msg := fmt.Sprintf("Volume %s could not be found", volumeID) + if strings.Contains(err.Error(), vol404Msg) { + return nil + } return err } return nil @@ -335,6 +343,7 @@ func (op *Openstack) ExpandVolume(volumeID string, status string, size int) erro } var blockStorageServiceClient *gophercloud.ServiceClient var err error + var client *gophercloud.ServiceClient switch status { case volumeInUseStates: if op.BsOpts.AuthStrategy == "keystone" { @@ -358,12 +367,20 @@ func (op *Openstack) ExpandVolume(volumeID string, status string, size int) erro } } blockStorageServiceClient.Microversion = "3.42" - - return volumeactions.ExtendSize(blockStorageServiceClient, volumeID, opts).ExtractErr() + client = blockStorageServiceClient case volumeAvailableStatus: - return volumeactions.ExtendSize(op.BlockStorageClient, volumeID, opts).ExtractErr() + client = op.BlockStorageClient + default: + return fmt.Errorf("volume cannot be resized, when status is %s", status) + } + vol, err := volumes.Get(client, volumeID).Extract() + if err != nil { + return err + } + if vol.Size == size { + return nil } - return fmt.Errorf("volume cannot be resized, when status is %s", status) + return volumeactions.ExtendSize(client, volumeID, opts).ExtractErr() } func (op *Openstack) GetAvailability() (string, error) {