3
3
printf " \n=== Managing Web App Slot in Azure ===\n"
4
4
5
5
pingwebapp () {
6
- # a helper function to ping a webapp
7
- url=` echo $slot1 | jq ' ."properties.hostNames"[0]' --raw-output`
8
- curl -I ` echo $url `
6
+ url=` echo " $1 " | jq ' ."properties.hostNames"[0]' --raw-output`
7
+ curl -I ` echo " $url " `
9
8
}
10
9
11
10
# setup
12
11
printf " \nSetup: Creating a new resource group: %s at location: %s.\n" " $groupName " " $location "
13
12
14
- appName=` randomName testweb`
13
+ appName1=` randomName testweb`
14
+ appName2=` randomName testweb`
15
+ appName3=` randomName testweb`
16
+ planName1=` randomName testplan`
17
+ planName2=` randomName testplan`
18
+ planName3=` randomName testplan`
15
19
slotname1=" staging"
16
20
slotname2=" testing"
17
- planName=` randomName testplan`
18
- tier=" Standard"
21
+ slotname3=" staging"
22
+ tier1=" Standard"
23
+ tier2=" Premium"
19
24
apiversion=" 2015-08-01"
20
25
resourceType=" Microsoft.Web/sites"
21
26
22
27
azure group create --name " $groupName " --location " $location "
23
28
24
- printf " \n1. Create a new app service plan %s " " $planName "
25
- azure app service plan create -n " $planName " -g " $groupName " -l " $location " --tier " $tier "
29
+ printf " \n1. Create a new app service plan %s " " $planName1 "
30
+ azure app service plan create -n " $planName1 " -g " $groupName " -l " $location " --tier " $tier1 "
26
31
27
- printf " \n2. Create a new web app %s " " $appName "
28
- webappInfo =` azure webapp create -g " $groupName " -n " $appName " -l " $location " --plan " $planName " `
32
+ printf " \n2. Create a new web app %s " " $appName1 "
33
+ webappInfo1 =` azure webapp create -g " $groupName " -n " $appName1 " -l " $location " --plan " $planName1 " `
29
34
30
- printf " \nValidating web app name %s " " $appName "
31
- [ $( echo $webappInfo | jq ' .name' --raw-output) == " $appName " ]
35
+ printf " \nValidating web app name %s " " $appName1 "
36
+ [ $( echo $webappInfo1 | jq ' .name' --raw-output) == " $appName1 " ]
32
37
33
38
printf " \n3. Create a web app slot %s " " $slotname1 "
34
- slot1=` azure webapp slot create -g " $groupName " --plan " $planName " -n " $appName " --slot " $slotname1 " `
35
- appWithSlotName1=" $appName /$slotname1 "
39
+ slot1=` azure webapp slot create -g " $groupName " --plan " $planName1 " -n " $appName1 " --slot " $slotname1 " `
40
+ appWithSlotName1=" $appName1 /$slotname1 "
36
41
37
42
printf " \nValidating web app slot %s " " $slotname1 "
38
43
[ $( echo $slot1 | jq ' .name' --raw-output) == " $appWithSlotName1 " ]
39
44
40
45
printf " \nValidating web app slot get for %s " " $slotname1 "
41
- slot1=` azure webapp slot get -g " $groupName " -n " $appName " --slot " $slotname1 " `
46
+ slot1=` azure webapp slot get -g " $groupName " -n " $appName1 " --slot " $slotname1 " `
42
47
[ $( echo $slot1 | jq ' .name' --raw-output) == " $appWithSlotName1 " ]
43
48
44
49
printf " \nValidating web app slot via pipline obj for %s " " $slotname1 "
45
- slot1=` echo " $webappInfo " | azure webapp slot get --slot " $slotname1 " `
50
+ slot1=` echo " $webappInfo1 " | azure webapp slot get --slot " $slotname1 " `
46
51
47
52
printf " \n4. Create another web app slot %s " " $slotname2 "
48
- slot2=` azure webapp slot create -g " $groupName " --plan " $planName " -n " $appName " --slot " $slotname2 " `
49
- appWithSlotName2=" $appName /$slotname2 "
53
+ slot2=` azure webapp slot create -g " $groupName " --plan " $planName1 " -n " $appName1 " --slot " $slotname2 " `
54
+ appWithSlotName2=" $appName1 /$slotname2 "
50
55
51
56
printf " \n5. Get the webapp slots:"
52
- slots=` azure webapp slot get -g " $groupName " -n " $appName " `
57
+ slots=` azure webapp slot get -g " $groupName " -n " $appName1 " `
53
58
slotN1=` echo $slots | jq ' .[0].name' `
54
59
slotN2=` echo $slots | jq ' .[1].name' `
55
60
slotNames=` echo $slotN1 $slotN2 `
@@ -59,26 +64,26 @@ printf "\nValidating web app slots %s " "$slotname1 and $slotname2"
59
64
[[ $slotNames == * " $appWithSlotName2 " * ]]
60
65
61
66
printf " \n6. Change web app slot %s service plan" " $slotname2 "
62
- appName2=` randomName testweb`
63
- planName2=` randomName testplan`
64
- servicePlanInfo3=` azure app service plan create -n " $planName3 " -g " $groupName " -l " $location " --tier " $tier " `
67
+ servicePlanInfo2=` azure app service plan create -n " $planName2 " -g " $groupName " -l " $location " --tier " $tier2 " `
65
68
# slot3=`azure webapp slot create -g "$groupName" --plan "$planName3" -n "$appName" --slot "$slotname2"`
66
- slot1=` azure webapp slot set -g " $groupName " -n " $appName " --slot " $slotname1 " --plan " $planName2 " `
69
+ slot1=` azure webapp slot set -g " $groupName " -n " $appName1 " --slot " $slotname1 " --plan " $planName2 " `
67
70
71
+ printf " \nValidating web app slots %s " " $slotname1 "
72
+ [ $( echo $slot1 | jq ' .name' --raw-output) == " $appName1 /$slotname1 " ]
73
+ [[ $( echo $slot1 | jq ' ."properties.serverFarmId"' ) == * " $planName2 " * ]]
68
74
69
75
printf " \n7. Set web app slot %s config properties"
70
76
# Unable to test pipline. verity property name and value instead.
71
77
72
78
printf " \n8. Set web app slot settings and connection strings"
73
79
appsettings=" {\" setting1\" :\" valueA\" ,\" setting2\" :\" valueB\" }"
74
80
connectionstrings=" { \" connstring1\" : { \" Type\" : \" MySql\" , \" Value\" : \" string value 1\" }, \" connstring2\" : { \" Type\" : \" SqlAzure\" , \" Value\" : \" string value 2\" } }"
75
- slot1=` azure webapp slot set -g " $groupName " --plan " $planName " -n " $appName " --slot " $slotname1 " --connectionstrings " $connectionstrings " --appsettings " $appsettings " `
76
-
81
+ slot1=` azure webapp slot set -g " $groupName " --plan " $planName1 " -n " $appName1 " --slot " $slotname1 " --connectionstrings " $connectionstrings " --appsettings " $appsettings " `
77
82
78
83
printf " \n9. Get web app slot %s publishing profile" " $slotname1 "
79
84
outputFile1=" webappslot-profile-1"
80
85
outputFile2=" webappslot-profile-2"
81
- azure webapp slot profile get -g " $groupName " -n " $appName " --slot " $slotname1 " --outputfile " $outputFile1 "
86
+ azure webapp slot profile get -g " $groupName " -n " $appName1 " --slot " $slotname1 " --outputfile " $outputFile1 "
82
87
83
88
printf " \n10. Get web app slot %s publishing profile via pipline obj" " $slotname1 "
84
89
# Unable to test pipline. verity property name and value instead.
@@ -88,18 +93,16 @@ printf "\nValidating web app slot profile output file"
88
93
[ -s " $outputFile1 " ]
89
94
# [ -s "$outputFile2" ]
90
95
91
-
92
96
printf " \n11. Get web app slot metrics %s " " $slotname1 "
93
97
for i in {1..10}
94
98
do
95
- pingwebapp $slot1
99
+ pingwebapp " $slot1 "
96
100
done
97
101
98
102
endTime=` date +" %A, %B %d, %Y %X" `
99
103
startTime=` date +" %A, %B %d, %Y %X" --date " 3 hour ago" `
100
104
metricsNames=" [\" CPU\" ,\" Request\" ]"
101
-
102
- metrics=` azure webapp slot metrics get -g " $groupName " -n " $appName " --slot " $slotname1 " --granularity PT1M --starttime " $startTime " --endtime " $endTime " --metrics " $metricsNames " `
105
+ metrics=` azure webapp slot metrics get -g " $groupName " -n " $appName1 " --slot " $slotname1 " --granularity PT1M --starttime " $startTime " --endtime " $endTime " --metrics " $metricsNames " `
103
106
104
107
printf " \nValidating web app slot metrics via pipline obj %s " " $slotname1 "
105
108
# Unable to test pipline. verity property name and value instead.
@@ -126,64 +129,55 @@ printf "\nValidating web app slot %s running " "$slotname1"
126
129
[ $( echo $slot1 | jq ' ."properties.state"' --raw-output) == " Running" ]
127
130
128
131
printf " \n16 Restart web app slot: %s." " $slotname1 "
129
- slot1=` echo " $slot1 " | azure webapp slot restart `
132
+ slot1=` azure webapp slot restart -g " $groupName " -n " $appName1 " -- slot " $slotname1 " `
130
133
printf " \nValidating web app slot %s Running " " $slotname1 "
131
134
[ $( echo $slot1 | jq ' ."properties.state"' --raw-output) == " Running" ]
132
135
133
- printf " \n17 Restart web app slot: %s." " $slotname1 "
136
+ printf " \n17 Restart web app slot: %s with pipline object ." " $slotname1 "
134
137
slot1=` echo " $slot1 " | azure webapp slot restart`
135
138
printf " \nValidating web app slot %s Running " " $slotname1 "
136
139
[ $( echo $slot1 | jq ' ."properties.state"' --raw-output) == " Running" ]
137
140
138
- # Clone ------
139
141
# Need to create a 'Premium' plan for clone test
140
- printf " \n2. Create a new web app for clone testing"
141
- groupName1=` randomName testrg`
142
- appName1=` randomName testweb`
143
- destAppName=` randomName testweb`
144
- planName1=` randomName testplan`
145
- destPlanName=` randomName testplan`
146
- slotnameClone=" staging"
147
- tier1=" Premium"
142
+ printf " \n18. Create a new web app for clone testing"
148
143
location1=" eastus"
149
144
150
- azure group create --name " $groupName1 " --location " $location "
151
- azure app service plan create -n " $planName1 " -g " $groupName1 " -l " $location " --tier " $tier1 "
152
- webappInfo=` azure webapp create -g " $groupName1 " -n " $appName1 " -l " $location " --plan " $planName1 " `
153
- printf " \n18. Clone web app slot to a slot."
154
- slotClone=` azure webapp slot create -g " $groupName1 " -n " $appName1 " --slot " $slotnameClone " --sourcewebapp " $webappInfo " `
155
- appWithSlotNameClone=" $appName1 /slotnameClone"
145
+ azure app service plan set -n " $planName1 " -g " $groupName " --tier " $tier2 "
146
+ webappInfo2=` azure webapp create -g " $groupName " -n " $appName2 " -l " $location " --plan " $planName2 " `
156
147
157
- printf " \nValidating cloned web app slot %s " " $slotnameClone "
158
- [ $( echo $slotClone | jq ' .name' --raw-output) == " $appWithSlotNameClone " ]
148
+ printf " \n19. Clone web app slot to a slot."
149
+ slotClone=` azure webapp slot create -g " $groupName " -n " $appName2 " --slot " $slotname3 " --sourcewebapp " $webappInfo2 " `
150
+ appWithSlotNameClone=" $appName2 /$slotname3 "
159
151
160
- printf " \nValidating web app slot get for %s " " $slotnameClone "
161
- slotClone=` azure webapp slot get -g " $groupName " -n " $appName1 " --slot " $slotnameClone " `
152
+ printf " \nValidating cloned web app slot %s " " $slotname3 "
162
153
[ $( echo $slotClone | jq ' .name' --raw-output) == " $appWithSlotNameClone " ]
163
154
164
- printf " \n2. Create a new web app for clone testing"
165
- slot1=` azure webapp slot create -g " $groupName1 " --plan " $planName1 " -n " $appName1 " --slot " $slotnameClone " `
166
- slotN1=" $appname1$slotnameClone "
167
-
168
- printf " \n2. Create a new web app for clone testing"
169
- servicePlan=` azure app service plan create -n " $destAppName " -g " $groupName1 " -l " $location1 " --tier " $tier1 " `
170
- webappInfo2=` azure webapp create -g " $groupName1 " -n " $destAppName " -l " $location1 " --plan " $destPlanName " `
171
- slot2=` azure webapp slot create -g " $groupName1 " -n " $destAppName " --slot " $slotnameClone " --sourcewebapp " $webappInfo2 " `
155
+ printf " \nValidating web app slot get for %s " " $slotname3 "
156
+ slotClone=` azure webapp slot get -g " $groupName " -n " $appName2 " --slot " $slotname3 " `
157
+ [ $( echo $slotClone | jq ' .name' --raw-output) == " $appWithSlotNameClone " ]
172
158
173
- printf " \nValidating web app slot get for %s " " $slotnameClone "
159
+ printf " \n20. Create a new web app for clone testing"
160
+ slot2=` azure webapp slot create -g " $groupName " --plan " $planName2 " -n " $appName2 " --slot " $slotname3 " `
161
+ slotN1=" $appName2 /$slotname3 "
174
162
163
+ printf " \n21. Create a new web app for clone testing"
164
+ servicePlan=` azure app service plan create -n " $planName3 " -g " $groupName " -l " $location1 " --tier " $tier2 " `
165
+ webappInfo3=` azure webapp create -g " $groupName " -n " $appName3 " -l " $location1 " --plan " $planName3 " `
166
+ slot3=` azure webapp slot create -g " $groupName " -n " $appName3 " --slot " $slotname3 " --sourcewebapp " $webappInfo3 " `
175
167
176
- # -------
168
+ printf " \nValidating web app slot get for %s " " $slotname3 "
169
+ appWithSlotName3=" $appName3 /$slotname3 "
170
+ [ $( echo $slot3 | jq ' .name' --raw-output) == " $appWithSlotName3 " ]
177
171
178
172
# Cleanup
179
- printf " \n20 . Remove web app slot: %s." " $slotname1 "
180
- azure webapp slot remove -g " $groupName " -n " $appName " --slot " $slotname1 " --force
173
+ printf " \n22 . Remove web app slot: %s." " $slotname1 "
174
+ azure webapp slot remove -g " $groupName " -n " $appName1 " --slot " $slotname1 " --force
181
175
182
- printf " \n20 . Remove web app: %s." " $appName "
183
- azure webapp remove -g " $groupName " -n " $appName " --force
176
+ printf " \n23 . Remove web app: %s." " $appName1 "
177
+ azure webapp remove -g " $groupName " -n " $appName1 " --force
184
178
185
- printf " \n20 . Remove app service plan: %s." " $planName "
186
- azure app service plan remove -g " $groupName " -n " $planName " --force
179
+ printf " \n24 . Remove app service plan: %s." " $planName1 "
180
+ azure app service plan remove -g " $groupName " -n " $planName1 " --force
187
181
188
- printf " \n20 . Remove resource group: %s." " $groupName "
182
+ printf " \n25 . Remove resource group: %s." " $groupName "
189
183
azure group remove --name " $groupName " --force
0 commit comments