Skip to content

Commit 6a644b1

Browse files
committed
merge test changes
2 parents 6703cf7 + 9922ce3 commit 6a644b1

File tree

11 files changed

+320
-137
lines changed

11 files changed

+320
-137
lines changed

examples/webapp-management/02-WebAppSlot.sh

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

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

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

12-
appName=`randomName testweb`
1313
slotname1="staging"
1414
slotname2="testing"
15-
planName=`randomName testplan`
16-
tier="Standard"
15+
slotname3="staging"
16+
tier1="Standard"
17+
tier2="Premium"
1718
apiversion="2015-08-01"
1819
resourceType="Microsoft.Web/sites"
1920

2021
az resourcemanager group create --name "$groupName" --location "$location"
2122

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

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

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

3132
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"
3435

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

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

4243
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"`
4445

4546
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"
4849

4950
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"`
5152
slotN1=`echo $slots | jq '.[0].name'`
5253
slotN2=`echo $slots | jq '.[1].name'`
5354
slotNames=`echo $slotN1 $slotN2`
@@ -57,33 +58,49 @@ printf "\nValidating web app slots %s " "$slotname1 and $slotname2"
5758
[[ $slotNames == *"$appWithSlotName2"* ]]
5859

5960
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"`
6276

6377
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+
6482
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" ]
6589

6690
printf "\n11. Get web app slot metrics %s " "$slotname1"
6791
for i in {1..10}
6892
do
69-
pingwebapp $slot1
93+
pingwebapp "$slot1"
7094
done
7195

7296
endTime=`date +"%A, %B %d, %Y %X"`
7397
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"`
78100

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
86101
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
87104

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

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

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

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

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

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

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

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

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
141169

142-
printf "\n20. Remove resource group: %s." "$groupName"
170+
printf "\n23. Remove resource group: %s." "$groupName"
171+
az group rm --name "$groupName" --force

examples/webapp-management/03-WebApp.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,8 @@ printf "\n=== Managing Web Apps in Azure ===\n"
44
printf "\nSetup: Creating a new resource group: %s at location: %s.\n" "$groupName" "$location"
55
az resourcemanager group create --name "$groupName" --location "$location"
66

7-
appName1=`randomName testweb`
8-
appName2=`randomName testweb`
9-
appName3=`randomName testweb`
10-
appName4=`randomName testweb`
117
slotname1="staging"
128
slotname2="testing"
13-
planName1=`randomName testplan`
14-
planName2=`randomName testplan`
15-
planName3=`randomName testplan`
16-
planName4=`randomName testplan`
179
tier1="Shared"
1810
tier2="Standard"
1911
tier3="Premium"

src/CLU/Commands.Common.ScenarioTest/ExamplesTests/WebsitesTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,32 @@ public void AppServicePlanTest()
3232
helper.RunScript("01-AppServicePlan");
3333
}
3434

35-
[Fact(Skip = "TODO: Work in progress")]
35+
[Fact]
3636
public void WebAppSlotTest()
3737
{
3838
var helper = _collectionState.GetRunner("webapp-management");
39+
helper.EnvironmentVariables.Add("appName1", helper.GenerateName("testweb"));
40+
helper.EnvironmentVariables.Add("appName2", helper.GenerateName("testweb"));
41+
helper.EnvironmentVariables.Add("appName3", helper.GenerateName("testweb"));
42+
helper.EnvironmentVariables.Add("appName4", helper.GenerateName("testweb"));
43+
helper.EnvironmentVariables.Add("planName1", helper.GenerateName("testplan"));
44+
helper.EnvironmentVariables.Add("planName2", helper.GenerateName("testplan"));
45+
helper.EnvironmentVariables.Add("planName3", helper.GenerateName("testplan"));
3946
helper.RunScript("02-WebAppSlot");
4047
}
4148

4249
[Fact]
4350
public void WebAppTest()
4451
{
4552
var helper = _collectionState.GetRunner("webapp-management");
53+
helper.EnvironmentVariables.Add("appName1", helper.GenerateName("testweb"));
54+
helper.EnvironmentVariables.Add("appName2", helper.GenerateName("testweb"));
55+
helper.EnvironmentVariables.Add("appName3", helper.GenerateName("testweb"));
56+
helper.EnvironmentVariables.Add("appName4", helper.GenerateName("testweb"));
57+
helper.EnvironmentVariables.Add("planName1", helper.GenerateName("testplan"));
58+
helper.EnvironmentVariables.Add("planName2", helper.GenerateName("testplan"));
59+
helper.EnvironmentVariables.Add("planName3", helper.GenerateName("testplan"));
60+
helper.EnvironmentVariables.Add("planName4", helper.GenerateName("testplan"));
4661
helper.RunScript("03-WebApp");
4762
}
4863
}

