azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

AzurePS 0.8.13 :: Azure Virtual Machine commands silently fail

Open pcgeek86 opened this issue 11 years ago • 18 comments

Say, for instance, you are running:

  • Windows 8.1
  • Windows Management Framework Core 5.0 November 2014 Preview (PowerShell 5.0)
  • Microsoft Azure PowerShell module version 0.8.13.

And you have the following configuration:

  • You authenticate to Azure using the Add-AzureAccount command from PowerShell, with the -Credential parameter, using an Azure Active Directory (AAD) Organizational Account.
  • The account you authenticate to Azure with has co-administrator access to more than one Azure platform subscription.
  • One of your two subscriptions has a cloud service with an Azure virtual machine provisioned, and running, inside of it.

Finally, you perform the following steps:

  1. You use the Select-AzureSubscription command to select the Azure subscription that does not have the cloud service / virtual machine in it.
  2. You call the Stop-AzureVM or Export-AzureVM commands against the cloud service / virtual machine. (eg. Stop-AzureVM -ServiceName mycloudsvc -Name vm01 -Force;)
  3. No error / exception is thrown, and the command silently returns.
  4. You add the -Verbose parameter to either command, and still, no output is emitted.
  5. You somehow (magically) realize that you have the wrong subscription selected.
  6. You begin ripping your hair out.
  7. You select the correct Azure subscription and proceed normally.

Given the previous scenario, is it possible to thrown an exception when the specified cloud service / virtual machine is not found, for all of the VM-related commands? It seems like poor design to silently fail, without notifying the end user (me) what is [not] occurring in the background, and why, and how to resolve it.

Cheers, Trevor Sullivan Microsoft MVP: PowerShell http://twitter.com/pcgeek86 http://trevorsullivan.net

pcgeek86 avatar Jan 27 '15 15:01 pcgeek86

Thanks for the feedback Trevor @pcgeek86 I'll add it to the TO FIX list

singhkays avatar Feb 13 '15 22:02 singhkays

@pcgeek86 @doctordns @alexandair @robplank @pzerger @trondhindenes @mattallison Since you folks gave great feedback on the Switch-AzureMode thread, I'd like to get your feedback as a powershell consumer here as well. I was testing this with the latest release 0.9.7 and a warning is now thrown in the above situation.

We evaluated if we should throw a ResourceNotFound exception as well and it seems this would be a large breaking change on the project that would replace warnings with the above exception in the below cmdlets. We think it's probably best not to break existing script by introducing an exception to all of these cmdlets. What do you folks think?

Set-AzureLoadBalancedEndpoint Get-AzureVMDscExtensionStatus Export-AzureVM Get-AzureRemoteDesktopFile Get-AzureVM Get-AzureWinRMUri Remove-AzureVM Restart-AzureVM Save-AzureVMImage Start-AzureVM Stop-AzureVM Update-AzureVM

singhkays avatar Aug 21 '15 19:08 singhkays

Definetely not throw an exception (terminating error) (the powershell design guidelines describe clearly what should cause a terminating error). The event Trevor is describing should clearly throw a non-terminating error. I'm not sure that the question is regarding the list of cmdlets, could you elaborate?

trondhindenes avatar Aug 21 '15 19:08 trondhindenes

I'll describe the desired outcome in code, using the core PowerShell commands as examples.

### Creates a non-terminating error, because the user asked for a specific process
Get-Process -Name nonexistent; 

### Doesn't throw any errors, because the process may or may not exist, based on search criteria
Get-Process -Name *maybenonexistent*;

### Throws an error because a specific item was requested
Get-Item -Path C:\windows\notepad222.exe;

### Doesn't throw any errors, because no items matched the search criteria
Get-Item -Path c:\windows\*notepad222*.exe;

Cheers, Trevor Sullivan Microsoft MVP: PowerShell

pcgeek86 avatar Aug 21 '15 19:08 pcgeek86

I have a hard time working through why get-process and get-item should behave differently.

Intuitively, I understand it - processes sometimes aren't running but files tend to be more absolute, but from a pure behavioral perspective, get-thing X should return the same type of error if X doesn't exist regardless of X being a process or file or registry key or whatever.

MattAllison avatar Aug 21 '15 19:08 MattAllison

I would prefer a non-terminating error in case the resource was not found. In other words, if I perform some action against 4 VMs and I've mistyped the name of one of them, I want to get result for 3 existing VMs and error message for the forth, nonexistent, VM. If, for some reason, I want to turn that error into terminating one, I can specify -ErrorAction stop.

alexandair avatar Aug 21 '15 21:08 alexandair

+1 to @alexandair comment.

Regards,

Pete Zerger, MVP (System Center Cloud and Datacenter Management) Founder, System Center Central: http://www.systemcentercentral.com Azure IaaS Book (coming soon) http://InsideTheMicrosoftCloud.com

On Fri, Aug 21, 2015 at 4:17 PM, alexandair [email protected] wrote:

I would prefer a non-terminating error in case the resource was not found. In other words, if I perform some action against 4 VMs and I've mistyped the name of one of them, I want to get result for 3 existing VMs and error message for the forth, nonexistent, VM. If, for some reason, I want to turn that error into terminating one, I can specify -ErrorAction stop.

