Skip to content

Commit

Permalink
Adding support for maintenance configuration for SQL DB (#13926)
Browse files Browse the repository at this point in the history
* Adding support for maintenance configuration for SQL DB

* Update Changelog

* Remove completer

* Update ChangeLog.md

Move the new item to the top of upcoming release to avoid merge issue when release branch merge back.

Co-authored-by: Jin Lei <[email protected]>
  • Loading branch information
Roman Khotsyn and msJinLei authored Jan 14, 2021
1 parent c86c51c commit 1362838
Show file tree
Hide file tree
Showing 25 changed files with 16,426 additions and 25 deletions.
34 changes: 34 additions & 0 deletions src/Sql/Sql.Test/ScenarioTests/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1112,3 +1112,37 @@ function DelegateSubnetToSQLMIAndGetVnet ($vnetName, $subnetName, $resourceGroup

return $vnet
}

<#
.SYNOPSIS
Generates default public maintenance configuration id for specified location
#>
function Get-DefaultPublicMaintenanceConfigurationId($location)
{
$subscriptionId = (Get-AzContext).Subscription.Id

return "/subscriptions/${subscriptionId}/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_Default";
}

<#
.SYNOPSIS
Generates public maintenance configuration id for specified location and schedule name
#>
function Get-PublicMaintenanceConfigurationName($location, $scheduleName)
{
$shortLocation = $location -replace '\s',''

return "SQL_${shortLocation}_${scheduleName}";
}

<#
.SYNOPSIS
Generates public maintenance configuration id for specified location and schedule name
#>
function Get-PublicMaintenanceConfigurationId($location, $scheduleName)
{
$subscriptionId = (Get-AzContext).Subscription.Id
$configName = Get-PublicMaintenanceConfigurationName $location $scheduleName

return "/subscriptions/${subscriptionId}/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/${configName}";
}
22 changes: 22 additions & 0 deletions src/Sql/Sql.Test/ScenarioTests/DatabaseCrudTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ public void TestDatabaseCreateWithZoneRedundancy()
RunPowerShellTest("Test-CreateDatabaseWithZoneRedundancy");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestDatabaseCreateWithMaintenanceConfigurationId()
{
RunPowerShellTest("Test-CreateDatabaseWithMaintenanceConfigurationId");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestDatabaseUpdate()
Expand Down Expand Up @@ -113,6 +120,14 @@ public void TestDatabaseUpdateWithZoneRedundancyNotSpecified()
RunPowerShellTest("Test-UpdateDatabaseWithZoneRedundantNotSpecified");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestDatabaseUpdateWithMaintenanceConfigurationId()
{
RunPowerShellTest("Test-UpdateDatabaseWithMaintenanceConfigurationId");
}


[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestUpdateServerlessDatabase()
Expand Down Expand Up @@ -141,6 +156,13 @@ public void TestDatabaseGetWithZoneRedundancy()
RunPowerShellTest("Test-GetDatabaseWithZoneRedundancy");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestDatabaseGetWithMaintenanceConfigurationId()
{
RunPowerShellTest("Test-GetDatabaseWithMaintenanceConfigurationId");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestDatabaseRemove()
Expand Down
121 changes: 121 additions & 0 deletions src/Sql/Sql.Test/ScenarioTests/DatabaseCrudTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,50 @@ function Test-CreateDatabaseWithZoneRedundancy
}
}

<#
.SYNOPSIS
Tests creating a database with maintenance.
#>
function Test-CreateDatabaseWithMaintenanceConfigurationId
{
# Setup
$location = Get-Location "Microsoft.Sql" "operations" "East US 2 EUAP"
$rg = Create-ResourceGroupForTest $location

try
{
$server = Create-ServerForTest $rg $location

# Create database with default maintenance
$databaseName = Get-DatabaseName
$mId = Get-DefaultPublicMaintenanceConfigurationId $location
$serverResourceId = "/subscriptions/${subscriptionId}/resourceGroups/${rgname}/providers/Microsoft.Sql/servers/${serverName}"
$job = New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName `
-DatabaseName $databaseName -Edition Premium -MaintenanceConfigurationId $mId -AsJob -Force
$job | Wait-Job
$db = $job.Output

Assert-AreEqual $db.DatabaseName $databaseName
Assert-NotNull $db.Edition
Assert-NotNull $db.MaintenanceConfigurationId
Assert-AreEqual $mId.ToLower() $db.MaintenanceConfigurationId.ToLower()

# Create database with non-default maintenance
$databaseName = Get-DatabaseName
$mId = Get-PublicMaintenanceConfigurationId $location "DB_1"
$db = New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName `
-DatabaseName $databaseName -Edition Premium -MaintenanceConfigurationId $mId -Force
Assert-AreEqual $db.DatabaseName $databaseName
Assert-NotNull $db.Edition
Assert-NotNull $db.MaintenanceConfigurationId
Assert-AreEqual $mId.ToLower() $db.MaintenanceConfigurationId.ToLower()
}
finally
{
Remove-ResourceGroupForTest $rg
}
}

<#
.SYNOPSIS
Tests creating a database with Backup Storage Redundancy
Expand Down Expand Up @@ -579,6 +623,44 @@ function Test-UpdateDatabaseWithZoneRedundant ()
}
}

