Skip to content

Commit 9a16de0

Browse files
committed
Merge pull request Azure#1580 from hovsepm/clu
Added deployment tests.
2 parents ac26cd9 + 12d9bc6 commit 9a16de0

File tree

16 files changed

+166
-14
lines changed

16 files changed

+166
-14
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Param(
2+
[string]$groupName,
3+
[string]$location,
4+
[string]$rName,
5+
)
6+
7+
Write-Host "=== Managing Resources in Azure ==="
8+
9+
Write-Host "1. Creating a new resource group"
10+
New-AzureRmResourceGroup -Name $groupName -Location $location
11+
$destinationGroupName = $groupName + "Destination"
12+
13+
Write-Host "2. Registering Resource Provider Namespace."
14+
$providerNamespace="Providers.Test"
15+
Register-AzureRmResourceProvider -ProviderNamespace $providerNamespace -Force
16+
17+
Write-Host "3. Creating a new Resource"
18+
$resourceType = $providerNamespace + "/statefulResources"
19+
$apiversion="2014-04-01"
20+
New-AzureRmResource -Name $rName -Location $location -Tags @{Name = "testtag"; Value = "testval"} -ResourceGroupName $groupName -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -ApiVersion $apiversion -Force
21+
22+
Write-Host "4. Get information about Resource"
23+
$resourceInfo = Get-AzureRmResource -ResourceGroupName $groupName
24+
Write-Host "Validating Resource name"
25+
Assert-AreEqual $rName $resourceInfo.Name
26+
27+
Write-Host "5. Find Resource with name"
28+
$foundResource = Find-AzureRmResource -ResourceType $resourceType -ResourceNameContains $rName
29+
Write-Host "Validating Resource name"
30+
Assert-AreEqual $rName $foundResource.Name
31+
32+
Write-Host "6. Update Resource"
33+
Set-AzureRmResource -ResourceGroupName $groupName -ResourceName $rName -ResourceType $resourceType -Tags @{Name = "testtagUpdated"; Value = "testvalueUpdated"} -Force
34+
35+
Write-Host "7. Move Resource to resource group"
36+
New-AzureRmResourceGroup -Name $destinationGroupName -Location $location
37+
Move-AzureRmResource -DestinationResourceGroupName $destinationGroupName -ResourceId $resourceInfo.ResourceId -Force
38+
39+
Write-Host "8. Removing resource"
40+
$foundResource = Find-AzureRmResource -ResourceType $resourceType -ResourceNameContains $rName
41+
Remove-AzureRmResource -ResourceId $foundResource.ResourceId -Force
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Param(
2+
[string]$groupName,
3+
[string]$location
4+
)
5+
6+
Write-Host "=== Provisioning Deployments in Azure ==="
7+
8+
Write-Host "1. Create a new resource group"
9+
New-AzureRmResourceGroup -Name $groupName -Location $location
10+
11+
Write-Host "2. Test template"
12+
$siteName = Get-ResourceName
13+
$list = Test-AzureResourceGroupTemplate -ResourceGroupName $groupName -TemplateFile sampleTemplate.json -siteName $siteName -hostingPlanName $siteName -siteLocation $location -sku Free -workerSize 0
14+
Write-Host $list
15+
# Assert
16+
Assert-AreEqual 0 @($list).Count
17+
18+
Write-Host "3. Provisioning Deployment"
19+
$deployment = New-AzureRmResourceGroupDeployment -Name $siteName -ResourceGroupName $groupName -TemplateFile sampleTemplate.json -TemplateParameterFile sampleTemplateParams.json
20+
Write-Host $deployment
21+
# Assert
22+
Assert-AreEqual Succeeded $deployment.ProvisioningState
23+
24+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -e
3+
printf "\n=== Provisioning Deployments in Azure ===\n"
4+
5+
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
6+
azure group create --name "$groupName" --location "$location"
7+
8+
printf "\n2. Test template with dynamic parameters\n"
9+
siteName=`randomName testrn`
10+
azure group deployment test -g "$groupName" --templatefile $BASEDIR/resource-management/sampleTemplate.json --siteName "$siteName" --hostingPlanName "$siteName" --siteLocation "$location" --sku "Standard" --workerSize "0"
11+
12+
printf "\n3. Test template with JSON parameter object\n"
13+
azure group deployment test -g "$groupName" --templatefile $BASEDIR/resource-management/sampleTemplate.json --templateparameterobject "{\"siteName\":\"$siteName\",\"hostingPlanName\":\"$siteName\",\"siteLocation\":\"$location\",\"sku\":\"Standard\",\"workerSize\": 0 }"
14+
15+
printf "\n4. Provisioning Deployment\n"
16+
deploymentInfo=`azure group deployment create --Name "$siteName" --ResourceGroupName "$groupName" --TemplateFile $BASEDIR/resource-management/sampleTemplate.json --TemplateParameterFile $BASEDIR/resource-management/sampleTemplateParams.json`
17+
echo $deploymentInfo
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"siteName": {
6+
"type": "string"
7+
},
8+
"hostingPlanName": {
9+
"type": "string"
10+
},
11+
"siteLocation": {
12+
"type": "string"
13+
},
14+
"sku": {
15+
"type": "string",
16+
"allowedValues": [
17+
"Free",
18+
"Shared",
19+
"Basic",
20+
"Standard"
21+
],
22+
"defaultValue": "Free"
23+
},
24+
"workerSize": {
25+
"type": "int",
26+
"allowedValues": [
27+
0,
28+
1,
29+
2
30+
],
31+
"defaultValue": 0
32+
}
33+
},
34+
"resources": [
35+
{
36+
"apiVersion": "2014-04-01",
37+
"name": "[parameters('hostingPlanName')]",
38+
"type": "Microsoft.Web/serverfarms",
39+
"location": "[parameters('siteLocation')]",
40+
"properties": {
41+
"name": "[parameters('hostingPlanName')]",
42+
"sku": "[parameters('sku')]",
43+
"workerSize": "[parameters('workerSize')]",
44+
"numberOfWorkers": 1
45+
}
46+
}
47+
]
48+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"siteName": {
3+
"value": "hao"
4+
},
5+
"hostingPlanName": {
6+
"value": "xDeploymentTestHost26668"
7+
},
8+
"siteLocation": {
9+
"value": "West US"
10+
},
11+
"sku": {
12+
"value": "Standard"
13+
},
14+
"workerSize": {
15+
"value": 0
16+
}
17+
}

