Skip to content

Test script for webapp slot #1610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 83 additions & 54 deletions examples/webapp-management/02-WebAppSlot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,52 @@ set -e
printf "\n=== Managing Web App Slot in Azure ===\n"

pingwebapp() {
# a helper function to ping a webapp
url=`echo "$1" | jq '."properties.hostNames"[0]' --raw-output`
curl -I `echo "$url"`
}

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

appName=`randomName testweb`
slotname1="staging"
slotname2="testing"
planName=`randomName testplan`
tier="Standard"
slotname3="staging"
tier1="Standard"
tier2="Premium"
apiversion="2015-08-01"
resourceType="Microsoft.Web/sites"

az group create --name "$groupName" --location "$location"

printf "\n1. Create a new app service plan %s " "$planName"
az app service plan create -n "$planName" -g "$groupName" -l "$location" --tier "$tier"
printf "\n1. Create a new app service plan %s " "$planName1"
az app service plan create -n "$planName1" -g "$groupName" -l "$location" --tier "$tier1"

printf "\n2. Create a new web app %s " "$appName"
webappInfo=`az webapp create -g "$groupName" -n "$appName" -l "$location" --plan "$planName"`
printf "\n2. Create a new web app %s " "$appName1"
webappInfo1=`az webapp create -g "$groupName" -n "$appName1" -l "$location" --plan "$planName1"`

printf "\nValidating web app name %s " "$appName"
[ $(echo $webappInfo | jq '.name' --raw-output) == "$appName" ]
printf "\nValidating web app name %s " "$appName1"
[ $(echo $webappInfo1 | jq '.name' --raw-output) == "$appName1" ]

printf "\n3. Create a web app slot %s " "$slotname1"
slot1=`az webapp slot create -g "$groupName" --plan "$planName" -n "$appName" --slot "$slotname1"`
appWithSlotName1="$appName/$slotname1"
slot1=`az webapp slot create -g "$groupName" --plan "$planName1" -n "$appName1" --slot "$slotname1"`
appWithSlotName1="$appName1/$slotname1"

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

printf "\nValidating web app slot get for %s " "$slotname1"
slot1=`az webapp slot get -g "$groupName" -n "$appName" --slot "$slotname1"`
slot1=`az webapp slot get -g "$groupName" -n "$appName1" --slot "$slotname1"`
[ $(echo $slot1 | jq '.name' --raw-output) == "$appWithSlotName1" ]

printf "\nValidating web app slot via pipline obj for %s " "$slotname1"
slot1=`echo "$webappInfo" | az webapp slot get --slot "$slotname1"`
slot1=`echo "$webappInfo1" | az webapp slot get --slot "$slotname1"`

printf "\n4. Create another web app slot %s " "$slotname2"
slot2=`az webapp slot create -g "$groupName" --plan "$planName" -n "$appName" --slot "$slotname2"`
appWithSlotName2="$appName/$slotname2"
slot2=`az webapp slot create -g "$groupName" --plan "$planName1" -n "$appName1" --slot "$slotname2"`
appWithSlotName2="$appName1/$slotname2"

printf "\n5. Get the webapp slots:"
slots=`az webapp slot get -g "$groupName" -n "$appName"`
slots=`az webapp slot get -g "$groupName" -n "$appName1"`
slotN1=`echo $slots | jq '.[0].name'`
slotN2=`echo $slots | jq '.[1].name'`
slotNames=`echo $slotN1 $slotN2`
Expand All @@ -57,34 +58,50 @@ printf "\nValidating web app slots %s " "$slotname1 and $slotname2"
[[ $slotNames == *"$appWithSlotName2"* ]]

printf "\n6. Change web app slot %s service plan" "$slotname2"
printf "\n7. Set web app slot %s config properties" "$slotname2"
printf "\n8. Set web app slot %s settings and connection strings" "$slotname2"
servicePlanInfo2=`az app service plan create -n "$planName2" -g "$groupName" -l "$location" --tier "$tier2"`
# slot3=`az webapp slot create -g "$groupName" --plan "$planName3" -n "$appName" --slot "$slotname2"`
slot1=`az webapp slot set -g "$groupName" -n "$appName1" --slot "$slotname1" --plan "$planName2"`

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

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

