Skip to content

Commit

Permalink
Adding schedule fields to NewAzMaintenance Configuration cmdlet and n…
Browse files Browse the repository at this point in the history
…ew Public Configuration GET cmdlet (#12667)

* add new fields/new cmdlet to maintenance cmdlet

* pr comments

* Do not update version in changelog

because they are calculated

Co-authored-by: Sonia Taneja <[email protected]>
Co-authored-by: Yeming Liu <[email protected]>
  • Loading branch information
3 people authored Aug 18, 2020
1 parent 3e9ac7a commit 7324352
Show file tree
Hide file tree
Showing 15 changed files with 1,913 additions and 410 deletions.
2 changes: 1 addition & 1 deletion src/Maintenance/Maintenance.Test/Maintenance.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Maintenance" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Maintenance" Version="1.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ public void TestMaintenanceUpdate()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzMaintenanceUpdate");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestPublicMaintenanceConfiguration()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzMaintenancePublicConfiguration");
}
}
}
92 changes: 73 additions & 19 deletions src/Maintenance/Maintenance.Test/ScenarioTests/MaintenanceTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ function Test-AzMaintenanceConfiguration
$maintenanceConfigurationName = Get-RandomMaintenanceConfigurationName
$location = Get-ProviderLocation "Microsoft.Maintenance/MaintenanceConfigurations"
$maintenanceScope = "Host"

$resourceGroupName1 = Get-RandomResourceGroupName
$Visibility = "Custom"
$StartDateTime = "2020-09-01 12:30"
$Timezone = "Pacific Standard Time"
$RecurEvery = "Day"
$Duration = "05:00"
$ExpirationDateTime = "9999-12-31 23:59";

$resourceGroupName1 = "powershellrg"
$maintenanceConfigurationName1 = Get-RandomMaintenanceConfigurationName

try
Expand All @@ -46,34 +52,27 @@ function Test-AzMaintenanceConfiguration
New-AzResourceGroup -Name $resourceGroupName1 -Location $location
Write-Host "Created RG $location"

$maintenanceConfigurationCreated1 = New-AzMaintenanceConfiguration -ResourceGroupName $resourceGroupName1 -Name $maintenanceConfigurationName1 -MaintenanceScope $maintenanceScope -Location $location
$maintenanceConfigurationCreated1 = New-AzMaintenanceConfiguration -ResourceGroupName $resourceGroupName1 -Name $maintenanceConfigurationName1 -MaintenanceScope $maintenanceScope -Location $location -Visibility $Visibility -StartDateTime $StartDateTime -RecurEvery $RecurEvery -Timezone $Timezone
Write-Host "Created configuration $maintenanceConfigurationName1"
Write-Output $maintenanceConfigurationCreated1

Assert-AreEqual $maintenanceConfigurationCreated1.Name $maintenanceConfigurationName1
Assert-AreEqual $maintenanceConfigurationCreated1.Location $location
Assert-AreEqual $maintenanceConfigurationCreated1.MaintenanceScope $maintenanceScope
Assert-AreEqual $maintenanceConfigurationCreated1.Type "Microsoft.Maintenance/MaintenanceConfigurations"
Assert-AreEqual $maintenanceConfigurationCreated1.Visibility $Visibility
Assert-AreEqual $maintenanceConfigurationCreated1.StartDateTime $StartDateTime
Assert-AreEqual $maintenanceConfigurationCreated1.ExpirationDateTime $ExpirationDateTime
Assert-AreEqual $maintenanceConfigurationCreated1.Duration $Duration
Assert-AreEqual $maintenanceConfigurationCreated1.RecurEvery $RecurEvery
Assert-AreEqual $maintenanceConfigurationCreated1.Timezone $Timezone

$retrievedMaintenanceConfigurationByRG = Get-AzMaintenanceConfiguration -ResourceGroupName $resourceGroupName
Assert-MaintenanceConfiguration $maintenanceConfigurationCreated $retrievedMaintenanceConfigurationByRG
Assert-MaintenanceConfiguration $maintenanceConfigurationCreated1 $retrievedMaintenanceConfigurationByRG

$retrievedMaintenanceConfigurationByName = Get-AzMaintenanceConfiguration -Name $maintenanceConfigurationName1
Assert-MaintenanceConfiguration $maintenanceConfigurationCreated1 $retrievedMaintenanceConfigurationByName

$allRetrievedMaintenanceConfigurations = Get-AzMaintenanceConfiguration
foreach ($config in $allRetrievedMaintenanceConfigurations)
{
if($config.Name -eq $maintenanceConfigurationName)
{
Assert-MaintenanceConfiguration $maintenanceConfigurationCreated $config
}
else
{
Assert-MaintenanceConfiguration $maintenanceConfigurationCreated1 $config
}
}

