Skip to content

Commit

Permalink
Fix some bugs that encounter when write e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffyjf committed Sep 13, 2022
1 parent e7d1ed3 commit 2ee6937
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/driver/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
25 changes: 21 additions & 4 deletions pkg/openstack/openstack_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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" {
Expand All @@ -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) {
Expand Down

0 comments on commit 2ee6937

Please sign in to comment.