azure-linux-automation/remote-scripts/ICA-PERF-MONGODB-BENCHMARK-...

194 строки
6.3 KiB
PowerShell

<#-------------Create Deployment Start------------------#>
Import-Module .\TestLibs\RDFELibs.psm1 -Force
$result = ""
$testResult = ""
$resultArr = @()
$isDeployed = DeployVMS -setupType $currentTestData.setupType -Distro $Distro -xmlConfig $xmlConfig
if ($isDeployed)
{
try
{
$allVMData = GetAllDeployementData -DeployedServices $isDeployed
$serverVMData = $allVMData
#
# PROVISION VMS FOR LISA WILL ENABLE ROOT USER AND WILL MAKE ENABLE PASSWORDLESS AUTHENTICATION ACROSS ALL VMS IN SAME HOSTED SERVICE.
#
ProvisionVMsForLisa -allVMData $allVMData
#endregion
#region Geting Test Data from remote XML file
#$mdXMLURL = $($currentTestData.remoteXML)
#LogMsg "Downloading apache test XML : $mdXMLURL ..."
#$mdXMLFileName = $($mdXMLURL.Split("/")[$mdXMLURL.Split("/").Count-1])
#$out = Invoke-WebRequest -Uri $mdXMLURL -OutFile "$LogDir\$mdXMLFileName"
$mdXMLData = [xml](Get-Content -Path ".\XML\Perf_MangoDB.xml")
LogMsg "Generating constansts.sh ..."
$constantsFile = "$LogDir\constants.sh"
Set-Content -Value "#Generated by Azure Automation." -Path $constantsFile
foreach ($mdParam in $mdXMLData.config.testCases.test.testParams.param )
{
if ($mdParam -imatch "MD_SERVER")
{
Add-Content -Value "MD_SERVER=$($serverVMData.InternalIP)" -Path $constantsFile
LogMsg "MD_SERVER=$($serverVMData.InternalIP) added to constansts.sh"
}
else
{
Add-Content -Value "$mdParam" -Path $constantsFile
LogMsg "$mdParam added to constansts.sh"
}
}
LogMsg "constanst.sh created successfully..."
#endregion
#region EXECUTE TEST
Set-Content -Value "/root/performance_md.sh &> mdConsoleLogs.txt" -Path "$LogDir\StartMDTest.sh"
RemoteCopy -uploadTo $serverVMData.PublicIP -port $serverVMData.SSHPort -files ".\$constantsFile,.\remote-scripts\performance_md.sh,.\$LogDir\StartMDTest.sh" -username "root" -password $password -upload
$out = RunLinuxCmd -ip $serverVMData.PublicIP -port $serverVMData.SSHPort -username "root" -password $password -command "chmod +x *.sh"
$testJob = RunLinuxCmd -ip $serverVMData.PublicIP -port $serverVMData.SSHPort -username "root" -password $password -command "/root/StartMDTest.sh" -RunInBackground
#endregion
#region MONITOR TEST
while ( (Get-Job -Id $testJob).State -eq "Running" )
{
$currentStatus = RunLinuxCmd -ip $serverVMData.PublicIP -port $serverVMData.SSHPort -username "root" -password $password -command "tail -n 1 /root/mdConsoleLogs.txt"
LogMsg "Current Test Staus : $currentStatus"
WaitFor -seconds 10
}
RemoteCopy -downloadFrom $serverVMData.PublicIP -port $serverVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "/root/mdConsoleLogs.txt"
RemoteCopy -downloadFrom $serverVMData.PublicIP -port $serverVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "/root/summary.log"
$finalStatus = RunLinuxCmd -ip $serverVMData.PublicIP -port $serverVMData.SSHPort -username "root" -password $password -command "cat /root/state.txt"
$mdSummary = Get-Content -Path "$LogDir\summary.log" -ErrorAction SilentlyContinue
if ($finalStatus -eq "TestCompleted")
{
$mdConsoleData = Get-Content -Path "$LogDir\mdConsoleLogs.txt"
$readCount = 0
$writeCount = 0
$readWriteCount = 0
$totalWriteIOPS = 0
$totalReadIOPS = 0
$totalReadWriteIOPS = 0
$avgReadIOPS = 0
$avgWriteIOPS = 0
$avgReadWriteIOPS = 0
foreach ($line in $mdConsoleData)
{
if ( $line -imatch "r: false, w: true,")
{
$writeLogs = $true
$readLogs = $false
$readWriteLogs = $false
}
if ( $line -imatch "r: true, w: false,")
{
$writeLogs = $false
$readLogs = $true
$readWriteLogs = $false
}
if ( $line -imatch "r: true, w: true,")
{
$writeLogs = $false
$readLogs = $false
$readWriteLogs = $true
}
if ( $writeLogs )
{
if ( $line -imatch "ops/sec" )
{
$totalWriteIOPS += [int]$line.Split(" ")[0]
$writeCount++
}
}
if ( $readLogs )
{
if ( $line -imatch "ops/sec" )
{
$totalReadIOPS += [int]$line.Split(" ")[0]
$readCount++
}
}
if ( $readWriteLogs )
{
if ( $line -imatch "ops/sec" )
{
$totalReadWriteIOPS += [int]$line.Split(" ")[0]
$readWriteCount++
}
}
}
$avgReadIOPS = [int]($totalReadIOPS/$readCount)
$avgWriteIOPS = [int]($totalWriteIOPS/$writeCount)
$avgReadWriteIOPS = [int]($totalReadWriteIOPS/$readWriteCount)
$mdSummary = "R:$avgReadIOPS,W:$avgWriteIOPS,RW=$avgReadWriteIOPS"
}
#endregion
if (!$mdSummary)
{
LogMsg "summary.log file is empty."
$mdSummary = $finalStatus
}
if ( $finalStatus -imatch "TestFailed")
{
LogErr "Test failed. Last known status : $currentStatus."
$testResult = "FAIL"
}
elseif ( $finalStatus -imatch "TestAborted")
{
LogErr "Test Aborted. Last known status : $currentStatus."
$testResult = "ABORTED"
}
elseif ( $finalStatus -imatch "TestCompleted")
{
LogMsg "Test Completed. Result : $finalStatus."
$testResult = "PASS"
}
elseif ( $finalStatus -imatch "TestRunning")
{
LogMsg "Powershell backgroud job for test is completed but VM is reporting that test is still running. Please check $LogDir\mdConsoleLogs.txt"
LogMsg "Contests of state.txt : $finalStatus"
$testResult = "PASS"
}
LogMsg "Test result : $testResult"
LogMsg "Test Completed"
}
catch
{
$ErrorMessage = $_.Exception.Message
LogMsg "EXCEPTION : $ErrorMessage"
}
Finally
{
$metaData = "8KB IOPS"
if (!$testResult)
{
$testResult = "Aborted"
}
$resultArr += $testResult
$resultSummary += CreateResultSummary -testResult $mdSummary -metaData $metaData -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName# if you want to publish all result then give here all test status possibilites. if you want just failed results, then give here just "FAIL". You can use any combination of PASS FAIL ABORTED and corresponding test results will be published!
}
}
else
{
$testResult = "Aborted"
$resultArr += $testResult
}
$result = GetFinalResultHeader -resultarr $resultArr
#Clean up the setup
DoTestCleanUp -result $result -testName $currentTestData.testName -deployedServices $isDeployed -ResourceGroups $isDeployed
#Return the result and summery to the test suite script..
return $result, $resultSummary