printf "\n8. Set web app slot settings and connection strings"
appsettings="{\"setting1\":\"valueA\",\"setting2\":\"valueB\"}"
connectionstrings="{ \"connstring1\": { \"Type\": \"MySql\", \"Value\": \"string value 1\" }, \"connstring2\": { \"Type\": \"SqlAzure\", \"Value\": \"string value 2\" } }"
slot1=`az webapp slot set -g "$groupName" --plan "$planName1" -n "$appName1" --slot "$slotname1" --connectionstrings "$connectionstrings" --appsettings "$appsettings"`

printf "\n9. Get web app slot %s publishing profile" "$slotname1"
outputFile1="webappslot-profile-1"
outputFile2="webappslot-profile-2"
az webapp slot profile get -g "$groupName" -n "$appName1" --slot "$slotname1" --outputfile "$outputFile1"

printf "\n10. Get web app slot %s publishing profile via pipline obj" "$slotname1"
# Unable to test pipline. verity property name and value instead.
# echo "$slot1" | az webapp slot profile get --outputfile "$outputFile2"

printf "\nValidating web app slot profile output file"
[ -s "$outputFile1" ]
# [ -s "$outputFile2" ]

printf "\n11. Get web app slot metrics %s " "$slotname1"
for i in {1..10}
do
pingwebapp $slot1
pingwebapp "$slot1"
done

endTime=`date +"%A, %B %d, %Y %X"`
startTime=`date +"%A, %B %d, %Y %X" --date "3 hour ago"`
$metricsNames="\"('CPU', 'Requests')\""

# !Not able to test since complex object issue.
metrics=`az webapp slot metrics get -g "$groupName" -n "$appName" --slot "$slotname1" --granularity PT1M --starttime "$startTime" --endtime "$endTime" --metrics "$metricsNames"`

printf "\nValidating web app slot metrics %s " "$slotname1"
for i in $metricsNames
do
[ $(echo $metrics ) == "$i" ]
done

# !Not able to test pipeline for now
printf "\nValidating web app slot metrics via pipline obj %s " "$slotname1"
metricsNames="[\"CPU\",\"Request\"]"
metrics=`az webapp slot metrics get -g "$groupName" -n "$appName1" --slot "$slotname1" --granularity PT1M --starttime "$startTime" --endtime "$endTime" --metrics "$metricsNames"`

printf "\nValidating web app slot metrics via pipline obj %s " "$slotname1"
# Unable to test pipline. verity property name and value instead.
# echo "$slot1" | az webapp slot metrics get --metrics "$metricsNames" --starttime "$startTime" --endtime "$endTime" --granularity PT1M

printf "\n12. Stop web app slot: %s." "$slotname1"
slot1=`echo "$slot1" | az webapp slot stop`
printf "\nValidating web app slot %s stopped " "$slotname1"
Expand All @@ -106,37 +123,49 @@ printf "\nValidating web app slot %s running " "$slotname1"
[ $(echo $slot1 | jq '."properties.state"' --raw-output) == "Running" ]

printf "\n16 Restart web app slot: %s." "$slotname1"
slot1=`echo "$slot1" | az webapp slot restart`
slot1=`az webapp slot restart -g "$groupName" -n "$appName1" --slot "$slotname1"`
printf "\nValidating web app slot %s Running " "$slotname1"
[ $(echo $slot1 | jq '."properties.state"' --raw-output) == "Running" ]

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

# Clone ------
# !Not able to test since complex object input issue.
# printf "\n10. Clone web app slot: %s." "$slotname1"
# slotClone=`az web app slot clone`
# appWithSlotNameClone="$appName/slotname1"
# Need to create a 'Premium' plan for clone test
printf "\n18. Create a new web app for clone testing"
location1="eastus"

# printf "\nValidating cloned web app slot %s " "$slotname1"
# [ $(echo $slotClone | jq '.name' --raw-output) == "$appWithSlotNameClone" ]
az app service plan set -n "$planName1" -g "$groupName" --tier "$tier2"
webappInfo2=`az webapp create -g "$groupName" -n "$appName3" -l "$location" --plan "$planName1"`

# printf "\nValidating web app slot get for %s " "$slotname1"
# slot1=`az webapp slot get -g "$groupName" -n "$appName" --slot "$slotname1"`
# [ $(echo $slot1 | jq '.name' --raw-output) == "$appWithSlotNameClone" ]
#-------
printf "\n19. Clone web app slot to a slot."
slotClone=`az webapp slot create -g "$groupName" -n "$appName3" --slot "$slotname3" --sourcewebapp "$webappInfo2"`
appWithSlotNameClone="$appName3/$slotname3"

