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