187 строки
6.6 KiB
PowerShell
187 строки
6.6 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
|
|
{
|
|
$noServer = $true
|
|
$noClient = $true
|
|
$mcSummary = $null
|
|
$serverMachines = @()
|
|
$MC_Servers = ""
|
|
foreach ( $vmData in $allVMData )
|
|
{
|
|
if ( $vmData.RoleName -imatch "Server" )
|
|
{
|
|
$serverMachines += $vmData
|
|
$noServer = $false
|
|
if ( $MC_Servers )
|
|
{
|
|
$MC_Servers += ",$($vmData.InternalIP):11211"
|
|
}
|
|
else
|
|
{
|
|
$MC_Servers ="$($vmData.InternalIP):11211"
|
|
}
|
|
}
|
|
elseif ( $vmData.RoleName -imatch "Client" )
|
|
{
|
|
$clientVMData = $vmData
|
|
$noClient = $fase
|
|
}
|
|
}
|
|
$MC_Servers = $MC_Servers.Trim()
|
|
if ( $noServer )
|
|
{
|
|
Throw "No any server VM defined. Be sure that, server VM role name matches with the pattern `"*server*`". Aborting Test."
|
|
}
|
|
if ( $noSlave )
|
|
{
|
|
Throw "No any client VM defined. Be sure that, client machine role names matches with pattern `"*client*`" Aborting Test."
|
|
}
|
|
#region CONFIGURE VMs for TEST
|
|
|
|
LogMsg "CLIENT VM details :"
|
|
LogMsg " RoleName : $($clientVMData.RoleName)"
|
|
LogMsg " Public IP : $($clientVMData.PublicIP)"
|
|
LogMsg " SSH Port : $($clientVMData.SSHPort)"
|
|
$i = 1
|
|
foreach ( $vmData in $serverMachines )
|
|
{
|
|
LogMsg "SERVER #$i VM details :"
|
|
LogMsg " RoleName : $($vmData.RoleName)"
|
|
LogMsg " Public IP : $($vmData.PublicIP)"
|
|
LogMsg " SSH Port : $($vmData.SSHPort)"
|
|
$i += 1
|
|
}
|
|
#
|
|
# PROVISION VMS FOR LISA WILL ENABLE ROOT USER AND WILL MAKE ENABLE PASSWORDLESS AUTHENTICATION ACROSS ALL VMS IN SAME HOSTED SERVICE.
|
|
#
|
|
ProvisionVMsForLisa -allVMData $allVMData -installPackagesOnRoleNames "DO-NOT-INSTALL"
|
|
#
|
|
foreach ( $vmData in $allVMData )
|
|
{
|
|
LogMsg "Adding $($vmData.InternalIP) $($vmData.RoleName) to /etc/hosts of $($clientVMData.RoleName) "
|
|
$out = RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "echo $($vmData.InternalIP) $($vmData.RoleName) >> /etc/hosts"
|
|
}
|
|
#endregion
|
|
|
|
#region Geting Test Data from remote XML file
|
|
#$mcXMLURL = $($currentTestData.remoteXML)
|
|
#LogMsg "Downloading apache test XML : $mcXMLURL ..."
|
|
#$mcXMLFileName = $($mcXMLURL.Split("/")[$mcXMLURL.Split("/").Count-1])
|
|
#$out = Invoke-WebRequest -Uri $mcXMLURL -OutFile "$LogDir\$mcXMLFileName"
|
|
|
|
$mcXMLData = [xml](Get-Content -Path ".\XML\Perf_memcached.xml")
|
|
|
|
LogMsg "Generating constansts.sh ..."
|
|
$constantsFile = "$LogDir\constants.sh"
|
|
Set-Content -Value "#Generated by Azure Automation." -Path $constantsFile
|
|
foreach ($mcParam in $mcXMLData.config.testCases.test.testParams.param )
|
|
{
|
|
if ($mcParam -imatch "MC_SERVERS")
|
|
{
|
|
Add-Content -Value "MC_SERVERS=`"$MC_Servers`"" -Path $constantsFile
|
|
LogMsg "MC_SERVERS=$MC_Servers added to constansts.sh"
|
|
}
|
|
else
|
|
{
|
|
Add-Content -Value "$mcParam" -Path $constantsFile
|
|
LogMsg "$mcParam added to constansts.sh"
|
|
}
|
|
}
|
|
LogMsg "constanst.sh created successfully..."
|
|
#endregion
|
|
|
|
|
|
#region EXECUTE TEST
|
|
Set-Content -Value "/root/performance_mc.sh &> mcConsoleLogs.txt" -Path "$LogDir\StartMCTest.sh"
|
|
RemoteCopy -uploadTo $clientVMData.PublicIP -port $clientVMData.SSHPort -files ".\$constantsFile,.\remote-scripts\performance_mc.sh,.\$LogDir\StartMCTest.sh" -username "root" -password $password -upload
|
|
$out = RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "chmod +x *.sh"
|
|
$testJob = RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "/root/StartMCTest.sh" -RunInBackground
|
|
#endregion
|
|
|
|
#region MONITOR TEST
|
|
while ( (Get-Job -Id $testJob).State -eq "Running" )
|
|
{
|
|
$currentStatus = RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "tail -n 1 /root/mcConsoleLogs.txt"
|
|
LogMsg "Current Test Staus : $currentStatus"
|
|
WaitFor -seconds 10
|
|
}
|
|
$finalStatus = RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "cat /root/state.txt"
|
|
RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "/root/mcConsoleLogs.txt"
|
|
RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "/root/summary.log"
|
|
$mcConsoleLogs = (Get-Content "$LogDir\mcConsoleLogs.txt")
|
|
foreach ( $line in $mcConsoleLogs )
|
|
{
|
|
if ( $line -imatch "seconds to load data" )
|
|
{
|
|
$mcResult = $line.Trim()
|
|
}
|
|
}
|
|
$mcSummary = Get-Content -Path "$LogDir\summary.log" -ErrorAction SilentlyContinue
|
|
#endregion
|
|
|
|
if (!$mcSummary)
|
|
{
|
|
LogMsg "summary.log file is empty."
|
|
$mcSummary = "<EMPTY>"
|
|
}
|
|
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 : $mcResult."
|
|
$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\mcConsoleLogs.txt"
|
|
LogMsg "Contests of summary.log : $mcSummary"
|
|
$testResult = "PASS"
|
|
}
|
|
LogMsg "Test result : $testResult"
|
|
LogMsg "Test Completed"
|
|
}
|
|
catch
|
|
{
|
|
$ErrorMessage = $_.Exception.Message
|
|
LogMsg "EXCEPTION : $ErrorMessage"
|
|
}
|
|
Finally
|
|
{
|
|
$metaData = ""
|
|
if (!$testResult)
|
|
{
|
|
$testResult = "Aborted"
|
|
}
|
|
$resultArr += $testResult
|
|
$resultSummary += CreateResultSummary -testResult $mcResult -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 |