src/CLU/Commands.Common/AzurePSCmdlet.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
using System.Linq;
3030
using System.Threading;
3131
using Microsoft.Azure.Commands.Common.Authentication.Factories;
32+
using Microsoft.ApplicationInsights;
33+
using Microsoft.ApplicationInsights.Extensibility;
3234
using Microsoft.Rest;
3335

3436
namespace Microsoft.Azure.Commands.Utilities.Common
@@ -45,7 +47,7 @@ public abstract class AzurePSCmdlet : PSCmdlet, IDisposable
4547
protected static AzurePSDataCollectionProfile _dataCollectionProfile = null;
4648
protected static string _errorRecordFolderPath = null;
4749
protected const string _fileTimeStampSuffixFormat = "yyyy-MM-dd-THH-mm-ss-fff";
48-
50+
protected string _clientRequestId = Guid.NewGuid().ToString();
4951
public IClientFactory ClientFactory { get; set; }
5052

5153
public IAuthenticationFactory AuthenticationFactory { get; set; }
@@ -55,7 +57,7 @@ public abstract class AzurePSCmdlet : PSCmdlet, IDisposable
5557
protected AzurePSQoSEvent QosEvent;
5658

5759
protected virtual bool IsUsageMetricEnabled {
58-
get { return false; }
60+
get { return true; }
5961
}
6062

6163
protected virtual bool IsErrorMetricEnabled
@@ -85,6 +87,11 @@ protected virtual bool IsErrorMetricEnabled
8587
public AzurePSCmdlet()
8688
{
8789
_debugMessages = new ConcurrentQueue<string>();
90+
//TODO: Inject from CI server
91+
MetricHelper.AddTelemetryClient(new TelemetryClient
92+
{
93+
InstrumentationKey = "963c4276-ec20-48ad-b9ab-3968e9da5578"
94+
});
8895
#if DEBUG
8996
if (!TestMockSupport.RunningMocked)
9097
{
@@ -214,6 +221,9 @@ protected static AzurePSDataCollectionProfile GetDataCollectionProfile()
214221
/// <returns>true if allowed</returns>
215222
public static bool IsDataCollectionAllowed()
216223
{
224+
//TODO: CLU - remove before final release
225+
return true;
226+
217227
if (_dataCollectionProfile != null &&
218228
_dataCollectionProfile.EnableAzureDataCollection.HasValue &&
219229
_dataCollectionProfile.EnableAzureDataCollection.Value)
@@ -299,7 +309,7 @@ protected override void BeginProcessing()
299309
ProductInfoHeaderValue userAgentValue = new ProductInfoHeaderValue(
300310
ModuleName, string.Format("v{0}", ModuleVersion));
301311
ClientFactory.UserAgents.Add(userAgentValue);
302-
ClientFactory.AddHandler(new CmdletInfoHandler(this.CommandRuntime.ToString(), this.ParameterSetName));
312+
ClientFactory.AddHandler(new CmdletInfoHandler(this.CommandRuntime.ToString(), this.ParameterSetName, this._clientRequestId));
303313
ServiceClientTracing.AddTracingInterceptor(_adalListener);
304314
ServiceClientTracing.IsEnabled = true;
305315
base.BeginProcessing();
@@ -347,7 +357,7 @@ protected bool IsVerbose()
347357
{
348358
QosEvent.Exception = errorRecord.Exception;
349359
QosEvent.IsSuccess = false;
350-
LogQosEvent(true);
360+
LogQosEvent();
351361
}
352362

353363
base.WriteError(errorRecord);
@@ -500,7 +510,7 @@ private void RecordDebugMessages()
500510
/// <summary>
501511
/// Invoke this method when the cmdlet is completed or terminated.
502512
/// </summary>
503-
protected void LogQosEvent(bool waitForMetricSending = false)
513+
protected void LogQosEvent()
504514
{
505515
if (QosEvent == null)
506516
{
@@ -524,7 +534,7 @@ protected void LogQosEvent(bool waitForMetricSending = false)
524534
try
525535
{
526536
MetricHelper.LogQoSEvent(QosEvent, IsUsageMetricEnabled, IsErrorMetricEnabled);
527-
MetricHelper.FlushMetric(waitForMetricSending);
537+
MetricHelper.FlushMetric();
528538
WriteDebug("Finish sending metric.");
529539
}
530540
catch (Exception e)

src/CLU/Commands.Common/AzurePowerShell.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class AzurePowerShell
4545
public const string DataStoreVariable = "_azpsh_data_store";
4646

4747
public static ProductInfoHeaderValue UserAgentValue = new ProductInfoHeaderValue(
48-
"AzurePowershell",
48+
"CLU",
4949
string.Format("v{0}", AzurePowerShell.AssemblyVersion));
5050

5151
public static String ProfileDirectory = Directory.GetCurrentDirectory();

0 commit comments

Comments
 (0)