Skip to content

Commit 8f54a4b

Browse files
authored
Merge pull request Azure#4788 from spaoliello/preview
Don't NullRef during Get-AzureDeployment when the cloud service has extended configuration
2 parents aa14b80 + f9a7cf5 commit 8f54a4b

File tree

8 files changed

+2335
-4
lines changed

8 files changed

+2335
-4
lines changed

src/ServiceManagement/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@
224224
<None Include="Resources\DiagnosticsExtension\Files\diagnostics.wadcfgx">
225225
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
226226
</None>
227+
<None Include="Resources\ServiceManagement\Files\dSMSTest.cscfg">
228+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
229+
</None>
230+
<None Include="Resources\ServiceManagement\Files\dSMSTest.cspkg">
231+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
232+
</None>
227233
<None Include="Resources\SqlIaaSExtension\SqlIaaSExtensionTests.ps1">
228234
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
229235
</None>
@@ -302,6 +308,9 @@
302308
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\RunAzurePlatformVMImageNegativeTest.json">
303309
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
304310
</None>
311+
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\RunDSMSHostedServiceTest.json">
312+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
313+
</None>
305314
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\RunEnableAndDisableDataCollectionTests.json">
306315
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
307316
</None>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
**********************************************************************************************
4+
5+
This file was generated by a tool from the project file: ServiceConfiguration.Cloud.cscfg
6+
7+
Changes to this file may cause incorrect behavior and will be lost if the file is regenerated.
8+
9+
**********************************************************************************************
10+
-->
11+
<ServiceConfiguration serviceName="AzureCloudService1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="5" osVersion="*" schemaVersion="2015-04.2.6">
12+
<Role name="WorkerRole1">
13+
<Instances count="1" />
14+
<ConfigurationSettings>
15+
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
16+
<Setting name="DummySetting" value="Foo" />
17+
</ConfigurationSettings>
18+
<Certificates>
19+
<Certificate name="ThumbprintCert" thumbprint="{{PLACEHOLDER}}" thumbprintAlgorithm="sha1" />
20+
<Certificate name="dSMSCert" sourceLocation="/genevacustomers/monitoring/prod/warmpath/test/auxweb/certificates/chained/portaldogfoodmdscert.pfx" />
21+
</Certificates>
22+
</Role>
23+
</ServiceConfiguration>

src/ServiceManagement/Common/Commands.ScenarioTest/Resources/ServiceManagement/ServiceManagementTests.ps1

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,73 @@ function Run-AutoGeneratedVirtualMachineCmdletTests
296296
}
297297
}
298298

299+
# Run dSMS Hosted Service test
300+
function Run-DSMSHostedServiceTest
301+
{
302+
# Setup
303+
$svcName = 'pstest' + (Get-CloudServiceName);
304+
$location = Get-DefaultLocation;
305+
306+
$storageName = 'pstest' + (getAssetName);
307+
New-AzureStorageAccount -StorageAccountName $storageName -Location $location;
308+
309+
# Associate the new storage account with the current subscription
310+
Set-CurrentStorageAccountName $storageName;
311+
312+
$testMode = Get-ComputeTestMode;
313+
if ($testMode.ToLower() -ne 'playback')
314+
{
315+
$cspkg = '.\Resources\ServiceManagement\Files\dSMSTest.cspkg';
316+
}
317+
else
318+
{
319+
$cspkg = "https://${storageName}.blob.azure.windows.net/blob/dSMSTest.cspkg";
320+
}
321+
$cscfg = "$TestOutputRoot\Resources\ServiceManagement\Files\dSMSTest.cscfg";
322+
$cscfgChanged = "$TestOutputRoot\Resources\ServiceManagement\Files\dSMSTest-changed.cscfg";
323+
324+
# Create a temporary self-signed cert
325+
$cert = New-SelfSignedCertificate -DnsName "example.local" -CertStoreLocation "Cert:\CurrentUser\My";
326+
$certPath = "Cert:\CurrentUser\My\$($cert.Thumbprint)"
327+
# Update the cscfg to use the new cert
328+
(Get-Content $cscfg) | ForEach-Object {$_ -replace "\{\{PLACEHOLDER\}\}", $cert.Thumbprint} | Set-Content $cscfgChanged;
329+
330+
try
331+
{
332+
# Create Hosted Service
333+
$result = New-AzureService -ServiceName $svcName -Location $location -Label $svcName -Description $svcName;
334+
335+
# Upload the certificate
336+
Add-AzureCertificate -ServiceName $svcName -CertToDeploy $cert;
337+
338+
# Deploy to staging
339+
$result = New-AzureDeployment -ServiceName $svcName -Package $cspkg -Configuration $cscfgChanged -Label $svcName -Slot Staging;
340+
341+
# Get Deployment
342+
$deploy = Get-AzureDeployment -ServiceName $svcName -Slot Staging;
343+
344+
# Make a change
345+
$newConfig = $deploy.Configuration -replace 'Setting name="DummySetting" value="Foo"', 'Setting name="DummySetting" value="Bar"';
346+
$newConfig | Set-Content $cscfgChanged;
347+
348+
# Update configuration
349+
$result = Set-AzureDeployment -Config -ServiceName $svcName -Configuration $cscfgChanged -Slot Staging;
350+
}
351+
finally
352+
{
353+
# Cleanup
354+
Cleanup-CloudService $svcName;
355+
Cleanup-Storage $storageName;
356+
if (Test-Path $cscfgChanged)
357+
{
358+
Remove-Item $cscfgChanged;
359+
}
360+
if (Test-Path $certPath)
361+
{
362+
Remove-Item $certPath
363+
}
364+
}
365+
}
299366