# Cleanup
printf "\n20. Remove web app slot: %s." "$slotname1"
az webapp slot remove -g "$groupName" -n "$appName" --slot "$slotname1"
printf "\nValidating cloned web app slot %s " "$slotname3"
[ $(echo $slotClone | jq '.name' --raw-output) == "$appWithSlotNameClone" ]

printf "\n20. Remove web app: %s." "$appName"
az webapp remove -g "$groupName" -n "$appName"
printf "\nValidating web app slot get for %s " "$slotname3"
slotClone=`az webapp slot get -g "$groupName" -n "$appName3" --slot "$slotname3"`
[ $(echo $slotClone | jq '.name' --raw-output) == "$appWithSlotNameClone" ]

printf "\n20. Remove app service plan: %s." "$planName"
az app service plan remove -g "$groupName" -n "$planName"
printf "\n20. Create a new web app for clone testing"
slot2=`az webapp slot create -g "$groupName" --plan "$planName1" -n "$appName3" --slot "$slotname3"`

printf "\n21. Create a new web app for clone testing"
servicePlan=`az app service plan create -n "$planName3" -g "$groupName" -l "$location1" --tier "$tier2"`
webappInfo3=`az webapp create -g "$groupName" -n "$appName4" -l "$location1" --plan "$planName3"`
slot3=`az webapp slot create -g "$groupName" --plan "$planName3" -n "$appName4" --slot "$slotname3" --sourcewebapp "$slot2"`

printf "\nValidating web app slot get for %s " "$slotname3"
appWithSlotName3="$appName4/$slotname3"
[ $(echo $slot3 | jq '.name' --raw-output) == "$appWithSlotName3" ]

# Cleanup
printf "\n22. Remove web app slot: %s." "$slotname1"
az webapp slot remove -g "$groupName" -n "$appName1" --slot "$slotname1" --force
az webapp slot remove -g "$groupName" -n "$appName1" --slot "$slotname2" --force

printf "\n20. Remove resource group: %s." "$groupName"
printf "\n23. Remove resource group: %s." "$groupName"
az group remove --name "$groupName" --force
8 changes: 0 additions & 8 deletions examples/webapp-management/03-WebApp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@ printf "\n=== Managing Web Apps in Azure ===\n"
printf "\nSetup: Creating a new resource group: %s at location: %s.\n" "$groupName" "$location"
az group create --name "$groupName" --location "$location"

appName1=`randomName testweb`
appName2=`randomName testweb`
appName3=`randomName testweb`
appName4=`randomName testweb`
slotname1="staging"
slotname2="testing"
planName1=`randomName testplan`
planName2=`randomName testplan`
planName3=`randomName testplan`
planName4=`randomName testplan`
tier1="Shared"
tier2="Standard"
tier3="Premium"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,32 @@ public void AppServicePlanTest()
helper.RunScript("01-AppServicePlan");
}

[Fact(Skip = "TODO: Work in progress")]
[Fact]
public void WebAppSlotTest()
{
var helper = _collectionState.GetRunner("webapp-management");
helper.EnvironmentVariables.Add("appName1", helper.GenerateName("testweb"));
helper.EnvironmentVariables.Add("appName2", helper.GenerateName("testweb"));
helper.EnvironmentVariables.Add("appName3", helper.GenerateName("testweb"));
helper.EnvironmentVariables.Add("appName4", helper.GenerateName("testweb"));
helper.EnvironmentVariables.Add("planName1", helper.GenerateName("testplan"));
helper.EnvironmentVariables.Add("planName2", helper.GenerateName("testplan"));
helper.EnvironmentVariables.Add("planName3", helper.GenerateName("testplan"));
helper.RunScript("02-WebAppSlot");
}

[Fact]
public void WebAppTest()
{
var helper = _collectionState.GetRunner("webapp-management");
helper.EnvironmentVariables.Add("appName1", helper.GenerateName("testweb"));
helper.EnvironmentVariables.Add("appName2", helper.GenerateName("testweb"));
helper.EnvironmentVariables.Add("appName3", helper.GenerateName("testweb"));
helper.EnvironmentVariables.Add("appName4", helper.GenerateName("testweb"));
helper.EnvironmentVariables.Add("planName1", helper.GenerateName("testplan"));
helper.EnvironmentVariables.Add("planName2", helper.GenerateName("testplan"));
helper.EnvironmentVariables.Add("planName3", helper.GenerateName("testplan"));
helper.EnvironmentVariables.Add("planName4", helper.GenerateName("testplan"));
helper.RunScript("03-WebApp");
}
}
Expand Down