Skip to content

Commit 7caebc1

Browse files
author
Hao Chen
committed
Updated webapp slot tests script.
1 parent 37d7262 commit 7caebc1

File tree

1 file changed

+62
-68
lines changed

1 file changed

+62
-68
lines changed

examples/webapp-management/02-WebAppSlot.sh

Lines changed: 62 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,58 @@ set -e
33
printf "\n=== Managing Web App Slot in Azure ===\n"
44

55
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"`
98
}
109

1110
#setup
1211
printf "\nSetup: Creating a new resource group: %s at location: %s.\n" "$groupName" "$location"
1312

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`
1519
slotname1="staging"
1620
slotname2="testing"
17-
planName=`randomName testplan`
18-
tier="Standard"
21+
slotname3="staging"
22+
tier1="Standard"
23+
tier2="Premium"
1924
apiversion="2015-08-01"
2025
resourceType="Microsoft.Web/sites"
2126

2227
azure group create --name "$groupName" --location "$location"
2328

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"
2631

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"`
2934

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" ]
3237

3338
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"
3641

3742
printf "\nValidating web app slot %s " "$slotname1"
3843
[ $(echo $slot1 | jq '.name' --raw-output) == "$appWithSlotName1" ]
3944

4045
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"`
4247
[ $(echo $slot1 | jq '.name' --raw-output) == "$appWithSlotName1" ]
4348

4449
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"`
4651

4752
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"
5055

5156
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"`
5358
slotN1=`echo $slots | jq '.[0].name'`
5459
slotN2=`echo $slots | jq '.[1].name'`
5560
slotNames=`echo $slotN1 $slotN2`
@@ -59,26 +64,26 @@ printf "\nValidating web app slots %s " "$slotname1 and $slotname2"
5964
[[ $slotNames == *"$appWithSlotName2"* ]]
6065

6166
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"`
6568
# 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"`
6770

71+
printf "\nValidating web app slots %s " "$slotname1"
72+
[ $(echo $slot1 | jq '.name' --raw-output) == "$appName1/$slotname1" ]
73+
[[ $(echo $slot1 | jq '."properties.serverFarmId"') == *"$planName2"* ]]
6874

6975
printf "\n7. Set web app slot %s config properties"
7076
# Unable to test pipline. verity property name and value instead.
7177

7278
printf "\n8. Set web app slot settings and connection strings"
7379
appsettings="{\"setting1\":\"valueA\",\"setting2\":\"valueB\"}"
7480
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"`
7782

7883
printf "\n9. Get web app slot %s publishing profile" "$slotname1"
7984
outputFile1="webappslot-profile-1"
8085
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"
8287

8388
printf "\n10. Get web app slot %s publishing profile via pipline obj" "$slotname1"
8489
# Unable to test pipline. verity property name and value instead.
@@ -88,18 +93,16 @@ printf "\nValidating web app slot profile output file"
8893
[ -s "$outputFile1" ]
8994
# [ -s "$outputFile2" ]
9095

91-
9296
printf "\n11. Get web app slot metrics %s " "$slotname1"
9397
for i in {1..10}
9498
do
95-
pingwebapp $slot1
99+
pingwebapp "$slot1"
96100
done
97101

98102
endTime=`date +"%A, %B %d, %Y %X"`
99103
startTime=`date +"%A, %B %d, %Y %X" --date "3 hour ago"`
100104
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"`
103106

104107
printf "\nValidating web app slot metrics via pipline obj %s " "$slotname1"
105108
# Unable to test pipline. verity property name and value instead.
@@ -126,64 +129,55 @@ printf "\nValidating web app slot %s running " "$slotname1"
126129
[ $(echo $slot1 | jq '."properties.state"' --raw-output) == "Running" ]
127130

128131
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"`
130133
printf "\nValidating web app slot %s Running " "$slotname1"
131134
[ $(echo $slot1 | jq '."properties.state"' --raw-output) == "Running" ]
132135

133-
printf "\n17 Restart web app slot: %s." "$slotname1"
136+
printf "\n17 Restart web app slot: %s with pipline object." "$slotname1"
134137
slot1=`echo "$slot1" | azure webapp slot restart`
135138
printf "\nValidating web app slot %s Running " "$slotname1"
136139
[ $(echo $slot1 | jq '."properties.state"' --raw-output) == "Running" ]
137140

138-
# Clone ------
139141
# 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"
148143
location1="eastus"
149144

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"`
156147

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"
159151

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"
162153
[ $(echo $slotClone | jq '.name' --raw-output) == "$appWithSlotNameClone" ]
163154

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" ]
172158

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"
174162

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"`
175167

176-
#-------
168+
printf "\nValidating web app slot get for %s " "$slotname3"
169+
appWithSlotName3="$appName3/$slotname3"
170+
[ $(echo $slot3 | jq '.name' --raw-output) == "$appWithSlotName3" ]
177171

178172
# 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
181175

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
184178

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
187181

188-
printf "\n20. Remove resource group: %s." "$groupName"
182+
printf "\n25. Remove resource group: %s." "$groupName"
189183
azure group remove --name "$groupName" --force

0 commit comments

Comments
 (0)