fix: resize Azure disk issue when it's in attached state

fix comments
This commit is contained in:
andyzhangx 2020-11-19 07:25:11 +00:00
parent e64ebe0131
commit 0d38026687
2 changed files with 18 additions and 4 deletions

View File

@ -297,6 +297,10 @@ func (c *ManagedDiskController) ResizeDisk(diskURI string, oldSize resource.Quan
return newSizeQuant, nil
}
if result.DiskProperties.DiskState != compute.Unattached {
return oldSize, fmt.Errorf("azureDisk - disk resize is only supported on Unattached disk, current disk state: %s, already attached to %s", result.DiskProperties.DiskState, to.String(result.ManagedBy))
}
diskParameter := compute.DiskUpdate{
DiskUpdateProperties: &compute.DiskUpdateProperties{
DiskSizeGB: &requestGiB,

View File

@ -311,7 +311,7 @@ func TestResizeDisk(t *testing.T) {
diskName: diskName,
oldSize: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
newSize: *resource.NewQuantity(3*(1024*1024*1024), resource.BinarySI),
existedDisk: compute.Disk{Name: to.StringPtr("disk1"), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB}},
existedDisk: compute.Disk{Name: to.StringPtr("disk1"), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB, DiskState: compute.Unattached}},
expectedQuantity: *resource.NewQuantity(3*(1024*1024*1024), resource.BinarySI),
expectedErr: false,
},
@ -330,7 +330,7 @@ func TestResizeDisk(t *testing.T) {
diskName: diskName,
oldSize: *resource.NewQuantity(1*(1024*1024*1024), resource.BinarySI),
newSize: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
existedDisk: compute.Disk{Name: to.StringPtr("disk1"), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB}},
existedDisk: compute.Disk{Name: to.StringPtr("disk1"), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB, DiskState: compute.Unattached}},
expectedQuantity: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
expectedErr: false,
},
@ -339,7 +339,7 @@ func TestResizeDisk(t *testing.T) {
diskName: fakeGetDiskFailed,
oldSize: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
newSize: *resource.NewQuantity(3*(1024*1024*1024), resource.BinarySI),
existedDisk: compute.Disk{Name: to.StringPtr(fakeGetDiskFailed), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB}},
existedDisk: compute.Disk{Name: to.StringPtr(fakeGetDiskFailed), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB, DiskState: compute.Unattached}},
expectedQuantity: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
expectedErr: true,
expectedErrMsg: fmt.Errorf("Retriable: false, RetryAfter: 0s, HTTPStatusCode: 0, RawError: Get Disk failed"),
@ -349,11 +349,21 @@ func TestResizeDisk(t *testing.T) {
diskName: fakeCreateDiskFailed,
oldSize: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
newSize: *resource.NewQuantity(3*(1024*1024*1024), resource.BinarySI),
existedDisk: compute.Disk{Name: to.StringPtr(fakeCreateDiskFailed), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB}},
existedDisk: compute.Disk{Name: to.StringPtr(fakeCreateDiskFailed), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB, DiskState: compute.Unattached}},
expectedQuantity: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
expectedErr: true,
expectedErrMsg: fmt.Errorf("Retriable: false, RetryAfter: 0s, HTTPStatusCode: 0, RawError: Create Disk failed"),
},
{
desc: "an error shall be returned if disk is not in Unattached state",
diskName: fakeCreateDiskFailed,
oldSize: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
newSize: *resource.NewQuantity(3*(1024*1024*1024), resource.BinarySI),
existedDisk: compute.Disk{Name: to.StringPtr(fakeCreateDiskFailed), DiskProperties: &compute.DiskProperties{DiskSizeGB: &diskSizeGB, DiskState: compute.Attached}},
expectedQuantity: *resource.NewQuantity(2*(1024*1024*1024), resource.BinarySI),
expectedErr: true,
expectedErrMsg: fmt.Errorf("azureDisk - disk resize is only supported on Unattached disk, current disk state: Attached, already attached to "),
},
}
for i, test := range testCases {