Skip to content

Commit bdb7a53

Browse files
authored
Merge pull request #2479 from tlao33/dev
Adding AKV support to sqlvm powershell with tests and help files added
2 parents ab80a66 + 0f04f4c commit bdb7a53

16 files changed

+6463
-3854
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/Commands.Compute.Test.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,11 @@
333333
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DscExtensionTests\TestGetAzureRmVMDscExtension.json">
334334
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
335335
</None>
336+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.SqlIaaSExtensionTests\TestSqlIaaSAKVExtension.json">
337+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
338+
</None>
336339
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.SqlIaaSExtensionTests\TestSqlIaaSExtension.json">
337-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
340+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
338341
</None>
339342
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineBootDiagnosticsTests\TestLinuxVirtualMachineBootDiagnostics.json">
340343
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

src/ResourceManager/Compute/Commands.Compute.Test/Common/ComputeTestController.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ public ComputeTestController()
7676
helper = new EnvironmentSetupHelper();
7777
}
7878

79+
public void RunPsTest(ServiceManagemenet.Common.Models.XunitTracingInterceptor logger, params string[] scripts)
80+
{
81+
var callingClassType = TestUtilities.GetCallingClass(2);
82+
var mockName = TestUtilities.GetCurrentMethodName(2);
83+
84+
helper.TracingInterceptor = logger;
85+
RunPsTestWorkflow(
86+
() => scripts,
87+
// no custom initializer
88+
null,
89+
// no custom cleanup
90+
null,
91+
callingClassType,
92+
mockName);
93+
}
94+
7995
public void RunPsTest(params string[] scripts)
8096
{
8197
var callingClassType = TestUtilities.GetCallingClass(2);

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/SqlIaaSExtensionTests.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,26 @@ namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests
55
{
66
public class SqlIaaSExtensionTests
77
{
8+
ServiceManagemenet.Common.Models.XunitTracingInterceptor _logger;
89
public SqlIaaSExtensionTests(Xunit.Abstractions.ITestOutputHelper output)
910
{
10-
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
11+
_logger = new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output);
12+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
1113
}
1214

1315
[Fact]
1416
[Trait(Category.AcceptanceType, Category.CheckIn)]
1517
public void TestSqlIaaSExtension()
1618
{
17-
ComputeTestController.NewInstance.RunPsTest("Test-SetAzureRmVMSqlServerExtension");
19+
ComputeTestController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmVMSqlServerExtension");
1820
}
21+
22+
[Fact]
23+
[Trait(Category.AcceptanceType, Category.CheckIn)]
24+
public void TestSqlIaaSAKVExtension()
25+
{
26+
ComputeTestController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmVMSqlServerAKVExtension");
27+
}
28+
1929
}
2030
}

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/SqlIaaSExtensionTests.ps1