— Reply to this email directly or view it on GitHub https://github.com/Azure/azure-powershell/issues/115#issuecomment-133565738 .

pzerger avatar Aug 22 '15 06:08 pzerger

Kay, First - thanks for asking. Much appreciated.

It seems to me that any get-* cmdlet should never throw a terminating error if 'object not found'. Like the existing -item cmdlets, any Azure cmdlet should fail gracefully as per PowerShell design guidelines. If I need the failure to lead to a terminating error (and that may be the right answer in some cases), PowerShell provides the mechanism to do that as Alexandair notes. Otherwise, please do not complicate things unnecessarily. Trevor shows a better example of how to fail gracefully which I agree with.

Hope this is the answer you were looking for! ;-)

doctordns avatar Aug 22 '15 11:08 doctordns

@MattAllison How do Get-Item and Get-Process work different? In the examples I provided, they work the same, which is being used as a basis for how the Azure cmdlets should work.

Cheers, Trevor Sullivan Microsoft MVP: PowerShell

pcgeek86 avatar Aug 22 '15 17:08 pcgeek86

I was perhaps taking your examples too literally.

In the first, you said non-terminating error. In the second, you said error which I inferred to be something other than non-terminating due to the lack of specificity that accompanied the first.


From: Trevor Sullivanmailto:[email protected] Sent: ‎8/‎22/‎2015 10:40 AM To: Azure/azure-powershellmailto:[email protected] Cc: MattAllisonmailto:[email protected] Subject: Re: [azure-powershell] AzurePS 0.8.13 :: Azure Virtual Machine commands silently fail (#115)

@MattAllison How do Get-Item and Get-Process work different? In the examples I provided, they work the same, which is being used as a basis for how the Azure cmdlets should work.

Cheers, Trevor Sullivan Microsoft MVP: PowerShell


Reply to this email directly or view it on GitHub: https://github.com/Azure/azure-powershell/issues/115#issuecomment-133731172

MattAllison avatar Aug 22 '15 19:08 MattAllison

@MattAllison While I could have been more explicit, your inference is where the miscommunication stemmed from.

pcgeek86 avatar Aug 22 '15 21:08 pcgeek86

@TrevorSullivan I absolutely agree.

And from things like this, software bugs are born. :)


From: Trevor Sullivanmailto:[email protected] Sent: ‎8/‎22/‎2015 2:45 PM To: Azure/azure-powershellmailto:[email protected] Cc: MattAllisonmailto:[email protected] Subject: Re: [azure-powershell] AzurePS 0.8.13 :: Azure Virtual Machine commands silently fail (#115)

@MattAllison While I could have been more explicit, your inference is where the miscommunication stemmed from.


Reply to this email directly or view it on GitHub: https://github.com/Azure/azure-powershell/issues/115#issuecomment-133756959

MattAllison avatar Aug 23 '15 01:08 MattAllison

I seriously cannot believe we're spending time discussing what should cause terminating/non-terminating errors with a MS product group. I means, read the PowerShell design guide. It's pretty much crystal clear.

trondhindenes avatar Aug 23 '15 08:08 trondhindenes

@tronhindenes come to the MS conference in Basel this week, we'll have a beer with @alexandair and your frustrations will disappear.

Regards,

Pete Zerger, MVP Founder, SystemCenterCentral.com Azure IaaS Book (coming soon) - http://insidethemicrosoftcloud.com On Sun, Aug 23, 2015 at 10:00 AM, Azure/azure-powershell [email protected] wrote: I seriously cannot believe we're spending time discussing what should cause terminating/non-terminating errors with a MS product group. I means, read the PowerShell design guide. It's pretty much crystal clear.

— Reply to this email directly or view it on GitHub [https://github.com/Azure/azure-powershell/issues/115#issuecomment-133798453] .[https://github.com/notifications/beacon/AJ0QC7WF87M96add-ci71P4O-GgiYRsDks5oqXUMgaJpZM4DXzPz.gif]

pzerger avatar Aug 23 '15 08:08 pzerger

Would love to @pzerger. Didn't make it this year :-( (btw, I hope I'm not coming across as frustrated. Puzzled, but not frustrated :-) )

trondhindenes avatar Aug 23 '15 08:08 trondhindenes

+1 to @alexandair comment

robplank avatar Aug 23 '15 23:08 robplank

Thank you all for the feedback folks!

@trondhindenes This seemed like a big enough change so I wanted to make sure I included community on this decision so that it wasn't a surprise or worse, a wrong one that breaks folks' workflows :)

Regarding the other cmdlets I mentioned in my question, this stems from the fact that these cmdlets are executing the base cmdlet code here

https://github.com/Azure/azure-powershell/blob/dev/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/IaaSDeploymentManagementCmdletBase.cs#L82

The WriteWarning call above will be changed to WriteError.

powershell

singhkays avatar Aug 24 '15 21:08 singhkays

@singhkay Thank you, Kay!!! Appreciate your efforts on this.

Cheers, Trevor Sullivan

pcgeek86 avatar Aug 24 '15 22:08 pcgeek86