346 строки
13 KiB
PowerShell
346 строки
13 KiB
PowerShell
Import-Module .\TestLibs\RDFELibs.psm1 -Force
|
|
$result = ""
|
|
$testResult = ""
|
|
$resultArr = @()
|
|
$isDeployed = DeployVMS -setupType $currentTestData.setupType -Distro $Distro -xmlConfig $xmlConfig
|
|
if ($isDeployed)
|
|
{
|
|
try
|
|
{
|
|
$noClient = $true
|
|
$noServer = $true
|
|
foreach ( $vmData in $allVMData )
|
|
{
|
|
if ( $vmData.RoleName -imatch "client" )
|
|
{
|
|
$clientVMData = $vmData
|
|
$noClient = $false
|
|
}
|
|
elseif ( $vmData.RoleName -imatch "server" )
|
|
{
|
|
$noServer = $fase
|
|
$serverVMData = $vmData
|
|
}
|
|
}
|
|
if ( $noClient )
|
|
{
|
|
Throw "No any master VM defined. Be sure that, Client VM role name matches with the pattern `"*master*`". Aborting Test."
|
|
}
|
|
if ( $noServer )
|
|
{
|
|
Throw "No any slave VM defined. Be sure that, Server machine role names matches with pattern `"*slave*`" Aborting Test."
|
|
}
|
|
#region CONFIGURE VM FOR TERASORT TEST
|
|
LogMsg "CLIENT VM details :"
|
|
LogMsg " RoleName : $($clientVMData.RoleName)"
|
|
LogMsg " Public IP : $($clientVMData.PublicIP)"
|
|
LogMsg " SSH Port : $($clientVMData.SSHPort)"
|
|
LogMsg " Location : $($clientVMData.Location)"
|
|
LogMsg "SERVER VM details :"
|
|
LogMsg " RoleName : $($serverVMData.RoleName)"
|
|
LogMsg " Public IP : $($serverVMData.PublicIP)"
|
|
LogMsg " SSH Port : $($serverVMData.SSHPort)"
|
|
LogMsg " Location : $($serverVMData.Location)"
|
|
#
|
|
# 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 "none"
|
|
|
|
#endregion
|
|
|
|
LogMsg "Generating constansts.sh ..."
|
|
$constantsFile = "$LogDir\constants.sh"
|
|
|
|
#region Check if VMs share same Public IP
|
|
Set-Content -Value "#Generated by Azure Automation." -Path $constantsFile
|
|
|
|
if ( $clientVMData.PublicIP -eq $serverVMData.PublicIP )
|
|
{
|
|
Add-Content -Value "server=$($serverVMData.InternalIP)" -Path $constantsFile
|
|
Add-Content -Value "client=$($clientVMData.InternalIP)" -Path $constantsFile
|
|
}
|
|
else
|
|
{
|
|
Add-Content -Value "server=$($serverVMData.PublicIP)" -Path $constantsFile
|
|
Add-Content -Value "client=$($clientVMData.PublicIP)" -Path $constantsFile
|
|
}
|
|
#endregion
|
|
|
|
foreach ( $param in $currentTestData.TestParameters.param)
|
|
{
|
|
Add-Content -Value "$param" -Path $constantsFile
|
|
if ($param -imatch "bufferLenghs=")
|
|
{
|
|
$testBuffers= $param.Replace("bufferLenghs=(","").Replace(")","").Split(" ")
|
|
}
|
|
if ($param -imatch "connections=" )
|
|
{
|
|
$testConnections = $param.Replace("connections=(","").Replace(")","").Split(" ")
|
|
}
|
|
if ( $param -imatch "IPversion" )
|
|
{
|
|
if ( $param -imatch "IPversion=6" )
|
|
{
|
|
$IPVersion = "IPv6"
|
|
Add-Content -Value "serverIpv6=$($serverVMData.PublicIPv6)" -Path $constantsFile
|
|
Add-Content -Value "clientIpv6=$($clientVMData.PublicIPv6)" -Path $constantsFile
|
|
}
|
|
else
|
|
{
|
|
$IPVersion = "IPv4"
|
|
}
|
|
}
|
|
}
|
|
LogMsg "constanst.sh created successfully..."
|
|
LogMsg (Get-Content -Path $constantsFile)
|
|
#endregion
|
|
|
|
|
|
#region EXECUTE TEST
|
|
$myString = @"
|
|
cd /root/
|
|
./perf_iperf3.sh &> iperf3tcpConsoleLogs.txt
|
|
. azuremodules.sh
|
|
collect_VM_properties
|
|
"@
|
|
Set-Content "$LogDir\Startiperf3tcpTest.sh" $myString
|
|
RemoteCopy -uploadTo $clientVMData.PublicIP -port $clientVMData.SSHPort -files ".\$constantsFile,.\remote-scripts\azuremodules.sh,.\remote-scripts\perf_iperf3.sh,.\SetupScripts\ConfigureUbuntu1604IPv6.sh,.\$LogDir\Startiperf3tcpTest.sh" -username "root" -password $password -upload
|
|
RemoteCopy -uploadTo $clientVMData.PublicIP -port $clientVMData.SSHPort -files $currentTestData.files -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/Startiperf3tcpTest.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 -1 iperf3tcpConsoleLogs.txt"
|
|
LogMsg "Current Test Staus : $currentStatus"
|
|
WaitFor -seconds 20
|
|
}
|
|
$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/iperf3tcpConsoleLogs.txt"
|
|
$iperf3LogDir = "$LogDir\iperf3Data"
|
|
New-Item -itemtype directory -path $iperf3LogDir -Force -ErrorAction SilentlyContinue | Out-Null
|
|
RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $iperf3LogDir -files "iperf-client-tcp*"
|
|
RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $iperf3LogDir -files "iperf-server-tcp*"
|
|
RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "VM_properties.csv"
|
|
|
|
$testSummary = $null
|
|
$iperf3LogDir = "$LogDir\iperf3Data"
|
|
#region START tcp ANALYSIS
|
|
$clientfolder = $iperf3LogDir
|
|
$serverfolder = $iperf3LogDir
|
|
|
|
#clientData
|
|
$files = Get-ChildItem -Path $clientfolder
|
|
$FinalClientThroughputArr=@()
|
|
$FinalServerThroughputArr=@()
|
|
|
|
$FinalServerClientTCPResultObjArr = @()
|
|
|
|
function GetTCPDataObject()
|
|
{
|
|
$objNode = New-Object -TypeName PSObject
|
|
Add-Member -InputObject $objNode -MemberType NoteProperty -Name BufferSize -Value $null -Force
|
|
Add-Member -InputObject $objNode -MemberType NoteProperty -Name Connections -Value $null -Force
|
|
Add-Member -InputObject $objNode -MemberType NoteProperty -Name ClientTxGbps -Value $null -Force
|
|
return $objNode
|
|
}
|
|
|
|
foreach ( $Buffer in $testBuffers )
|
|
{
|
|
foreach ( $connection in $testConnections )
|
|
{
|
|
|
|
$currentResultObj = GetTCPDataObject
|
|
|
|
$currentConnectionClientTxGbps = 0
|
|
$currentConnectionClientTxGbpsArr = @()
|
|
|
|
$currentConnectionserverTxGbps = 0
|
|
$currentConnectionserverTxGbpsArr = @()
|
|
|
|
foreach ( $file in $files )
|
|
{
|
|
if ( $file.Name -imatch "iperf-client-tcp-$IPVersion-buffer-$($Buffer)K-conn-$connection-instance-*" )
|
|
{
|
|
|
|
$currentInstanceclientJsonText = $null
|
|
$currentInstanceclientJsonObj = $null
|
|
$currentInstanceClientPacketLoss = @()
|
|
$currentInstanceClientThroughput = $null
|
|
$fileName = $file.Name
|
|
try
|
|
{
|
|
$currentInstanceclientJsonText = ([string]( Get-Content "$clientfolder\$fileName")).Replace("-nan","0")
|
|
$currentInstanceclientJsonObj = ConvertFrom-Json -InputObject $currentInstanceclientJsonText
|
|
}
|
|
catch
|
|
{
|
|
LogErr " $fileName : RETURNED NULL"
|
|
}
|
|
if ( $currentInstanceclientJsonObj.end.sum_sent )
|
|
{
|
|
$currentInstanceClientThroughput = $currentInstanceclientJsonObj.end.sum_sent.bits_per_second/1000000000
|
|
}
|
|
else
|
|
{
|
|
if ($currentInstanceclientJsonObj.error)
|
|
{
|
|
LogErr " $fileName : Error Found : $($currentInstanceclientJsonObj.error)"
|
|
}
|
|
$totalStreams = 0
|
|
$totalBitsPerSecond = 0
|
|
foreach ( $interval in $currentInstanceclientJsonObj.intervals)
|
|
{
|
|
$totalBitsPerSecond += $interval.sum.bits_per_second
|
|
$totalStreams+=1
|
|
}
|
|
if ($totalStreams -ge 1)
|
|
{
|
|
LogMsg " $fileName : Analysed $totalStreams intervals."
|
|
$currentInstanceClientThroughput = ($totalBitsPerSecond/$totalStreams)/1000000000
|
|
}
|
|
else
|
|
{
|
|
LogErr " $fileName : Error : No connection intervals found."
|
|
}
|
|
#Write-Host " $($currentJsonObj.error) $currentFileClientThroughput"
|
|
}
|
|
if($currentInstanceClientThroughput)
|
|
{
|
|
LogMsg " $fileName : Data collected successfully."
|
|
$currentConnectionClientTxGbpsArr += $currentInstanceClientThroughput
|
|
}
|
|
}
|
|
}
|
|
$currentConnectionClientTxGbps = [math]::Round((($currentConnectionClientTxGbpsArr | Measure-Object -Average).Average),2)
|
|
Write-Host "Client: $Buffer . $connection . $currentConnectionClientTxGbps"
|
|
$FinalClientThroughputArr += $currentConnectionClientTxGbps
|
|
$FinalClientTCPLossArr += $currentConnectionClientTCPLoss
|
|
|
|
$currentResultObj.BufferSize = $Buffer
|
|
$currentResultObj.Connections = $connection
|
|
$currentResultObj.ClientTxGbps = $currentConnectionClientTxGbps
|
|
|
|
$FinalServerClientTCPResultObjArr += $currentResultObj
|
|
Write-Host "-------------------------------"
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
foreach ( $tcpResultObject in $FinalServerClientTCPResultObjArr )
|
|
{
|
|
$connResult="ClientTxGbps=$($tcpResultObject.ClientTxGbps)"
|
|
$metaData = "Buffer=$($tcpResultObject.BufferSize)K Connections=$($tcpResultObject.Connections)"
|
|
$resultSummary += CreateResultSummary -testResult $connResult -metaData $metaData -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName
|
|
}
|
|
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."
|
|
$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\zkConsoleLogs.txt"
|
|
LogMsg "Contests of summary.log : $testSummary"
|
|
$testResult = "PASS"
|
|
}
|
|
LogMsg "Test result : $testResult"
|
|
LogMsg "Test Completed"
|
|
|
|
|
|
LogMsg "Uploading the test results.."
|
|
$dataSource = $xmlConfig.config.Azure.database.server
|
|
$user = $xmlConfig.config.Azure.database.user
|
|
$password = $xmlConfig.config.Azure.database.password
|
|
$database = $xmlConfig.config.Azure.database.dbname
|
|
$dataTableName = $xmlConfig.config.Azure.database.dbtable
|
|
$TestCaseName = $xmlConfig.config.Azure.database.testTag
|
|
if ($dataSource -And $user -And $password -And $database -And $dataTableName)
|
|
{
|
|
$GuestDistro = cat "$LogDir\VM_properties.csv" | Select-String "OS type"| %{$_ -replace ",OS type,",""}
|
|
|
|
#$TestCaseName = "LINUX-NEXT-UPSTREAM-TEST"
|
|
if ( $UseAzureResourceManager )
|
|
{
|
|
$HostType = "Azure-ARM"
|
|
}
|
|
else
|
|
{
|
|
$HostType = "Azure"
|
|
}
|
|
$HostBy = ($xmlConfig.config.Azure.General.Location).Replace('"','')
|
|
$HostOS = cat "$LogDir\VM_properties.csv" | Select-String "Host Version"| %{$_ -replace ",Host Version,",""}
|
|
$GuestOSType = "Linux"
|
|
$GuestDistro = cat "$LogDir\VM_properties.csv" | Select-String "OS type"| %{$_ -replace ",OS type,",""}
|
|
$GuestSize = $clientVMData.InstanceSize
|
|
$KernelVersion = cat "$LogDir\VM_properties.csv" | Select-String "Kernel version"| %{$_ -replace ",Kernel version,",""}
|
|
$ProtocolType = "TCP"
|
|
|
|
$connectionString = "Server=$dataSource;uid=$user; pwd=$password;Database=$database;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;"
|
|
$SQLQuery = "INSERT INTO $dataTableName (TestCaseName,TestDate,HostType,HostBy,HostOS,GuestOSType,GuestDistro,GuestSize,KernelVersion,IPVersion,ProtocolType,NumberOfConnections,Throughput_Gbps,Latency_ms) VALUES "
|
|
|
|
foreach ($tcpResult in $FinalServerClientTCPResultObjArr)
|
|
{
|
|
$SQLQuery += "('$TestCaseName','$(Get-Date -Format yyyy-MM-dd)','$HostType','$HostBy','$HostOS','$GuestOSType','$GuestDistro','$GuestSize','$KernelVersion','$IPVersion','$ProtocolType','$($tcpResult.Connections)','$($tcpResult.ClientTxGbps)','0'),"
|
|
}
|
|
$SQLQuery = $SQLQuery.TrimEnd(',')
|
|
LogMsg $SQLQuery
|
|
$connection = New-Object System.Data.SqlClient.SqlConnection
|
|
$connection.ConnectionString = $connectionString
|
|
$connection.Open()
|
|
|
|
$command = $connection.CreateCommand()
|
|
$command.CommandText = $SQLQuery
|
|
$result = $command.executenonquery()
|
|
$connection.Close()
|
|
LogMsg "Uploading the test results done!!"
|
|
}
|
|
else
|
|
{
|
|
LogMsg "Invalid database details. Failed to upload result to database!"
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
$ErrorMessage = $_.Exception.Message
|
|
LogMsg "EXCEPTION : $ErrorMessage"
|
|
}
|
|
Finally
|
|
{
|
|
$metaData = "iperf3tcp RESULT"
|
|
if (!$testResult)
|
|
{
|
|
$testResult = "Aborted"
|
|
}
|
|
$resultArr += $testResult
|
|
}
|
|
}
|
|
|
|
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
|