300367
# Run New-AzureComputeArgumentList Cmdlet Tests Using Method Names
301368
function Run-NewAzureComputeArgumentListTests

src/ServiceManagement/Common/Commands.ScenarioTest/ServiceManagement/ScenarioTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ public void RunAutoGeneratedVirtualMachineCmdletTests()
7979
this.RunPowerShellTest("Run-AutoGeneratedVirtualMachineCmdletTests");
8080
}
8181

82+
[Fact]
83+
[Trait(Category.Service, Category.ServiceManagement)]
84+
[Trait(Category.AcceptanceType, Category.CheckIn)]
85+
[Trait(Category.AcceptanceType, Category.BVT)]
86+
public void RunDSMSHostedServiceTest()
87+
{
88+
this.RunPowerShellTest("Run-DSMSHostedServiceTest");
89+
}
90+
8291
[Fact]
8392
[Trait(Category.Service, Category.ServiceManagement)]
8493
[Trait(Category.AcceptanceType, Category.CheckIn)]

src/ServiceManagement/Common/Commands.ScenarioTest/SessionRecords/Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests/RunDSMSHostedServiceTest.json

Lines changed: 2210 additions & 0 deletions
Large diffs are not rendered by default.

src/ServiceManagement/Compute/Commands.ServiceManagement/Model/CertificateConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ public class CertificateConfiguration
1919
public string Thumbprint { get; set; }
2020

2121
public string ThumbprintAlgorithm { get; set; }
22+
23+
public string SourceLocation { get; set; }
2224
}
2325
}

src/ServiceManagement/Compute/Commands.ServiceManagement/Model/RoleConfiguration.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public RoleConfiguration(XElement data)
4545
{
4646
var certificate = new CertificateConfiguration
4747
{
48-
Thumbprint = setting.Attribute("thumbprint").Value,
49-
ThumbprintAlgorithm = setting.Attribute("thumbprintAlgorithm").Value
48+
Thumbprint = setting.Attribute("thumbprint") == null ? null : setting.Attribute("thumbprint").Value,
49+
ThumbprintAlgorithm = setting.Attribute("thumbprintAlgorithm") == null ? null : setting.Attribute("thumbprintAlgorithm").Value,
50+
SourceLocation = setting.Attribute("sourceLocation") == null ? null : setting.Attribute("sourceLocation").Value,
5051
};
5152

5253
this.Certificates.Add(setting.Attribute("name").Value, certificate);
@@ -104,8 +105,18 @@ internal XElement Serialize()
104105
{
105106
XElement certificateElement = new XElement(this.ns + "Certificate");
106107
certificateElement.SetAttributeValue("name", certificate.Key);
107-
certificateElement.SetAttributeValue("thumbprint", certificate.Value.Thumbprint);
108-
certificateElement.SetAttributeValue("thumbprintAlgorithm", certificate.Value.ThumbprintAlgorithm);
108+
if (certificate.Value.Thumbprint != null)
109+
{
110+
certificateElement.SetAttributeValue("thumbprint", certificate.Value.Thumbprint);
111+
}
112+
if (certificate.Value.ThumbprintAlgorithm != null)
113+
{
114+
certificateElement.SetAttributeValue("thumbprintAlgorithm", certificate.Value.ThumbprintAlgorithm);
115+
}
116+
if (certificate.Value.SourceLocation != null)
117+
{
118+
certificateElement.SetAttributeValue("sourceLocation", certificate.Value.SourceLocation);
119+
}
109120
certificatesElement.Add(certificateElement);
110121
}
111122

0 commit comments

Comments
 (0)