src/CLU/Commands.Common.ScenarioTest/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"Commands.Common.Authentication": "",
2222
"Commands.ResourceManager.Common": "",
2323
"Microsoft.Azure.Commands.Profile": "",
24-
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
24+
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
2525
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
2626
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
2727
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",

src/CLU/Commands.ResourceManager.Cmdlets/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"System.Threading": "4.0.11-beta-23516",
4747
"System.Threading.Tasks": "4.0.11-beta-23516",
4848
"System.Threading.Thread": "4.0.0-beta-23516",
49-
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
49+
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
5050
"Microsoft.Extensions.Caching.Memory": "1.0.0-rc1-final"
5151
},
5252
"compilationOptions": {"emitEntryPoint": true}

src/CLU/Commands.ScenarioTests.ResourceManager.Common/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"Commands.Common": "",
2121
"Commands.Common.Authentication": "",
2222
"Commands.ResourceManager.Common": "",
23-
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
23+
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
2424
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
2525
"Microsoft.Rest.ClientRuntime": "1.8.2",
2626
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",

src/CLU/Microsoft.Azure.Commands.Network/project.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"Microsoft.CLU": "1.0.0",
2020
"Commands.Common.Authentication": "",
2121
"Commands.Common": "",
22-
"Microsoft.Azure.Graph.RBAC": "2.1.0-preview",
23-
"Microsoft.Azure.Management.Authorization": "2.1.0-preview",
24-
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
22+
"Microsoft.Azure.Graph.RBAC": "2.1.1-preview",
23+
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
24+
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
2525
"Microsoft.Azure.Management.Network": "3.0.3-preview",
2626
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
2727
"Microsoft.Rest.ClientRuntime": "1.8.2",

