Skip to content

Commit acda8fa

Browse files
authored
Merge pull request #3327 from anilyela/dev-ClassicCmdletChanges
New parameters in New-AzureVMSqlServerAutoBackupConfig cmdlet to support Auto Backup for SQL Server 2016 VMs (Classic cmdlet changes)
2 parents 4dd63ab + 70106ae commit acda8fa

19 files changed

+70139
-118057
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@
226226
<None Include="Resources\DiagnosticsExtension\Files\diagnostics.wadcfgx">
227227
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
228228
</None>
229+
<None Include="Resources\SqlIaaSExtension\SqlIaaSExtensionTests.ps1">
230+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
231+
</None>
229232
<None Include="Resources\DscExtension\DscExtensionTests.ps1">
230233
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
231234
</None>
@@ -361,6 +364,9 @@
361364
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\TestNewAzureVMWithBYOL.json">
362365
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
363366
</None>
367+
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.SqlIaaSExtensionTests\TestGetAzureVMSqlIaaSExtension.json">
368+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
369+
</None>
364370
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.TrafficManagerTests\TestAddAzureTrafficManagerEndpoint.json">
365371
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
366372
</None>
@@ -432,6 +438,7 @@
432438
<Compile Include="CredentialTests\CredentialTestHelper.cs" />
433439
<Compile Include="ChefExtension\ChefExtensionTests.cs" />
434440
<Compile Include="DiagnosticsExtension\DiagnosticsExtensionTests.cs" />
441+
<Compile Include="SqlIaaSExtensionTests\SqlIaaSExtensionTests.cs" />
435442
<Compile Include="DscExtension\DscExtensionTests.cs" />
436443
<Compile Include="MediaServicesTests\MediaServicesTests.cs" />
437444
<Compile Include="Properties\Resources.Designer.cs">
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
$PLACEHOLDER = "PLACEHOLDER1@";
2+
3+
<#
4+
.SYNOPSIS
5+
End to end Sql IaaS extension test that tests Get-AzureVMSqlServerExtension cmdlet. It does the following:
6+
1) Creates cloud service and a VM with SQL 2016 Image.
7+
2) Installs the extension by calling Set-AzureVMSqlServerExtension cmdlet on the VM.
8+
3) Calls Get-AzureVMSqlServerExtension cmdlet to check the status of the extension installation.
9+
4) Sets Auto Patching and Auto Backup settings by calling Set-AzureVMDscExtension cmdlet on the VM.
10+
5) Calls Get-AzureVMSqlServerExtension cmdlet to get extension details and verify it with values updated with Set-AzureVMSqlServerExtension.
11+
#>
12+
function Test-GetAzureVMSqlIaaSExtension
13+
{
14+
Set-StrictMode -Version latest; $ErrorActionPreference = 'Stop'
15+
16+
# Setup
17+
$location = Get-DefaultLocation
18+
$storageName = getAssetName
19+
20+
try
21+
{
22+
New-AzureStorageAccount -StorageAccountName $storageName -Location $location
23+
Set-CurrentStorageAccountName $storageName
24+
25+
$vmName = "pshelltestvm1"
26+
$svcName = Get-CloudServiceName
27+
28+
# Get latest SQL 2016 VM Image
29+
$family = "SQL Server 2016 RTM Enterprise on Windows Server 2012 R2"
30+
$image = Get-AzureVMImage | where { $_.ImageFamily -eq $family } | sort PublishedDate -Descending | select -ExpandProperty ImageName -First 1
31+
32+
# Create new cloud service
33+
New-AzureService -ServiceName $svcName -Location $location
34+
35+
# Create the VM config
36+
$vmsize = "A5"
37+
$vm1 = New-AzureVMConfig -Name $vmname -InstanceSize $vmsize -ImageName $image
38+
39+
# Create the SQL VM
40+
$user = "localadmin";
41+
$password = $PLACEHOLDER;
42+
$vm1 | Add-AzureProvisioningConfig -Windows -AdminUsername $user -Password $password
43+
New-AzureVM –ServiceName $svcname -VMs $vm1
44+
45+
#Do actual changes and work here
46+
47+
# 1) Installs the SqlIaaS extension by calling Set-AzureVMSqlServerExtension cmdlet on a VM.
48+
$vm = Get-AzureVM -ServiceName $svcName -Name $vmName
49+
$vm | Set-AzureVMSqlServerExtension | Update-AzureVM
50+
51+
# 2) Calls Get-AzureRmVMSqlServerExtension cmdlet to verify the status of the extension installation.
52+
$extension = $vm | Get-AzureVMSqlServerExtension
53+
Assert-NotNull $extension
54+
Assert-NotNull $extension.ExtensionName
55+
Assert-NotNull $extension.Publisher
56+
Assert-NotNull $extension.Version
57+
58+
# Repeat until the extension is ready.
59+
[TimeSpan] $timeout = [TimeSpan]::FromMinutes(30)
60+
$maxTime = [datetime]::Now + $timeout
61+
62+
while($true)
63+
{
64+
if($extension -ne $null -and $extension.ExtensionStatus -ne $null)
65+
{
66+
if(($extension.ExtensionStatus -eq "Ready"))
67+
{
68+
break;
69+
}
70+
}
71+
72+
if([datetime]::Now -gt $maxTime)
73+
{
74+
Throw "The Sql Server Extension did not report any status within the given timeout from VM [$vmName]"
75+
}
76+
77+
if ($env:AZURE_TEST_MODE -eq "Record"){
78+
sleep -Seconds 15
79+
}
80+
81+
$extension = $vm | Get-AzureVMSqlServerExtension
82+
}
83+
84+
# 3) Update Auto Patching and Auto Backup settings
85+
$storageContext = (Get-AzureStorageAccount -StorageAccountName $storageName).Context
86+
$aps = New-AzureVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Thursday" -MaintenanceWindowStartingHour 20 `
87+
-MaintenanceWindowDuration 120 -PatchCategory "Important"
88+
$abs = New-AzureVMSqlServerAutoBackupConfig -Enable -RetentionPeriodInDays 20 -StorageContext $storageContext -BackupScheduleType Manual `
89+
-BackupSystemDbs -FullBackupStartHour 10 -FullBackupWindowInHours 5 -FullBackupFrequency Daily -LogBackupFrequencyInMinutes 30
90+
Get-AzureVM -ServiceName $svcName -Name $vmName | Set-AzureVMSqlServerExtension -AutoPatchingSettings $aps -AutoBackupSettings $abs | Update-AzureVM
91+
92+
# Wait few minutes for the settings to be applied and to cover the lag for guest agent to pick up updated status.
93+
if ($env:AZURE_TEST_MODE -eq "Record"){
94+
sleep -Seconds 300
95+
}
96+
97+
# 4) Get the extension and verify the values.
98+
$extension = Get-AzureVM -ServiceName $svcName -Name $vmName | Get-AzureVMSqlServerExtension
99+
100+
Assert-AreEqual $extension.AutoPatchingSettings.DayOfWeek "Thursday"
101+
Assert-AreEqual $extension.AutoPatchingSettings.MaintenanceWindowStartingHour 20
102+
Assert-AreEqual $extension.AutoPatchingSettings.MaintenanceWindowDuration 120
103+
Assert-AreEqual $extension.AutoPatchingSettings.PatchCategory "Important"
104+
105+
Assert-AreEqual $extension.AutoBackupSettings.RetentionPeriod 20
106+
Assert-AreEqual $extension.AutoBackupSettings.Enable $true
107+
Assert-AreEqual $extension.AutoBackupSettings.BackupScheduleType "Manual"
108+
Assert-AreEqual $extension.AutoBackupSettings.FullBackupFrequency "Daily"
109+
Assert-AreEqual $extension.AutoBackupSettings.BackupSystemDbs $true
110+
Assert-AreEqual $extension.AutoBackupSettings.FullBackupStartTime 10
111+
Assert-AreEqual $extension.AutoBackupSettings.FullBackupWindowHours 5
112+
Assert-AreEqual $extension.AutoBackupSettings.LogBackupFrequency 30
113+
114+
# Uninstall Extension
115+
$vm = Get-AzureVM -ServiceName $svcName -Name $vmName | Set-AzureVMSqlServerExtension -Uninstall | Update-AzureVM
116+
}
117+
finally
118+
{
119+
# Cleanup
120+
Remove-AzureStorageAccount -StorageAccountName $storageName -ErrorAction SilentlyContinue
121+
Cleanup-CloudService $svcName
122+
}
123+
}

src/ServiceManagement/Common/Commands.ScenarioTest/SessionRecords/Microsoft.WindowsAzure.Commands.ScenarioTest.SqlIaaSExtensionTests/TestGetAzureVMSqlIaaSExtension.json

Lines changed: 15744 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Collections.Generic;
16+
using System.IO;
17+
using System.Linq;
18+
using Microsoft.Azure.Test;
19+
using Microsoft.WindowsAzure.Management;
20+
using Microsoft.WindowsAzure.Management.Compute;
21+
using Microsoft.WindowsAzure.Management.Network;
22+
using Microsoft.WindowsAzure.Management.Storage;
23+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
24+
using Xunit;
25+
using Microsoft.Azure.Commands.Common.Authentication;
26+
using Xunit.Abstractions;
27+
using Microsoft.WindowsAzure.ServiceManagemenet.Common.Models;
28+
29+
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
30+
{
31+
public class SqlIaaSExtensionTests
32+
{
33+
private EnvironmentSetupHelper helper = new EnvironmentSetupHelper();
34+
35+
public SqlIaaSExtensionTests(ITestOutputHelper output)
36+
{
37+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
38+
}
39+
40+
[Fact]
41+
[Trait(Category.AcceptanceType, Category.CheckIn)]
42+
[Trait(Category.AcceptanceType, Category.BVT)]
43+
public void TestGetAzureVMSqlIaaSExtension()
44+
{
45+
this.RunPowerShellTest("Test-GetAzureVMSqlIaaSExtension");
46+
}
47+
48+
protected void SetupManagementClients()
49+
{
50+
var rdfeTestFactory = new RDFETestEnvironmentFactory();
51+
var managementClient = TestBase.GetServiceClient<ManagementClient>(rdfeTestFactory);
52+
var computeClient = TestBase.GetServiceClient<ComputeManagementClient>(rdfeTestFactory);
53+
var networkClient = TestBase.GetServiceClient<NetworkManagementClient>(rdfeTestFactory);
54+
var storageClient = TestBase.GetServiceClient<StorageManagementClient>(rdfeTestFactory);
55+
56+
helper.SetupSomeOfManagementClients(
57+
managementClient,
58+
computeClient,
59+
networkClient,
60+
storageClient);
61+
}
62+
63+
protected void RunPowerShellTest(params string[] scripts)
64+
{
65+
using (UndoContext context = UndoContext.Current)
66+
{
67+
context.Start(TestUtilities.GetCallingClass(1), TestUtilities.GetCurrentMethodName(2));
68+
69+
SetupManagementClients();
70+
71+
var modules = new List<string>
72+
{
73+
"Resources\\SqlIaaSExtension\\SqlIaaSExtensionTests.ps1",
74+
"Resources\\ServiceManagement\\Common.ps1",
75+
".\\Assert.ps1",
76+
@"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Compute\AzurePreview.psd1"
77+
};
78+
79+
helper.SetupEnvironment(AzureModule.AzureServiceManagement);
80+
helper.SetupModules(AzureModule.AzureServiceManagement, modules.ToArray());
81+
82+
83+
var scriptEnvPath = new List<string>();
84+
scriptEnvPath.Add(
85+
string.Format(
86+
"$env:PSModulePath=\"{0};$env:PSModulePath\"",
87+
@"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Compute".AsAbsoluteLocation()));
88+
89+
helper.RunPowerShellTest(scriptEnvPath, scripts);
90+
}
91+
}
92+
}
93+
}

src/ServiceManagement/Compute/Commands.ServiceManagement/Commands.ServiceManagement.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@
177177
<Compile Include="Common\ConstantStringTypes.cs" />
178178
<Compile Include="Common\DiagnosticsHelper.cs" />
179179
<Compile Include="IaaS\Extensions\Diagnostics\WADPrivateConfigSchema.cs" />
180+
<Compile Include="IaaS\Extensions\SqlServer\AzureVMSqlServerConfiguration.cs" />
181+
<Compile Include="IaaS\Extensions\SqlServer\AzureVMSqlServerKeyVaultCredential.cs" />
180182
<Compile Include="IaaS\Extensions\SqlServer\AzureVMSqlServerPublicAutoBackupSettings.cs" />
181183
<Compile Include="IaaS\Extensions\SqlServer\AzureVMSqlServerPublicKeyVaultCredentialSettings.cs" />
182184
<Compile Include="IaaS\Extensions\SqlServer\AzureVMSqlServerPrivateKeyVaultCredentialSettings.cs" />

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoBackupSettings.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,35 @@ public class AutoBackupSettings
5050
/// Password required for certification when encryption is enabled
5151
/// </summary>
5252
public string Password { get; set; }
53+
54+
/// <summary>
55+
/// Whether to include system databases in Backup
56+
/// </summary>
57+
public bool? BackupSystemDbs { get; set; }
58+
59+
/// <summary>
60+
/// Gets the Backup Schedule Type
61+
/// </summary>
62+
public string BackupScheduleType { get; set; }
63+
64+
/// <summary>
65+
/// Gets the Full Backup Frequency
66+
/// </summary>
67+
public string FullBackupFrequency { get; set; }
68+
69+
/// <summary>
70+
/// Gets the Full Backup Start Time
71+
/// </summary>
72+
public int? FullBackupStartTime { get; set; }
73+
74+
/// <summary>
75+
/// Gets the Full Backup Window Hours
76+
/// </summary>
77+
public int? FullBackupWindowHours { get; set; }
78+
79+
/// <summary>
80+
/// Gets the Log Backup Frequency
81+
/// </summary>
82+
public int? LogBackupFrequency { get; set; }
5383
}
5484
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Collections.Generic;
16+
17+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions
18+
{
19+
/// <summary>
20+
/// SQL Server Configuration object that is returned by extension as a substatus.
21+
/// </summary>
22+
public class AzureVMSqlServerConfiguration
23+
{
24+
/// <summary>
25+
/// Auto Patching report object
26+
/// </summary>
27+
public class AutoPatchingReport
28+
{
29+
public string Name { get; set; }
30+
public int Status { get; set; }
31+
public bool Enable { get; set; }
32+
public string DayOfWeek { get; set; }
33+
public int MaintenanceWindowStartingHour { get; set; }
34+
public int MaintenanceWindowDuration { get; set; }
35+
public string PatchCategory { get; set; }
36+
}
37+
38+
/// <summary>
39+
/// Auto Backup report object
40+
/// </summary>
41+
public class AutoBackupReport
42+
{
43+
public string Name { get; set; }
44+
public int Status { get; set; }
45+
public bool Enable { get; set; }
46+
public bool EnableEncryption { get; set; }
47+
public string StorageAccountUrl { get; set; }
48+
public int RetentionPeriod { get; set; }
49+
public string BackupScheduleType { get; set; }
50+
public bool? BackupSystemDbs { get; set; }
51+
public string FullBackupFrequency { get; set; }
52+
public int? FullBackupStartTime { get; set; }
53+
public int? FullBackupWindowHours { get; set; }
54+
public int? LogBackupFrequency { get; set; }
55+
}
56+
57+
/// <summary>
58+
/// Azure Key Vault report object
59+
/// </summary>
60+
public class AzureKeyVaultReport
61+
{
62+
public string Name { get; set; }
63+
public int Status { get; set; }
64+
public bool Enable { get; set; }
65+
public bool EnableEncryption { get; set; }
66+
public List<AzureVMSqlServerKeyVaultCredential> CredentialsList { get; set; }
67+
}
68+
69+
/// <summary>
70+
/// Auto telemetry report object
71+
/// </summary>
72+
public class AutoTelemetrySettingsReport
73+
{
74+
public string Name { get; set; }
75+
public int Status { get; set; }
76+
public string Location { get; set; }
77+
public string PerformanceCollectorStatus { get; set; }
78+
}
79+
80+
/// <summary>
81+
/// Auto patching settings
82+
/// </summary>
83+
public AutoPatchingReport AutoPatching { get; set; }
84+
85+
/// <summary>
86+
/// Auto-backup settings
87+
/// </summary>
88+
public AutoBackupReport AutoBackup { get; set; }
89+
90+
/// <summary>
91+
/// AkV settings
92+
/// </summary>
93+
public AzureKeyVaultReport AzureKeyVault { get; set; }
94+
95+
/// <summary>
96+
/// Auto-telemetry settings
97+
/// </summary>
98+
public AutoTelemetrySettingsReport AutoTelemetryReport { get; set; }
99+
}
100+
}

0 commit comments

Comments
 (0)