<#
.SYNOPSIS
Tests updating a database with maintenance
#>
function Test-UpdateDatabaseWithMaintenanceConfigurationId
{
# Setup
$location = Get-Location "Microsoft.Sql" "operations" "East US 2 EUAP"
$rg = Create-ResourceGroupForTest $location

try
{
$server = Create-ServerForTest $rg $location

# Create database without specifying maintenance
$defaultMId = Get-DefaultPublicMaintenanceConfigurationId $location
$databaseName = Get-DatabaseName
$db1 = New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName `
-Edition Premium -Force
Assert-AreEqual $db1.DatabaseName $databaseName
Assert-NotNull $db1.MaintenanceConfigurationId
Assert-AreEqual $defaultMId.ToLower() $db1.MaintenanceConfigurationId.ToLower()

# Alter database maintenance
$mId = Get-PublicMaintenanceConfigurationId $location "DB_1"
$sdb1 = Set-AzSqlDatabase -ResourceGroupName $db1.ResourceGroupName -ServerName $db1.ServerName -DatabaseName $db1.DatabaseName `
-MaintenanceConfigurationId $mId

Assert-AreEqual $sdb1.DatabaseName $databaseName
Assert-NotNull $sdb1.MaintenanceConfigurationId
Assert-AreEqual $mId.ToLower() $sdb1.MaintenanceConfigurationId.ToLower()
}
finally
{
Remove-ResourceGroupForTest $rg
}
}

<#
.SYNOPSIS
Tests updating a vcore database
Expand Down Expand Up @@ -849,6 +931,45 @@ function Test-GetDatabaseWithZoneRedundancy
}
}

<#
.SYNOPSIS
Tests getting a database with maintenance
#>
function Test-GetDatabaseWithMaintenanceConfigurationId
{
# Setup
$location = Get-Location "Microsoft.Sql" "operations" "East US 2 EUAP"
$rg = Create-ResourceGroupForTest $location
try
{
$server = Create-ServerForTest $rg $location

# Create database without specifying maintenance
$defaultMId = Get-DefaultPublicMaintenanceConfigurationId $location
$databaseName = Get-DatabaseName
$db1 = New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName `
-Edition Premium -Force

$gdb1 = Get-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupname -ServerName $server.ServerName -DatabaseName $db1.DatabaseName
Assert-AreEqual $gdb1.DatabaseName $db1.DatabaseName
Assert-AreEqual $defaultMId.ToLower() $gdb1.MaintenanceConfigurationId.ToLower()

# Create database with maintenance (try using name instead of full id)
$databaseName = Get-DatabaseName
$mName = Get-PublicMaintenanceConfigurationName $location "DB_1"
$mId = Get-PublicMaintenanceConfigurationId $location "DB_1"
$db2 = New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName `
-DatabaseName $databaseName -Edition Premium -MaintenanceConfigurationId $mName

$gdb2 = Get-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupname -ServerName $server.ServerName -DatabaseName $db2.DatabaseName
Assert-AreEqual $gdb2.DatabaseName $db2.DatabaseName
Assert-AreEqual $mId.ToLower() $gdb2.MaintenanceConfigurationId.ToLower()
}
finally
{
Remove-ResourceGroupForTest $rg
}
}

<#
.SYNOPSIS
Expand Down
21 changes: 21 additions & 0 deletions src/Sql/Sql.Test/ScenarioTests/ElasticPoolCrudTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public void TestElasticPoolCreateWithZoneRedundancy()
RunPowerShellTest("Test-CreateElasticPoolWithZoneRedundancy");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestElasticPoolCreateWithMaintenanceConfigurationId()
{
RunPowerShellTest("Test-CreateElasticPoolWithMaintenanceConfigurationId");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestElasticPoolUpdate()
Expand Down Expand Up @@ -87,6 +94,13 @@ public void TestElasticPoolUpdateWithZoneRedundancy()
RunPowerShellTest("Test-UpdateElasticPoolWithZoneRedundancy");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestElasticPoolUpdateWithMaintenanceConfigurationId()
{
RunPowerShellTest("Test-UpdateElasticPoolWithMaintenanceConfigurationId");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestElasticPoolGet()
Expand All @@ -101,6 +115,13 @@ public void TestElasticPoolGetWithZoneRedundancy()
RunPowerShellTest("Test-GetElasticPoolWithZoneRedundancy");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestElasticPoolGetWithMaintenanceConfigurationId()
{
RunPowerShellTest("Test-GetElasticPoolWithMaintenanceConfigurationId");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestElasticPoolRemove()
Expand Down
Loading

0 comments on commit 1362838

Please sign in to comment.