src/CLU/Microsoft.Azure.Commands.Profile.Test/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"Commands.ResourceManager.Common": "",
2323
"Commands.ScenarioTests.ResourceManager.Common": "",
2424
"Microsoft.Azure.Commands.Profile": "",
25-
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
25+
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
2626
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
2727
"Microsoft.Rest.ClientRuntime": "1.8.2",
2828
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",

src/CLU/Microsoft.Azure.Commands.Profile/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"Commands.Common": "",
2121
"Commands.Common.Authentication": "",
2222
"Commands.ResourceManager.Common": "",
23-
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
23+
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
2424
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
2525
"Microsoft.Rest.ClientRuntime": "1.8.2",
2626
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",

src/CLU/Microsoft.Azure.Commands.Resources.Test/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"Microsoft.Azure.Commands.Resources": "",
2525
"Microsoft.Azure.Graph.RBAC": "2.1.1-preview",
2626
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
27-
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
27+
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
2828
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
2929
"Microsoft.Rest.ClientRuntime": "1.8.2",
3030
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",

src/CLU/Microsoft.Azure.Commands.Resources/Models.ResourceGroups/ResourceClient.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using Microsoft.Azure.Management.Resources.Models;
2424
using Microsoft.Rest.Azure;
2525
using Newtonsoft.Json;
26+
using Newtonsoft.Json.Linq;
2627
using System;
2728
using System.Collections;
2829
using System.Collections.Generic;
@@ -328,7 +329,9 @@ private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParame
328329
}
329330
else
330331
{
331-
deployment.Properties.Template = DataStore.ReadFileAsText(parameters.TemplateFile);
332+
var textData = DataStore.ReadFileAsText(parameters.TemplateFile);
333+
deployment.Properties.Template = string.IsNullOrEmpty(textData) ?
334+
(object)textData : JObject.Parse(DataStore.ReadFileAsText(parameters.TemplateFile));
332335
}
333336

334337
if (Uri.IsWellFormedUriString(parameters.ParameterUri, UriKind.Absolute))
@@ -340,7 +343,9 @@ private Deployment CreateBasicDeployment(ValidatePSResourceGroupDeploymentParame
340343
}
341344
else
342345
{
343-
deployment.Properties.Parameters = GetDeploymentParameters(parameters.TemplateParameterObject);
346+
var deploymentParameters = GetDeploymentParameters(parameters.TemplateParameterObject);
347+
deployment.Properties.Parameters = string.IsNullOrEmpty(deploymentParameters) ?
348+
(object) deploymentParameters : JObject.Parse(deploymentParameters);
344349
}
345350

346351
return deployment;

src/CLU/Microsoft.Azure.Commands.Resources/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"Commands.ResourceManager.Cmdlets": "",
2424
"Microsoft.Azure.Graph.RBAC": "2.1.1-preview",
2525
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
26-
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
26+
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
2727
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
2828
"Microsoft.Rest.ClientRuntime": "1.8.2",
2929
"Microsoft.Rest.ClientRuntime.Azure": "2.5.4",

src/CLU/Microsoft.Azure.Commands.Websites.Test/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"Microsoft.Azure.Commands.Profile": "",
2323
"Microsoft.Azure.Commands.Websites": "",
2424
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
25-
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
25+
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
2626
"Microsoft.Azure.Management.Websites": "1.0.0-preview",
2727
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
2828
"Microsoft.Rest.ClientRuntime": "1.8.2",

src/CLU/Microsoft.Azure.Commands.Websites/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"Microsoft.Azure.Commands.Profile": "",
2626
"Microsoft.Azure.Graph.RBAC": "2.1.1-preview",
2727
"Microsoft.Azure.Management.Authorization": "2.3.0-preview",
28-
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
28+
"Microsoft.Azure.Management.Resources": "3.3.1-preview",
2929
"Microsoft.Azure.Management.Websites": "1.0.0-preview",
3030
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
3131
"Microsoft.Rest.ClientRuntime": "1.8.2",

0 commit comments

Comments
 (0)