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

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

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

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

@ -2705,75 +2705,82 @@ Function DoTestCleanUp($result, $testName, $DeployedServices, $ResourceGroups, [
$isVMLogsCollected = $false
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(!$keepUserDirectory)
if($EconomyMode -and (-not $IsLastCaseInCycle))
{
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
{
$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
LogMsg "Preserving the Resource Group(s) $group"
LogMsg "Setting tags : preserve = yes; testName = $testName"
$hash = @{}
$hash.Add($preserveKeyword,"yes")
$hash.Add("testName","$testName")
$out = Set-AzureRmResourceGroup -Name $group -Tag $hash
LogMsg "Collecting VM logs.."
if ( !$isVMLogsCollected)
{
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.."
}
}
GetVMLogs -allVMData $allVMData
}
}
}
else
{
LogMsg "Preserving the Resource Group(s) $group"
LogMsg "Setting tags : preserve = yes; testName = $testName"
$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)
$isVMLogsCollected = $true
if(!$keepUserDirectory -and !$keepReproInact -and $EconomyMode)
{
RemoveAllFilesFromHomeDirectory -allDeployedVMs $allVMData
}
if($keepReproInact)
{
RemoveAllFilesFromHomeDirectory -allDeployedVMs $allVMData
$xmlConfig.config.Azure.Deployment.$setupType.isDeployed = "NO"
}
if($keepReproInact)
{
$xmlConfig.config.Azure.Deployment.$setupType.isDeployed = "NO"
}
}
}