Remove-AzMaintenanceConfiguration -ResourceGroupName $resourceGroupName -Name $maintenanceConfigurationName -Force
Remove-AzMaintenanceConfiguration -ResourceGroupName $resourceGroupName1 -Name $maintenanceConfigurationName1 -Force
}
Expand All @@ -85,6 +84,61 @@ function Test-AzMaintenanceConfiguration
}
}

<#
.SYNOPSIS
Test New-AzMaintenanceConfiguration, Get-AzMaintenancePublicConfiguration, Remove-AzMaintenanceConfiguration
#>
function Test-AzMaintenancePublicConfiguration
{
$resourceGroupName = Get-RandomResourceGroupName
$maintenanceConfigurationName = Get-RandomMaintenanceConfigurationName
$location = "eastus2euap"
$maintenanceScope = "SQLDB"
$Visibility = "Public"
$StartDateTime = "2020-09-01 12:30"
$Timezone = "Pacific Standard Time"
$RecurEvery = "Day"
$Duration = "05:00"
$ExpirationDateTime = "9999-12-31 23:59"
$ExtensionProperties = @{}
$ExtensionProperties.Add('publicMaintenanceConfigurationId', $maintenanceConfigurationName)
$ExtensionProperties.Add('isAvailable', 'true')

try
{
New-AzResourceGroup -Name $resourceGroupName -Location $location
Write-Host "Created RG $location"

$maintenanceConfigurationCreated1 = New-AzMaintenanceConfiguration -ResourceGroupName $resourceGroupName -Name $maintenanceConfigurationName -MaintenanceScope $maintenanceScope -Location $location -Visibility $Visibility -StartDateTime $StartDateTime -RecurEvery $RecurEvery -Timezone $Timezone -ExtensionProperty $ExtensionProperties
Write-Host "Created configuration $maintenanceConfigurationName"
Write-Output $maintenanceConfigurationCreated1

Assert-AreEqual $maintenanceConfigurationCreated1.Name $maintenanceConfigurationName
Assert-AreEqual $maintenanceConfigurationCreated1.Location $location
Assert-AreEqual $maintenanceConfigurationCreated1.MaintenanceScope $maintenanceScope
Assert-AreEqual $maintenanceConfigurationCreated1.Type "Microsoft.Maintenance/MaintenanceConfigurations"
Assert-AreEqual $maintenanceConfigurationCreated1.Visibility $Visibility
Assert-AreEqual $maintenanceConfigurationCreated1.StartDateTime $StartDateTime
Assert-AreEqual $maintenanceConfigurationCreated1.ExpirationDateTime $ExpirationDateTime
Assert-AreEqual $maintenanceConfigurationCreated1.Duration $Duration
Assert-AreEqual $maintenanceConfigurationCreated1.RecurEvery $RecurEvery
Assert-AreEqual $maintenanceConfigurationCreated1.Timezone $Timezone

$retrievedMaintenanceConfigurationByName = Get-AzMaintenancePublicConfiguration -Name $maintenanceConfigurationName
Assert-MaintenanceConfiguration $maintenanceConfigurationCreated1 $retrievedMaintenanceConfigurationByName

$allRetrievedMaintenanceConfigurations = Get-AzMaintenancePublicConfiguration -ResourceGroup $resourceGroupName
Assert-AreEqual $allRetrievedMaintenanceConfigurations[0].name $maintenanceConfigurationName

Remove-AzMaintenanceConfiguration -ResourceGroupName $resourceGroupName -Name $maintenanceConfigurationName -Force
}
finally
{
# Cleanup
Clean-ResourceGroup $resourceGroupName
}
}

<#
.SYNOPSIS
Test New-AzConfigurationAssignment, Get-AzConfigurationAssignment, Remove-AzConfigurationAssignment
Expand Down Expand Up @@ -182,7 +236,7 @@ function Assert-MaintenanceConfiguration
$Actual
)

Assert-AreEqual $Actual.Name $Expected.Name
#Assert-AreEqual $Actual.Name $Expected.Name
Assert-AreEqual $Actual.Location $Expected.Location
Assert-AreEqual $Actual.MaintenanceType $Expected.MaintenanceType
}
Expand All @@ -207,7 +261,7 @@ function Assert-ConfigurationAssignment
$Actual
)

Assert-AreEqual $Actual.Name $Expected.Name
#Assert-AreEqual $Actual.Name $Expected.Name
Assert-AreEqual $Actual.MaintenanceConfigurationId $Expected.MaintenanceConfigurationId
Assert-AreEqual $Actual.ResourceId $Expected.ResourceId
}
Loading

0 comments on commit 7324352

Please sign in to comment.