Added option to ForceDeleteResources.

This commit is contained in:
Shital Savekar 2017-11-17 20:44:16 +05:30
Родитель ef5584ac09
Коммит e46f180cdc
3 изменённых файлов: 90 добавлений и 68 удалений

Просмотреть файл

@ -32,7 +32,8 @@ param (
[string] $customKernel, [string] $customKernel,
[string] $customLIS, [string] $customLIS,
[string] $customLISBranch, [string] $customLISBranch,
[string] $resizeVMsAfterDeployment [string] $resizeVMsAfterDeployment,
[switch] $ForceDeleteResources
) )
Import-Module .\TestLibs\AzureWinUtils.psm1 -Force -Scope Global Import-Module .\TestLibs\AzureWinUtils.psm1 -Force -Scope Global
@ -62,6 +63,10 @@ if($EnableAcceleratedNetworking)
{ {
Set-Variable -Name EnableAcceleratedNetworking -Value $true -Scope Global Set-Variable -Name EnableAcceleratedNetworking -Value $true -Scope Global
} }
if($ForceDeleteResources)
{
Set-Variable -Name ForceDeleteResources -Value $true -Scope Global
}
if($resizeVMsAfterDeployment) if($resizeVMsAfterDeployment)
{ {
Set-Variable -Name resizeVMsAfterDeployment -Value $resizeVMsAfterDeployment -Scope Global Set-Variable -Name resizeVMsAfterDeployment -Value $resizeVMsAfterDeployment -Scope Global
@ -87,6 +92,7 @@ if ( $RunSelectedTests )
{ {
Set-Variable -Name RunSelectedTests -Value $RunSelectedTests -Scope Global Set-Variable -Name RunSelectedTests -Value $RunSelectedTests -Scope Global
} }
if ( $xmlConfig.config.Azure.General.StorageAccount -imatch "NewStorage_" ) if ( $xmlConfig.config.Azure.General.StorageAccount -imatch "NewStorage_" )
{ {
$NewASMStorageAccountType = ($xmlConfig.config.Azure.General.StorageAccount).Replace("NewStorage_","") $NewASMStorageAccountType = ($xmlConfig.config.Azure.General.StorageAccount).Replace("NewStorage_","")

Просмотреть файл

@ -593,18 +593,27 @@ Function CreateResourceGroupDeployment([string]$RGName, $location, $setupType, $
} }
else else
{ {
LogErr "Failed to Resource Group."
$retValue = $false $retValue = $false
$VMsCreated = Get-AzureRmVM -ResourceGroupName $RGName LogErr "Failed to create Resource Group - $RGName."
if ( $VMsCreated ) if ($ForceDeleteResources)
{ {
LogMsg "Keeping Failed resource group, as we found $($VMsCreated.Count) VM(s) deployed." LogMsg "-ForceDeleteResources is Set. Deleting $RGName."
}
else
{
LogMsg "Removing Failed resource group, as we found 0 VM(s) deployed."
DeleteResourceGroup -RGName $RGName DeleteResourceGroup -RGName $RGName
} }
else
{
$VMsCreated = Get-AzureRmVM -ResourceGroupName $RGName
if ( $VMsCreated )
{
LogMsg "Keeping Failed resource group, as we found $($VMsCreated.Count) VM(s) deployed."
}
else
{
LogMsg "Removing Failed resource group, as we found 0 VM(s) deployed."
DeleteResourceGroup -RGName $RGName
}
}
} }
} }
catch catch

Просмотреть файл

@ -2705,76 +2705,83 @@ Function DoTestCleanUp($result, $testName, $DeployedServices, $ResourceGroups, [
$isVMLogsCollected = $false $isVMLogsCollected = $false
foreach ($group in $ResourceGroups) foreach ($group in $ResourceGroups)
{ {
if($result -eq "PASS") if ($ForceDeleteResources)
{ {
if($EconomyMode -and (-not $IsLastCaseInCycle)) LogMsg "-ForceDeleteResources is Set. Deleting $group."
}
else
{
if($result -eq "PASS")
{ {
LogMsg "Skipping cleanup of Resource Group : $group." if($EconomyMode -and (-not $IsLastCaseInCycle))
if(!$keepUserDirectory)
{ {
RemoveAllFilesFromHomeDirectory -allDeployedVMs $allVMData LogMsg "Skipping cleanup of Resource Group : $group."
if(!$keepUserDirectory)
{
RemoveAllFilesFromHomeDirectory -allDeployedVMs $allVMData
}
}
else
{
$RGdetails = Get-AzureRmResourceGroup -Name $group
if ( $RGdetails.Tags )
{
if ( ( $RGdetails.Tags[0].Name -eq $preserveKeyword ) -and ( $RGdetails.Tags[0].Value -eq "yes" ))
{
LogMsg "Skipping Cleanup of preserved resource group."
LogMsg "Collecting VM logs.."
if ( !$isVMLogsCollected)
{
GetVMLogs -allVMData $allVMData
}
$isVMLogsCollected = $true
}
}
else
{
if ( $keepReproInact )
{
LogMsg "Skipping cleanup due to 'keepReproInact' flag is set."
}
else
{
LogMsg "Cleaning up deployed test virtual machines."
$isClened = DeleteResourceGroup -RGName $group
if (!$isClened)
{
LogMsg "CleanUP unsuccessful for $group.. Please delete the services manually."
}
else
{
LogMsg "CleanUP Successful for $group.."
}
}
}
} }
} }
else else
{ {
$RGdetails = Get-AzureRmResourceGroup -Name $group LogMsg "Preserving the Resource Group(s) $group"
if ( $RGdetails.Tags ) LogMsg "Setting tags : preserve = yes; testName = $testName"
{ $hash = @{}
if ( ( $RGdetails.Tags[0].Name -eq $preserveKeyword ) -and ( $RGdetails.Tags[0].Value -eq "yes" )) $hash.Add($preserveKeyword,"yes")
{ $hash.Add("testName","$testName")
LogMsg "Skipping Cleanup of preserved resource group." $out = Set-AzureRmResourceGroup -Name $group -Tag $hash
LogMsg "Collecting VM logs.." LogMsg "Collecting VM logs.."
if ( !$isVMLogsCollected) if ( !$isVMLogsCollected)
{
GetVMLogs -allVMData $allVMData
}
$isVMLogsCollected = $true
}
}
else
{ {
if ( $keepReproInact ) GetVMLogs -allVMData $allVMData
{
LogMsg "Skipping cleanup due to 'keepReproInact' flag is set."
}
else
{
LogMsg "Cleaning up deployed test virtual machines."
$isClened = DeleteResourceGroup -RGName $group
if (!$isClened)
{
LogMsg "CleanUP unsuccessful for $group.. Please delete the services manually."
}
else
{
LogMsg "CleanUP Successful for $group.."
}
}
} }
} $isVMLogsCollected = $true
} if(!$keepUserDirectory -and !$keepReproInact -and $EconomyMode)
else {
{ RemoveAllFilesFromHomeDirectory -allDeployedVMs $allVMData
LogMsg "Preserving the Resource Group(s) $group" }
LogMsg "Setting tags : preserve = yes; testName = $testName" if($keepReproInact)
$hash = @{}
$hash.Add($preserveKeyword,"yes")
$hash.Add("testName","$testName")
$out = Set-AzureRmResourceGroup -Name $group -Tag $hash
LogMsg "Collecting VM logs.."
if ( !$isVMLogsCollected)
{
GetVMLogs -allVMData $allVMData
}
$isVMLogsCollected = $true
if(!$keepUserDirectory -and !$keepReproInact -and $EconomyMode)
{ {
RemoveAllFilesFromHomeDirectory -allDeployedVMs $allVMData $xmlConfig.config.Azure.Deployment.$setupType.isDeployed = "NO"
} }
if($keepReproInact) }
{
$xmlConfig.config.Azure.Deployment.$setupType.isDeployed = "NO"
}
} }
} }
} }