Michael Sync

Michael Sync

Crisp, minimal personal blog

02 May 2014

Windows Azure Deployment – Problem and Solution


Scott wrote a great post CI DEPLOYMENT OF AZURE WEB ROLES USING TEAMCITY about deploying Azure WebRole from Azure PowerShell SDK. I used it as a reference. It didn’t work for me. maybe it’s because of my setting. I don’t know. I have to update a few things for his script. I am sharing it here for those who might have the same issue.

Contents

  1. Error in importing the module
  2. CurrentStorageAccount is not set
  3. Authentication and Certificate Issues
  4. Server Busy

💡 ScottGu announced about the release of Windows Azure SDK 2.2. Please refer to this link Windows Azure: Announcing release of Windows Azure SDK 2.2 (with lots of goodies) for more information. But that version wasn’t available when I was playing around with Azure. All API that I used and the experience that I had comes from SDK 2.1.

Problem: Error in importing the module

You need to import the Azure module before you start doing anything with Azure CmdLet but if there is more than

1
2
Write-Output "Running Azure Imports"
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\*.psd1"

Error Message

Import-Module : Path cannot be processed because it resolved to more than one file; can process only one file at a time.

At line:1 char:1

  • Import-Module “C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Az”

  • CategoryInfo : InvalidOperation: (System.Collecti…[System.String]:Collection`1) [Import-Module], RuntimeException

  • FullyQualifiedErrorId : AmbiguousPath,Microsoft.PowerShell.Commands.ImportModuleCommand

Import-Azure

Solution

Use Azure.psd1 instead.

1
2
Write-Output "Running Azure Imports"
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"

Output

PS C:\> Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1&"
  
VERBOSE: Loading module from path 'C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1'.
VERBOSE: Importing cmdlet 'Add-AzureCacheWorkerRole'.
VERBOSE: Importing cmdlet 'Add-AzureCertificate'.
VERBOSE: Importing cmdlet 'Add-AzureDataDisk'.
VERBOSE: Importing cmdlet 'Add-AzureDisk'.
.....

Problem: Issue with multiple Azure subscriptions with the same name

Duplicated Subscription Name

The code below is for getting the azure deployment to determine whether we need to publish new package or update the existing page.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
$subscription = '[Your Subscription Name]'
$service = '[Your Azure Service Name]'
$slot = 'staging' #staging or production
$package = '[ProjectName]\bin\[BuildConfigName]\app.publish\[ProjectName].cspkg'
$configuration = '[ProjectName]\bin\[BuildConfigName]\app.publish\ServiceConfiguration.Cloud.cscfg'
$timeStampFormat = 'g'
$deploymentLabel = 'ContinuousDeploy to $service v%build.number%'

Write-Output 'Running Azure Imports'
Import-Module 'C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\*.psd1'
Import-AzurePublishSettingsFile 'C:\TeamCity\[PSFileName].publishsettings'
Set-AzureSubscription -CurrentStorageAccount $service -SubscriptionName $subscription

function Publish(){
 $deployment = Get-AzureDeployment -ServiceName $service -Slot $slot -ErrorVariable a -ErrorAction silentlycontinue

But I got the following error at the line where I call Get-AzureDeployment.

Error Message

VERBOSE: 3:26:54 PM – Begin Operation: Get-AzureDeployment

Get-AzureDeployment : “An exception occurred when calling the ServiceManagement API. HTTP Status Code: 404. Service

Management Error Code: ResourceNotFound. Message: No deployments were found.. Operation Tracking ID:

b27b43c1bf5a47fb97167ede7e364206.”

At C:\BuildAgent\work\e02c76f07d491d1d\scripts\azure_deploy.ps1:57 char:27

  • $completeDeployment = Get-AzureDeployment -ServiceName $service -Slot $slot

  • CategoryInfo : CloseError: (:) [Get-AzureDeployment], ServiceManagementClientException

  • FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.ServiceManagement.HostedServices.GetAzureDeploymentCommand

VERBOSE: 3:26:54 PM – Completed Operation: Get-AzureDeployment

Solution

I tried deploying the project from Visual Studio a couple of times. The publish wizard can’t detect the service that I created so I assumed that both Azure powershell cmdlet and the publish wizard from VS got the same issue. Then I realized that it is because I have multiple subscriptions that have the same name.Surprisingly, the most of Azure API are based on “subscriptionName " instead of the name..

The solution for this issue is that you need to set the id when you call Set-AzureSubscription API. The updated code will be looked like that below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
$subscriptionId = '[Your Subscription Id]'
$subscriptionName = '[Your Subscription Name]'

$service = '[Your Azure Service Name]'
$slot = 'staging' #staging or production
$package = '[ProjectName]\bin\[BuildConfigName]\app.publish\[ProjectName].cspkg'
$configuration = '[ProjectName]\bin\[BuildConfigName]\app.publish\ServiceConfiguration.Cloud.cscfg'
$timeStampFormat = 'g'
$deploymentLabel = 'ContinuousDeploy to $service v%build.number%'

Write-Output 'Running Azure Imports'
Import-Module 'C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\*.psd1'
Import-AzurePublishSettingsFile 'C:\TeamCity\[PSFileName].publishsettings'
Set-AzureSubscription -CurrentStorageAccount $service -SubscriptionName $subscriptionName -SubscriptionId $subscriptionId

function Publish(){
$deployment = Get-AzureDeployment -ServiceName $service -Slot $slot -ErrorVariable a -ErrorAction silentlycontinue

Problem: CurrentStorageAccount is not set

data servers

The error message that I got is “Current storage account is not set”. It’s a bit misleading because as you can see in the code below (esp: last line), I did set the current storage but why did I get this message?

Error Message

New-AzureDeployment : CurrentStorageAccount is not set. Use Set-AzureSubscription subname -CurrentStorageAccount

storageaccount to set it.

At C:\BuildAgent\work\e02c76f07d491d1d\scripts\azure_deploy.ps1:55 char:15

  • $opstat = New-AzureDeployment -Slot $slot -Package $package -Configuration $

  • CategoryInfo : CloseError: (:) [New-AzureDeployment], ArgumentException

  • FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.ServiceManagement.HostedServices.NewAzureDeploymentCommand

Solution

The problem was that I have many subscription accounts and I created the storage account in wrong subscription account. The solution is just to create new storage account in correct subscription account from Azure web console.

Problem: Authentication and Certificate Issues

Security

The error message that I got is “Current storage account is not set”. It’s a bit misleading because as you can see in the code below (esp: last line), I did set the current storage but why did I get this message?

Error Messages

New-AzureDeployment : “An exception occurred when calling the ServiceManagement API. HTTP Status Code: 403. Service

Management Error Code: AuthenticationFailed. Message: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.. Operation Tracking ID: .”

At line:1 char:1

  • New-AzureDeployment -Slot “staging” -Package “MyProject.Azure\bin\Release\app.publish

  • CategoryInfo : CloseError: (:) [New-AzureDeployment], ServiceManagementClientException

  • FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.ServiceManagement.HostedServices.NewAzureDeploymentCommand

New-AzureDeployment : “An exception occurred when calling the ServiceManagement API. HTTP Status Code: 400. Service

Management Error Code: BadRequest. Message: The certificate with thumbprint 426bed136649263b9a154f5fdc1f2707a6ecf482 was not found.. Operation Tracking ID: f5925a7eb5a44dcf8c56c6e950cc8229.”

At C:\BuildAgent\work\e02c76f07d491d1d\Scripts\azure_deploy.ps1:62 char:15

  • $opstat = New-AzureDeployment -Slot $slot -Package $package -Configuration $ …

  • CategoryInfo : CloseError: (:) [New-AzureDeployment], ServiceManagementClientException

  • FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.ServiceManagement.HostedServices.NewAzureDeploymentCommand

Solution #1

  • Add-AzureCertificate -serviceName <CLOUDSERVICENAME> -certToDeploy (get-item cert:\CurrentUser\MY\<THUMBPRINT>)
  • Add-AzureCertificate -serviceName hivewebrole -certToDeploy (get-item "cert:\Local Machine\Personal\426BED136649263B9A154F5FDC1F2707A6ECF482")

And need to pass the certificate information from powershell script. I will show you the updated script later.

Solution #2

  • edit thumbprint in ServiceConfiguration.Cloud.cscfg or ServiceConfiguration.Local.cscfg (Please refer to this post [“Continuous Delivery for Cloud Services in Windows Azure][5]”. I highly recommend you to read this post if you are new to Azure deployment. )

It doesn’t matter which solution you choose. You will still need to pass the cert from your script.

Here is the updated script that contains the code for passing the cert.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$thumbprint = '[The tumbprint of your certificate.]'
$myCert = Get-Item cert:\\CurrentUser\My\$thumbprint

$subscriptionId = '[Your Subscription Id]'
$subscriptionName = '[Your Subscription Name]'

$service = '[Your Azure Service Name]'
$slot = 'staging' #staging or production
$package = '[ProjectName]\bin\[BuildConfigName]\app.publish\[ProjectName].cspkg'
$configuration = '[ProjectName]\bin\[BuildConfigName]\app.publish\ServiceConfiguration.Cloud.cscfg'
$timeStampFormat = 'g'
$deploymentLabel = 'ContinuousDeploy to $service v%build.number%'

Write-Output 'Running Azure Imports'
Import-Module 'C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\*.psd1'
Import-AzurePublishSettingsFile 'C:\TeamCity\[PSFileName].publishsettings'

Set-AzureSubscription -CurrentStorageAccount $service -SubscriptionName $subscriptionName -SubscriptionId $subscriptionId -Certificate $myCert

Write-Output 'Set-AzureSubscription'

function Publish(){
$deployment = Get-AzureDeployment -ServiceName $service -Slot $slot -ErrorVariable a -ErrorAction silentlycontinue

Additional, you might get the error below when you import the Azure publish setting file after making changes in certificate.

PS C:\Windows\system32> Import-AzurePublishSettingsFile “C:\Users\root\Downloads\Visual Studio Ultimate with MSDN-Windows
Azure MSDN – Visual Studio Ultimate-BizSpark–credentials.publishsettings” Import-AzurePublishSettingsFile : No certificate was found in the certificate store with thumbprint EB3E353EE50CB344F246D0D975557CBAB1C38494 At line:1 char:1

  • Import-AzurePublishSettingsFile “C:\Users\root\Downloads\Visual Studio Ultimate w
  • CategoryInfo : CloseError: (:) [Import-AzurePublishSettingsFile], ArgumentException
  • FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.Subscription.ImportAzurePublishSettingsCommand

The solution for that you need to do either one of them that I listed below.

  • Close and re-open the powershell   OR
  • Delete all files under C:\Users[User]\AppData\Roaming\Windows Azure Powershell,  
  • Restart the server

Problem: Server Busy

DDos attack

( Yes. I captured the screenshot of “DDoS Attack Visualization” video from Logstalgia  because it’s pretty cool. You should go and check out the project as well. )

But no. Windows Azure wasn’t under DDOS attack.

Error Message

Set-AzureDeployment : “An exception occurred when calling the ServiceManagement API. HTTP Status Code: 503. Service Management Error Code: ServerBusy. Message: The server is currently unavailable to receive requests. Please retry request.. Operation Tracking ID: 9b4dfd5616b34c87bfaf6f808a9d22be.” At C:\BuildAgent\work\e02c76f07d491d1d\Scripts\azure_deploy.ps1:77 char:22

  • $setdeployment = Set-AzureDeployment -Upgrade -Slot $slot -Package $package …
  • CategoryInfo : CloseError: (:) [Set-AzureDeployment], ServiceManagementClientException
  • FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.ServiceManagement.HostedServices.SetAzureDeploymemand

Solution

The only solution is that you need to wait a bit and try to deploy it again.

I think that’s pretty much it.. I haven’t played around with SDK 2.2 yet.. I will leave this series open and if I got something new then I will post it here again..

Thanks!