Lines changed: 157 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,121 @@
1010
8) Test with incorrect Name and crrect Version
1111
9) Test with incorrect Name and incorrect Version
1212
#>
13+
14+
function Test-SetAzureRmVMSqlServerAKVExtension
15+
{
16+
Set-StrictMode -Version latest; $ErrorActionPreference = 'Stop'
17+
18+
# Setup
19+
$rgname = Get-ComputeTestResourceName
20+
$loc = Get-ComputeVMLocation
21+
22+
try
23+
{
24+
# Common
25+
New-AzureRmResourceGroup -Name $rgname -Location $loc -Force;
26+
27+
# VM Profile & Hardware
28+
$vmsize = 'Standard_A2';
29+
$vmname = 'vm' + $rgname;
30+
$p = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize;
31+
Assert-AreEqual $p.HardwareProfile.VmSize $vmsize;
32+
33+
# NRP
34+
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
35+
$vnet = New-AzureRmVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
36+
$vnet = Get-AzureRmVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
37+
$subnetId = $vnet.Subnets[0].Id;
38+
$pubip = New-AzureRmPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
39+
$pubip = Get-AzureRmPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
40+
$pubipId = $pubip.Id;
41+
$nic = New-AzureRmNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
42+
$nic = Get-AzureRmNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
43+
$nicId = $nic.Id;
44+
45+
$p = Add-AzureRmVMNetworkInterface -VM $p -Id $nicId;
46+
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1;
47+
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].Id $nicId;
48+
49+
# Storage Account
50+
$stoname = 'sto' + $rgname;
51+
$stotype = 'Standard_GRS';
52+
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
53+
Retry-IfException { $global:stoaccount = Get-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname; }
54+
55+
$osDiskName = 'osDisk';
56+
$osDiskCaching = 'ReadWrite';
57+
$osDiskVhdUri = "https://$stoname.blob.core.windows.net/test/os.vhd";
58+
$dataDiskVhdUri1 = "https://$stoname.blob.core.windows.net/test/data1.vhd";
59+
60+
$p = Set-AzureRmVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption FromImage;
61+
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
62+
63+
# OS & Image
64+
$user = "localadmin";
65+
$password = 'Bull_dog1';
66+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
67+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
68+
$computerName = 'test';
69+
$vhdContainer = "https://$stoname.blob.core.windows.net/test";
70+
71+
$p = Set-AzureRmVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred -ProvisionVMAgent;
72+
$p = Set-AzureRmVMSourceImage -VM $p -PublisherName MicrosoftSQLServer -Offer SQL2014SP1-WS2012R2 -Skus Enterprise -Version "latest"
73+
74+
# Virtual Machine
75+
New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $p;
76+
77+
#Do actual changes and work here
78+
79+
$extensionName = "Microsoft.SqlServer.Management.SqlIaaSAgent";
80+
81+
# 1) Installs the SqlIaaS extension by calling Set-AzureRmVMSqlServerExtension cmdlet on a VM.
82+
83+
$securepfxpwd = ConvertTo-SecureString –String "Amu6y/RzJcc7JBzdAdRVv6mk=" –AsPlainText –Force;
84+
$aps_akv = New-AzureVMSqlServerKeyVaultCredentialConfig -ResourceGroupName $rgname -Enable -CredentialName "CredentialTesting" -AzureKeyVaultUrl "https://Testkeyvault.vault.azure.net/" -ServicePrincipalName "0326921f-bf005595337c" -ServicePrincipalSecret $securepfxpwd;
85+
Set-AzureRmVMSqlServerExtension -KeyVaultCredentialSettings $aps_akv -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose;
86+
87+
# 2) Calls Get-AzureRmVMSqlServerExtension cmdlet to check the status of the extension installation.
88+
$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;
89+
90+
# 3) Verifies settings are correct given input
91+
92+
Assert-AreEqual $extension.KeyVaultCredentialSettings.CredentialName "CredentialTesting";
93+
94+
# 4) Update extension values
95+
96+
$aps_akv = New-AzureVMSqlServerKeyVaultCredentialConfig -ResourceGroupName $rgname -Enable -CredentialName "CredentialTest" -AzureKeyVaultUrl "https://Testkeyvault.vault.azure.net/" -ServicePrincipalName "0326921f-82af-4ab3-9d46-bf005595337c" -ServicePrincipalSecret $securepfxpwd;
97+
Set-AzureRmVMSqlServerExtension -KeyVaultCredentialSettings $aps_akv -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose;
98+
99+
# 5) Verify changes
100+
$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;
101+
102+
Assert-AreEqual $extension.KeyVaultCredentialSettings.CredentialName "CredentialTest"
103+
104+
# 6) Test with correct Name and Version
105+
106+
Set-AzureRmVMSqlServerExtension -KeyVaultCredentialSettings $aps_akv -ResourceGroupName $rgname -VMName $vmName -Name $extensionName -Version "1.2"
107+
108+
# 7) Test with correct Name and incorrect Version
109+
Set-AzureRmVMSqlServerExtension -KeyVaultCredentialSettings $aps_akv -ResourceGroupName $rgname -VMName $vmName -Name $extensionName -Version "1.*"
110+
}
111+
finally
112+
{
113+
# Cleanup
114+
if(Get-AzureRmResourceGroup -Name $rgname -Location $loc)
115+
{
116+
#Remove-AzureRmResourceGroup -Name $rgname -Force;
117+
}
118+
}
119+
}
120+
13121
function Test-SetAzureRmVMSqlServerExtension
14122
{
15-
Set-StrictMode -Version latest; $ErrorActionPreference = 'Stop'
123+
Set-StrictMode -Version latest; $ErrorActionPreference = 'Stop'
16124

17-
# Setup
125+
# Setup
18126
$rgname = Get-ComputeTestResourceName
19-
$loc = Get-ComputeVMLocation
127+
$loc = Get-ComputeVMLocation
20128

21129
try
22130
{
@@ -31,7 +139,7 @@ function Test-SetAzureRmVMSqlServerExtension
31139

32140
# NRP
33141
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
34-
$vnet = New-AzureRmVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -DnsServer "10.1.1.1" -Subnet $subnet;
142+
$vnet = New-AzureRmVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
35143
$vnet = Get-AzureRmVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
36144
$subnetId = $vnet.Subnets[0].Id;
37145
$pubip = New-AzureRmPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
@@ -57,9 +165,9 @@ function Test-SetAzureRmVMSqlServerExtension
57165
$dataDiskVhdUri1 = "https://$stoname.blob.core.windows.net/test/data1.vhd";
58166

59167
$p = Set-AzureRmVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption FromImage;
60-
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
168+
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
61169

62-
# OS & Image
170+
# OS & Image
63171
$user = "localadmin";
64172
$password = 'Bull_dog1';
65173
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
@@ -68,69 +176,68 @@ function Test-SetAzureRmVMSqlServerExtension
68176
$vhdContainer = "https://$stoname.blob.core.windows.net/test";
69177

70178
$p = Set-AzureRmVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred -ProvisionVMAgent;
71-
$p = Set-AzureRmVMSourceImage -VM $p -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version "latest"
179+
$p = Set-AzureRmVMSourceImage -VM $p -PublisherName MicrosoftSQLServer -Offer SQL2014SP1-WS2012R2 -Skus Enterprise -Version "latest"
72180

73181
# Virtual Machine
74182
New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $p;
75183

76-
#Do actual changes and work here
184+
#Do actual changes and work here
77185

78-
$extensionName = "Microsoft.SqlServer.Management.SqlIaaSAgent";
186+
$extensionName = "Microsoft.SqlServer.Management.SqlIaaSAgent";
79187

80-
# 1) Installs the SqlIaaS extension by calling Set-AzureRmVMSqlServerExtension cmdlet on a VM.
81-
$aps = New-AzureVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Thursday" -MaintenanceWindowStartingHour 20 -MaintenanceWindowDuration 120 -PatchCategory "Important"
82-
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose -Name $extensionName;
188+
# 1) Installs the SqlIaaS extension by calling Set-AzureRmVMSqlServerExtension cmdlet on a VM.
189+
$aps = New-AzureVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Thursday" -MaintenanceWindowStartingHour 20 -MaintenanceWindowDuration 120 -PatchCategory "Important"
190+
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose -Name $extensionName;
83191

84-
# 2) Calls Get-AzureRmVMSqlServerExtension cmdlet to check the status of the extension installation.
85-
$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;
192+
# 2) Calls Get-AzureRmVMSqlServerExtension cmdlet to check the status of the extension installation.
193+
$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;
86194

87-
# 3) Verifies settings are correct given input
88-
Assert-AreEqual $extension.AutoPatchingSettings.DayOfWeek "Thursday"
89-
Assert-AreEqual $extension.AutoPatchingSettings.MaintenanceWindowStartingHour 20
90-
Assert-AreEqual $extension.AutoPatchingSettings.MaintenanceWindowDuration 120
91-
Assert-AreEqual $extension.AutoPatchingSettings.PatchCategory "Important"
195+
# 3) Verifies settings are correct given input
196+
Assert-AreEqual $extension.AutoPatchingSettings.DayOfWeek "Thursday"
197+
Assert-AreEqual $extension.AutoPatchingSettings.MaintenanceWindowStartingHour 20
198+
Assert-AreEqual $extension.AutoPatchingSettings.MaintenanceWindowDuration 120
199+
Assert-AreEqual $extension.AutoPatchingSettings.PatchCategory "Important"
92200

93-
# 4) Update extension values
94-
$aps = New-AzureVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Monday" -MaintenanceWindowStartingHour 20 -MaintenanceWindowDuration 120 -PatchCategory "Important"
95-
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose -Name $extensionName;
201+
# 4) Update extension values
202+
$aps = New-AzureVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Monday" -MaintenanceWindowStartingHour 20 -MaintenanceWindowDuration 120 -PatchCategory "Important"
203+
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose -Name $extensionName;
96204

97-
# 5) Verify changes
98-
$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;
99-
Assert-AreEqual $extension.AutoPatchingSettings.DayOfWeek "Monday"
205+
# 5) Verify changes
206+
$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;
207+
Assert-AreEqual $extension.AutoPatchingSettings.DayOfWeek "Monday"
100208

101-
# 6) Test with correct Name and Version
102-
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -ResourceGroupName $rgname -VMName $vmName -Name $extensionName -Version "1.2"
209+
# 6) Test with correct Name and Version
210+
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -ResourceGroupName $rgname -VMName $vmName -Name $extensionName -Version "1.2"
103211

104-
# 7) Test with correct Name and incorrect Version
105-
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -ResourceGroupName $rgname -VMName $vmName -Name $extensionName -Version "1.*"
212+
# 7) Test with correct Name and incorrect Version
213+
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -ResourceGroupName $rgname -VMName $vmName -Name $extensionName -Version "1.*"
106214
}
107215
finally
108216
{
109-
# Cleanup
110-
if(Get-AzureRmResourceGroup -Name $rgname -Location $loc)
111-
{
112-
#Remove-AzureRmResourceGroup -Name $rgname -Force;
113-
}
217+
# Cleanup
218+
if(Get-AzureRmResourceGroup -Name $rgname -Location $loc)
219+
{
220+
#Remove-AzureRmResourceGroup -Name $rgname -Force;
221+
}
114222
}
115223
}
116224

117225
#helper methods for ARM
118226
function Get-DefaultResourceGroupLocation
119227
{
120-
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
121-
{
122-
$namespace = "Microsoft.Resources"
123-
$type = "resourceGroups"
124-
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
125-
126-
if ($location -eq $null)
127-
{
128-
return "West US"
129-
} else
130-
{
131-
return $location.Locations[0]
132-
}
133-
}
134-
135-
return "West US"
228+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
229+
{
230+
$namespace = "Microsoft.Resources"
231+
$type = "resourceGroups"
232+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
233+
234+
if ($location -eq $null)
235+
{
236+
return "West US"
237+
} else
238+
{
239+
return $location.Locations[0]
240+
}
241+
}
242+
return "West US"
136243
}

0 commit comments

Comments
 (0)