Skip to content

Commit 727639c

Browse files
author
Kamran Khan
committed
Show message to user if no extension status is available
1 parent 8c284b4 commit 727639c

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/ResourceManager/Compute/Commands.Compute/Extension/AzureDiskEncryption/GetAzureDiskEncryptionStatus.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,7 @@ private string GetExtensionStatusMessage(OSType currentOSType, bool returnSubsta
154154
(context.Statuses.Count < 1) ||
155155
(string.IsNullOrWhiteSpace(context.Statuses[0].Message)))
156156
{
157-
ThrowTerminatingError(new ErrorRecord(new ApplicationFailedException(string.Format(CultureInfo.CurrentUICulture, "Invalid extension status")),
158-
"InvalidResult",
159-
ErrorCategory.InvalidResult,
160-
null));
157+
throw new KeyNotFoundException(string.Format(CultureInfo.CurrentUICulture, "Invalid extension status"));
161158
}
162159

163160
if (returnSubstatusMessage)
@@ -351,17 +348,27 @@ public override void ExecuteCmdlet()
351348
DiskEncryptionSettings osVolumeEncryptionSettings = GetOsVolumeEncryptionSettings(vmParameters);
352349
EncryptionStatus dataVolumesEncrypted = AreDataVolumesEncrypted(vmParameters);
353350
AzureDiskEncryptionStatusContext encryptionStatus = null;
351+
string progressMessage = null;
354352

355353
OSType osType = GetOSType(vmParameters);
356354
switch (osType)
357355
{
358356
case OSType.Windows:
357+
try
358+
{
359+
progressMessage = GetExtensionStatusMessage(osType);
360+
}
361+
catch(KeyNotFoundException)
362+
{
363+
progressMessage = string.Format(CultureInfo.CurrentUICulture, "Extension status not available on the VM");
364+
}
365+
359366
encryptionStatus = new AzureDiskEncryptionStatusContext
360367
{
361368
OsVolumeEncrypted = osVolumeEncrypted,
362369
DataVolumesEncrypted = dataVolumesEncrypted,
363370
OsVolumeEncryptionSettings = osVolumeEncryptionSettings,
364-
ProgressMessage = GetExtensionStatusMessage(osType)
371+
ProgressMessage = progressMessage
365372
};
366373
WriteObject(encryptionStatus);
367374
break;
@@ -391,12 +398,21 @@ public override void ExecuteCmdlet()
391398
};
392399
}
393400

401+
try
402+
{
403+
progressMessage = GetExtensionStatusMessage(osType);
404+
}
405+
catch(KeyNotFoundException)
406+
{
407+
progressMessage = string.Format(CultureInfo.CurrentUICulture, "Extension status not available on the VM");
408+
}
409+
394410
encryptionStatus = new AzureDiskEncryptionStatusContext
395411
{
396412
OsVolumeEncrypted = (EncryptionStatus)Enum.Parse(typeof(EncryptionStatus), encryptionStatusParsed[AzureDiskEncryptionExtensionConstants.encryptionResultOsKey]),
397413
DataVolumesEncrypted = (EncryptionStatus)Enum.Parse(typeof(EncryptionStatus), encryptionStatusParsed[AzureDiskEncryptionExtensionConstants.encryptionResultDataKey]),
398414
OsVolumeEncryptionSettings = osVolumeEncryptionSettings,
399-
ProgressMessage = GetExtensionStatusMessage(osType)
415+
ProgressMessage = progressMessage
400416
};
401417
WriteObject(encryptionStatus);
402418
break;

0 commit comments

Comments
 (0)