diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..b4fcf5dc7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ + +XML/AzureSecrets.xml +TestResults* +iamshital.code-workspace +1 +TestConfiguration.xml +Temp* +report* diff --git a/AutomationManager.ps1 b/AutomationManager.ps1 new file mode 100644 index 000000000..f71e31a17 --- /dev/null +++ b/AutomationManager.ps1 @@ -0,0 +1,245 @@ +############################################################################################## +# AzureAutomationManager.ps1 +# Description : This script manages all the setup and test operations in Azure environemnt. +# It is an entry script of Azure Automation +# Operations : +# - Installing AzureSDK +# - VHD preparation : Installing packages required by ICA, LIS drivers and waagent +# - Uplaoding test VHD to cloud +# - Invokes azure test suite +## Author : v-shisav@microsoft.com +## Author : v-ampaw@microsoft.com +############################################################################################### +param ( +[CmdletBinding()] +[string] $xmlConfigFile, +[switch] $eMail, +[string] $logFilename="azure_ica.log", +[switch] $runtests, [switch]$onCloud, +[switch] $vhdprep, +[switch] $upload, +[switch] $help, +[string] $RGIdentifier, +[string] $cycleName, +[string] $RunSelectedTests, +[string] $TestPriority, +[string] $osImage, +[switch] $EconomyMode, +[switch] $keepReproInact, +[string] $DebugDistro, +[switch] $UseAzureResourceManager, +[string] $OverrideVMSize, +[switch] $EnableAcceleratedNetworking, +[string] $customKernel, +[string] $customLIS, +[string] $customLISBranch, +[string] $resizeVMsAfterDeployment, +[string] $ExistingResourceGroup, +[switch] $CleanupExistingRG, + +# Experimental Feature +[switch] $UseManagedDisks, + +[int] $coureCountExceededTimeout = 3600, +[int] $testIterations = 1, +[string] $tipSessionId="", +[string] $tipCluster="", +[switch] $ForceDeleteResources +) +Get-ChildItem .\Libraries -Recurse | Where-Object { $_.FullName.EndsWith(".psm1") } | ForEach-Object { Import-Module $_.FullName -Force -Global} + +$xmlConfig = [xml](Get-Content $xmlConfigFile) +$user = $xmlConfig.config.Azure.Deployment.Data.UserName +$password = $xmlConfig.config.Azure.Deployment.Data.Password +$sshKey = $xmlConfig.config.Azure.Deployment.Data.sshKey +$sshPublickey = $xmlConfig.config.Azure.Deployment.Data.sshPublicKey + +Set-Variable -Name user -Value $user -Scope Global +Set-Variable -Name password -Value $password -Scope Global +Set-Variable -Name sshKey -Value $sshKey -Scope Global +Set-Variable -Name sshPublicKey -Value $sshPublicKey -Scope Global +Set-Variable -Name sshPublicKeyThumbprint -Value $sshPublicKeyThumbprint -Scope Global +Set-Variable -Name PublicConfiguration -Value @() -Scope Global +Set-Variable -Name PrivateConfiguration -Value @() -Scope Global +Set-Variable -Name CurrentTestData -Value $CurrentTestData -Scope Global +Set-Variable -Name preserveKeyword -Value "preserving" -Scope Global +Set-Variable -Name tipSessionId -Value $tipSessionId -Scope Global +Set-Variable -Name tipCluster -Value $tipCluster -Scope Global + +Set-Variable -Name global4digitRandom -Value $(Get-Random -SetSeed $(Get-Random) -Maximum 9999 -Minimum 1111) -Scope Global +Set-Variable -Name coureCountExceededTimeout -Value $coureCountExceededTimeout -Scope Global + +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 +} + +if ( $OverrideVMSize ) +{ + Set-Variable -Name OverrideVMSize -Value $OverrideVMSize -Scope Global +} +if ( $customKernel ) +{ + Set-Variable -Name customKernel -Value $customKernel -Scope Global +} +if ( $customLIS ) +{ + Set-Variable -Name customLIS -Value $customLIS -Scope Global +} +if ( $customLISBranch ) +{ + Set-Variable -Name customLISBranch -Value $customLISBranch -Scope Global +} +if ( $RunSelectedTests ) +{ + Set-Variable -Name RunSelectedTests -Value $RunSelectedTests -Scope Global +} +if ($ExistingResourceGroup) +{ + Set-Variable -Name ExistingRG -Value $ExistingResourceGroup -Scope Global +} +if ($CleanupExistingRG) +{ + Set-Variable -Name CleanupExistingRG -Value $true -Scope Global +} +else +{ + Set-Variable -Name CleanupExistingRG -Value $false -Scope Global +} +if ($UseManagedDisks) +{ + Set-Variable -Name UseManagedDisks -Value $true -Scope Global +} +else +{ + Set-Variable -Name UseManagedDisks -Value $false -Scope Global +} + +if ( $xmlConfig.config.Azure.General.ARMStorageAccount -imatch "NewStorage_" ) +{ + $NewARMStorageAccountType = ($xmlConfig.config.Azure.General.ARMStorageAccount).Replace("NewStorage_","") + Set-Variable -Name NewARMStorageAccountType -Value $NewARMStorageAccountType -Scope Global +} +try +{ + $Platform = $xmlConfig.config.CurrentTestPlatform + + if ( $Platform -eq "Azure" ) + { + $testResults = "TestResults" + if (! (test-path $testResults)) + { + mkdir $testResults | out-null + } + $testStartTime = [DateTime]::Now.ToUniversalTime() + Set-Variable -Name testStartTime -Value $testStartTime -Scope Global + $testDir = $testResults + "\" + $cycleName + "-" + $testStartTime.ToString("yyyyMMddHHmmssff") + mkdir $testDir -ErrorAction SilentlyContinue | out-null + Set-Content -Value "" -Path .\report\testSummary.html -Force -ErrorAction SilentlyContinue | Out-Null + Set-Content -Value "" -Path .\report\AdditionalInfo.html -Force -ErrorAction SilentlyContinue | Out-Null + $logFile = $testDir + "\" + "AzureLogs.txt" + Set-Variable -Name logfile -Value $logFile -Scope Global + Set-Content -Path .\report\lastLogDirectory.txt -Value $testDir -ErrorAction SilentlyContinue + Set-Variable -Name Distro -Value $RGIdentifier -Scope Global + Set-Variable -Name onCloud -Value $onCloud -Scope Global + Set-Variable -Name xmlConfig -Value $xmlConfig -Scope Global + Set-Content -Path .\report\lastLogDirectory.txt -Value $testDir -ErrorAction SilentlyContinue + Set-Variable -Name vnetIsAllConfigured -Value $false -Scope Global + if($EconomyMode) + { + Set-Variable -Name EconomyMode -Value $true -Scope Global + if($keepReproInact) + { + Set-Variable -Name keepReproInact -Value $true -Scope Global + } + } + else + { + Set-Variable -Name EconomyMode -Value $false -Scope Global + if($keepReproInact) + { + Set-Variable -Name keepReproInact -Value $true -Scope Global + } + else + { + Set-Variable -Name keepReproInact -Value $false -Scope Global + } + } + $AzureSetup = $xmlConfig.config.Azure.General + LogMsg ("Info : AzureAutomationManager.ps1 - LIS on Azure Automation") + LogMsg ("Info : Created test results directory:", $testDir) + LogMsg ("Info : Logfile = ", $logfile) + LogMsg ("Info : Using config file $xmlConfigFile") + if ( ( $xmlConfig.config.Azure.General.ARMStorageAccount -imatch "ExistingStorage" ) -or ($xmlConfig.config.Azure.General.StorageAccount -imatch "ExistingStorage" ) ) + { + $regionName = $xmlConfig.config.Azure.General.Location.Replace(" ","").Replace('"',"").ToLower() + $regionStorageMapping = [xml](Get-Content .\XML\RegionAndStorageAccounts.xml) + + if ( $xmlConfig.config.Azure.General.ARMStorageAccount -imatch "standard") + { + $xmlConfig.config.Azure.General.ARMStorageAccount = $regionStorageMapping.AllRegions.$regionName.StandardStorage + LogMsg "Info : Selecting existing standard storage account in $regionName - $($regionStorageMapping.AllRegions.$regionName.StandardStorage)" + } + if ( $xmlConfig.config.Azure.General.ARMStorageAccount -imatch "premium") + { + $xmlConfig.config.Azure.General.ARMStorageAccount = $regionStorageMapping.AllRegions.$regionName.PremiumStorage + LogMsg "Info : Selecting existing premium storage account in $regionName - $($regionStorageMapping.AllRegions.$regionName.PremiumStorage)" + } + } + Set-Variable -Name UseAzureResourceManager -Value $true -Scope Global + $SelectedSubscription = RetryOperation -operation { Select-AzureRmSubscription -SubscriptionId $AzureSetup.SubscriptionID } -maxRetryCount 5 -description "Selecting subscription..." + $subIDSplitted = ($SelectedSubscription.Subscription.SubscriptionId).Split("-") + $userIDSplitted = ($SelectedSubscription.Account.Id).Split("-") + LogMsg "SubscriptionName : $($SelectedSubscription.Subscription.Name)" + LogMsg "SubscriptionId : $($subIDSplitted[0])-xxxx-xxxx-xxxx-$($subIDSplitted[4])" + LogMsg "User : $($userIDSplitted[0])-xxxx-xxxx-xxxx-$($userIDSplitted[4])" + LogMsg "ServiceEndpoint : $($SelectedSubscription.Environment.ActiveDirectoryServiceEndpointResourceId)" + LogMsg "CurrentStorageAccount : $($AzureSetup.ARMStorageAccount)" + if($keepReproInact) + { + LogMsg "PLEASE NOTE: keepReproInact is set. VMs will not be deleted after test is finished even if, test gets PASS." + } + + if ($DebugDistro) + { + $OsImage = $xmlConfig.config.Azure.Deployment.Data.Distro | ? { $_.name -eq $DebugDistro} | % { $_.OsImage } + Set-Variable -Name DebugOsImage -Value $OsImage -Scope Global + } + $testCycle = GetCurrentCycleData -xmlConfig $xmlConfig -cycleName $cycleName + $testSuiteResultDetails=.\AzureTestSuite.ps1 $xmlConfig -Distro $Distro -cycleName $cycleName -testIterations $testIterations + $logDirFilename = [System.IO.Path]::GetFilenameWithoutExtension($xmlConfigFile) + $summaryAll = GetTestSummary -testCycle $testCycle -StartTime $testStartTime -xmlFileName $logDirFilename -distro $Distro -testSuiteResultDetails $testSuiteResultDetails + $PlainTextSummary += $summaryAll[0] + $HtmlTextSummary += $summaryAll[1] + Set-Content -Value $HtmlTextSummary -Path .\report\testSummary.html -Force | Out-Null + $PlainTextSummary = $PlainTextSummary.Replace("
", "`r`n") + $PlainTextSummary = $PlainTextSummary.Replace("
", "")
+        $PlainTextSummary = $PlainTextSummary.Replace("
", "") + LogMsg "$PlainTextSummary" + if($eMail) + { + SendEmail $xmlConfig -body $HtmlTextSummary + } + } + else + { + LogError "$Platform not supported." + } +} +catch +{ + ThrowException($_) +} +Finally +{ + exit +} \ No newline at end of file diff --git a/AzureTestSuite.ps1 b/AzureTestSuite.ps1 new file mode 100644 index 000000000..f470af8f0 --- /dev/null +++ b/AzureTestSuite.ps1 @@ -0,0 +1,483 @@ +#v-shisav : STILL IN BETA VERSION + +param($xmlConfig, [string] $Distro, [string] $cycleName, [int] $testIterations) +Function RunTestsOnCycle ($cycleName , $xmlConfig, $Distro, $testIterations ) +{ + $StartTime = [Datetime]::Now.ToUniversalTime() + LogMsg "Starting the Cycle - $($CycleName.ToUpper())" + $executionCount = 0 + $dbEnvironment = "Azure" + $dbTestCycle = $CycleName.Trim() + $dbExecutionID = $dbDateTimeUTC = "$($StartTime.Year)-$($StartTime.Month)-$($StartTime.Day) $($StartTime.Hour):$($StartTime.Minute):$($StartTime.Second)" + $dbLocation = ($xmlConfig.config.Azure.General.Location).Replace('"','').Replace(" ","").ToLower() + $dbOverrideVMSize = $OverrideVMSize + if ( $EnableAcceleratedNetworking ) + { + $dbNetworking = "SRIOV" + } + else + { + $dbNetworking = "Synthetic" + } + foreach ( $tempDistro in $xmlConfig.config.Azure.Deployment.Data.Distro ) + { + if ( ($tempDistro.Name).ToUpper() -eq ($Distro).ToUpper() ) + { + if ( $UseAzureResourceManager ) + { + Write-Host $tempDistro.ARMImage + if ( ($tempDistro.ARMImage.Publisher -ne $null) -and ($tempDistro.ARMImage.Offer -ne $null) -and ($tempDistro.ARMImage.Sku -ne $null) -and ($tempDistro.ARMImage.Version -ne $null) ) + { + $ARMImage = $tempDistro.ARMImage + Set-Variable -Name ARMImage -Value $ARMImage -Scope Global + LogMsg "ARMImage name - $($ARMImage.Publisher) : $($ARMImage.Offer) : $($ARMImage.Sku) : $($ARMImage.Version)" + $dbARMImage = "$($ARMImage.Publisher) $($ARMImage.Offer) $($ARMImage.Sku) $($ARMImage.Version)" + } + if ( $tempDistro.OsVHD ) + { + $BaseOsVHD = $tempDistro.OsVHD.Trim() + Set-Variable -Name BaseOsVHD -Value $BaseOsVHD -Scope Global + LogMsg "Base VHD name - $BaseOsVHD" + } + } + else + { + if ( $tempDistro.OsImage ) + { + $BaseOsImage = $tempDistro.OsImage.Trim() + Set-Variable -Name BaseOsImage -Value $BaseOsImage -Scope Global + LogMsg "Base image name - $BaseOsImage" + } + } + } + } + if (!$BaseOsImage -and !$UseAzureResourceManager) + { + Throw "Please give ImageName or OsVHD for ASM deployment." + } + if (!$($ARMImage.Publisher) -and !$BaseOSVHD -and $UseAzureResourceManager) + { + Throw "Please give ARM Image / VHD for ARM deployment." + } + + #If Base OS VHD is present in another storage account, then copy to test storage account first. + if ($BaseOsVHD -imatch "/") + { + #Check if the test storage account is same as VHD's original storage account. + $givenVHDStorageAccount = $BaseOsVHD.Replace("https://","").Replace("http://","").Split(".")[0] + $ARMStorageAccount = $xmlConfig.config.Azure.General.ARMStorageAccount + + if ($givenVHDStorageAccount -ne $ARMStorageAccount ) + { + LogMsg "Your test VHD is not in target storage account ($ARMStorageAccount)." + LogMsg "Your VHD will be copied to $ARMStorageAccount now." + $sourceContainer = $BaseOsVHD.Split("/")[$BaseOsVHD.Split("/").Count - 2] + $vhdName = $BaseOsVHD.Split("/")[$BaseOsVHD.Split("/").Count - 1] + if ($ARMStorageAccount -inotmatch "NewStorage_") + { + $copyStatus = CopyVHDToAnotherStorageAccount -sourceStorageAccount $givenVHDStorageAccount -sourceStorageContainer $sourceContainer -destinationStorageAccount $ARMStorageAccount -destinationStorageContainer "vhds" -vhdName $vhdName + if (!$copyStatus) + { + Throw "Failed to copy the VHD to $ARMStorageAccount" + } + else + { + Set-Variable -Name BaseOsVHD -Value $vhdName -Scope Global + LogMsg "New Base VHD name - $vhdName" + } + } + else + { + Throw "Automation only supports copying VHDs to existing storage account." + } + #Copy the VHD to current storage account. + } + } + + LogMsg "Loading the cycle Data..." + + $currentCycleData = GetCurrentCycleData -xmlConfig $xmlConfig -cycleName $cycleName + + $xmlElementsToAdd = @("currentTest", "stateTimeStamp", "state", "emailSummary", "htmlSummary", "jobID", "testCaseResults") + foreach($element in $xmlElementsToAdd) + { + if (! $testCycle.${element}) + { + $newElement = $xmlConfig.CreateElement($element) + $newElement.set_InnerText("") + $results = $testCycle.AppendChild($newElement) + } + } + + + $testSuiteLogFile=$logFile + $testSuiteResultDetails=@{"totalTc"=0;"totalPassTc"=0;"totalFailTc"=0;"totalAbortedTc"=0} + $id = "" + + # Start JUnit XML report logger. + $reportFolder = "$pwd/report" + if(!(Test-Path $reportFolder)) + { + New-Item -ItemType "Directory" $reportFolder + } + StartLogReport("$reportFolder/report_$($testCycle.cycleName).xml") + $testsuite = StartLogTestSuite "CloudTesting" + + $testCount = $currentCycleData.test.Length + if (-not $testCount) + { + $testCount = 1 + } + + foreach ($test in $currentCycleData.test) + { + $originalTest = $test + if (-not $test) + { + $test = $currentCycleData.test + $originalTest = $test + } + if ($RunSelectedTests) + { + if ($RunSelectedTests.Trim().Replace(" ","").Split(",") -contains $test.Name) + { + $currentTestData = GetCurrentTestData -xmlConfig $xmlConfig -testName $test.Name + $originalTestName = $currentTestData.testName + if ( $currentTestData.AdditionalCustomization.Networking -eq "SRIOV" ) + { + Set-Variable -Name EnableAcceleratedNetworking -Value $true -Scope Global + } + } + else + { + LogMsg "Skipping $($test.Name) because it is not in selected tests to run." + Continue; + } + } + else + { + $currentTestData = GetCurrentTestData -xmlConfig $xmlConfig -testName $test.Name + $originalTestName = $currentTestData.testName + } + # Generate Unique Test + for ( $testIterationCount = 1; $testIterationCount -le $testIterations; $testIterationCount ++ ) + { + if ( $testIterations -ne 1 ) + { + $currentTestData.testName = "$($originalTestName)-$testIterationCount" + $test.Name = "$($originalTestName)-$testIterationCount" + } + $server = $xmlConfig.config.global.ServerEnv.Server + $cluster = $xmlConfig.config.global.ClusterEnv.Cluster + $rdosVersion = $xmlConfig.config.global.ClusterEnv.RDOSVersion + $fabricVersion = $xmlConfig.config.global.ClusterEnv.FabricVersion + $Location = $xmlConfig.config.global.ClusterEnv.Location + $testId = $currentTestData.TestId + $testSetup = $currentTestData.setupType + $lisBuild = $xmlConfig.config.global.VMEnv.LISBuild + $lisBuildBranch = $xmlConfig.config.global.VMEnv.LISBuildBranch + $VMImageDetails = $xmlConfig.config.global.VMEnv.VMImageDetails + $waagentBuild=$xmlConfig.config.global.VMEnv.waagentBuild + # For the last test running in economy mode, set the IsLastCaseInCycle flag so that the deployments could be cleaned up + if ($EconomyMode -and $counter -eq ($testCount - 1)) + { + Set-Variable -Name IsLastCaseInCycle -Value $true -Scope Global + } + else + { + Set-Variable -Name IsLastCaseInCycle -Value $false -Scope Global + } + if ($currentTestData) + { + + if (!( $currentTestData.Platform.Contains($xmlConfig.config.CurrentTestPlatform))) + { + LogMsg "$($currentTestData.testName) does not support $($xmlConfig.config.CurrentTestPlatform) platform." + continue; + } + if(($testPriority -imatch $currentTestData.Priority ) -or (!$testPriority)) + { + $testcase = StartLogTestCase $testsuite "$($test.Name)" "CloudTesting.$($testCycle.cycleName)" + $testSuiteResultDetails.totalTc = $testSuiteResultDetails.totalTc +1 + $stopWatch = SetStopWatch + Set-Variable -Name currentTestData -Value $currentTestData -Scope Global + mkdir "$testDir\$($currentTestData.testName)" -ErrorAction SilentlyContinue | out-null + $testCaseLogFile = $testDir + "\" + $($currentTestData.testName) + "\" + "azure_ica.log" + $global:logFile = $testCaseLogFile + Set-Content -Value "" -Path $testCaseLogFile -Force | Out-Null + if ((!$currentTestData.SubtestValues -and !$currentTestData.TestMode)) + { + #Tests With No subtests and no SubValues will be executed here.. + try + { + $testMode = "single" + $testResult = "" + $LogDir = "$testDir\$($currentTestData.testName)" + Set-Variable -Name LogDir -Value $LogDir -Scope Global + LogMsg "~~~~~~~~~~~~~~~TEST STARTED : $($currentTestData.testName)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + $testScriptPs1 = $currentTestData.PowershellScript + $startTime = [Datetime]::Now.ToUniversalTime() + $command = ".\Testscripts\Windows\" + $testScriptPs1 + LogMsg "Starting test $($currentTestData.testName)" + $testResult = Invoke-Expression $command + } + catch + { + $testResult = "Aborted" + $ErrorMessage = $_.Exception.Message + LogMsg "EXCEPTION : $ErrorMessage" + } + finally + { + $executionCount += 1 + $testResult = RefineTestResult1 -tempResult $testResult + $endTime = [Datetime]::Now.ToUniversalTime() + $testRunDuration = GetStopWatchElapasedTime $stopWatch "mm" + $testCycle.emailSummary += "$($currentTestData.testName) Execution Time: $testRunDuration minutes
" + $testCycle.emailSummary += " $($currentTestData.testName) : $testResult
" + $testResultRow = "" + LogMsg "~~~~~~~~~~~~~~~TEST END : $($currentTestData.testName)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + $dbTestName = $($currentTestData.testName) + $dbTestResult = $testResult + } + if($testResult -imatch "PASS") + { + $testSuiteResultDetails.totalPassTc = $testSuiteResultDetails.totalPassTc +1 + $testResultRow = "PASS" + FinishLogTestCase $testcase + $testCycle.htmlSummary += "$executionCount$($currentTestData.testName)$testRunDuration min$testResultRow" + } + elseif($testResult -imatch "FAIL") + { + $testSuiteResultDetails.totalFailTc = $testSuiteResultDetails.totalFailTc +1 + $testResultRow = "FAIL" + $caseLog = Get-Content -Raw $testCaseLogFile + FinishLogTestCase $testcase "FAIL" "$($test.Name) failed." $caseLog + $testCycle.htmlSummary += "$executionCount$($currentTestData.testName)$(AddReproVMDetailsToHtmlReport)$testRunDuration min$testResultRow" + } + elseif($testResult -imatch "ABORTED") + { + $testSuiteResultDetails.totalAbortedTc = $testSuiteResultDetails.totalAbortedTc +1 + $testResultRow = "ABORT" + $caseLog = Get-Content -Raw $testCaseLogFile + FinishLogTestCase $testcase "ERROR" "$($test.Name) is aborted." $caseLog + $testCycle.htmlSummary += "$executionCount$($currentTestData.testName)$(AddReproVMDetailsToHtmlReport)$testRunDuration min$testResultRow" + } + else + { + LogErr "Test Result is empty." + $testSuiteResultDetails.totalAbortedTc = $testSuiteResultDetails.totalAbortedTc +1 + $caseLog = Get-Content -Raw $testCaseLogFile + $testResultRow = "ABORT" + FinishLogTestCase $testcase "ERROR" "$($test.Name) is aborted." $caseLog + $testCycle.htmlSummary += "$executionCount$tempHtmlText$(AddReproVMDetailsToHtmlReport)$testRunDuration min$testResultRow" + } + } + else + { + try + { + $testMode = "multi" + $testResult = @() + $LogDir = "$testDir\$($currentTestData.testName)" + Set-Variable -Name LogDir -Value $LogDir -Scope Global + LogMsg "~~~~~~~~~~~~~~~TEST STARTED : $($currentTestData.testName)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + $testScriptPs1 = $currentTestData.PowershellScript + $command = ".\Testscripts\Windows\" + $testScriptPs1 + LogMsg "$command" + LogMsg "Starting multiple tests : $($currentTestData.testName)" + $startTime = [Datetime]::Now.ToUniversalTime() + $testResult = Invoke-Expression $command + } + catch + { + $testResult[0] = "ABORTED" + $ErrorMessage = $_.Exception.Message + LogMsg "EXCEPTION : $ErrorMessage" + } + finally + { + $testResult = RefineTestResult2 -testResult $testResult + try { + $tempHtmlText = ($testResult[1]).Substring(0,((($testResult[1]).Length)-6)) + } + catch { + $tempHtmlText = "Unable to parse the results. Will be fixed shortly." + } + $executionCount += 1 + $testRunDuration = GetStopWatchElapasedTime $stopWatch "mm" + $testRunDuration = $testRunDuration.ToString() + $testCycle.emailSummary += "$($currentTestData.testName) Execution Time: $testRunDuration minutes
" + $testCycle.emailSummary += " $($currentTestData.testName) : $($testResult[0])
" + $testCycle.emailSummary += "$($testResult[1])" + $summary = "$($testResult[1])" + LogMsg "~~~~~~~~~~~~~~~TEST END : $($currentTestData.testName)~~~~~~~~~~" + } + if($testResult[0] -imatch "PASS") + { + $testSuiteResultDetails.totalPassTc = $testSuiteResultDetails.totalPassTc +1 + $testResultRow = "PASS" + FinishLogTestCase $testcase + $testCycle.htmlSummary += "$executionCount$tempHtmlText$testRunDuration min$testResultRow" + } + elseif($testResult[0] -imatch "FAIL") + { + $testSuiteResultDetails.totalFailTc = $testSuiteResultDetails.totalFailTc +1 + $caseLog = Get-Content -Raw $testCaseLogFile + $testResultRow = "FAIL" + FinishLogTestCase $testcase "FAIL" "$($test.Name) failed." $caseLog + $testCycle.htmlSummary += "$executionCount$tempHtmlText$(AddReproVMDetailsToHtmlReport)$testRunDuration min$testResultRow" + } + elseif($testResult[0] -imatch "ABORTED") + { + $testSuiteResultDetails.totalAbortedTc = $testSuiteResultDetails.totalAbortedTc +1 + $caseLog = Get-Content -Raw $testCaseLogFile + $testResultRow = "ABORT" + FinishLogTestCase $testcase "ERROR" "$($test.Name) is aborted." $caseLog + $testCycle.htmlSummary += "$executionCount$tempHtmlText$(AddReproVMDetailsToHtmlReport)$testRunDuration min$testResultRow" + } + else + { + LogErr "Test Result is empty." + $testSuiteResultDetails.totalAbortedTc = $testSuiteResultDetails.totalAbortedTc +1 + $caseLog = Get-Content -Raw $testCaseLogFile + $testResultRow = "ABORT" + FinishLogTestCase $testcase "ERROR" "$($test.Name) is aborted." $caseLog + $testCycle.htmlSummary += "$executionCount$tempHtmlText$(AddReproVMDetailsToHtmlReport)$testRunDuration min$testResultRow" + } + } + if ($xmlSecrets) + { + try + { + $testLogFolder = "TestLogs" + $testLogStorageAccount = $xmlSecrets.secrets.testLogsStorageAccount + $testLogStorageAccountKey = $xmlSecrets.secrets.testLogsStorageAccountKey + $ticks= (Get-Date).Ticks + $uploadFileName = ".\temp\$($currentTestData.testName)-$ticks.zip" + $out = ZipFiles -zipfilename $uploadFileName -sourcedir $LogDir + $uploadLink = .\Extras\UploadFilesToStorageAccount.ps1 -filePaths $uploadFileName -destinationStorageAccount $testLogStorageAccount -destinationContainer "logs" -destinationFolder "$testLogFolder" -destinationStorageKey $testLogStorageAccountKey + $utctime = (Get-Date).ToUniversalTime() + $dbDateTimeUTC = "$($utctime.Year)-$($utctime.Month)-$($utctime.Day) $($utctime.Hour):$($utctime.Minute):$($utctime.Second)" + $dataSource = $xmlSecrets.secrets.DatabaseServer + $dbuser = $xmlSecrets.secrets.DatabaseUser + $dbpassword = $xmlSecrets.secrets.DatabasePassword + $database = $xmlSecrets.secrets.DatabaseName + $dataTableName = "AzureTestResultsMasterTable" + $dbTestName = $($currentTestData.testName) + $SQLQuery = "INSERT INTO $dataTableName (DateTimeUTC,Environment,TestCycle,ExecutionID,TestName,TestResult,ARMImage,OsVHD,KernelVersion,LISVersion,GuestDistro,AzureHost,Location,OverrideVMSize,Networking,LogFile,BuildURL) VALUES " + if ($testMode -eq "multi") + { + $SQLQuery += "('$dbDateTimeUTC','$dbEnvironment','$dbTestCycle','$dbExecutionID','$dbTestName','$($testResult[0])','$dbARMImage','$BaseOsVHD','$finalKernelVersion','$finalLISVersion','$GuestDistro','$HostVersion','$dbLocation','$dbOverrideVMSize','$dbNetworking','$uploadLink', '$env:BUILD_URL`consoleFull')," + foreach ($tempResult in $summary.Split('>')) + { + if ($tempResult) + { + $tempResult = $tempResult.Trim().Replace("
$($CurrentTestData.ProvisionTimeExtensions)<") + { + $ExecutePS = $true + } + if ($line -imatch '') + { + $ExecutePS = $false + } + if ( ($line -imatch "EXECUTE-PS-" ) -and $ExecutePS) + { + $PSoutout = "" + $line = $line.Trim() + $line = $line.Replace("EXECUTE-PS-","") + $line = $line.Split(">") + $line = $line.Split("<") + LogMsg "Executing Powershell command from Extensions.XML file : $($line[2])..." + $PSoutout = Invoke-Expression -Command $line[2] + $extensionString = $extensionString.Replace("EXECUTE-PS-$($line[2])",$PSoutout) + sleep -Milliseconds 1 + } + } + $extensionXML = [xml]$extensionString +} + +$LocationLower = $Location.Replace(" ","").ToLower().Replace('"','') +if ( $NewARMStorageAccountType ) +{ + #$StorageAccountName = $($NewARMStorageAccountType.ToLower().Replace("_","").Replace("standard","std").Replace("premium","prm")) + "$RGRandomNumber" + "$LocationLower" + $StorageAccountName = $($NewARMStorageAccountType.ToLower().Replace("_","")) + "$RGRandomNumber" + #$StorageAccountName = "$LocationLower" + "$RGRandomNumber" + LogMsg "Using New ARM Storage Account : $StorageAccountName" + $StorageAccountType= $NewARMStorageAccountType +} +else +{ + LogMsg "Using ARM Storage Account : $StorageAccountName" +} +$bootDiagnosticsSA = "icadiagnostic$RGRandomNumber" +LogMsg "Using API VERSION : $apiVersion" +$ExistingVnet = $null +if ($RGXMLData.ARMVnetName -ne $null) +{ + $ExistingVnet = $RGXMLData.ARMVnetName + LogMsg "Getting $ExistingVnet Virtual Netowrk info ..." + $ExistingVnetResourceGroupName = ( Get-AzureRmResource | Where {$_.Name -eq $ExistingVnet}).ResourceGroupName + LogMsg "ARM VNET : $ExistingVnet (ResourceGroup : $ExistingVnetResourceGroupName)" + $virtualNetworkName = $ExistingVnet +} + +#Generate Single Indent +for($i =0; $i -lt 4; $i++) +{ + $singleIndent += " " +} + +#Generate Indent Levels +for ($i =0; $i -lt 30; $i++) +{ + $indent += $singleIndent + $indents += $indent +} + + +#Check if the deployment Type is single VM deployment or multiple VM deployment +$numberOfVMs = 0 +$EnableIPv6 = $false +$ForceLoadBalancerForSingleVM = $false +foreach ( $newVM in $RGXMLData.VirtualMachine) +{ + $numberOfVMs += 1 + if ( !$EnableIPv6 ) + { + foreach ( $endpoint in $newVM.EndPoints ) + { + if ( $endpoint.EnableIPv6 -eq "True" ) + { + $EnableIPv6 = $true + } + if ( $endpoint.LoadBalanced -eq "True" ) + { + $ForceLoadBalancerForSingleVM = $true + } + } + } +} + + +$StorageProfileScriptBlock = { + Add-Content -Value "$($indents[4])^storageProfile^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + if ($ARMImage -and !$osVHD) + { + LogMsg ">>Using ARMImage : $($ARMImage.Publisher):$($ARMImage.Offer):$($ARMImage.Sku):$($ARMImage.Version)" + Add-Content -Value "$($indents[5])^imageReference^ : " -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^publisher^: ^$publisher^," -Path $jsonFile + Add-Content -Value "$($indents[6])^offer^: ^$offer^," -Path $jsonFile + Add-Content -Value "$($indents[6])^sku^: ^$sku^," -Path $jsonFile + Add-Content -Value "$($indents[6])^version^: ^$version^" -Path $jsonFile + Add-Content -Value "$($indents[5])}," -Path $jsonFile + } + elseif ($CurrentTestData.Publisher -and $CurrentTestData.Offer) + { + Add-Content -Value "$($indents[5])^imageReference^ : " -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^publisher^: ^$publisher^," -Path $jsonFile + Add-Content -Value "$($indents[6])^offer^: ^$offer^," -Path $jsonFile + Add-Content -Value "$($indents[6])^sku^: ^$sku^," -Path $jsonFile + Add-Content -Value "$($indents[6])^version^: ^$version^" -Path $jsonFile + Add-Content -Value "$($indents[5])}," -Path $jsonFile + } + Add-Content -Value "$($indents[5])^osDisk^ : " -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + if($osVHD) + { + LogMsg ">>Using VHD : $osVHD" + Add-Content -Value "$($indents[6])^image^: " -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^uri^: ^[concat('http://',variables('StorageAccountName'),'.blob.core.windows.net/vhds/','$osVHD')]^" -Path $jsonFile + Add-Content -Value "$($indents[6])}," -Path $jsonFile + Add-Content -Value "$($indents[6])^osType^: ^Linux^," -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^$vmName-OSDisk^," -Path $jsonFile + #Add-Content -Value "$($indents[6])^osType^: ^Linux^," -Path $jsonFile + Add-Content -Value "$($indents[6])^vhd^: " -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^uri^: ^[concat('http://',variables('StorageAccountName'),'.blob.core.windows.net/vhds/','$vmName-$RGrandomWord-osdisk.vhd')]^" -Path $jsonFile + Add-Content -Value "$($indents[6])}," -Path $jsonFile + Add-Content -Value "$($indents[6])^caching^: ^ReadWrite^," -Path $jsonFile + Add-Content -Value "$($indents[6])^createOption^: ^FromImage^" -Path $jsonFile + } + else + { + if ($UseManagedDisks) + { + Add-Content -Value "$($indents[6])^name^: ^$vmName-OSDisk^," -Path $jsonFile + Add-Content -Value "$($indents[6])^createOption^: ^FromImage^," -Path $jsonFile + Add-Content -Value "$($indents[6])^managedDisk^: " -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^storageAccountType^: ^$StorageAccountType^" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + + } + else + { + Add-Content -Value "$($indents[6])^name^: ^$vmName-OSDisk^," -Path $jsonFile + Add-Content -Value "$($indents[6])^createOption^: ^FromImage^," -Path $jsonFile + Add-Content -Value "$($indents[6])^vhd^: " -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^uri^: ^[concat('http://',variables('StorageAccountName'),'.blob.core.windows.net/vhds/','$vmName-$RGrandomWord-osdisk.vhd')]^" -Path $jsonFile + Add-Content -Value "$($indents[6])}," -Path $jsonFile + Add-Content -Value "$($indents[6])^caching^: ^ReadWrite^" -Path $jsonFile + } + } + Add-Content -Value "$($indents[5])}," -Path $jsonFile + $dataDiskAdded = $false + Add-Content -Value "$($indents[5])^dataDisks^ : " -Path $jsonFile + Add-Content -Value "$($indents[5])[" -Path $jsonFile + foreach ( $dataDisk in $newVM.DataDisk ) + { + if ( $dataDisk.LUN -ge 0 ) + { + if( $dataDiskAdded ) + { + Add-Content -Value "$($indents[6])," -Path $jsonFile + } + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^name^: ^$vmName-disk-lun-$($dataDisk.LUN)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^diskSizeGB^: ^$($dataDisk.DiskSizeInGB)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^lun^: ^$($dataDisk.LUN)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^createOption^: ^Empty^," -Path $jsonFile + Add-Content -Value "$($indents[7])^caching^: ^$($dataDisk.HostCaching)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^vhd^:" -Path $jsonFile + Add-Content -Value "$($indents[7]){" -Path $jsonFile + Add-Content -Value "$($indents[8])^uri^: ^[concat('http://',variables('StorageAccountName'),'.blob.core.windows.net/vhds/','$vmName-$RGrandomWord-disk-lun-$($dataDisk.LUN).vhd')]^" -Path $jsonFile + Add-Content -Value "$($indents[7])}" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + LogMsg "Added $($dataDisk.DiskSizeInGB)GB Datadisk to $($dataDisk.LUN)." + $dataDiskAdded = $true + } + } + Add-Content -Value "$($indents[5])]" -Path $jsonFile + Add-Content -Value "$($indents[4])}" -Path $jsonFile +} + + +#region Generate JSON file +Set-Content -Value "$($indents[0]){" -Path $jsonFile -Force + Add-Content -Value "$($indents[1])^`$schema^: ^https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#^," -Path $jsonFile + Add-Content -Value "$($indents[1])^contentVersion^: ^1.0.0.0^," -Path $jsonFile + Add-Content -Value "$($indents[1])^parameters^: {}," -Path $jsonFile + Add-Content -Value "$($indents[1])^variables^:" -Path $jsonFile + Add-Content -Value "$($indents[1]){" -Path $jsonFile + + #region Variables + Add-Content -Value "$($indents[2])^StorageAccountName^: ^$StorageAccountName^," -Path $jsonFile + Add-Content -Value "$($indents[2])^dnsNameForPublicIP^: ^$dnsNameForPublicIP^," -Path $jsonFile + Add-Content -Value "$($indents[2])^dnsNameForPublicIPv6^: ^$dnsNameForPublicIPv6^," -Path $jsonFile + Add-Content -Value "$($indents[2])^adminUserName^: ^$user^," -Path $jsonFile + Add-Content -Value "$($indents[2])^adminPassword^: ^$($password.Replace('"',''))^," -Path $jsonFile + Add-Content -Value "$($indents[2])^sshKeyPublicThumbPrint^: ^$sshPublicKeyThumbprint^," -Path $jsonFile + Add-Content -Value "$($indents[2])^sshKeyPath^: ^$sshPath^," -Path $jsonFile + Add-Content -Value "$($indents[2])^sshKeyData^: ^$sshKeyData^," -Path $jsonFile + Add-Content -Value "$($indents[2])^location^: ^$($Location.Replace('"',''))^," -Path $jsonFile + Add-Content -Value "$($indents[2])^publicIPv4AddressName^: ^$PublicIPName^," -Path $jsonFile + Add-Content -Value "$($indents[2])^publicIPv6AddressName^: ^$PublicIPv6Name^," -Path $jsonFile + + Add-Content -Value "$($indents[2])^virtualNetworkName^: ^$virtualNetworkName^," -Path $jsonFile + Add-Content -Value "$($indents[2])^nicName^: ^$nicName^," -Path $jsonFile + Add-Content -Value "$($indents[2])^addressPrefix^: ^10.0.0.0/16^," -Path $jsonFile + Add-Content -Value "$($indents[2])^vmSourceImageName^ : ^$osImage^," -Path $jsonFile + Add-Content -Value "$($indents[2])^CompliedSourceImageName^ : ^[concat('/',subscription().subscriptionId,'/services/images/',variables('vmSourceImageName'))]^," -Path $jsonFile + Add-Content -Value "$($indents[2])^defaultSubnetPrefix^: ^10.0.0.0/24^," -Path $jsonFile + #Add-Content -Value "$($indents[2])^subnet2Prefix^: ^10.0.1.0/24^," -Path $jsonFile + Add-Content -Value "$($indents[2])^vmStorageAccountContainerName^: ^vhds^," -Path $jsonFile + Add-Content -Value "$($indents[2])^publicIPAddressType^: ^Dynamic^," -Path $jsonFile + Add-Content -Value "$($indents[2])^storageAccountType^: ^$storageAccountType^," -Path $jsonFile + if ($ExistingVnet) + { + Add-Content -Value "$($indents[2])^virtualNetworkResourceGroup^: ^$ExistingVnetResourceGroupName^," -Path $jsonFile + Add-Content -Value "$($indents[2])^vnetID^: ^[resourceId(variables('virtualNetworkResourceGroup'), 'Microsoft.Network/virtualNetworks', '$virtualNetworkName')]^," -Path $jsonFile + } + else + { + Add-Content -Value "$($indents[2])^defaultSubnet^: ^$defaultSubnetName^," -Path $jsonFile + Add-Content -Value "$($indents[2])^defaultSubnetID^: ^[concat(variables('vnetID'),'/subnets/', variables('defaultSubnet'))]^," -Path $jsonFile + Add-Content -Value "$($indents[2])^vnetID^: ^[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]^," -Path $jsonFile + } + if ($ExistingRG) + { + Add-Content -Value "$($indents[2])^availabilitySetName^: ^$customAVSetName^," -Path $jsonFile + } + else + { + Add-Content -Value "$($indents[2])^availabilitySetName^: ^$availibilitySetName^," -Path $jsonFile + } + Add-Content -Value "$($indents[2])^lbName^: ^$LoadBalancerName^," -Path $jsonFile + Add-Content -Value "$($indents[2])^lbID^: ^[resourceId('Microsoft.Network/loadBalancers',variables('lbName'))]^," -Path $jsonFile + Add-Content -Value "$($indents[2])^frontEndIPv4ConfigID^: ^[concat(variables('lbID'),'/frontendIPConfigurations/LoadBalancerFrontEndIPv4')]^," -Path $jsonFile + Add-Content -Value "$($indents[2])^frontEndIPv6ConfigID^: ^[concat(variables('lbID'),'/frontendIPConfigurations/LoadBalancerFrontEndIPv6')]^," -Path $jsonFile + Add-Content -Value "$($indents[2])^lbIPv4PoolID^: ^[concat(variables('lbID'),'/backendAddressPools/BackendPoolIPv4')]^," -Path $jsonFile + Add-Content -Value "$($indents[2])^lbIPv6PoolID^: ^[concat(variables('lbID'),'/backendAddressPools/BackendPoolIPv6')]^," -Path $jsonFile + Add-Content -Value "$($indents[2])^lbProbeID^: ^[concat(variables('lbID'),'/probes/tcpProbe')]^" -Path $jsonFile + #Add more variables here, if required.. + #Add more variables here, if required.. + #Add more variables here, if required.. + #Add more variables here, if required.. + Add-Content -Value "$($indents[1])}," -Path $jsonFile + LogMsg "Added Variables.." + + #endregion + + #region Define Resources + Add-Content -Value "$($indents[1])^resources^:" -Path $jsonFile + Add-Content -Value "$($indents[1])[" -Path $jsonFile + + #region Common Resources for all deployments.. + + #region availabilitySets + if ($ExistingRG) + { + LogMsg "Using existing Availibility Set: $customAVSetName" + } + else + { + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^$apiVersion^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Compute/availabilitySets^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^[variables('availabilitySetName')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + if ( $tipSessionId -and $tipCluster) + { + Add-Content -Value "$($indents[3])^tags^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^TipNode.SessionId^: ^$tipSessionId^" -Path $jsonFile + Add-Content -Value "$($indents[3])}," -Path $jsonFile + } + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + if ( $tipSessionId -and $tipCluster) + { + Add-Content -Value "$($indents[4])^internalData^:" -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^pinnedFabricCluster^ : ^$tipCluster^" -Path $jsonFile + Add-Content -Value "$($indents[4])}" -Path $jsonFile + } + Add-Content -Value "$($indents[3])}" -Path $jsonFile + Add-Content -Value "$($indents[2])}," -Path $jsonFile + LogMsg "Added availabilitySet $availibilitySetName.." + } + #endregion + + #region publicIPAddresses + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^$apiVersion^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Network/publicIPAddresses^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^[variables('publicIPv4AddressName')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^publicIPAllocationMethod^: ^[variables('publicIPAddressType')]^," -Path $jsonFile + Add-Content -Value "$($indents[4])^dnsSettings^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^domainNameLabel^: ^[variables('dnsNameForPublicIP')]^" -Path $jsonFile + Add-Content -Value "$($indents[4])}" -Path $jsonFile + Add-Content -Value "$($indents[3])}" -Path $jsonFile + Add-Content -Value "$($indents[2])}," -Path $jsonFile + LogMsg "Added Public IP Address $PublicIPName.." + #endregion + + #region New ARM Storage Account, if necessory! + if ( $NewARMStorageAccountType ) + { + + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^2015-06-15^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Storage/storageAccounts^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^[variables('StorageAccountName')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^accountType^: ^$($NewARMStorageAccountType.Trim())^" -Path $jsonFile + Add-Content -Value "$($indents[3])}" -Path $jsonFile + Add-Content -Value "$($indents[2])}," -Path $jsonFile + LogMsg "Added New Storage Account $StorageAccountName.." + } + #endregion + + #region New ARM Bood Diagnostic Account if Storage Account Type is Premium LRS. + + if ($StorageAccountType -imatch "Premium_LRS") + { + + $bootDiagnosticsSA = ([xml](Get-Content .\XML\RegionAndStorageAccounts.xml)).AllRegions.$LocationLower.StandardStorage + $diagnosticRG = $StorageAccountRG = ($GetAzureRMStorageAccount | where {$_.StorageAccountName -eq $bootDiagnosticsSA}).ResourceGroupName.ToString() + <# + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^2015-06-15^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Storage/storageAccounts^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^$bootDiagnosticsSA^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^accountType^: ^Standard_LRS^" -Path $jsonFile + Add-Content -Value "$($indents[3])}" -Path $jsonFile + Add-Content -Value "$($indents[2])}," -Path $jsonFile + $diagnosticRG = $RGName + LogMsg "Added boot diagnostic Storage Account $bootDiagnosticsSA.." + #> + } + else + { + $bootDiagnosticsSA = $StorageAccountName + $diagnosticRG = $StorageAccountRG + } + #endregion + + #region virtualNetworks + if (!$ExistingVnet) + { + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^$apiVersion^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Network/virtualNetworks^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^[variables('virtualNetworkName')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + #AddressSpace + Add-Content -Value "$($indents[4])^addressSpace^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^addressPrefixes^: " -Path $jsonFile + Add-Content -Value "$($indents[5])[" -Path $jsonFile + Add-Content -Value "$($indents[6])^[variables('addressPrefix')]^" -Path $jsonFile + Add-Content -Value "$($indents[5])]" -Path $jsonFile + Add-Content -Value "$($indents[4])}," -Path $jsonFile + #Subnets + Add-Content -Value "$($indents[4])^subnets^: " -Path $jsonFile + Add-Content -Value "$($indents[4])[" -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^[variables('defaultSubnet')]^," -Path $jsonFile + Add-Content -Value "$($indents[6])^properties^: " -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^addressPrefix^: ^[variables('defaultSubnetPrefix')]^" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + #Add-Content -Value "$($indents[5]){" -Path $jsonFile + # Add-Content -Value "$($indents[6])^name^: ^[variables('subnet2Name')]^," -Path $jsonFile + # Add-Content -Value "$($indents[6])^properties^: " -Path $jsonFile + # Add-Content -Value "$($indents[6]){" -Path $jsonFile + # Add-Content -Value "$($indents[7])^addressPrefix^: ^[variables('subnet2Prefix')]^" -Path $jsonFile + # Add-Content -Value "$($indents[6])}" -Path $jsonFile + #Add-Content -Value "$($indents[5])}" -Path $jsonFile + Add-Content -Value "$($indents[4])]" -Path $jsonFile + Add-Content -Value "$($indents[3])}" -Path $jsonFile + Add-Content -Value "$($indents[2])}," -Path $jsonFile + LogMsg "Added Virtual Network $virtualNetworkName.." + } + #endregion + + #endregion + + #region publicIPAddresses + if ( $EnableIPv6 ) + { + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^$apiVersion^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Network/publicIPAddresses^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^[variables('publicIPv6AddressName')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^publicIPAllocationMethod^: ^[variables('publicIPAddressType')]^," -Path $jsonFile + Add-Content -Value "$($indents[4])^publicIPAddressVersion^: ^IPv6^," -Path $jsonFile + Add-Content -Value "$($indents[4])^dnsSettings^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^domainNameLabel^: ^[variables('dnsNameForPublicIPv6')]^" -Path $jsonFile + Add-Content -Value "$($indents[4])}" -Path $jsonFile + Add-Content -Value "$($indents[3])}" -Path $jsonFile + Add-Content -Value "$($indents[2])}," -Path $jsonFile + LogMsg "Added Public IPv6 Address $PublicIPv6Name.." + } + #endregion + + #region Multiple VM Deployment + + if ( ($numberOfVMs -gt 1) -or ($EnableIPv6) -or ($ForceLoadBalancerForSingleVM) ) + { + + #region LoadBalancer + LogMsg "Adding Load Balancer ..." + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^$apiVersion^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Network/loadBalancers^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^[variables('lbName')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^dependsOn^: " -Path $jsonFile + Add-Content -Value "$($indents[3])[" -Path $jsonFile + if ( $EnableIPv6 ) + { + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPv6AddressName'))]^," -Path $jsonFile + } + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPv4AddressName'))]^" -Path $jsonFile + Add-Content -Value "$($indents[3])]," -Path $jsonFile + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^frontendIPConfigurations^: " -Path $jsonFile + Add-Content -Value "$($indents[4])[" -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^LoadBalancerFrontEndIPv4^," -Path $jsonFile + Add-Content -Value "$($indents[6])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^publicIPAddress^:" -Path $jsonFile + Add-Content -Value "$($indents[7]){" -Path $jsonFile + Add-Content -Value "$($indents[8])^id^: ^[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPv4AddressName'))]^" -Path $jsonFile + Add-Content -Value "$($indents[7])}" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + + #region IPV6 frondend loadbalancer config + if ( $EnableIPv6 ) + { + Add-Content -Value "$($indents[5])," -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^LoadBalancerFrontEndIPv6^," -Path $jsonFile + Add-Content -Value "$($indents[6])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^publicIPAddress^:" -Path $jsonFile + Add-Content -Value "$($indents[7]){" -Path $jsonFile + Add-Content -Value "$($indents[8])^id^: ^[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPv6AddressName'))]^" -Path $jsonFile + Add-Content -Value "$($indents[7])}" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + } + #endregion + + Add-Content -Value "$($indents[4])]," -Path $jsonFile + Add-Content -Value "$($indents[4])^backendAddressPools^:" -Path $jsonFile + Add-Content -Value "$($indents[4])[" -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^:^BackendPoolIPv4^" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + if ( $EnableIPv6 ) + { + Add-Content -Value "$($indents[5])," -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^:^BackendPoolIPv6^" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + } + Add-Content -Value "$($indents[4])]," -Path $jsonFile + #region Normal Endpoints + + Add-Content -Value "$($indents[4])^inboundNatRules^:" -Path $jsonFile + Add-Content -Value "$($indents[4])[" -Path $jsonFile +$LBPorts = 0 +$EndPointAdded = $false +$role = 0 +foreach ( $newVM in $RGXMLData.VirtualMachine) +{ + if($newVM.RoleName) + { + $vmName = $newVM.RoleName + } + else + { + $vmName = $RGName+"-role-"+$role + } + foreach ( $endpoint in $newVM.EndPoints) + { + if ( !($endpoint.LoadBalanced) -or ($endpoint.LoadBalanced -eq "False") ) + { + if ( $EndPointAdded ) + { + Add-Content -Value "$($indents[5])," -Path $jsonFile + } + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^$vmName-$($endpoint.Name)^," -Path $jsonFile + Add-Content -Value "$($indents[6])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^frontendIPConfiguration^:" -Path $jsonFile + Add-Content -Value "$($indents[7]){" -Path $jsonFile + Add-Content -Value "$($indents[8])^id^: ^[variables('frontEndIPv4ConfigID')]^" -Path $jsonFile + Add-Content -Value "$($indents[7])}," -Path $jsonFile + Add-Content -Value "$($indents[7])^protocol^: ^$($endpoint.Protocol)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^frontendPort^: ^$($endpoint.PublicPort)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^backendPort^: ^$($endpoint.LocalPort)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^enableFloatingIP^: false" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + LogMsg "Added inboundNatRule Name:$vmName-$($endpoint.Name) frontendPort:$($endpoint.PublicPort) backendPort:$($endpoint.LocalPort) Protocol:$($endpoint.Protocol)." + $EndPointAdded = $true + } + else + { + $LBPorts += 1 + } + } + $role += 1 +} + Add-Content -Value "$($indents[4])]" -Path $jsonFile + #endregion + + #region LoadBalanced Endpoints +if ( $LBPorts -gt 0 ) +{ + Add-Content -Value "$($indents[4])," -Path $jsonFile + Add-Content -Value "$($indents[4])^loadBalancingRules^:" -Path $jsonFile + Add-Content -Value "$($indents[4])[" -Path $jsonFile +$probePorts = 0 +$EndPointAdded = $false +$addedLBPort = $null +$role = 0 +foreach ( $newVM in $RGXMLData.VirtualMachine) +{ + if($newVM.RoleName) + { + $vmName = $newVM.RoleName + } + else + { + $vmName = $RGName+"-role-"+$role + } + + foreach ( $endpoint in $newVM.EndPoints) + { + if ( ($endpoint.LoadBalanced -eq "True") -and !($addedLBPort -imatch "$($endpoint.Name)-$($endpoint.PublicPort)" ) ) + { + if ( $EndPointAdded ) + { + Add-Content -Value "$($indents[5])," -Path $jsonFile + } + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^$RGName-LB-$($endpoint.Name)^," -Path $jsonFile + Add-Content -Value "$($indents[6])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + + Add-Content -Value "$($indents[7])^frontendIPConfiguration^:" -Path $jsonFile + Add-Content -Value "$($indents[7]){" -Path $jsonFile + if ($endpoint.EnableIPv6 -eq "True") + { + Add-Content -Value "$($indents[8])^id^: ^[variables('frontEndIPv6ConfigID')]^" -Path $jsonFile + } + else + { + Add-Content -Value "$($indents[8])^id^: ^[variables('frontEndIPv4ConfigID')]^" -Path $jsonFile + } + Add-Content -Value "$($indents[7])}," -Path $jsonFile + Add-Content -Value "$($indents[7])^backendAddressPool^:" -Path $jsonFile + Add-Content -Value "$($indents[7]){" -Path $jsonFile + if ($endpoint.EnableIPv6 -eq "True") + { + Add-Content -Value "$($indents[8])^id^: ^[variables('lbIPv6PoolID')]^" -Path $jsonFile + } + else + { + Add-Content -Value "$($indents[8])^id^: ^[variables('lbIPv4PoolID')]^" -Path $jsonFile + } + Add-Content -Value "$($indents[7])}," -Path $jsonFile + Add-Content -Value "$($indents[7])^protocol^: ^$($endpoint.Protocol)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^frontendPort^: ^$($endpoint.PublicPort)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^backendPort^: ^$($endpoint.LocalPort)^" -Path $jsonFile + + + if ( $endpoint.ProbePort ) + { + $probePorts += 1 + Add-Content -Value "$($indents[7])," -Path $jsonFile + Add-Content -Value "$($indents[7])^probe^:" -Path $jsonFile + Add-Content -Value "$($indents[7]){" -Path $jsonFile + Add-Content -Value "$($indents[8])^id^: ^[concat(variables('lbID'),'/probes/$RGName-LB-$($endpoint.Name)-probe')]^" -Path $jsonFile + Add-Content -Value "$($indents[7])}," -Path $jsonFile + LogMsg "Enabled Probe for loadBalancingRule Name:$RGName-LB-$($endpoint.Name) : $RGName-LB-$($endpoint.Name)-probe." + } + else + { + if ( $endpoint.EnableIPv6 -ne "True" ) + { + Add-Content -Value "$($indents[7])," -Path $jsonFile + Add-Content -Value "$($indents[7])^enableFloatingIP^: false," -Path $jsonFile + Add-Content -Value "$($indents[7])^idleTimeoutInMinutes^: 5" -Path $jsonFile + } + } + Add-Content -Value "$($indents[6])}" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + LogMsg "Added loadBalancingRule Name:$RGName-LB-$($endpoint.Name) frontendPort:$($endpoint.PublicPort) backendPort:$($endpoint.LocalPort) Protocol:$($endpoint.Protocol)." + if ( $addedLBPort ) + { + $addedLBPort += "-$($endpoint.Name)-$($endpoint.PublicPort)" + } + else + { + $addedLBPort = "$($endpoint.Name)-$($endpoint.PublicPort)" + } + $EndPointAdded = $true + } + } + $role += 1 +} + Add-Content -Value "$($indents[4])]" -Path $jsonFile +} + #endregion + + #region Probe Ports +if ( $probePorts -gt 0 ) +{ + Add-Content -Value "$($indents[4])," -Path $jsonFile + Add-Content -Value "$($indents[4])^probes^:" -Path $jsonFile + Add-Content -Value "$($indents[4])[" -Path $jsonFile + +$EndPointAdded = $false +$addedProbes = $null +$role = 0 +foreach ( $newVM in $RGXMLData.VirtualMachine) +{ + if($newVM.RoleName) + { + $vmName = $newVM.RoleName + } + else + { + $vmName = $RGName+"-role-"+$role + } + foreach ( $endpoint in $newVM.EndPoints) + { + if ( ($endpoint.LoadBalanced -eq "True") ) + { + if ( $endpoint.ProbePort -and !($addedProbes -imatch "$($endpoint.Name)-probe-$($endpoint.ProbePort)")) + { + if ( $EndPointAdded ) + { + Add-Content -Value "$($indents[5])," -Path $jsonFile + } + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^$RGName-LB-$($endpoint.Name)-probe^," -Path $jsonFile + Add-Content -Value "$($indents[6])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^protocol^ : ^$($endpoint.Protocol)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^port^ : ^$($endpoint.ProbePort)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^intervalInSeconds^ : ^15^," -Path $jsonFile + Add-Content -Value "$($indents[7])^numberOfProbes^ : ^$probePorts^" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + LogMsg "Added probe :$RGName-LB-$($endpoint.Name)-probe Probe Port:$($endpoint.ProbePort) Protocol:$($endpoint.Protocol)." + if ( $addedProbes ) + { + $addedProbes += "-$($endpoint.Name)-probe-$($endpoint.ProbePort)" + } + else + { + $addedProbes = "$($endpoint.Name)-probe-$($endpoint.ProbePort)" + } + $EndPointAdded = $true + } + } + } + + $role += 1 +} + Add-Content -Value "$($indents[4])]" -Path $jsonFile +} + #endregion + + Add-Content -Value "$($indents[3])}" -Path $jsonFile + Add-Content -Value "$($indents[2])}," -Path $jsonFile + LogMsg "Addded Load Balancer." + #endregion + + $vmAdded = $false + $role = 0 +foreach ( $newVM in $RGXMLData.VirtualMachine) +{ + $VnetName = $RGXMLData.VnetName + if ( $OverrideVMSize ) + { + $instanceSize = $OverrideVMSize + } + else + { + $instanceSize = $newVM.ARMInstanceSize + } + + $ExistingSubnet = $newVM.ARMSubnetName + $DnsServerIP = $RGXMLData.DnsServerIP + if($newVM.RoleName) + { + $vmName = $newVM.RoleName + } + else + { + $vmName = $RGName+"-role-"+$role + "-$($randomNum)" + } + $NIC = "PrimaryNIC" + "-$vmName" + + if ( $vmAdded ) + { + Add-Content -Value "$($indents[2])," -Path $jsonFile + } + + #region networkInterfaces + LogMsg "Adding Network Interface Card $NIC" + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^2016-09-01^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Network/networkInterfaces^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^$NIC^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^dependsOn^: " -Path $jsonFile + Add-Content -Value "$($indents[3])[" -Path $jsonFile + if ( $EnableIPv6 ) + { + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPv6AddressName'))]^," -Path $jsonFile + } + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPv4AddressName'))]^," -Path $jsonFile + if(!$ExistingVnet) + { + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]^," -Path $jsonFile + } + Add-Content -Value "$($indents[4])^[variables('lbID')]^" -Path $jsonFile + Add-Content -Value "$($indents[3])]," -Path $jsonFile + + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^ipConfigurations^: " -Path $jsonFile + Add-Content -Value "$($indents[4])[" -Path $jsonFile + + #region IPv4 Config + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^IPv4Config1^," -Path $jsonFile + Add-Content -Value "$($indents[6])^properties^: " -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^privateIPAddressVersion^:^IPv4^," -Path $jsonFile + Add-Content -Value "$($indents[7])^loadBalancerBackendAddressPools^:" -Path $jsonFile + Add-Content -Value "$($indents[7])[" -Path $jsonFile + Add-Content -Value "$($indents[8]){" -Path $jsonFile + Add-Content -Value "$($indents[9])^id^: ^[concat(variables('lbID'), '/backendAddressPools/BackendPoolIPv4')]^" -Path $jsonFile + Add-Content -Value "$($indents[8])}" -Path $jsonFile + Add-Content -Value "$($indents[7])]," -Path $jsonFile + + #region Enable InboundRules in NIC + Add-Content -Value "$($indents[7])^loadBalancerInboundNatRules^:" -Path $jsonFile + Add-Content -Value "$($indents[7])[" -Path $jsonFile + $EndPointAdded = $false + foreach ( $endpoint in $newVM.EndPoints) + { + if ( !($endpoint.LoadBalanced) -or ($endpoint.LoadBalanced -eq "False") ) + { + if ( $EndPointAdded ) + { + Add-Content -Value "$($indents[8])," -Path $jsonFile + } + Add-Content -Value "$($indents[8]){" -Path $jsonFile + Add-Content -Value "$($indents[9])^id^:^[concat(variables('lbID'),'/inboundNatRules/$vmName-$($endpoint.Name)')]^" -Path $jsonFile + Add-Content -Value "$($indents[8])}" -Path $jsonFile + LogMsg "Enabled inboundNatRule Name:$vmName-$($endpoint.Name) frontendPort:$($endpoint.PublicPort) backendPort:$($endpoint.LocalPort) Protocol:$($endpoint.Protocol) to $NIC." + $EndPointAdded = $true + } + } + + Add-Content -Value "$($indents[7])]," -Path $jsonFile + #endregion + + Add-Content -Value "$($indents[7])^subnet^:" -Path $jsonFile + Add-Content -Value "$($indents[7]){" -Path $jsonFile + if ( $existingSubnet ) + { + Add-Content -Value "$($indents[8])^id^: ^[concat(variables('vnetID'),'/subnets/', '$existingSubnet')]^" -Path $jsonFile + } + else + { + Add-Content -Value "$($indents[8])^id^: ^[variables('defaultSubnetID')]^" -Path $jsonFile + } + Add-Content -Value "$($indents[7])}," -Path $jsonFile + Add-Content -Value "$($indents[7])^privateIPAllocationMethod^: ^Dynamic^" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + #endregion + + + + #region IPv6 Config... + if ( $EnableIPv6 ) + { + Add-Content -Value "$($indents[5])," -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^IPv6Config1^," -Path $jsonFile + Add-Content -Value "$($indents[6])^properties^: " -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^privateIPAddressVersion^:^IPv6^," -Path $jsonFile + Add-Content -Value "$($indents[7])^loadBalancerBackendAddressPools^:" -Path $jsonFile + Add-Content -Value "$($indents[7])[" -Path $jsonFile + Add-Content -Value "$($indents[8]){" -Path $jsonFile + Add-Content -Value "$($indents[9])^id^: ^[concat(variables('lbID'), '/backendAddressPools/BackendPoolIPv6')]^" -Path $jsonFile + Add-Content -Value "$($indents[8])}" -Path $jsonFile + Add-Content -Value "$($indents[7])]," -Path $jsonFile + Add-Content -Value "$($indents[7])^privateIPAllocationMethod^: ^Dynamic^" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + } + #endregion + Add-Content -Value "$($indents[4])]" -Path $jsonFile + if ($EnableAcceleratedNetworking) + { + Add-Content -Value "$($indents[4])," -Path $jsonFile + Add-Content -Value "$($indents[4])^enableAcceleratedNetworking^: true" -Path $jsonFile + LogMsg "Enabled Accelerated Networking." + } + Add-Content -Value "$($indents[3])}" -Path $jsonFile + + + Add-Content -Value "$($indents[2])}," -Path $jsonFile + LogMsg "Added NIC $NIC.." + #endregion + + #region multiple Nics + [System.Collections.ArrayList]$NicNameList= @() + foreach ($NetworkInterface in $newVM.NetworkInterfaces) + { + $NicName = $NetworkInterface.Name + $NicNameList.add($NicName) + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^2016-09-01^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Network/networkInterfaces^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^$NicName^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^dependsOn^: " -Path $jsonFile + Add-Content -Value "$($indents[3])[" -Path $jsonFile + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]^," -Path $jsonFile + Add-Content -Value "$($indents[4])^[variables('lbID')]^" -Path $jsonFile + Add-Content -Value "$($indents[3])]," -Path $jsonFile + + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^ipConfigurations^: " -Path $jsonFile + Add-Content -Value "$($indents[4])[" -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^IPv4Config1^," -Path $jsonFile + Add-Content -Value "$($indents[6])^properties^: " -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^subnet^:" -Path $jsonFile + Add-Content -Value "$($indents[7]){" -Path $jsonFile + Add-Content -Value "$($indents[8])^id^: ^[variables('defaultSubnetID')]^" -Path $jsonFile + Add-Content -Value "$($indents[7])}" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + Add-Content -Value "$($indents[4])]" -Path $jsonFile + if ($EnableAcceleratedNetworking) + { + Add-Content -Value "$($indents[4])," -Path $jsonFile + Add-Content -Value "$($indents[4])^enableAcceleratedNetworking^: true" -Path $jsonFile + LogMsg "Enabled Accelerated Networking for $NicName." + } + Add-Content -Value "$($indents[3])}" -Path $jsonFile + Add-Content -Value "$($indents[2])}," -Path $jsonFile + } + #endregion + #region virtualMachines + LogMsg "Adding Virtual Machine $vmName" + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^2017-03-30^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Compute/virtualMachines^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^$vmName^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + if ($publisher -imatch "clear-linux-project") + { + LogMsg " Adding plan information for clear-linux.." + Add-Content -Value "$($indents[3])^plan^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^name^: ^$sku^," -Path $jsonFile + Add-Content -Value "$($indents[4])^product^: ^clear-linux-os^," -Path $jsonFile + Add-Content -Value "$($indents[4])^publisher^: ^clear-linux-project^" -Path $jsonFile + Add-Content -Value "$($indents[3])}," -Path $jsonFile + } + Add-Content -Value "$($indents[3])^tags^: {^GlobalRandom^: ^$GlobalRandom^}," -Path $jsonFile + Add-Content -Value "$($indents[3])^dependsOn^: " -Path $jsonFile + Add-Content -Value "$($indents[3])[" -Path $jsonFile + if ($ExistingRG) + { + #Add-Content -Value "$($indents[4])^[concat('Microsoft.Compute/availabilitySets/', variables('availabilitySetName'))]^," -Path $jsonFile + } + else + { + Add-Content -Value "$($indents[4])^[concat('Microsoft.Compute/availabilitySets/', variables('availabilitySetName'))]^," -Path $jsonFile + } + if ( $NewARMStorageAccountType) + { + Add-Content -Value "$($indents[4])^[concat('Microsoft.Storage/storageAccounts/', variables('StorageAccountName'))]^," -Path $jsonFile + } + if($NicNameList) + { + foreach($NicName in $NicNameList) + { + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/networkInterfaces/', '$NicName')]^," -Path $jsonFile + } + } + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/networkInterfaces/', '$NIC')]^" -Path $jsonFile + Add-Content -Value "$($indents[3])]," -Path $jsonFile + + #region VM Properties + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + #region availabilitySet + Add-Content -Value "$($indents[4])^availabilitySet^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^id^: ^[resourceId('Microsoft.Compute/availabilitySets','$customAVSetName')]^" -Path $jsonFile + Add-Content -Value "$($indents[4])}," -Path $jsonFile + #endregion + + #region Hardware Profile + Add-Content -Value "$($indents[4])^hardwareProfile^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^vmSize^: ^$instanceSize^" -Path $jsonFile + Add-Content -Value "$($indents[4])}," -Path $jsonFile + #endregion + + #region OSProfie + Add-Content -Value "$($indents[4])^osProfile^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^computername^: ^$vmName^," -Path $jsonFile + Add-Content -Value "$($indents[5])^adminUsername^: ^[variables('adminUserName')]^," -Path $jsonFile + Add-Content -Value "$($indents[5])^adminPassword^: ^[variables('adminPassword')]^" -Path $jsonFile + #Add-Content -Value "$($indents[5])^linuxConfiguration^:" -Path $jsonFile + #Add-Content -Value "$($indents[5]){" -Path $jsonFile + # Add-Content -Value "$($indents[6])^ssh^:" -Path $jsonFile + # Add-Content -Value "$($indents[6]){" -Path $jsonFile + # Add-Content -Value "$($indents[7])^publicKeys^:" -Path $jsonFile + # Add-Content -Value "$($indents[7])[" -Path $jsonFile + # Add-Content -Value "$($indents[8])[" -Path $jsonFile + # Add-Content -Value "$($indents[9]){" -Path $jsonFile + # Add-Content -Value "$($indents[10])^path^:^$sshPath^," -Path $jsonFile + # Add-Content -Value "$($indents[10])^keyData^:^$sshKeyData^" -Path $jsonFile + # Add-Content -Value "$($indents[9])}" -Path $jsonFile + # Add-Content -Value "$($indents[8])]" -Path $jsonFile + # Add-Content -Value "$($indents[7])]" -Path $jsonFile + # Add-Content -Value "$($indents[6])}" -Path $jsonFile + #Add-Content -Value "$($indents[5])}" -Path $jsonFile + Add-Content -Value "$($indents[4])}," -Path $jsonFile + #endregion + + #region Storage Profile + Invoke-Command -ScriptBlock $StorageProfileScriptBlock + Add-Content -Value "$($indents[4])," -Path $jsonFile + #endregion + + LogMsg "Added Virtual Machine $vmName" + + #region Network Profile + Add-Content -Value "$($indents[4])^networkProfile^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^networkInterfaces^: " -Path $jsonFile + Add-Content -Value "$($indents[5])[" -Path $jsonFile + #region configure multiple Nics to networkProfile + if($NicNameList) + { + foreach($NicName in $NicNameList) + { + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^id^: ^[resourceId('Microsoft.Network/networkInterfaces','$NicName')]^," -Path $jsonFile + Add-Content -Value "$($indents[7])^properties^: { ^primary^: false }" -Path $jsonFile + Add-Content -Value "$($indents[6])}," -Path $jsonFile + LogMsg "Attached Network Interface Card `"$NicName`" to Virtual Machine `"$vmName`"." + } + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^id^: ^[resourceId('Microsoft.Network/networkInterfaces','$NIC')]^," -Path $jsonFile + Add-Content -Value "$($indents[7])^properties^: { ^primary^: true }" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + LogMsg "Attached Network Interface Card `"$NIC`" to Virtual Machine `"$vmName`"." + } + else + { + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^id^: ^[resourceId('Microsoft.Network/networkInterfaces','$NIC')]^" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + } + #endregion + Add-Content -Value "$($indents[5])]" -Path $jsonFile + Add-Content -Value "$($indents[4])}" -Path $jsonFile + + + #region Enable boot dignostics. + Add-Content -Value "$($indents[4])," -Path $jsonFile + Add-Content -Value "$($indents[4])^diagnosticsProfile^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^bootDiagnostics^: " -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^enabled^: true," -Path $jsonFile + Add-Content -Value "$($indents[6])^storageUri^: ^[reference(resourceId('$diagnosticRG', 'Microsoft.Storage/storageAccounts', '$bootDiagnosticsSA'), '2015-06-15').primaryEndpoints['blob']]^" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + Add-Content -Value "$($indents[4])}" -Path $jsonFile + #endregion + + Add-Content -Value "$($indents[3])}" -Path $jsonFile + #endregion + + Add-Content -Value "$($indents[2])}" -Path $jsonFile + #endregion + + $vmAdded = $true + $role = $role + 1 + $vmCount = $role +} + Add-Content -Value "$($indents[1])]" -Path $jsonFile + } + #endregion + + #region Single VM Deployment... +if ( ($numberOfVMs -eq 1) -and !$EnableIPv6 -and !$ForceLoadBalancerForSingleVM ) +{ + if ($ExistingRG) + { + if($newVM.RoleName) + { + $vmName = $newVM.RoleName + "-$($randomNum)" + } + else + { + $vmName = $RGName+"-role-0-$($randomNum)" + } + } + else + { + if($newVM.RoleName) + { + $vmName = $newVM.RoleName + } + else + { + $vmName = $RGName+"-role-0" + } + } + $vmAdded = $false + $newVM = $RGXMLData.VirtualMachine + $vmCount = $vmCount + 1 + $VnetName = $RGXMLData.VnetName + if ( $OverrideVMSize ) + { + $instanceSize = $OverrideVMSize + } + else + { + $instanceSize = $newVM.ARMInstanceSize + } + $SubnetName = $newVM.ARMSubnetName + $DnsServerIP = $RGXMLData.DnsServerIP + $NIC = "PrimaryNIC" + "-$vmName" + $SecurityGroupName = "SG-$vmName" + + #region networkInterfaces + LogMsg "Adding Network Interface Card $NIC.." + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^2016-09-01^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Network/networkInterfaces^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^$NIC^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^dependsOn^: " -Path $jsonFile + Add-Content -Value "$($indents[3])[" -Path $jsonFile + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPv4AddressName'))]^," -Path $jsonFile + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/networkSecurityGroups/', '$SecurityGroupName')]^," -Path $jsonFile + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]^" -Path $jsonFile + Add-Content -Value "$($indents[3])]," -Path $jsonFile + + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^ipConfigurations^: " -Path $jsonFile + Add-Content -Value "$($indents[4])[" -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^IPv4Config$($randomNum)^," -Path $jsonFile + Add-Content -Value "$($indents[6])^properties^: " -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^privateIPAllocationMethod^: ^Dynamic^," -Path $jsonFile + Add-Content -Value "$($indents[7])^publicIPAddress^:" -Path $jsonFile + Add-Content -Value "$($indents[7]){" -Path $jsonFile + Add-Content -Value "$($indents[8])^id^: ^[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPv4AddressName'))]^" -Path $jsonFile + Add-Content -Value "$($indents[7])}," -Path $jsonFile + Add-Content -Value "$($indents[7])^subnet^:" -Path $jsonFile + Add-Content -Value "$($indents[7]){" -Path $jsonFile + Add-Content -Value "$($indents[8])^id^: ^[variables('defaultSubnetID')]^" -Path $jsonFile + Add-Content -Value "$($indents[7])}" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + Add-Content -Value "$($indents[4])]," -Path $jsonFile + Add-Content -Value "$($indents[4])^networkSecurityGroup^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^id^: ^[resourceId('Microsoft.Network/networkSecurityGroups','$SecurityGroupName')]^" -Path $jsonFile + Add-Content -Value "$($indents[4])}" -Path $jsonFile + if ($EnableAcceleratedNetworking) + { + Add-Content -Value "$($indents[4])," -Path $jsonFile + Add-Content -Value "$($indents[4])^enableAcceleratedNetworking^: true" -Path $jsonFile + LogMsg "Enabled Accelerated Networking for $NIC." + } + Add-Content -Value "$($indents[3])}" -Path $jsonFile + Add-Content -Value "$($indents[2])}," -Path $jsonFile + LogMsg "Added NIC $NIC.." + #region multiple Nics + [System.Collections.ArrayList]$NicNameList= @() + foreach ($NetworkInterface in $newVM.NetworkInterfaces) + { + $NicName = $NetworkInterface.Name + $NicNameList.add($NicName) + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^2016-09-01^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Network/networkInterfaces^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^$NicName^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^dependsOn^: " -Path $jsonFile + Add-Content -Value "$($indents[3])[" -Path $jsonFile + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]^" -Path $jsonFile + Add-Content -Value "$($indents[3])]," -Path $jsonFile + + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^ipConfigurations^: " -Path $jsonFile + Add-Content -Value "$($indents[4])[" -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^IPv4Config1^," -Path $jsonFile + Add-Content -Value "$($indents[6])^properties^: " -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^subnet^:" -Path $jsonFile + Add-Content -Value "$($indents[7]){" -Path $jsonFile + Add-Content -Value "$($indents[8])^id^: ^[variables('defaultSubnetID')]^" -Path $jsonFile + Add-Content -Value "$($indents[7])}" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + Add-Content -Value "$($indents[4])]" -Path $jsonFile + if ($EnableAcceleratedNetworking) + { + Add-Content -Value "$($indents[4])," -Path $jsonFile + Add-Content -Value "$($indents[4])^enableAcceleratedNetworking^: true" -Path $jsonFile + LogMsg "Enabled Accelerated Networking for $NicName." + } + Add-Content -Value "$($indents[3])}" -Path $jsonFile + Add-Content -Value "$($indents[2])}," -Path $jsonFile + } + #endregion + + #endregion + + #region networkSecurityGroups + LogMsg "Adding Security Group $SecurityGroupName.." + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^$apiVersion^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Network/networkSecurityGroups^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^$SecurityGroupName^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^securityRules^: " -Path $jsonFile + Add-Content -Value "$($indents[4])[" -Path $jsonFile + #region Add Endpoints... + $securityRulePriority = 101 + $securityRuleAdded = $false + foreach ( $endpoint in $newVM.EndPoints) + { + if ( $securityRuleAdded ) + { + Add-Content -Value "$($indents[5])," -Path $jsonFile + $securityRulePriority += 10 + } + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^name^: ^$($endpoint.Name)^," -Path $jsonFile + Add-Content -Value "$($indents[6])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^protocol^: ^$($endpoint.Protocol)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^sourcePortRange^: ^*^," -Path $jsonFile + Add-Content -Value "$($indents[7])^destinationPortRange^: ^$($endpoint.PublicPort)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^sourceAddressPrefix^: ^*^," -Path $jsonFile + Add-Content -Value "$($indents[7])^destinationAddressPrefix^: ^*^," -Path $jsonFile + Add-Content -Value "$($indents[7])^access^: ^Allow^," -Path $jsonFile + Add-Content -Value "$($indents[7])^priority^: $securityRulePriority," -Path $jsonFile + Add-Content -Value "$($indents[7])^direction^: ^Inbound^" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + LogMsg "Added securityRule Name:$($endpoint.Name) destinationPortRange:$($endpoint.PublicPort) Protocol:$($endpoint.Protocol) Priority:$securityRulePriority." + $securityRuleAdded = $true + } + #endregion + Add-Content -Value "$($indents[4])]," -Path $jsonFile + Add-Content -Value "$($indents[4])^networkInterfaces^: " -Path $jsonFile + Add-Content -Value "$($indents[4])[" -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^id^:^[resourceId('Microsoft.Network/networkInterfaces','$NIC')]^" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + #region configure multiple Nics + foreach($NicName in $NicNameList) + { + Add-Content -Value "$($indents[5])," -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^id^:^[resourceId('Microsoft.Network/networkInterfaces','$NicName')]^" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + LogMsg "Added Nic $NicName to Security Group $SecurityGroupName" + } + #endregion + Add-Content -Value "$($indents[4])]" -Path $jsonFile + Add-Content -Value "$($indents[3])}" -Path $jsonFile + + Add-Content -Value "$($indents[2])}," -Path $jsonFile + LogMsg "Added Security Group $SecurityGroupName.." + #endregion + + #region virtualMachines + LogMsg "Adding Virtual Machine $vmName.." + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^2017-03-30^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Compute/virtualMachines^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^$vmName^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + if ($publisher -imatch "clear-linux-project") + { + LogMsg " Adding plan information for clear-linux.." + Add-Content -Value "$($indents[3])^plan^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^name^: ^$sku^," -Path $jsonFile + Add-Content -Value "$($indents[4])^product^: ^clear-linux-os^," -Path $jsonFile + Add-Content -Value "$($indents[4])^publisher^: ^clear-linux-project^" -Path $jsonFile + Add-Content -Value "$($indents[3])}," -Path $jsonFile + } + Add-Content -Value "$($indents[3])^dependsOn^: " -Path $jsonFile + Add-Content -Value "$($indents[3])[" -Path $jsonFile + if ($ExistingRG) + { + #Add-Content -Value "$($indents[4])^[concat('Microsoft.Compute/availabilitySets/', variables('availabilitySetName'))]^," -Path $jsonFile + } + else + { + Add-Content -Value "$($indents[4])^[concat('Microsoft.Compute/availabilitySets/', variables('availabilitySetName'))]^," -Path $jsonFile + } + #region configure multiple Nics to virtualMachines + foreach($NicName in $NicNameList) + { + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/networkInterfaces/', '$NicName')]^," -Path $jsonFile + LogMsg "Added Nic $NicName to virtualMachines" + } + if ( $NewARMStorageAccountType) + { + Add-Content -Value "$($indents[4])^[concat('Microsoft.Storage/storageAccounts/', variables('StorageAccountName'))]^," -Path $jsonFile + } + Add-Content -Value "$($indents[4])^[concat('Microsoft.Network/networkInterfaces/', '$NIC')]^" -Path $jsonFile + LogMsg "Added Nic $NIC to virtualMachines" + #endregion + Add-Content -Value "$($indents[3])]," -Path $jsonFile + #region VM Properties + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + #region availabilitySet + Add-Content -Value "$($indents[4])^availabilitySet^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^id^: ^[resourceId('Microsoft.Compute/availabilitySets','$customAVSetName')]^" -Path $jsonFile + Add-Content -Value "$($indents[4])}," -Path $jsonFile + #endregion + #region Hardware Profile + Add-Content -Value "$($indents[4])^hardwareProfile^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^vmSize^: ^$instanceSize^" -Path $jsonFile + Add-Content -Value "$($indents[4])}," -Path $jsonFile + #endregion + if ($ExistingRG) + { + #region availabilitySet + Add-Content -Value "$($indents[4])^availabilitySet^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^id^: ^[resourceId('Microsoft.Compute/availabilitySets','$customAVSetName')]^" -Path $jsonFile + Add-Content -Value "$($indents[4])}," -Path $jsonFile + #endregion + } + #region OSProfie + Add-Content -Value "$($indents[4])^osProfile^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^computername^: ^$vmName^," -Path $jsonFile + Add-Content -Value "$($indents[5])^adminUsername^: ^[variables('adminUserName')]^," -Path $jsonFile + Add-Content -Value "$($indents[5])^adminPassword^: ^[variables('adminPassword')]^" -Path $jsonFile + Add-Content -Value "$($indents[4])}," -Path $jsonFile + #endregion + + #region Storage Profile + Invoke-Command -ScriptBlock $StorageProfileScriptBlock + Add-Content -Value "$($indents[4])," -Path $jsonFile + #endregion + + #region Network Profile + Add-Content -Value "$($indents[4])^networkProfile^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^networkInterfaces^: " -Path $jsonFile + Add-Content -Value "$($indents[5])[" -Path $jsonFile + #region configure multiple Nics to networkProfile + if($NicNameList) + { + foreach($NicName in $NicNameList) + { + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^id^: ^[resourceId('Microsoft.Network/networkInterfaces','$NicName')]^," -Path $jsonFile + Add-Content -Value "$($indents[7])^properties^: { ^primary^: false }" -Path $jsonFile + Add-Content -Value "$($indents[6])}," -Path $jsonFile + } + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^id^: ^[resourceId('Microsoft.Network/networkInterfaces','$NIC')]^," -Path $jsonFile + Add-Content -Value "$($indents[7])^properties^: { ^primary^: true }" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + } + else + { + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^id^: ^[resourceId('Microsoft.Network/networkInterfaces','$NIC')]^" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + } + #endregion + Add-Content -Value "$($indents[5])]" -Path $jsonFile + <# + Add-Content -Value "$($indents[5])]," -Path $jsonFile + Add-Content -Value "$($indents[5])^inputEndpoints^: " -Path $jsonFile + Add-Content -Value "$($indents[5])[" -Path $jsonFile + + #region Add Endpoints... + $EndPointAdded = $false + foreach ( $endpoint in $newVM.EndPoints) + { + if ( $EndPointAdded ) + { + Add-Content -Value "$($indents[6])," -Path $jsonFile + } + Add-Content -Value "$($indents[6]){" -Path $jsonFile + Add-Content -Value "$($indents[7])^enableDirectServerReturn^: ^False^," -Path $jsonFile + Add-Content -Value "$($indents[7])^endpointName^: ^$($endpoint.Name)^," -Path $jsonFile + Add-Content -Value "$($indents[7])^privatePort^: $($endpoint.LocalPort)," -Path $jsonFile + Add-Content -Value "$($indents[7])^publicPort^: $($endpoint.PublicPort)," -Path $jsonFile + Add-Content -Value "$($indents[7])^protocol^: ^$($endpoint.Protocol)^" -Path $jsonFile + Add-Content -Value "$($indents[6])}" -Path $jsonFile + LogMsg "Added input endpoint Name:$($endpoint.Name) PublicPort:$($endpoint.PublicPort) PrivatePort:$($endpoint.LocalPort) Protocol:$($endpoint.Protocol)." + $EndPointAdded = $true + } + #endregion + + Add-Content -Value "$($indents[5])]" -Path $jsonFile + #> + + Add-Content -Value "$($indents[4])}" -Path $jsonFile + #endregion + LogMsg "Added Network Profile." + + + #region Enable boot dignostics. + Add-Content -Value "$($indents[4])," -Path $jsonFile + Add-Content -Value "$($indents[4])^diagnosticsProfile^: " -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + Add-Content -Value "$($indents[5])^bootDiagnostics^: " -Path $jsonFile + Add-Content -Value "$($indents[5]){" -Path $jsonFile + Add-Content -Value "$($indents[6])^enabled^: true," -Path $jsonFile + Add-Content -Value "$($indents[6])^storageUri^: ^[reference(resourceId('$diagnosticRG', 'Microsoft.Storage/storageAccounts', '$bootDiagnosticsSA'), '2015-06-15').primaryEndpoints['blob']]^" -Path $jsonFile + Add-Content -Value "$($indents[5])}" -Path $jsonFile + Add-Content -Value "$($indents[4])}" -Path $jsonFile + LogMsg "Added Diagnostics Profile." + #endregion + + + Add-Content -Value "$($indents[3])}" -Path $jsonFile + + #endregion + LogMsg "Added Virtual Machine $vmName" + Add-Content -Value "$($indents[2])}" -Path $jsonFile + #endregion + + #region Extensions +if ( $CurrentTestData.ProvisionTimeExtensions) +{ + foreach ( $extension in $CurrentTestData.ProvisionTimeExtensions.Split(",") ) + { + $extension = $extension.Trim() + foreach ( $newExtn in $extensionXML.Extensions.Extension ) + { + if ($newExtn.Name -eq $extension) + { + Add-Content -Value "$($indents[2])," -Path $jsonFile + Add-Content -Value "$($indents[2]){" -Path $jsonFile + Add-Content -Value "$($indents[3])^apiVersion^: ^$apiVersion^," -Path $jsonFile + Add-Content -Value "$($indents[3])^type^: ^Microsoft.Compute/virtualMachines/extensions^," -Path $jsonFile + Add-Content -Value "$($indents[3])^name^: ^$vmName/$extension^," -Path $jsonFile + Add-Content -Value "$($indents[3])^location^: ^[variables('location')]^," -Path $jsonFile + Add-Content -Value "$($indents[3])^dependsOn^: " -Path $jsonFile + Add-Content -Value "$($indents[3])[" -Path $jsonFile + Add-Content -Value "$($indents[4])^[concat('Microsoft.Compute/virtualMachines/', '$vmName')]^" -Path $jsonFile + Add-Content -Value "$($indents[3])]," -Path $jsonFile + + Add-Content -Value "$($indents[3])^properties^:" -Path $jsonFile + Add-Content -Value "$($indents[3]){" -Path $jsonFile + Add-Content -Value "$($indents[4])^publisher^:^$($newExtn.Publisher)^," -Path $jsonFile + Add-Content -Value "$($indents[4])^type^:^$($newExtn.OfficialName)^," -Path $jsonFile + Add-Content -Value "$($indents[4])^typeHandlerVersion^:^$($newExtn.LatestVersion)^" -Path $jsonFile + if ($newExtn.PublicConfiguration) + { + Add-Content -Value "$($indents[4])," -Path $jsonFile + Add-Content -Value "$($indents[4])^settings^:" -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + $isConfigAdded = $false + foreach ($extnConfig in $newExtn.PublicConfiguration.ChildNodes) + { + if ( $isConfigAdded ) + { + Add-Content -Value "$($indents[5])," -Path $jsonFile + } + Add-Content -Value "$($indents[5])^$($extnConfig.Name)^ : ^$($extnConfig.'#text')^" -Path $jsonFile + LogMsg "Added $extension Extension : Public Configuration : $($extnConfig.Name) = $($extnConfig.'#text')" + $isConfigAdded = $true + } + Add-Content -Value "$($indents[4])}" -Path $jsonFile + + } + if ( $newExtn.PrivateConfiguration ) + { + Add-Content -Value "$($indents[4])," -Path $jsonFile + Add-Content -Value "$($indents[4])^protectedSettings^:" -Path $jsonFile + Add-Content -Value "$($indents[4]){" -Path $jsonFile + $isConfigAdded = $false + foreach ($extnConfig in $newExtn.PrivateConfiguration.ChildNodes) + { + if ( $isConfigAdded ) + { + Add-Content -Value "$($indents[5])," -Path $jsonFile + } + if($extnConfig.ChildNodes.Count -eq 1 -and $extnConfig.ChildNodes[0].NodeType -eq 'Text') + { + Add-Content -Value "$($indents[5])^$($extnConfig.Name)^ : ^$($extnConfig.'#text')^" -Path $jsonFile + LogMsg "Added $extension Extension : Private Configuration : $($extnConfig.Name) = $( ( ( $extnConfig.'#text' -replace "\w","*") -replace "\W","*" ) )" + } + else + { + Add-Content -Value "$($indents[5])^$($extnConfig.Name)^ :" -Path $jsonFile + Add-Content -Value "$($indents[6]){" -Path $jsonFile + $index = 0 + foreach($childNode in $extnConfig.ChildNodes) + { + $index++ + if($index -lt $extnConfig.ChildNodes.Count) + { + Add-Content -Value "$($indents[7])^$($childNode.Name)^ : ^$($childNode.'#text')^," -Path $jsonFile + } + if($index -eq $extnConfig.ChildNodes.Count) + { + Add-Content -Value "$($indents[7])^$($childNode.Name)^ : ^$($childNode.'#text')^" -Path $jsonFile + } + } + Add-Content -Value "$($indents[6])}" -Path $jsonFile + } + $isConfigAdded = $true + } + Add-Content -Value "$($indents[4])}" -Path $jsonFile + } + Add-Content -Value "$($indents[3])}" -Path $jsonFile + Add-Content -Value "$($indents[2])}" -Path $jsonFile + } + } + } +} + #endregion extension + + Add-Content -Value "$($indents[1])]" -Path $jsonFile + #endregion +} +Add-Content -Value "$($indents[0])}" -Path $jsonFile +Set-Content -Path $jsonFile -Value (Get-Content $jsonFile).Replace("^",'"') -Force +#endregion + + LogMsg "Template generated successfully." + return $createSetupCommand, $RGName, $vmCount +} + +Function DeployResourceGroups ($xmlConfig, $setupType, $Distro, $getLogsIfFailed = $false, $GetDeploymentStatistics = $false, [string]$region = "", [string]$storageAccount = "") +{ + if( (!$EconomyMode) -or ( $EconomyMode -and ($xmlConfig.config.Azure.Deployment.$setupType.isDeployed -eq "NO"))) + { + try + { + + $VerifiedGroups = $NULL + $retValue = $NULL + #$ExistingGroups = RetryOperation -operation { Get-AzureRmResourceGroup } -description "Getting information of existing resource groups.." -retryInterval 5 -maxRetryCount 5 + $i = 0 + $role = 1 + $setupTypeData = $xmlConfig.config.Azure.Deployment.$setupType + #$isAllDeployed = CreateAllResourceGroupDeployments -setupType $setupType -xmlConfig $xmlConfig -Distro $Distro -region $region -storageAccount $storageAccount -DebugRG "ICA-RG-SingleVM-TEST-UQJB-636620979900" + $isAllDeployed = CreateAllResourceGroupDeployments -setupType $setupType -xmlConfig $xmlConfig -Distro $Distro -region $region -storageAccount $storageAccount + $isAllVerified = "False" + $isAllConnected = "False" + #$isAllDeployed = @("True","ICA-RG-IEndpointSingleHS-U1510-8-10-12-34-9","30") + if($isAllDeployed[0] -eq "True") + { + $deployedGroups = $isAllDeployed[1] + $resourceGroupCount = $isAllDeployed[2] + $DeploymentElapsedTime = $isAllDeployed[3] + $GroupsToVerify = $deployedGroups.Split('^') + #if ( $GetDeploymentStatistics ) + #{ + # $VMBooTime = GetVMBootTime -DeployedGroups $deployedGroups -TimeoutInSeconds 1800 + # $verifyAll = VerifyAllDeployments -GroupsToVerify $GroupsToVerify -GetVMProvisionTime $GetDeploymentStatistics + # $isAllVerified = $verifyAll[0] + # $VMProvisionTime = $verifyAll[1] + #} + #else + #{ + # $isAllVerified = VerifyAllDeployments -GroupsToVerify $GroupsToVerify + #} + #if ($isAllVerified -eq "True") + #{ + $allVMData = GetAllDeployementData -ResourceGroups $deployedGroups + Set-Variable -Name allVMData -Value $allVMData -Force -Scope Global + $isAllConnected = isAllSSHPortsEnabledRG -AllVMDataObject $allVMData + if ($isAllConnected -eq "True") + { + $VerifiedGroups = $deployedGroups + $retValue = $VerifiedGroups + #$vnetIsAllConfigured = $false + $xmlConfig.config.Azure.Deployment.$setupType.isDeployed = $retValue + #Collecting Initial Kernel + if ( Test-Path -Path .\Extras\UploadDeploymentDataToDB.ps1 ) + { + $out = .\Extras\UploadDeploymentDataToDB.ps1 -allVMData $allVMData -DeploymentTime $DeploymentElapsedTime.TotalSeconds + } + $KernelLogOutput= GetAndCheckKernelLogs -allDeployedVMs $allVMData -status "Initial" + } + else + { + LogErr "Unable to connect Some/All SSH ports.." + $retValue = $NULL + } + #} + #else + #{ + # Write-Host "Provision Failed for one or more VMs" + # $retValue = $NULL + #} + + } + else + { + LogErr "One or More Deployments are Failed..!" + $retValue = $NULL + } + # get the logs of the first provision-failed VM + #if ($retValue -eq $NULL -and $getLogsIfFailed -and $DebugOsImage) + #{ + # foreach ($service in $GroupsToVerify) + # { + # $VMs = Get-AzureVM -ServiceName $service + # foreach ($vm in $VMs) + # { + # if ($vm.InstanceStatus -ne "ReadyRole" ) + # { + # $out = GetLogsFromProvisionFailedVM -vmName $vm.Name -serviceName $service -xmlConfig $xmlConfig + # return $NULL + # } + # } + # } + #} + } + catch + { + LogMsg "Exception detected. Source : DeployVMs()" + $line = $_.InvocationInfo.ScriptLineNumber + $script_name = ($_.InvocationInfo.ScriptName).Replace($PWD,".") + $ErrorMessage = $_.Exception.Message + LogErr "EXCEPTION : $ErrorMessage" + LogErr "Source : Line $line in script $script_name." + $retValue = $NULL + } + } + else + { + $retValue = $xmlConfig.config.Azure.Deployment.$setupType.isDeployed + $KernelLogOutput= GetAndCheckKernelLogs -allDeployedVMs $allVMData -status "Initial" + } + if ( $GetDeploymentStatistics ) + { + return $retValue, $DeploymentElapsedTime + } + else + { + return $retValue + } +} + +Function isAllSSHPortsEnabledRG($AllVMDataObject) +{ + LogMsg "Trying to Connect to deployed VM(s)" + $timeout = 0 + do + { + $WaitingForConnect = 0 + foreach ( $vm in $AllVMDataObject) + { + $out = Test-TCP -testIP $($vm.PublicIP) -testport $($vm.SSHPort) + if ($out -ne "True") + { + LogMsg "Connecting to $($vm.PublicIP) : $($vm.SSHPort) : Failed" + $WaitingForConnect = $WaitingForConnect + 1 + } + else + { + LogMsg "Connecting to $($vm.PublicIP) : $($vm.SSHPort) : Connected" + } + } + if($WaitingForConnect -gt 0) + { + $timeout = $timeout + 1 + LogMsg "$WaitingForConnect VM(s) still awaiting to open SSH port.." + LogMsg "Retry $timeout/100" + sleep 3 + $retValue = "False" + } + else + { + LogMsg "ALL VM's SSH port is/are open now.." + $retValue = "True" + } + + } + While (($timeout -lt 100) -and ($WaitingForConnect -gt 0)) + + #Following Code will be enabled once https://github.com/Azure/azure-powershell/issues/4168 issue resolves. + + #if ($retValue -eq "False") + #{ + # foreach ( $vm in $AllVMDataObject) + # { + # $out = Test-TCP -testIP $($vm.PublicIP) -testport $($vm.SSHPort) + # if ($out -ne "True") + # { + # LogMsg "Getting boot diagnostic data from $($vm.RoleName)" + # $bootData = Get-AzureRmVMBootDiagnosticsData -ResourceGroupName $vm.ResourceGroupName -Name $vm.RoleName -Linux + # Set-Content -Value $bootData -Path "$LogDir\$($vm.RoleName)-SSH-Fail-Boot-Logs.txt" + # } + # } + #} + + return $retValue +} + +Function CreateRGDeploymentWithTempParameters([string]$RGName, $TemplateFile, $TemplateParameterFile) +{ + $FailCounter = 0 + $retValue = "False" + $ResourceGroupDeploymentName = $RGName + "-deployment" + While(($retValue -eq $false) -and ($FailCounter -lt 1)) + { + try + { + $FailCounter++ + LogMsg "Creating Deployment using $TemplateFile $TemplateParameterFile..." + $createRGDeployment = New-AzureRmResourceGroupDeployment -Name $ResourceGroupDeploymentName -ResourceGroupName $RGName -TemplateFile $TemplateFile -TemplateParameterFile $TemplateParameterFile -Verbose + $operationStatus = $createRGDeployment.ProvisioningState + if ($operationStatus -eq "Succeeded") + { + LogMsg "Resource Group Deployment Created." + $retValue = $true + } + else + { + LogErr "Failed to create Resource Group Deployment." + $retValue = $false + } + } + catch + { + $retValue = $false + } + } + return $retValue +} + +Function CreateAllRGDeploymentsWithTempParameters($templateName, $location, $TemplateFile, $TemplateParameterFile) +{ + $resourceGroupCount = 0 + $curtime = Get-Date + $isServiceDeployed = "False" + $retryDeployment = 0 + $groupName = "ICA-RG-" + $templateName + "-" + $curtime.Month + "-" + $curtime.Day + "-" + $curtime.Hour + "-" + $curtime.Minute + "-" + $curtime.Second + + while (($isServiceDeployed -eq "False") -and ($retryDeployment -lt 3)) + { + LogMsg "Creating Resource Group : $groupName." + LogMsg "Verifying that Resource group name is not in use." + $isRGDeleted = DeleteResourceGroup -RGName $groupName + if ($isRGDeleted) + { + $isServiceCreated = CreateResourceGroup -RGName $groupName -location $location + if ($isServiceCreated -eq "True") + { + $DeploymentStartTime = (Get-Date) + $CreateRGDeployments = CreateRGDeploymentWithTempParameters -RGName $groupName -location $location -TemplateFile $TemplateFile -TemplateParameterFile $TemplateParameterFile + $DeploymentEndTime = (Get-Date) + $DeploymentElapsedTime = $DeploymentEndTime - $DeploymentStartTime + if ( $CreateRGDeployments ) + { + $retValue = "True" + $isServiceDeployed = "True" + $resourceGroupCount = $resourceGroupCount + 1 + $deployedGroups = $groupName + + } + else + { + LogErr "Unable to Deploy one or more VM's" + $retryDeployment = $retryDeployment + 1 + $retValue = "False" + $isServiceDeployed = "False" + } + } + else + { + LogErr "Unable to create $groupName" + $retryDeployment = $retryDeployment + 1 + $retValue = "False" + $isServiceDeployed = "False" + } + } + else + { + LogErr "Unable to delete existing resource group - $groupName" + $retryDeployment = $retryDeployment + 1 + $retValue = "False" + $isServiceDeployed = "False" + } + } + return $retValue, $deployedGroups, $resourceGroupCount, $DeploymentElapsedTime +} + +Function CopyVHDToAnotherStorageAccount ($sourceStorageAccount,$sourceStorageContainer,$destinationStorageAccount,$destinationStorageContainer,$vhdName,$destVHDName) +{ + $retValue = $false + if (!$destVHDName) + { + $destVHDName = $vhdName + } + $saInfoCollected = $false + $retryCount = 0 + $maxRetryCount = 999 + while(!$saInfoCollected -and ($retryCount -lt $maxRetryCount)) + { + try + { + $retryCount += 1 + LogMsg "[Attempt $retryCount/$maxRetryCount] : Getting Existing Storage Account details ..." + $GetAzureRmStorageAccount = $null + $GetAzureRmStorageAccount = Get-AzureRmStorageAccount + if ($GetAzureRmStorageAccount -eq $null) + { + throw + } + $saInfoCollected = $true + } + catch + { + $saInfoCollected = $false + LogErr "Error in fetching Storage Account info. Retrying in 10 seconds." + sleep -Seconds 10 + } + } + + LogMsg "Retrieving $sourceStorageAccount storage account key" + $SrcStorageAccountKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $(($GetAzureRmStorageAccount | Where {$_.StorageAccountName -eq "$sourceStorageAccount"}).ResourceGroupName) -Name $sourceStorageAccount)[0].Value + [string]$SrcStorageAccount = $sourceStorageAccount + [string]$SrcStorageBlob = $vhdName + $SrcStorageContainer = $sourceStorageContainer + + + LogMsg "Retrieving $destinationStorageAccount storage account key" + $DestAccountKey= (Get-AzureRmStorageAccountKey -ResourceGroupName $(($GetAzureRmStorageAccount | Where {$_.StorageAccountName -eq "$destinationStorageAccount"}).ResourceGroupName) -Name $destinationStorageAccount)[0].Value + [string]$DestAccountName = $destinationStorageAccount + [string]$DestBlob = $destVHDName + $DestContainer = $destinationStorageContainer + + $context = New-AzureStorageContext -StorageAccountName $srcStorageAccount -StorageAccountKey $srcStorageAccountKey + $expireTime = Get-Date + $expireTime = $expireTime.AddYears(1) + $SasUrl = New-AzureStorageBlobSASToken -container $srcStorageContainer -Blob $srcStorageBlob -Permission R -ExpiryTime $expireTime -FullUri -Context $Context + + $destContext = New-AzureStorageContext -StorageAccountName $destAccountName -StorageAccountKey $destAccountKey + $testContainer = Get-AzureStorageContainer -Name $destContainer -Context $destContext -ErrorAction Ignore + if ($testContainer -eq $null) + { + $out = New-AzureStorageContainer -Name $destContainer -context $destContext + } + # Start the Copy + LogMsg "Copy $vhdName --> $($destContext.StorageAccountName) : Running" + $out = Start-AzureStorageBlobCopy -AbsoluteUri $SasUrl -DestContainer $destContainer -DestContext $destContext -DestBlob $destBlob -Force + # + # Monitor replication status + # + $CopyingInProgress = $true + while($CopyingInProgress) + { + $CopyingInProgress = $false + $status = Get-AzureStorageBlobCopyState -Container $destContainer -Blob $destBlob -Context $destContext + if ($status.Status -ne "Success") + { + $CopyingInProgress = $true + } + else + { + LogMsg "Copy $DestBlob --> $($destContext.StorageAccountName) : Done" + $retValue = $true + + } + if ($CopyingInProgress) + { + $copyPercentage = [math]::Round( $(($status.BytesCopied * 100 / $status.TotalBytes)) , 2 ) + LogMsg "Bytes Copied:$($status.BytesCopied), Total Bytes:$($status.TotalBytes) [ $copyPercentage % ]" + Sleep -Seconds 10 + } + } + return $retValue +} + +Function SetResourceGroupLock ([string]$ResourceGroup, [string]$LockNote, [string]$LockName="ReproVM", $LockType = "CanNotDelete") +{ + $parameterErrors = 0 + if ($LockNote -eq $null) + { + LogErr "You did not provide -LockNote . Please give a valid note." + $parameterErrors += 1 + } + if ($ResourceGroup -eq $null) + { + LogErr "You did not provide -ResourceGroup .." + $parameterErrors += 1 + } + if ($parameterErrors -eq 0) + { + LogMsg "Adding '$LockName' lock to '$ResourceGroup'" + $lock = Set-AzureRmResourceLock -LockName $LockName -LockLevel $LockType -LockNotes $LockNote -Force -ResourceGroupName $ResourceGroup + if ( $lock.Properties.level -eq $LockType) + { + LogMsg ">>>$ResourceGroup LOCKED<<<." + } + else + { + LogErr "Something went wrong. Please try again." + } + } + else + { + LogMsg "Fix the paremeters and try again." + } +} \ No newline at end of file diff --git a/Libraries/CommonFunctions.psm1 b/Libraries/CommonFunctions.psm1 index de94f24b6..be477805e 100644 --- a/Libraries/CommonFunctions.psm1 +++ b/Libraries/CommonFunctions.psm1 @@ -7,6 +7,7 @@ Function ThrowException($Exception) Write-Host "SOURCE : Line $line in script $script_name." Throw "Calling function - $($MyInvocation.MyCommand)" } + function LogVerbose () { param @@ -63,15 +64,13 @@ function LogMsg() } } -Function LogErr +Function LogErr { param ( [string]$text ) - { - LogError ($text) - } + LogError $text } Function LogWarn() @@ -116,4 +115,2505 @@ Function ValiateXMLs( [string]$ParentFolder ) $xmlErrorFiles | ForEach-Object -Process {LogMsg $_} Throw "Please fix above ($($xmlErrorFiles.Count)) XML files." } +} + +Function ProvisionVMsForLisa($allVMData, $installPackagesOnRoleNames) +{ + $scriptUrl = "https://raw.githubusercontent.com/iamshital/lis-test/master/WS2012R2/lisa/remote-scripts/ica/provisionLinuxForLisa.sh" + $sshPrivateKeyPath = ".\ssh\myPrivateKey.key" + $sshPrivateKey = "myPrivateKey.key" + LogMsg "Downloading $scriptUrl ..." + $scriptName = $scriptUrl.Split("/")[$scriptUrl.Split("/").Count-1] + $start_time = Get-Date + $out = Invoke-WebRequest -Uri $scriptUrl -OutFile "$LogDir\$scriptName" + LogMsg "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)" + + $keysGenerated = $false + foreach ( $vmData in $allVMData ) + { + LogMsg "Configuring $($vmData.RoleName) for LISA test..." + RemoteCopy -uploadTo $vmData.PublicIP -port $vmData.SSHPort -files ".\Testscripts\Linux\enableRoot.sh,.\Testscripts\Linux\enablePasswordLessRoot.sh,.\$LogDir\provisionLinuxForLisa.sh" -username $user -password $password -upload + $out = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username $user -password $password -command "chmod +x /home/$user/*.sh" -runAsSudo + $rootPasswordSet = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username $user -password $password -command "/home/$user/enableRoot.sh -password $($password.Replace('"',''))" -runAsSudo + LogMsg $rootPasswordSet + if (( $rootPasswordSet -imatch "ROOT_PASSWRD_SET" ) -and ( $rootPasswordSet -imatch "SSHD_RESTART_SUCCESSFUL" )) + { + LogMsg "root user enabled for $($vmData.RoleName) and password set to $password" + } + else + { + Throw "Failed to enable root password / starting SSHD service. Please check logs. Aborting test." + } + $out = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username "root" -password $password -command "cp -ar /home/$user/*.sh ." + if ( $keysGenerated ) + { + RemoteCopy -uploadTo $vmData.PublicIP -port $vmData.SSHPort -files ".\$LogDir\sshFix.tar" -username "root" -password $password -upload + $keyCopyOut = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username "root" -password $password -command "./enablePasswordLessRoot.sh" + LogMsg $keyCopyOut + if ( $keyCopyOut -imatch "KEY_COPIED_SUCCESSFULLY" ) + { + $keysGenerated = $true + LogMsg "SSH keys copied to $($vmData.RoleName)" + $md5sumCopy = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username "root" -password $password -command "md5sum .ssh/id_rsa" + if ( $md5sumGen -eq $md5sumCopy ) + { + LogMsg "md5sum check success for .ssh/id_rsa." + } + else + { + Throw "md5sum check failed for .ssh/id_rsa. Aborting test." + } + } + else + { + Throw "Error in copying SSH key to $($vmData.RoleName)" + } + } + else + { + $out = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username "root" -password $password -command "rm -rf /root/sshFix*" + $keyGenOut = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username "root" -password $password -command "./enablePasswordLessRoot.sh" + LogMsg $keyGenOut + if ( $keyGenOut -imatch "KEY_GENERATED_SUCCESSFULLY" ) + { + $keysGenerated = $true + LogMsg "SSH keys generated in $($vmData.RoleName)" + RemoteCopy -download -downloadFrom $vmData.PublicIP -port $vmData.SSHPort -files "/root/sshFix.tar" -username "root" -password $password -downloadTo $LogDir + $md5sumGen = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username "root" -password $password -command "md5sum .ssh/id_rsa" + } + else + { + Throw "Error in generating SSH key in $($vmData.RoleName)" + } + } + + } + + $packageInstallJobs = @() + foreach ( $vmData in $allVMData ) + { + if ( $installPackagesOnRoleNames ) + { + if ( $installPackagesOnRoleNames -imatch $vmData.RoleName ) + { + LogMsg "Executing $scriptName ..." + $jobID = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username "root" -password $password -command "/root/$scriptName" -RunInBackground + $packageInstallObj = New-Object PSObject + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name ID -Value $jobID + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name RoleName -Value $vmData.RoleName + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name PublicIP -Value $vmData.PublicIP + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name SSHPort -Value $vmData.SSHPort + $packageInstallJobs += $packageInstallObj + #endregion + } + else + { + LogMsg "$($vmData.RoleName) is set to NOT install packages. Hence skipping package installation on this VM." + } + } + else + { + LogMsg "Executing $scriptName ..." + $jobID = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username "root" -password $password -command "/root/$scriptName" -RunInBackground + $packageInstallObj = New-Object PSObject + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name ID -Value $jobID + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name RoleName -Value $vmData.RoleName + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name PublicIP -Value $vmData.PublicIP + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name SSHPort -Value $vmData.SSHPort + $packageInstallJobs += $packageInstallObj + #endregion + } + } + + $packageInstallJobsRunning = $true + while ($packageInstallJobsRunning) + { + $packageInstallJobsRunning = $false + foreach ( $job in $packageInstallJobs ) + { + if ( (Get-Job -Id $($job.ID)).State -eq "Running" ) + { + $currentStatus = RunLinuxCmd -ip $job.PublicIP -port $job.SSHPort -username "root" -password $password -command "tail -n 1 /root/provisionLinux.log" + LogMsg "Package Installation Status for $($job.RoleName) : $currentStatus" + $packageInstallJobsRunning = $true + } + else + { + RemoteCopy -download -downloadFrom $job.PublicIP -port $job.SSHPort -files "/root/provisionLinux.log" -username "root" -password $password -downloadTo $LogDir + Rename-Item -Path "$LogDir\provisionLinux.log" -NewName "$($job.RoleName)-provisionLinux.log" -Force | Out-Null + } + } + if ( $packageInstallJobsRunning ) + { + WaitFor -seconds 10 + } + } +} + +function InstallCustomKernel ($customKernel, $allVMData, [switch]$RestartAfterUpgrade) +{ + try + { + $currentKernelVersion = "" + $upgradedKernelVersion = "" + $customKernel = $customKernel.Trim() + if( ($customKernel -ne "linuxnext") -and ($customKernel -ne "netnext") -and ($customKernel -ne "proposed") -and ($customKernel -ne "latest") -and !($customKernel.EndsWith(".deb")) -and !($customKernel.EndsWith(".rpm")) ) + { + LogErr "Only linuxnext, netnext, proposed, latest are supported. E.g. -customKernel linuxnext/netnext/proposed. Or use -customKernel , -customKernel " + } + else + { + $scriptName = "customKernelInstall.sh" + $jobCount = 0 + $kernelSuccess = 0 + $packageInstallJobs = @() + foreach ( $vmData in $allVMData ) + { + RemoteCopy -uploadTo $vmData.PublicIP -port $vmData.SSHPort -files ".\Testscripts\Linux\$scriptName,.\Testscripts\Linux\DetectLinuxDistro.sh" -username $user -password $password -upload + if ( $customKernel.StartsWith("localfile:")) + { + $customKernelFilePath = $customKernel.Replace('localfile:','') + RemoteCopy -uploadTo $vmData.PublicIP -port $vmData.SSHPort -files ".\$customKernelFilePath" -username $user -password $password -upload + } + RemoteCopy -uploadTo $vmData.PublicIP -port $vmData.SSHPort -files ".\Testscripts\Linux\$scriptName,.\Testscripts\Linux\DetectLinuxDistro.sh" -username $user -password $password -upload + + $out = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username $user -password $password -command "chmod +x *.sh" -runAsSudo + $currentKernelVersion = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username $user -password $password -command "uname -r" + LogMsg "Executing $scriptName ..." + $jobID = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username $user -password $password -command "/home/$user/$scriptName -customKernel $customKernel -logFolder /home/$user" -RunInBackground -runAsSudo + $packageInstallObj = New-Object PSObject + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name ID -Value $jobID + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name RoleName -Value $vmData.RoleName + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name PublicIP -Value $vmData.PublicIP + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name SSHPort -Value $vmData.SSHPort + $packageInstallJobs += $packageInstallObj + $jobCount += 1 + #endregion + } + + $packageInstallJobsRunning = $true + while ($packageInstallJobsRunning) + { + $packageInstallJobsRunning = $false + foreach ( $job in $packageInstallJobs ) + { + if ( (Get-Job -Id $($job.ID)).State -eq "Running" ) + { + $currentStatus = RunLinuxCmd -ip $job.PublicIP -port $job.SSHPort -username $user -password $password -command "tail -n 1 build-customKernel.txt" + LogMsg "Package Installation Status for $($job.RoleName) : $currentStatus" + $packageInstallJobsRunning = $true + } + else + { + if ( !(Test-Path -Path "$LogDir\$($job.RoleName)-build-customKernel.txt" ) ) + { + RemoteCopy -download -downloadFrom $job.PublicIP -port $job.SSHPort -files "build-customKernel.txt" -username $user -password $password -downloadTo $LogDir + if ( ( Get-Content "$LogDir\build-customKernel.txt" ) -imatch "CUSTOM_KERNEL_SUCCESS" ) + { + $kernelSuccess += 1 + } + Rename-Item -Path "$LogDir\build-customKernel.txt" -NewName "$($job.RoleName)-build-customKernel.txt" -Force | Out-Null + } + } + } + if ( $packageInstallJobsRunning ) + { + WaitFor -seconds 10 + } + } + if ( $kernelSuccess -eq $jobCount ) + { + LogMsg "Kernel upgraded to `"$customKernel`" successfully in $($allVMData.Count) VM(s)." + if ( $RestartAfterUpgrade ) + { + LogMsg "Now restarting VMs..." + $restartStatus = RestartAllDeployments -allVMData $allVMData + if ( $restartStatus -eq "True") + { + $retryAttempts = 5 + $isKernelUpgraded = $false + while ( !$isKernelUpgraded -and ($retryAttempts -gt 0) ) + { + $retryAttempts -= 1 + $upgradedKernelVersion = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username $user -password $password -command "uname -r" + LogMsg "Old kernel: $currentKernelVersion" + LogMsg "New kernel: $upgradedKernelVersion" + if ($currentKernelVersion -eq $upgradedKernelVersion) + { + LogErr "Kernel version is same after restarting VMs." + if ($customKernel -eq "latest") + { + LogMsg "Continuing the tests as default kernel is latest." + $isKernelUpgraded = $true + } + else + { + $isKernelUpgraded = $false + } + } + else + { + $isKernelUpgraded = $true + } + Add-Content -Value "Old kernel: $currentKernelVersion" -Path .\report\AdditionalInfo.html -Force + Add-Content -Value "New kernel: $upgradedKernelVersion" -Path .\report\AdditionalInfo.html -Force + return $isKernelUpgraded + } + } + else + { + return $false + } + } + return $true + } + else + { + LogErr "Kernel upgrade failed in $($jobCount-$kernelSuccess) VMs." + return $false + } + } + } + catch + { + LogErr "Exception in InstallCustomKernel." + return $false + } +} + +function InstallcustomLIS ($customLIS, $customLISBranch, $allVMData, [switch]$RestartAfterUpgrade) +{ + try + { + $customLIS = $customLIS.Trim() + if( ($customLIS -ne "lisnext") -and !($customLIS.EndsWith("tar.gz"))) + { + LogErr "Only lisnext and *.tar.gz links are supported. Use -customLIS lisnext -LISbranch . Or use -customLIS " + } + else + { + ProvisionVMsForLisa -allVMData $allVMData -installPackagesOnRoleNames none + $scriptName = "customLISInstall.sh" + $jobCount = 0 + $lisSuccess = 0 + $packageInstallJobs = @() + foreach ( $vmData in $allVMData ) + { + RemoteCopy -uploadTo $vmData.PublicIP -port $vmData.SSHPort -files ".\Testscripts\Linux\$scriptName,.\Testscripts\Linux\DetectLinuxDistro.sh" -username "root" -password $password -upload + $out = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username "root" -password $password -command "chmod +x *.sh" -runAsSudo + $currentlisVersion = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username "root" -password $password -command "modinfo hv_vmbus" + LogMsg "Executing $scriptName ..." + $jobID = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username "root" -password $password -command "/root/$scriptName -customLIS $customLIS -LISbranch $customLISBranch" -RunInBackground -runAsSudo + $packageInstallObj = New-Object PSObject + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name ID -Value $jobID + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name RoleName -Value $vmData.RoleName + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name PublicIP -Value $vmData.PublicIP + Add-member -InputObject $packageInstallObj -MemberType NoteProperty -Name SSHPort -Value $vmData.SSHPort + $packageInstallJobs += $packageInstallObj + $jobCount += 1 + #endregion + } + + $packageInstallJobsRunning = $true + while ($packageInstallJobsRunning) + { + $packageInstallJobsRunning = $false + foreach ( $job in $packageInstallJobs ) + { + if ( (Get-Job -Id $($job.ID)).State -eq "Running" ) + { + $currentStatus = RunLinuxCmd -ip $job.PublicIP -port $job.SSHPort -username "root" -password $password -command "tail -n 1 build-customLIS.txt" + LogMsg "Package Installation Status for $($job.RoleName) : $currentStatus" + $packageInstallJobsRunning = $true + } + else + { + if ( !(Test-Path -Path "$LogDir\$($job.RoleName)-build-customLIS.txt" ) ) + { + RemoteCopy -download -downloadFrom $job.PublicIP -port $job.SSHPort -files "build-customLIS.txt" -username "root" -password $password -downloadTo $LogDir + if ( ( Get-Content "$LogDir\build-customLIS.txt" ) -imatch "CUSTOM_LIS_SUCCESS" ) + { + $lisSuccess += 1 + } + Rename-Item -Path "$LogDir\build-customLIS.txt" -NewName "$($job.RoleName)-build-customLIS.txt" -Force | Out-Null + } + } + } + if ( $packageInstallJobsRunning ) + { + WaitFor -seconds 10 + } + } + + if ( $lisSuccess -eq $jobCount ) + { + LogMsg "lis upgraded to `"$customLIS`" successfully in all VMs." + if ( $RestartAfterUpgrade ) + { + LogMsg "Now restarting VMs..." + $restartStatus = RestartAllDeployments -allVMData $allVMData + if ( $restartStatus -eq "True") + { + $upgradedlisVersion = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username "root" -password $password -command "modinfo hv_vmbus" + LogMsg "Old lis: $currentlisVersion" + LogMsg "New lis: $upgradedlisVersion" + Add-Content -Value "Old lis: $currentlisVersion" -Path .\report\AdditionalInfo.html -Force + Add-Content -Value "New lis: $upgradedlisVersion" -Path .\report\AdditionalInfo.html -Force + return $true + } + else + { + return $false + } + } + return $true + } + else + { + LogErr "lis upgrade failed in $($jobCount-$lisSuccess) VMs." + return $false + } + } + } + catch + { + LogErr "Exception in InstallcustomLIS." + return $false + } +} + +function VerifyMellanoxAdapter($vmData) +{ + $maxRetryAttemps = 50 + $retryAttempts = 1 + $mellanoxAdapterDetected = $false + while ( !$mellanoxAdapterDetected -and ($retryAttempts -lt $maxRetryAttemps)) + { + $pciDevices = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username $user -password $password -command "lspci" -runAsSudo + if ( $pciDevices -imatch "Mellanox") + { + LogMsg "[Attempt $retryAttempts/$maxRetryAttemps] Mellanox Adapter detected in $($vmData.RoleName)." + $mellanoxAdapterDetected = $true + } + else + { + LogErr "[Attempt $retryAttempts/$maxRetryAttemps] Mellanox Adapter NOT detected in $($vmData.RoleName)." + $retryAttempts += 1 + } + } + return $mellanoxAdapterDetected +} + +function EnableSRIOVInAllVMs($allVMData) +{ + try + { + if( $EnableAcceleratedNetworking) + { + $scriptName = "ConfigureSRIOV.sh" + $jobCount = 0 + $kernelSuccess = 0 + $packageInstallJobs = @() + $sriovDetectedCount = 0 + $vmCount = 0 + + foreach ( $vmData in $allVMData ) + { + $vmCount += 1 + $currentMellanoxStatus = VerifyMellanoxAdapter -vmData $vmData + if ( $currentMellanoxStatus ) + { + LogMsg "Mellanox Adapter detected in $($vmData.RoleName)." + RemoteCopy -uploadTo $vmData.PublicIP -port $vmData.SSHPort -files ".\Testscripts\Linux\$scriptName" -username $user -password $password -upload + $out = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username $user -password $password -command "chmod +x *.sh" -runAsSudo + $sriovOutput = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username $user -password $password -command "/home/$user/$scriptName" -runAsSudo + $sriovDetectedCount += 1 + } + else + { + LogErr "Mellanox Adapter not detected in $($vmData.RoleName)." + } + #endregion + } + + if ($sriovDetectedCount -gt 0) + { + if ($sriovOutput -imatch "SYSTEM_RESTART_REQUIRED") + { + LogMsg "Updated SRIOV configuration. Now restarting VMs..." + $restartStatus = RestartAllDeployments -allVMData $allVMData + } + if ($sriovOutput -imatch "DATAPATH_SWITCHED_TO_VF") + { + $restartStatus="True" + } + } + $vmCount = 0 + $bondSuccess = 0 + $bondError = 0 + if ( $restartStatus -eq "True") + { + foreach ( $vmData in $allVMData ) + { + $vmCount += 1 + if ($sriovOutput -imatch "DATAPATH_SWITCHED_TO_VF") + { + $AfterIfConfigStatus = $null + $AfterIfConfigStatus = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username $user -password $password -command "dmesg" -runMaxAllowedTime 30 -runAsSudo + if ($AfterIfConfigStatus -imatch "Data path switched to VF") + { + LogMsg "Data path already switched to VF in $($vmData.RoleName)" + $bondSuccess += 1 + } + else + { + LogErr "Data path not switched to VF in $($vmData.RoleName)" + $bondError += 1 + } + } + else + { + $AfterIfConfigStatus = $null + $AfterIfConfigStatus = RunLinuxCmd -ip $vmData.PublicIP -port $vmData.SSHPort -username $user -password $password -command "/sbin/ifconfig -a" -runAsSudo + if ($AfterIfConfigStatus -imatch "bond") + { + LogMsg "New bond detected in $($vmData.RoleName)" + $bondSuccess += 1 + } + else + { + LogErr "New bond not detected in $($vmData.RoleName)" + $bondError += 1 + } + } + } + } + else + { + return $false + } + if ($vmCount -eq $bondSuccess) + { + return $true + } + else + { + return $false + } + } + else + { + return $true + } + } + catch + { + $line = $_.InvocationInfo.ScriptLineNumber + $script_name = ($_.InvocationInfo.ScriptName).Replace($PWD,".") + $ErrorMessage = $_.Exception.Message + LogErr "EXCEPTION : $ErrorMessage" + LogErr "Source : Line $line in script $script_name." + return $false + } +} + +Function DetectLinuxDistro($VIP, $SSHport, $testVMUser, $testVMPassword) +{ + if ( !$detectedDistro ) + { + $tempout = RemoteCopy -upload -uploadTo $VIP -port $SSHport -files ".\Testscripts\Linux\DetectLinuxDistro.sh" -username $testVMUser -password $testVMPassword 2>&1 | Out-Null + $tempout = RunLinuxCmd -username $testVMUser -password $testVMPassword -ip $VIP -port $SSHport -command "chmod +x *.sh" -runAsSudo 2>&1 | Out-Null + $DistroName = RunLinuxCmd -username $testVMUser -password $testVMPassword -ip $VIP -port $SSHport -command "/home/$user/DetectLinuxDistro.sh" -runAsSudo + if(($DistroName -imatch "Unknown") -or (!$DistroName)) + { + LogError "Linux distro detected : $DistroName" + Throw "Calling function - $($MyInvocation.MyCommand). Unable to detect distro." + } + else + { + if ($DistroName -imatch "UBUNTU") + { + $CleanedDistroName = "UBUNTU" + } + elseif ($DistroName -imatch "DEBIAN") + { + $CleanedDistroName = "DEBIAN" + } + elseif ($DistroName -imatch "CENTOS") + { + $CleanedDistroName = "CENTOS" + } + elseif ($DistroName -imatch "SLES") + { + $CleanedDistroName = "SLES" + } + elseif ($DistroName -imatch "SUSE") + { + $CleanedDistroName = "SUSE" + } + elseif ($DistroName -imatch "ORACLELINUX") + { + $CleanedDistroName = "ORACLELINUX" + } + elseif ($DistroName -imatch "REDHAT") + { + $CleanedDistroName = "REDHAT" + } + elseif ($DistroName -imatch "FEDORA") + { + $CleanedDistroName = "FEDORA" + } + elseif ($DistroName -imatch "COREOS") + { + $CleanedDistroName = "COREOS" + } + elseif ($DistroName -imatch "CLEARLINUX") + { + $CleanedDistroName = "CLEARLINUX" + } + else + { + $CleanedDistroName = "UNKNOWN" + } + Set-Variable -Name detectedDistro -Value $CleanedDistroName -Scope Global + SetDistroSpecificVariables -detectedDistro $detectedDistro + LogMsg "Linux distro detected : $CleanedDistroName" + } + } + else + { + LogMsg "Distro Already Detected as : $detectedDistro" + $CleanedDistroName = $detectedDistro + } + return $CleanedDistroName +} + +Function WaitFor($seconds,$minutes,$hours) +{ + if(!$hours -and !$minutes -and !$seconds) + { + Write-Host "Come on.. Mention at least one second bro ;-)" + } + else + { + if(!$hours) + { + $hours = 0 + } + if(!$minutes) + { + $minutes = 0 + } + if(!$seconds) + { + $seconds = 0 + } + + $timeToSleepInSeconds = ($hours*60*60) + ($minutes*60) + $seconds + $secondsRemaining = $timeToSleepInSeconds + $secondsRemainingPercentage = (100 - (($secondsRemaining/$timeToSleepInSeconds)*100)) + for ($i = 1; $i -le $timeToSleepInSeconds; $i++) + { + write-progress -Id 27 -activity SLEEPING -Status "$($secondsRemaining) seconds remaining..." -percentcomplete $secondsRemainingPercentage + $secondsRemaining = $timeToSleepInSeconds - $i + $secondsRemainingPercentage = (100 - (($secondsRemaining/$timeToSleepInSeconds)*100)) + sleep -Seconds 1 + } + write-progress -Id 27 -activity SLEEPING -Status "Wait Completed..!" -Completed + } + +} + +Function GetAndCheckKernelLogs($allDeployedVMs, $status, $vmUser, $vmPassword) +{ + try + { + if ( !$vmUser ) + { + $vmUser = $user + } + if ( !$vmPassword ) + { + $vmPassword = $password + } + $retValue = $false + foreach ($VM in $allDeployedVMs) + { + $BootLogDir="$Logdir\$($VM.RoleName)" + mkdir $BootLogDir -Force | Out-Null + LogMsg "Collecting $($VM.RoleName) VM Kernel $status Logs.." + $InitailBootLog="$BootLogDir\InitialBootLogs.txt" + $FinalBootLog="$BootLogDir\FinalBootLogs.txt" + $KernelLogStatus="$BootLogDir\KernelLogStatus.txt" + if($status -imatch "Initial") + { + $randomFileName = [System.IO.Path]::GetRandomFileName() + Set-Content -Value "A Random file." -Path "$Logdir\$randomFileName" + $out = RemoteCopy -uploadTo $VM.PublicIP -port $VM.SSHPort -files "$Logdir\$randomFileName" -username $vmUser -password $vmPassword -upload + Remove-Item -Path "$Logdir\$randomFileName" -Force + $out = RunLinuxCmd -ip $VM.PublicIP -port $VM.SSHPort -username $vmUser -password $vmPassword -command "dmesg > /home/$vmUser/InitialBootLogs.txt" -runAsSudo + $out = RemoteCopy -download -downloadFrom $VM.PublicIP -port $VM.SSHPort -files "/home/$vmUser/InitialBootLogs.txt" -downloadTo $BootLogDir -username $vmUser -password $vmPassword + LogMsg "$($VM.RoleName): $status Kernel logs collected ..SUCCESSFULLY" + LogMsg "Checking for call traces in kernel logs.." + $KernelLogs = Get-Content $InitailBootLog + $callTraceFound = $false + foreach ( $line in $KernelLogs ) + { + if (( $line -imatch "Call Trace" ) -and ($line -inotmatch "initcall ")) + { + LogError $line + $callTraceFound = $true + } + if ( $callTraceFound ) + { + if ( $line -imatch "\[<") + { + LogError $line + } + } + } + if ( !$callTraceFound ) + { + LogMsg "No any call traces found." + } + $detectedDistro = DetectLinuxDistro -VIP $VM.PublicIP -SSHport $VM.SSHPort -testVMUser $vmUser -testVMPassword $vmPassword + SetDistroSpecificVariables -detectedDistro $detectedDistro + $retValue = $true + } + elseif($status -imatch "Final") + { + $out = RunLinuxCmd -ip $VM.PublicIP -port $VM.SSHPort -username $vmUser -password $vmPassword -command "dmesg > /home/$vmUser/FinalBootLogs.txt" -runAsSudo + $out = RemoteCopy -download -downloadFrom $VM.PublicIP -port $VM.SSHPort -files "/home/$vmUser/FinalBootLogs.txt" -downloadTo $BootLogDir -username $vmUser -password $vmPassword + LogMsg "Checking for call traces in kernel logs.." + $KernelLogs = Get-Content $FinalBootLog + $callTraceFound = $false + foreach ( $line in $KernelLogs ) + { + if (( $line -imatch "Call Trace" ) -and ($line -inotmatch "initcall ")) + { + LogError $line + $callTraceFound = $true + } + if ( $callTraceFound ) + { + if ( $line -imatch "\[<") + { + LogError $line + } + } + } + if ( !$callTraceFound ) + { + LogMsg "No any call traces found." + } + $KernelDiff = Compare-Object -ReferenceObject (Get-Content $FinalBootLog) -DifferenceObject (Get-Content $InitailBootLog) + #Removing final dmesg file from logs to reduce the size of logs. We can alwayas see complete Final Logs as : Initial Kernel Logs + Difference in Kernel Logs + Remove-Item -Path $FinalBootLog -Force | Out-Null + if($KernelDiff -eq $null) + { + LogMsg "** Initial and Final Kernel Logs has same content **" + Set-Content -Value "*** Initial and Final Kernel Logs has same content ***" -Path $KernelLogStatus + $retValue = $true + } + else + { + $errorCount = 0 + Set-Content -Value "Following lines were added in the kernel log during execution of test." -Path $KernelLogStatus + LogMsg "Following lines were added in the kernel log during execution of test." + Add-Content -Value "-------------------------------START----------------------------------" -Path $KernelLogStatus + foreach ($line in $KernelDiff) + { + Add-Content -Value $line.InputObject -Path $KernelLogStatus + if ( ($line.InputObject -imatch "fail") -or ($line.InputObject -imatch "error") -or ($line.InputObject -imatch "warning")) + { + $errorCount += 1 + LogError $line.InputObject + } + else + { + LogMsg $line.InputObject + } + } + Add-Content -Value "--------------------------------EOF-----------------------------------" -Path $KernelLogStatus + } + LogMsg "$($VM.RoleName): $status Kernel logs collected and Compared ..SUCCESSFULLY" + if ($errorCount -gt 0) + { + LogError "Found $errorCount fail/error/warning messages in kernel logs during execution." + $retValue = $false + } + if ( $callTraceFound ) + { + if ( $UseAzureResourceManager ) + { + LogMsg "Preserving the Resource Group(s) $($VM.ResourceGroupName)" + LogMsg "Setting tags : $preserveKeyword = yes; testName = $testName" + $hash = @{} + $hash.Add($preserveKeyword,"yes") + $hash.Add("testName","$testName") + $out = Set-AzureRmResourceGroup -Name $($VM.ResourceGroupName) -Tag $hash + LogMsg "Setting tags : calltrace = yes; testName = $testName" + $hash = @{} + $hash.Add("calltrace","yes") + $hash.Add("testName","$testName") + $out = Set-AzureRmResourceGroup -Name $($VM.ResourceGroupName) -Tag $hash + } + else + { + LogMsg "Adding preserve tag to $($VM.ServiceName) .." + $out = Set-AzureService -ServiceName $($VM.ServiceName) -Description $preserveKeyword + } + } + } + else + { + LogMsg "pass value for status variable either final or initial" + $retValue = $false + } + } + } + catch + { + $retValue = $false + } + return $retValue +} + +Function CheckKernelLogs($allVMData, $vmUser, $vmPassword) +{ + try + { + $errorLines = @() + $errorLines += "Call Trace" + $errorLines += "rcu_sched self-detected stall on CPU" + $errorLines += "rcu_sched detected stalls on" + $errorLines += "BUG: soft lockup" + $totalErrors = 0 + if ( !$vmUser ) + { + $vmUser = $user + } + if ( !$vmPassword ) + { + $vmPassword = $password + } + $retValue = $false + foreach ($VM in $allVMData) + { + $vmErrors = 0 + $BootLogDir="$Logdir\$($VM.RoleName)" + mkdir $BootLogDir -Force | Out-Null + LogMsg "Collecting $($VM.RoleName) VM Kernel $status Logs.." + $currentKernelLogFile="$BootLogDir\CurrentKernelLogs.txt" + $out = RunLinuxCmd -ip $VM.PublicIP -port $VM.SSHPort -username $vmUser -password $vmPassword -command "dmesg > /home/$vmUser/CurrentKernelLogs.txt" -runAsSudo + $out = RemoteCopy -download -downloadFrom $VM.PublicIP -port $VM.SSHPort -files "/home/$vmUser/CurrentKernelLogs.txt" -downloadTo $BootLogDir -username $vmUser -password $vmPassword + LogMsg "$($VM.RoleName): $status Kernel logs collected ..SUCCESSFULLY" + foreach ($errorLine in $errorLines) + { + LogMsg "Checking for $errorLine in kernel logs.." + $KernelLogs = Get-Content $currentKernelLogFile + $callTraceFound = $false + foreach ( $line in $KernelLogs ) + { + if ( ($line -imatch "$errorLine") -and ($line -inotmatch "initcall ")) + { + LogError $line + $totalErrors += 1 + $vmErrors += 1 + } + if ( $line -imatch "\[<") + { + LogError $line + } + } + } + if ( $vmErrors -eq 0 ) + { + LogMsg "$($VM.RoleName) : No issues in kernel logs." + $retValue = $true + } + else + { + LogError "$($VM.RoleName) : $vmErrors errors found." + $retValue = $false + } + } + if ( $totalErrors -eq 0 ) + { + $retValue = $true + } + else + { + $retValue = $false + } + } + catch + { + $retValue = $false + } + return $retValue +} + +Function SetDistroSpecificVariables($detectedDistro) +{ + $python_cmd = "python" + LogMsg "Set `$python_cmd > $python_cmd" + Set-Variable -Name python_cmd -Value $python_cmd -Scope Global + Set-Variable -Name ifconfig_cmd -Value "ifconfig" -Scope Global + if(($detectedDistro -eq "SLES") -or ($detectedDistro -eq "SUSE")) + { + Set-Variable -Name ifconfig_cmd -Value "/sbin/ifconfig" -Scope Global + Set-Variable -Name fdisk -Value "/sbin/fdisk" -Scope Global + LogMsg "Set `$ifconfig_cmd > $ifconfig_cmd for $detectedDistro" + LogMsg "Set `$fdisk > /sbin/fdisk for $detectedDistro" + } + else + { + Set-Variable -Name fdisk -Value "fdisk" -Scope Global + LogMsg "Set `$fdisk > fdisk for $detectedDistro" + } +} + +Function DeployVMs ($xmlConfig, $setupType, $Distro, $getLogsIfFailed = $false, $GetDeploymentStatistics = $false, [string]$region = "", [string]$storageAccount = "", [int]$timeOutSeconds = 600) +{ + $AzureSetup = $xmlConfig.config.Azure.General + + if ($UseAzureResourceManager) + { + if($storageAccount) + { + LogMsg "CurrentStorageAccount : $($storageAccount)" + } + $retValue = DeployResourceGroups -xmlConfig $xmlConfig -setupType $setupType -Distro $Distro -getLogsIfFailed $getLogsIfFailed -GetDeploymentStatistics $GetDeploymentStatistics -region $region -storageAccount $storageAccount + } + else + { + if($storageAccount) + { + LogMsg "CurrentStorageAccount : $($storageAccount)" + } + $retValue = DeployManagementServices -xmlConfig $xmlConfig -setupType $setupType -Distro $Distro -getLogsIfFailed $getLogsIfFailed -GetDeploymentStatistics $GetDeploymentStatistics -region $region -storageAccount $storageAccount -timeOutSeconds $timeOutSeconds + } + if ( $retValue -and $customKernel) + { + LogMsg "Custom kernel: $customKernel will be installed on all machines..." + $kernelUpgradeStatus = InstallCustomKernel -customKernel $customKernel -allVMData $allVMData -RestartAfterUpgrade + if ( !$kernelUpgradeStatus ) + { + LogError "Custom Kernel: $customKernel installation FAIL. Aborting tests." + $retValue = "" + } + } + if ( $retValue -and $customLIS) + { + LogMsg "Custom LIS: $customLIS will be installed on all machines..." + $LISUpgradeStatus = InstallCustomLIS -customLIS $customLIS -allVMData $allVMData -customLISBranch $customLISBranch -RestartAfterUpgrade + if ( !$LISUpgradeStatus ) + { + LogError "Custom Kernel: $customKernel installation FAIL. Aborting tests." + $retValue = "" + } + } + if ( $retValue -and $EnableAcceleratedNetworking) + { + $SRIOVStatus = EnableSRIOVInAllVMs -allVMData $allVMData + if ( !$SRIOVStatus) + { + LogError "Failed to enable Accelerated Networking. Aborting tests." + $retValue = "" + } + } + + + + if ( $retValue -and $resizeVMsAfterDeployment) + { + $SRIOVStatus = EnableSRIOVInAllVMs -allVMData $allVMData + if ( $SRIOVStatus -ne "True" ) + { + LogError "Failed to enable Accelerated Networking. Aborting tests." + $retValue = "" + } + } + return $retValue +} + +Function Test-TCP($testIP, $testport) +{ + $socket = new-object Net.Sockets.TcpClient + $isConnected = "False" + try + { + $socket.Connect($testIP, $testPort) + } + catch [System.Net.Sockets.SocketException] + { + } + if ($socket.Connected) + { + $isConnected = "True" + } + $socket.Close() + return $isConnected +} + +Function RemoteCopy($uploadTo, $downloadFrom, $downloadTo, $port, $files, $username, $password, [switch]$upload, [switch]$download, [switch]$usePrivateKey, [switch]$doNotCompress) #Removed XML config +{ + $retry=1 + $maxRetry=20 + if($upload) + { +#LogMsg "Uploading the files" + if ($files) + { + $fileCounter = 0 + $tarFileName = ($uploadTo+"@"+$port).Replace(".","-")+".tar" + foreach ($f in $files.Split(",")) + { + if ( !$f ) + { + continue + } + else + { + if ( ( $f.Split(".")[$f.Split(".").count-1] -eq "sh" ) -or ( $f.Split(".")[$f.Split(".").count-1] -eq "py" ) ) + { + $out = .\tools\dos2unix.exe $f 2>&1 + LogMsg $out + } + $fileCounter ++ + } + } + if (($fileCounter -gt 2) -and (!($doNotCompress))) + { + $tarFileName = ($uploadTo+"@"+$port).Replace(".","-")+".tar" + foreach ($f in $files.Split(",")) + { + if ( !$f ) + { + continue + } + else + { + LogMsg "Compressing $f and adding to $tarFileName" + $CompressFile = .\tools\7za.exe a $tarFileName $f + if ( $CompressFile -imatch "Everything is Ok" ) + { + $CompressCount += 1 + } + } + } + if ( $CompressCount -eq $fileCounter ) + { + $retry=1 + $maxRetry=10 + while($retry -le $maxRetry) + { + if($usePrivateKey) + { + LogMsg "Uploading $tarFileName to $username : $uploadTo, port $port using PrivateKey authentication" + echo y | .\tools\pscp -i .\ssh\$sshKey -q -P $port $tarFileName $username@${uploadTo}: + $returnCode = $LASTEXITCODE + } + else + { + LogMsg "Uploading $tarFileName to $username : $uploadTo, port $port using Password authentication" + $curDir = $PWD + $uploadStatusRandomFile = "UploadStatusFile" + (Get-Random -Maximum 9999 -Minimum 1111) + ".txt" + $uploadStartTime = Get-Date + $uploadJob = Start-Job -ScriptBlock { cd $args[0]; Write-Host $args; Set-Content -Value "1" -Path $args[6]; $username = $args[4]; $uploadTo = $args[5]; echo y | .\tools\pscp -v -pw $args[1] -q -P $args[2] $args[3] $username@${uploadTo}: ; Set-Content -Value $LASTEXITCODE -Path $args[6];} -ArgumentList $curDir,$password,$port,$tarFileName,$username,${uploadTo},$uploadStatusRandomFile + sleep -Milliseconds 100 + $uploadJobStatus = Get-Job -Id $uploadJob.Id + $uploadTimout = $false + while (( $uploadJobStatus.State -eq "Running" ) -and ( !$uploadTimout )) + { + Write-Host "." -NoNewline + $now = Get-Date + if ( ($now - $uploadStartTime).TotalSeconds -gt 600 ) + { + $uploadTimout = $true + LogError "Upload Timout!" + } + sleep -Seconds 1 + $uploadJobStatus = Get-Job -Id $uploadJob.Id + } + Write-Host "" + $returnCode = Get-Content -Path $uploadStatusRandomFile + Remove-Item -Force $uploadStatusRandomFile | Out-Null + Remove-Job -Id $uploadJob.Id -Force | Out-Null + } + if(($returnCode -ne 0) -and ($retry -ne $maxRetry)) + { + LogWarn "Error in upload, Attempt $retry. Retrying for upload" + $retry=$retry+1 + WaitFor -seconds 10 + } + elseif(($returnCode -ne 0) -and ($retry -eq $maxRetry)) + { + Write-Host "Error in upload after $retry Attempt,Hence giving up" + $retry=$retry+1 + Throw "Calling function - $($MyInvocation.MyCommand). Error in upload after $retry Attempt,Hence giving up" + } + elseif($returnCode -eq 0) + { + LogMsg "Upload Success after $retry Attempt" + $retry=$maxRetry+1 + } + } + LogMsg "Removing compressed file : $tarFileName" + Remove-Item -Path $tarFileName -Force 2>&1 | Out-Null + LogMsg "Decompressing files in VM ..." + if ( $username -eq "root" ) + { + $out = RunLinuxCmd -username $username -password $password -ip $uploadTo -port $port -command "tar -xf $tarFileName" + } + else + { + $out = RunLinuxCmd -username $username -password $password -ip $uploadTo -port $port -command "tar -xf $tarFileName" -runAsSudo + } + + } + else + { + Throw "Calling function - $($MyInvocation.MyCommand). Failed to compress $files" + Remove-Item -Path $tarFileName -Force 2>&1 | Out-Null + } + } + else + { + $files = $files.split(",") + foreach ($f in $files) + { + if ( !$f ) + { + continue + } + $retry=1 + $maxRetry=10 + $testFile = $f.trim() + $recurse = "" + while($retry -le $maxRetry) + { + if($usePrivateKey) + { + LogMsg "Uploading $testFile to $username : $uploadTo, port $port using PrivateKey authentication" + echo y | .\tools\pscp -i .\ssh\$sshKey -q -P $port $testFile $username@${uploadTo}: + $returnCode = $LASTEXITCODE + } + else + { + LogMsg "Uploading $testFile to $username : $uploadTo, port $port using Password authentication" + $curDir = $PWD + $uploadStatusRandomFile = "UploadStatusFile" + (Get-Random -Maximum 9999 -Minimum 1111) + ".txt" + $uploadStartTime = Get-Date + $uploadJob = Start-Job -ScriptBlock { cd $args[0]; Write-Host $args; Set-Content -Value "1" -Path $args[6]; $username = $args[4]; $uploadTo = $args[5]; echo y | .\tools\pscp -v -pw $args[1] -q -P $args[2] $args[3] $username@${uploadTo}: ; Set-Content -Value $LASTEXITCODE -Path $args[6];} -ArgumentList $curDir,$password,$port,$testFile,$username,${uploadTo},$uploadStatusRandomFile + sleep -Milliseconds 100 + $uploadJobStatus = Get-Job -Id $uploadJob.Id + $uploadTimout = $false + while (( $uploadJobStatus.State -eq "Running" ) -and ( !$uploadTimout )) + { + Write-Host "." -NoNewline + $now = Get-Date + if ( ($now - $uploadStartTime).TotalSeconds -gt 600 ) + { + $uploadTimout = $true + LogError "Upload Timout!" + } + sleep -Seconds 1 + $uploadJobStatus = Get-Job -Id $uploadJob.Id + } + Write-Host "" + $returnCode = Get-Content -Path $uploadStatusRandomFile + Remove-Item -Force $uploadStatusRandomFile | Out-Null + Remove-Job -Id $uploadJob.Id -Force | Out-Null + } + if(($returnCode -ne 0) -and ($retry -ne $maxRetry)) + { + LogWarn "Error in upload, Attempt $retry. Retrying for upload" + $retry=$retry+1 + WaitFor -seconds 10 + } + elseif(($returnCode -ne 0) -and ($retry -eq $maxRetry)) + { + Write-Host "Error in upload after $retry Attempt,Hence giving up" + $retry=$retry+1 + Throw "Calling function - $($MyInvocation.MyCommand). Error in upload after $retry Attempt,Hence giving up" + } + elseif($returnCode -eq 0) + { + LogMsg "Upload Success after $retry Attempt" + $retry=$maxRetry+1 + } + } + } + } + } + else + { + LogMsg "No Files to upload...!" + Throw "Calling function - $($MyInvocation.MyCommand). No Files to upload...!" + } + + } + elseif($download) + { +#Downloading the files + if ($files) + { + $files = $files.split(",") + foreach ($f in $files) + { + $retry=1 + $maxRetry=50 + $testFile = $f.trim() + $recurse = "" + while($retry -le $maxRetry) + { + if($usePrivateKey) + { + LogMsg "Downloading $testFile from $username : $downloadFrom,port $port to $downloadTo using PrivateKey authentication" + $curDir = $PWD + $downloadStatusRandomFile = "DownloadStatusFile" + (Get-Random -Maximum 9999 -Minimum 1111) + ".txt" + $downloadStartTime = Get-Date + $downloadJob = Start-Job -ScriptBlock { $curDir=$args[0];$sshKey=$args[1];$port=$args[2];$testFile=$args[3];$username=$args[4];${downloadFrom}=$args[5];$downloadTo=$args[6];$downloadStatusRandomFile=$args[7]; cd $curDir; Set-Content -Value "1" -Path $args[6]; echo y | .\tools\pscp -i .\ssh\$sshKey -q -P $port $username@${downloadFrom}:$testFile $downloadTo; Set-Content -Value $LASTEXITCODE -Path $downloadStatusRandomFile;} -ArgumentList $curDir,$sshKey,$port,$testFile,$username,${downloadFrom},$downloadTo,$downloadStatusRandomFile + sleep -Milliseconds 100 + $downloadJobStatus = Get-Job -Id $downloadJob.Id + $downloadTimout = $false + while (( $downloadJobStatus.State -eq "Running" ) -and ( !$downloadTimout )) + { + Write-Host "." -NoNewline + $now = Get-Date + if ( ($now - $downloadStartTime).TotalSeconds -gt 600 ) + { + $downloadTimout = $true + LogError "Download Timout!" + } + sleep -Seconds 1 + $downloadJobStatus = Get-Job -Id $downloadJob.Id + } + Write-Host "" + $returnCode = Get-Content -Path $downloadStatusRandomFile + Remove-Item -Force $downloadStatusRandomFile | Out-Null + Remove-Job -Id $downloadJob.Id -Force | Out-Null + } + else + { + LogMsg "Downloading $testFile from $username : $downloadFrom,port $port to $downloadTo using Password authentication" + $curDir = (Get-Item -Path ".\" -Verbose).FullName + $downloadStatusRandomFile = "DownloadStatusFile" + (Get-Random -Maximum 9999 -Minimum 1111) + ".txt" + Set-Content -Value "1" -Path $downloadStatusRandomFile; + $downloadStartTime = Get-Date + $downloadJob = Start-Job -ScriptBlock { + $curDir=$args[0]; + $password=$args[1]; + $port=$args[2]; + $testFile=$args[3]; + $username=$args[4]; + ${downloadFrom}=$args[5]; + $downloadTo=$args[6]; + $downloadStatusRandomFile=$args[7]; + cd $curDir; + echo y | .\tools\pscp.exe -v -2 -unsafe -pw $password -q -P $port $username@${downloadFrom}:$testFile $downloadTo 2> $downloadStatusRandomFile; + Add-Content -Value "DownloadExtiCode_$LASTEXITCODE" -Path $downloadStatusRandomFile; + } -ArgumentList $curDir,$password,$port,$testFile,$username,${downloadFrom},$downloadTo,$downloadStatusRandomFile + sleep -Milliseconds 100 + $downloadJobStatus = Get-Job -Id $downloadJob.Id + $downloadTimout = $false + while (( $downloadJobStatus.State -eq "Running" ) -and ( !$downloadTimout )) + { + Write-Host "." -NoNewline + $now = Get-Date + if ( ($now - $downloadStartTime).TotalSeconds -gt 600 ) + { + $downloadTimout = $true + LogError "Download Timout!" + } + sleep -Seconds 1 + $downloadJobStatus = Get-Job -Id $downloadJob.Id + } + Write-Host "" + $downloadExitCode = (Select-String -Path $downloadStatusRandomFile -Pattern "DownloadExtiCode_").Line + if ( $downloadExitCode ) + { + $returnCode = $downloadExitCode.Replace("DownloadExtiCode_",'') + } + if ( $returnCode -eq 0) + { + LogMsg "Download command returned exit code 0" + } + else + { + $receivedFiles = Select-String -Path "$downloadStatusRandomFile" -Pattern "Sending file" + if ($receivedFiles.Count -ge 1) + { + LogMsg "Received $($receivedFiles.Count) file(s)" + $returnCode = 0 + } + else + { + LogMsg "Download command returned exit code $returnCode" + LogMsg "$(Get-Content -Path $downloadStatusRandomFile)" + } + } + Remove-Item -Force $downloadStatusRandomFile | Out-Null + Remove-Job -Id $downloadJob.Id -Force | Out-Null + } + if(($returnCode -ne 0) -and ($retry -ne $maxRetry)) + { + LogWarn "Error in download, Attempt $retry. Retrying for download" + $retry=$retry+1 + } + elseif(($returnCode -ne 0) -and ($retry -eq $maxRetry)) + { + Write-Host "Error in download after $retry Attempt,Hence giving up" + $retry=$retry+1 + Throw "Calling function - $($MyInvocation.MyCommand). Error in download after $retry Attempt,Hence giving up." + } + elseif($returnCode -eq 0) + { + LogMsg "Download Success after $retry Attempt" + $retry=$maxRetry+1 + } + } + } + } + else + { + LogMsg "No Files to download...!" + Throw "Calling function - $($MyInvocation.MyCommand). No Files to download...!" + } + } + else + { + LogMsg "Error: Upload/Download switch is not used!" + } +} + +Function WrapperCommandsToFile([string] $username,[string] $password,[string] $ip,[string] $command, [int] $port) +{ + if ( ( $lastLinuxCmd -eq $command) -and ($lastIP -eq $ip) -and ($lastPort -eq $port) -and ($lastUser -eq $username) ) + { + #Skip upload if current command is same as last command. + } + else + { + Set-Variable -Name lastLinuxCmd -Value $command -Scope Global + Set-Variable -Name lastIP -Value $ip -Scope Global + Set-Variable -Name lastPort -Value $port -Scope Global + Set-Variable -Name lastUser -Value $username -Scope Global + $command | out-file -encoding ASCII -filepath "$LogDir\runtest.sh" + RemoteCopy -upload -uploadTo $ip -username $username -port $port -password $password -files ".\$LogDir\runtest.sh" + del "$LogDir\runtest.sh" + } +} + +Function RunLinuxCmd([string] $username,[string] $password,[string] $ip,[string] $command, [int] $port, [switch]$runAsSudo, [Boolean]$WriteHostOnly, [Boolean]$NoLogsPlease, [switch]$ignoreLinuxExitCode, [int]$runMaxAllowedTime = 300, [switch]$RunInBackGround) +{ + if ($detectedDistro -ne "COREOS" ) + { + WrapperCommandsToFile $username $password $ip $command $port + } + $randomFileName = [System.IO.Path]::GetRandomFileName() + $maxRetryCount = 20 + $currentDir = $PWD.Path + $RunStartTime = Get-Date + + if($runAsSudo) + { + $plainTextPassword = $password.Replace('"',''); + if ( $detectedDistro -eq "COREOS" ) + { + $linuxCommand = "`"export PATH=/usr/share/oem/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/oem/bin:/opt/bin && echo $plainTextPassword | sudo -S env `"PATH=`$PATH`" $command && echo AZURE-LINUX-EXIT-CODE-`$? || echo AZURE-LINUX-EXIT-CODE-`$?`"" + $logCommand = "`"export PATH=/usr/share/oem/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/oem/bin:/opt/bin && echo $plainTextPassword | sudo -S env `"PATH=`$PATH`" $command`"" + } + else + { + + $linuxCommand = "`"echo $plainTextPassword | sudo -S bash -c `'bash runtest.sh ; echo AZURE-LINUX-EXIT-CODE-`$?`' `"" + $logCommand = "`"echo $plainTextPassword | sudo -S $command`"" + } + } + else + { + if ( $detectedDistro -eq "COREOS" ) + { + $linuxCommand = "`"export PATH=/usr/share/oem/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/oem/bin:/opt/bin && $command && echo AZURE-LINUX-EXIT-CODE-`$? || echo AZURE-LINUX-EXIT-CODE-`$?`"" + $logCommand = "`"export PATH=/usr/share/oem/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/oem/bin:/opt/bin && $command`"" + } + else + { + $linuxCommand = "`"bash -c `'bash runtest.sh ; echo AZURE-LINUX-EXIT-CODE-`$?`' `"" + $logCommand = "`"$command`"" + } + } + LogMsg ".\tools\plink.exe -t -pw $password -P $port $username@$ip $logCommand" + $returnCode = 1 + $attemptswt = 0 + $attemptswot = 0 + $notExceededTimeLimit = $true + $isBackGroundProcessStarted = $false + + while ( ($returnCode -ne 0) -and ($attemptswt -lt $maxRetryCount -or $attemptswot -lt $maxRetryCount) -and $notExceededTimeLimit) + { + if ($runwithoutt -or $attemptswt -eq $maxRetryCount) + { + Set-Variable -Name runwithoutt -Value true -Scope Global + $attemptswot +=1 + $runLinuxCmdJob = Start-Job -ScriptBlock ` + { ` + $username = $args[1]; $password = $args[2]; $ip = $args[3]; $port = $args[4]; $jcommand = $args[5]; ` + cd $args[0]; ` + #Write-Host ".\tools\plink.exe -t -C -v -pw $password -P $port $username@$ip $jcommand";` + .\tools\plink.exe -C -v -pw $password -P $port $username@$ip $jcommand;` + } ` + -ArgumentList $currentDir, $username, $password, $ip, $port, $linuxCommand + } + else + { + $attemptswt += 1 + $runLinuxCmdJob = Start-Job -ScriptBlock ` + { ` + $username = $args[1]; $password = $args[2]; $ip = $args[3]; $port = $args[4]; $jcommand = $args[5]; ` + cd $args[0]; ` + #Write-Host ".\tools\plink.exe -t -C -v -pw $password -P $port $username@$ip $jcommand";` + .\tools\plink.exe -t -C -v -pw $password -P $port $username@$ip $jcommand;` + } ` + -ArgumentList $currentDir, $username, $password, $ip, $port, $linuxCommand + } + $RunLinuxCmdOutput = "" + $debugOutput = "" + $LinuxExitCode = "" + if ( $RunInBackGround ) + { + While(($runLinuxCmdJob.State -eq "Running") -and ($isBackGroundProcessStarted -eq $false ) -and $notExceededTimeLimit) + { + $SSHOut = Receive-Job $runLinuxCmdJob 2> $LogDir\$randomFileName + $JobOut = Get-Content $LogDir\$randomFileName + if($jobOut) + { + foreach($outLine in $jobOut) + { + if($outLine -imatch "Started a shell") + { + $LinuxExitCode = $outLine + $isBackGroundProcessStarted = $true + $returnCode = 0 + } + else + { + $RunLinuxCmdOutput += "$outLine`n" + } + } + } + $debugLines = Get-Content $LogDir\$randomFileName + if($debugLines) + { + $debugString = "" + foreach ($line in $debugLines) + { + $debugString += $line + } + $debugOutput += "$debugString`n" + } + Write-Progress -Activity "Attempt : $attemptswot+$attemptswt : Initiating command in Background Mode : $logCommand on $ip : $port" -Status "Timeout in $($RunMaxAllowedTime - $RunElaplsedTime) seconds.." -Id 87678 -PercentComplete (($RunElaplsedTime/$RunMaxAllowedTime)*100) -CurrentOperation "SSH ACTIVITY : $debugString" + #Write-Host "Attempt : $attemptswot+$attemptswt : Initiating command in Background Mode : $logCommand on $ip : $port" + $RunCurrentTime = Get-Date + $RunDiffTime = $RunCurrentTime - $RunStartTime + $RunElaplsedTime = $RunDiffTime.TotalSeconds + if($RunElaplsedTime -le $RunMaxAllowedTime) + { + $notExceededTimeLimit = $true + } + else + { + $notExceededTimeLimit = $false + Stop-Job $runLinuxCmdJob + $timeOut = $true + } + } + WaitFor -seconds 2 + $SSHOut = Receive-Job $runLinuxCmdJob 2> $LogDir\$randomFileName + if($SSHOut ) + { + foreach ($outLine in $SSHOut) + { + if($outLine -imatch "AZURE-LINUX-EXIT-CODE-") + { + $LinuxExitCode = $outLine + $isBackGroundProcessTerminated = $true + } + else + { + $RunLinuxCmdOutput += "$outLine`n" + } + } + } + + $debugLines = Get-Content $LogDir\$randomFileName + if($debugLines) + { + $debugString = "" + foreach ($line in $debugLines) + { + $debugString += $line + } + $debugOutput += "$debugString`n" + } + Write-Progress -Activity "Attempt : $attemptswot+$attemptswt : Executing $logCommand on $ip : $port" -Status $runLinuxCmdJob.State -Id 87678 -SecondsRemaining ($RunMaxAllowedTime - $RunElaplsedTime) -Completed + if ( $isBackGroundProcessStarted -and !$isBackGroundProcessTerminated ) + { + LogMsg "$command is running in background with ID $($runLinuxCmdJob.Id) ..." + Add-Content -Path $LogDir\CurrentTestBackgroundJobs.txt -Value $runLinuxCmdJob.Id + $retValue = $runLinuxCmdJob.Id + } + else + { + Remove-Job $runLinuxCmdJob + if (!$isBackGroundProcessStarted) + { + LogError "Failed to start process in background.." + } + if ( $isBackGroundProcessTerminated ) + { + LogError "Background Process terminated from Linux side with error code : $($LinuxExitCode.Split("-")[4])" + $returnCode = $($LinuxExitCode.Split("-")[4]) + LogError $SSHOut + } + if($debugOutput -imatch "Unable to authenticate") + { + LogMsg "Unable to authenticate. Not retrying!" + Throw "Calling function - $($MyInvocation.MyCommand). Unable to authenticate" + + } + if($timeOut) + { + $retValue = "" + Throw "Calling function - $($MyInvocation.MyCommand). Tmeout while executing command : $command" + } + LogError "Linux machine returned exit code : $($LinuxExitCode.Split("-")[4])" + if ($attempts -eq $maxRetryCount) + { + Throw "Calling function - $($MyInvocation.MyCommand). Failed to execute : $command." + } + else + { + if ($notExceededTimeLimit) + { + LogMsg "Failed to execute : $command. Retrying..." + } + } + } + Remove-Item $LogDir\$randomFileName -Force | Out-Null + } + else + { + While($notExceededTimeLimit -and ($runLinuxCmdJob.State -eq "Running")) + { + $jobOut = Receive-Job $runLinuxCmdJob 2> $LogDir\$randomFileName + if($jobOut) + { + foreach ($outLine in $jobOut) + { + if($outLine -imatch "AZURE-LINUX-EXIT-CODE-") + { + $LinuxExitCode = $outLine + } + else + { + $RunLinuxCmdOutput += "$outLine`n" + } + } + } + $debugLines = Get-Content $LogDir\$randomFileName + if($debugLines) + { + $debugString = "" + foreach ($line in $debugLines) + { + $debugString += $line + } + $debugOutput += "$debugString`n" + } + Write-Progress -Activity "Attempt : $attemptswot+$attemptswt : Executing $logCommand on $ip : $port" -Status "Timeout in $($RunMaxAllowedTime - $RunElaplsedTime) seconds.." -Id 87678 -PercentComplete (($RunElaplsedTime/$RunMaxAllowedTime)*100) -CurrentOperation "SSH ACTIVITY : $debugString" + #Write-Host "Attempt : $attemptswot+$attemptswt : Executing $logCommand on $ip : $port" + $RunCurrentTime = Get-Date + $RunDiffTime = $RunCurrentTime - $RunStartTime + $RunElaplsedTime = $RunDiffTime.TotalSeconds + if($RunElaplsedTime -le $RunMaxAllowedTime) + { + $notExceededTimeLimit = $true + } + else + { + $notExceededTimeLimit = $false + Stop-Job $runLinuxCmdJob + $timeOut = $true + } + } + $jobOut = Receive-Job $runLinuxCmdJob 2> $LogDir\$randomFileName + if($jobOut) + { + foreach ($outLine in $jobOut) + { + if($outLine -imatch "AZURE-LINUX-EXIT-CODE-") + { + $LinuxExitCode = $outLine + } + else + { + $RunLinuxCmdOutput += "$outLine`n" + } + } + } + $debugLines = Get-Content $LogDir\$randomFileName + if($debugLines) + { + $debugString = "" + foreach ($line in $debugLines) + { + $debugString += $line + } + $debugOutput += "$debugString`n" + } + Write-Progress -Activity "Attempt : $attemptswot+$attemptswt : Executing $logCommand on $ip : $port" -Status $runLinuxCmdJob.State -Id 87678 -SecondsRemaining ($RunMaxAllowedTime - $RunElaplsedTime) -Completed + #Write-Host "Attempt : $attemptswot+$attemptswt : Executing $logCommand on $ip : $port" + Remove-Job $runLinuxCmdJob + Remove-Item $LogDir\$randomFileName -Force | Out-Null + if ($LinuxExitCode -imatch "AZURE-LINUX-EXIT-CODE-0") + { + $returnCode = 0 + LogMsg "$command executed successfully in $RunElaplsedTime seconds." -WriteHostOnly $WriteHostOnly -NoLogsPlease $NoLogsPlease + $retValue = $RunLinuxCmdOutput.Trim() + } + else + { + if (!$ignoreLinuxExitCode) + { + $debugOutput = ($debugOutput.Split("`n")).Trim() + foreach ($line in $debugOutput) + { + if($line) + { + LogError $line + } + } + } + if($debugOutput -imatch "Unable to authenticate") + { + LogMsg "Unable to authenticate. Not retrying!" + Throw "Calling function - $($MyInvocation.MyCommand). Unable to authenticate" + + } + if(!$ignoreLinuxExitCode) + { + if($timeOut) + { + $retValue = "" + LogError "Tmeout while executing command : $command" + } + LogError "Linux machine returned exit code : $($LinuxExitCode.Split("-")[4])" + if ($attemptswt -eq $maxRetryCount -and $attemptswot -eq $maxRetryCount) + { + Throw "Calling function - $($MyInvocation.MyCommand). Failed to execute : $command." + } + else + { + if ($notExceededTimeLimit) + { + LogError "Failed to execute : $command. Retrying..." + } + } + } + else + { + LogMsg "Command execution returned return code $($LinuxExitCode.Split("-")[4]) Ignoring.." + $retValue = $RunLinuxCmdOutput.Trim() + break + } + } + } + } + return $retValue +} +#endregion + +#region Test Case Logging +Function DoTestCleanUp($result, $testName, $DeployedServices, $ResourceGroups, [switch]$keepUserDirectory, [switch]$SkipVerifyKernelLogs) +{ + try + { + if($DeployedServices -or $ResourceGroups) + { + try + { + foreach ($vmData in $allVMData) + { + $out = RemoteCopy -upload -uploadTo $vmData.PublicIP -port $vmData.SSHPort -files .\Testscripts\Linux\CollectLogFile.sh -username $user -password $password + $out = RunLinuxCmd -username $user -password $password -ip $vmData.PublicIP -port $vmData.SSHPort -command "bash CollectLogFile.sh" -ignoreLinuxExitCode + $out = RemoteCopy -downloadFrom $vmData.PublicIP -port $vmData.SSHPort -username $user -password $password -files "$($vmData.RoleName)-*.txt" -downloadTo "$LogDir" -download + $finalKernelVersion = Get-Content "$LogDir\$($vmData.RoleName)-kernelVersion.txt" + Set-Variable -Name finalKernelVersion -Value $finalKernelVersion -Scope Global + #region LIS Version + $tempLIS = (Select-String -Path "$LogDir\$($vmData.RoleName)-lis.txt" -Pattern "^version:").Line + if ($tempLIS) + { + $finalLISVersion = $tempLIS.Split(":").Trim()[1] + } + else + { + $finalLISVersion = "NA" + } + Set-Variable -Name finalLISVersion -Value $finalLISVersion -Scope Global + Write-Host "Setting : finalLISVersion : $finalLISVersion" + #endregion + } + } + catch + { + $line = $_.InvocationInfo.ScriptLineNumber + $script_name = ($_.InvocationInfo.ScriptName).Replace($PWD,".") + $ErrorMessage = $_.Exception.Message + LogError "EXCEPTION : $ErrorMessage" + LogError "Source : Line $line in script $script_name." + LogError "Ignorable error in collecting final data from VMs." + } + $currentTestBackgroundJobs = Get-Content $LogDir\CurrentTestBackgroundJobs.txt -ErrorAction SilentlyContinue + if ( $currentTestBackgroundJobs ) + { + $currentTestBackgroundJobs = $currentTestBackgroundJobs.Split() + } + foreach ( $taskID in $currentTestBackgroundJobs ) + { + #Removal of background + LogMsg "Removing Background Job ID : $taskID..." + Remove-Job -Id $taskID -Force + Remove-Item $LogDir\CurrentTestBackgroundJobs.txt -ErrorAction SilentlyContinue + } + $user=$xmlConfig.config.Azure.Deployment.Data.UserName + if ( !$SkipVerifyKernelLogs ) + { + try + { + $KernelLogOutput=GetAndCheckKernelLogs -allDeployedVMs $allVMData -status "Final" #Collecting kernel logs after execution of test case : v-sirebb + } + catch + { + $ErrorMessage = $_.Exception.Message + LogMsg "EXCEPTION in GetAndCheckKernelLogs(): $ErrorMessage" + } + } + $isClened = @() + if ( !$UseAzureResourceManager ) + { + $hsNames = $DeployedServices + $allDeploymentData = $allVMData + $hsNames = $hsNames.Split("^") + $isVMLogsCollected = $false + foreach ($hs in $hsNames) + { + $hsDetails = Get-AzureService -ServiceName $hs + if (!($hsDetails.Description -imatch "DONOTDISTURB")) + { + if($result -eq "PASS") + { + if($EconomyMode -and (-not $IsLastCaseInCycle)) + { + LogMsg "Skipping cleanup of $hs." + if(!$keepUserDirectory) + { + RemoveAllFilesFromHomeDirectory -allDeployedVMs $allVMData + } + } + else + { + if ( $hsDetails.Description -imatch $preserveKeyword ) + { + LogMsg "Skipping cleanup of preserved service." + LogMsg "Collecting VM logs.." + if ( !$isVMLogsCollected ) + { + GetVMLogs -allVMData $allDeploymentData + } + $isVMLogsCollected = $true } + else + { + if ( $keepReproInact ) + { + LogMsg "Skipping cleanup due to 'keepReproInact' flag is set." + } + else + { + LogMsg "Collecting VM logs of PASS test case.." + $out = GetVMLogs -allVMData $allVMData + LogMsg "Cleaning up deployed test virtual machines." + $isClened = DeleteService -serviceName $hsDetails.ServiceName + if ($isClened -contains "False") + { + #LogMsg "CleanUP unsuccessful for $($hsDetails.ServiceName).. Please delete the services manually." + } + else + { + #LogMsg "CleanUP Successful for $($hsDetails.ServiceName).." + } + } + } + } + } + else + { + LogMsg "Preserving the hosted service(s) $hsNames" + LogMsg "Integrating Test Case Name in the `"Description`" of preserved setups.." + $suppressedOut = RetryOperation -operation { RunAzureCmd -AzureCmdlet "Set-AzureService -ServiceName $hs -Description `"Preserving this setup for FAILED/ABORTED test : $testName`"" -maxWaitTimeSeconds 120 } -maxRetryCount 5 -retryInterval 5 + LogMsg "Collecting VM logs.." + if ( !$isVMLogsCollected ) + { + GetVMLogs -allVMData $allDeploymentData + } + $isVMLogsCollected = $true + if(!$keepUserDirectory -and !$keepReproInact -and $EconomyMode) + { + RemoveAllFilesFromHomeDirectory -allDeployedVMs $allVMData + } + if($keepReproInact) + { + $xmlConfig.config.Azure.Deployment.$setupType.isDeployed = "NO" + } + } + } + else + { + if ($result -ne "PASS") + { + LogMsg "Collecting VM logs.." + GetVMLogs -allVMData $allDeploymentData + if($keepReproInact) + { + $xmlConfig.config.Azure.Deployment.$setupType.isDeployed = "NO" + } + } + LogMsg "Skipping cleanup, as service is marked as DO NOT DISTURB.." + } + } + } + else + { + $ResourceGroups = $ResourceGroups.Split("^") + $isVMLogsCollected = $false + foreach ($group in $ResourceGroups) + { + if ($ForceDeleteResources) + { + LogMsg "-ForceDeleteResources is Set. Deleting $group." + $isClened = DeleteResourceGroup -RGName $group + } + else + { + if($result -eq "PASS") + { + if($EconomyMode -and (-not $IsLastCaseInCycle)) + { + 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 + { + 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) + { + RemoveAllFilesFromHomeDirectory -allDeployedVMs $allVMData + } + if($keepReproInact) + { + $xmlConfig.config.Azure.Deployment.$setupType.isDeployed = "NO" + } + } + } + } + } + } + else + { + LogMsg "Skipping cleanup, as No services / resource groups deployed for cleanup!" + } + } + catch + { + $ErrorMessage = $_.Exception.Message + Write-Host "EXCEPTION in DoTestCleanUp : $ErrorMessage" + } +} + +Function GetFinalizedResult($resultArr, $checkValues, $subtestValues, $currentTestData) +{ + $result = "", "" + if (($resultArr -contains "FAIL") -or ($resultArr -contains "Aborted")) { + $result[0] = "FAIL" + } + else{ + $result[0] = "PASS" + } + $i = 0 + $subtestLen = $SubtestValues.Length + while ($i -lt $subtestLen) + { + $currentTestValue = $SubtestValues[$i] + $currentTestResult = $resultArr[$i] + $currentTestName = $currentTestData.testName + if ($checkValues -imatch $currentTestResult) + { + $result[1] += " $currentTestName : $currentTestValue : $currentTestResult
" + } + $i = $i + 1 + } + + return $result +} + +Function CreateResultSummary($testResult, $checkValues, $testName, $metaData) +{ + if ( $metaData ) + { + $resultString = " $testName : $metaData : $testResult
" + } + else + { + $resultString = " $testName : $testResult
" + } + return $resultString +} + +Function GetFinalResultHeader($resultArr){ + if(($resultArr -imatch "FAIL" ) -or ($resultArr -imatch "Aborted")) + { + $result = "FAIL" + if($resultArr -imatch "Aborted") + { + $result = "Aborted" + } + + } + else + { + $result = "PASS" + } + return $result +} + +Function SetStopWatch($str) +{ + $sw = [system.diagnostics.stopwatch]::startNew() + return $sw +} + +Function GetStopWatchElapasedTime([System.Diagnostics.Stopwatch]$sw, [string] $format) +{ + if ($format -eq "ss") + { + $num=$sw.Elapsed.TotalSeconds + } + elseif ($format -eq "hh") + { + $num=$sw.Elapsed.TotalHours + } + elseif ($format -eq "mm") + { + $num=$sw.Elapsed.TotalMinutes + } + return [System.Math]::Round($Num, 2) + +} + +Function GetVMLogs($allVMData) +{ + foreach ($testVM in $allVMData) + { + $testIP = $testVM.PublicIP + $testPort = $testVM.SSHPort + $LisLogFile = "LIS-Logs" + ".tgz" + try + { + LogMsg "Collecting logs from IP : $testIP PORT : $testPort" + RemoteCopy -upload -uploadTo $testIP -username $user -port $testPort -password $password -files '.\Testscripts\Linux\LIS-LogCollector.sh' + RunLinuxCmd -username $user -password $password -ip $testIP -port $testPort -command 'chmod +x LIS-LogCollector.sh' + $out = RunLinuxCmd -username $user -password $password -ip $testIP -port $testPort -command './LIS-LogCollector.sh -v' -runAsSudo + LogMsg $out + RemoteCopy -download -downloadFrom $testIP -username $user -password $password -port $testPort -downloadTo $LogDir -files $LisLogFile + LogMsg "Logs collected successfully from IP : $testIP PORT : $testPort" + Rename-Item -Path "$LogDir\$LisLogFile" -NewName ("LIS-Logs-" + $testVM.RoleName + ".tgz") -Force + } + catch + { + $ErrorMessage = $_.Exception.Message + LogError "EXCEPTION : $ErrorMessage" + LogError "Unable to collect logs from IP : $testIP PORT : $testPort" + } + } +} + +Function RemoveAllFilesFromHomeDirectory($allDeployedVMs) +{ + foreach ($DeployedVM in $allDeployedVMs) + { + $testIP = $DeployedVM.PublicIP + $testPort = $DeployedVM.SSHPort + try + { + LogMsg "Removing all files logs from IP : $testIP PORT : $testPort" + $out = RunLinuxCmd -username $user -password $password -ip $testIP -port $testPort -command 'rm -rf *' -runAsSudo + LogMsg "All files removed from /home/$user successfully. VM IP : $testIP PORT : $testPort" + } + catch + { + $ErrorMessage = $_.Exception.Message + Write-Host "EXCEPTION : $ErrorMessage" + Write-Host "Unable to remove files from IP : $testIP PORT : $testPort" + } + } +} + +Function GetAllDeployementData($DeployedServices, $ResourceGroups) +{ + $allDeployedVMs = @() + function CreateQuickVMNode() + { + $objNode = New-Object -TypeName PSObject + Add-Member -InputObject $objNode -MemberType NoteProperty -Name ServiceName -Value $ServiceName -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name ResourceGroupName -Value $ResourceGroupName -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name Location -Value $ResourceGroupName -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name RoleName -Value $RoleName -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name PublicIP -Value $PublicIP -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name PublicIPv6 -Value $PublicIP -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name InternalIP -Value $InternalIP -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name URL -Value $URL -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name URLv6 -Value $URL -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name Status -Value $Status -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name InstanceSize -Value $InstanceSize -Force + return $objNode + } + + if ( $UseAzureResourceManager ) + { + foreach ($ResourceGroup in $ResourceGroups.Split("^")) + { + LogMsg "Collecting $ResourceGroup data.." + + $allRGResources = (Get-AzureRmResource | where { $_.ResourceGroupName -eq $ResourceGroup } | Select ResourceType).ResourceType + LogMsg " Microsoft.Network/publicIPAddresses data collection in progress.." + $RGIPdata = Get-AzureRmResource -ResourceGroupName $ResourceGroup -ResourceType "Microsoft.Network/publicIPAddresses" -Verbose -ExpandProperties + LogMsg " Microsoft.Compute/virtualMachines data collection in progress.." + $RGVMs = Get-AzureRmResource -ResourceGroupName $ResourceGroup -ResourceType "Microsoft.Compute/virtualMachines" -Verbose -ExpandProperties + LogMsg " Microsoft.Network/networkInterfaces data collection in progress.." + $NICdata = Get-AzureRmResource -ResourceGroupName $ResourceGroup -ResourceType "Microsoft.Network/networkInterfaces" -Verbose -ExpandProperties + $currentRGLocation = (Get-AzureRmResourceGroup -ResourceGroupName $ResourceGroup).Location + $numberOfVMs = 0 + foreach ($testVM in $RGVMs) + { + $numberOfVMs += 1 + } + if ( ($numberOfVMs -gt 1) -or (($RGIPData | where { $_.Properties.publicIPAddressVersion -eq "IPv6" }).Properties.ipAddress) -or ($allRGResources -contains "Microsoft.Network/loadBalancers")) + { + LogMsg " Microsoft.Network/loadBalancers data collection in progress.." + $LBdata = Get-AzureRmResource -ResourceGroupName $ResourceGroup -ResourceType "Microsoft.Network/loadBalancers" -ExpandProperties -Verbose + } + foreach ($testVM in $RGVMs) + { + $QuickVMNode = CreateQuickVMNode + if ( ( $numberOfVMs -gt 1 ) -or (($RGIPData | where { $_.Properties.publicIPAddressVersion -eq "IPv6" }).Properties.ipAddress) -or ($allRGResources -contains "Microsoft.Network/loadBalancers")) + { + $InboundNatRules = $LBdata.Properties.InboundNatRules + foreach ($endPoint in $InboundNatRules) + { + if ( $endPoint.Name -imatch $testVM.ResourceName) + { + $endPointName = "$($endPoint.Name)".Replace("$($testVM.ResourceName)-","") + Add-Member -InputObject $QuickVMNode -MemberType NoteProperty -Name "$($endPointName)Port" -Value $endPoint.Properties.FrontendPort -Force + } + } + $LoadBalancingRules = $LBdata.Properties.LoadBalancingRules + foreach ( $LBrule in $LoadBalancingRules ) + { + if ( $LBrule.Name -imatch "$ResourceGroup-LB-" ) + { + $endPointName = "$($LBrule.Name)".Replace("$ResourceGroup-LB-","") + Add-Member -InputObject $QuickVMNode -MemberType NoteProperty -Name "$($endPointName)Port" -Value $LBrule.Properties.FrontendPort -Force + } + } + $Probes = $LBdata.Properties.Probes + foreach ( $Probe in $Probes ) + { + if ( $Probe.Name -imatch "$ResourceGroup-LB-" ) + { + $probeName = "$($Probe.Name)".Replace("$ResourceGroup-LB-","").Replace("-probe","") + Add-Member -InputObject $QuickVMNode -MemberType NoteProperty -Name "$($probeName)ProbePort" -Value $Probe.Properties.Port -Force + } + } + } + else + { + LogMsg " Microsoft.Network/networkSecurityGroups data collection in progress.." + $SGData = Get-AzureRmResource -ResourceGroupName $ResourceGroup -ResourceName "SG-$($testVM.ResourceName)" -ResourceType "Microsoft.Network/networkSecurityGroups" -ExpandProperties + foreach ($securityRule in $SGData.Properties.securityRules) + { + Add-Member -InputObject $QuickVMNode -MemberType NoteProperty -Name "$($securityRule.name)Port" -Value $securityRule.properties.destinationPortRange -Force + } + if($AllEndpoints.Length -eq 0) + { + $sg = Get-AzureRmNetworkSecurityGroup -ResourceGroupName $testVM.ResourceGroupName -Name "SG-$($testVM.ResourceName)" + foreach($rule in $sg.SecurityRules) + { + Add-Member -InputObject $QuickVMNode -MemberType NoteProperty -Name "$($rule.Name)Port" -Value $rule.DestinationPortRange[0] -Force + if (($rule.Name -imatch "Cleanuptool-22-Corpnet") -and ($QuickVMNode.SSHPort -ne "22")) + { + LogMsg " Cleanuptool-22-Corpnet detected. Applying workaroud." + Add-Member -InputObject $QuickVMNode -MemberType NoteProperty -Name "SSHPort" -Value "22" -Force + } + } + } + } + foreach ( $nic in $NICdata ) + { + if ( $nic.Name -imatch $testVM.ResourceName) + { + $QuickVMNode.InternalIP = "$($nic.Properties.IpConfigurations[0].Properties.PrivateIPAddress)" + } + } + $QuickVMNode.ResourceGroupName = $ResourceGroup + + $QuickVMNode.PublicIP = ($RGIPData | where { $_.Properties.publicIPAddressVersion -eq "IPv4" }).Properties.ipAddress + $QuickVMNode.PublicIPv6 = ($RGIPData | where { $_.Properties.publicIPAddressVersion -eq "IPv6" }).Properties.ipAddress + $QuickVMNode.URL = ($RGIPData | where { $_.Properties.publicIPAddressVersion -eq "IPv4" }).Properties.dnsSettings.fqdn + $QuickVMNode.URLv6 = ($RGIPData | where { $_.Properties.publicIPAddressVersion -eq "IPv6" }).Properties.dnsSettings.fqdn + $QuickVMNode.RoleName = $testVM.ResourceName + $QuickVMNode.Status = $testVM.Properties.ProvisioningState + $QuickVMNode.InstanceSize = $testVM.Properties.hardwareProfile.vmSize + $QuickVMNode.Location = $currentRGLocation + $allDeployedVMs += $QuickVMNode + } + LogMsg "Collected $ResourceGroup data!" + } + } + else + { + $allDeployedVMs = @() + foreach ($hostedservice in $DeployedServices.Split("^")) + { + LogMsg "Collecting $hostedservice data..." + $testServiceData = Get-AzureService -ServiceName $hostedservice + $DeployedVMs = Get-AzureVM -ServiceName $hostedService + foreach ($testVM in $DeployedVMs) + { + $QuickVMNode = CreateQuickVMNode + $AllEndpoints = Get-AzureEndpoint -VM $testVM + $QuickVMNode.ServiceName = $hostedservice + $QuickVMNode.RoleName = $testVM.InstanceName + $QuickVMNode.PublicIP = $AllEndpoints[0].Vip + $QuickVMNode.InternalIP = $testVM.IpAddress + $QuickVMNode.InstanceSize = $testVM.InstanceSize + foreach ($endpoint in $AllEndpoints) + { + Add-Member -InputObject $QuickVMNode -MemberType NoteProperty -Name "$($endpoint.Name)Port" -Value $endpoint.Port -Force + if ( $endpoint.ProbePort ) + { + Add-Member -InputObject $QuickVMNode -MemberType NoteProperty -Name "$($endpoint.Name)ProbePort" -Value $endpoint.ProbePort -Force + } + } + $QuickVMNode.URL = ($testVM.DNSName).Replace("http://","").Replace("/","") + $QuickVMNode.Status = $testVM.InstanceStatus + $allDeployedVMs += $QuickVMNode + } + LogMsg "Collected $hostedservice data!" + } + } + return $allDeployedVMs +} + +Function RestartAllDeployments($allVMData) +{ + $currentGUID = ([guid]::newguid()).Guid + $out = Save-AzureRmContext -Path "$env:TEMP\$($currentGUID).azurecontext" -Force + $restartJobs = @() + foreach ( $vmData in $AllVMData ) + { + if ( $UseAzureResourceManager) + { + LogMsg "Triggering Restart-$($vmData.RoleName)..." + $restartJobs += Start-Job -ScriptBlock { $vmData = $args[0] + $currentGUID = $args[1] + Import-AzureRmContext -AzureContext "$env:TEMP\$($currentGUID).azurecontext" + $restartVM = Restart-AzureRmVM -ResourceGroupName $vmData.ResourceGroupName -Name $vmData.RoleName -Verbose + } -ArgumentList $vmData,$currentGUID -Name "Restart-$($vmData.RoleName)" + } + else + { + $restartVM = Restart-AzureVM -ServiceName $vmData.ServiceName -Name $vmData.RoleName -Verbose + $isRestarted = $? + if ($isRestarted) + { + LogMsg "Restarted : $($vmData.RoleName)" + } + else + { + LogError "FAILED TO RESTART : $($vmData.RoleName)" + $retryCount = $retryCount + 1 + if ($retryCount -gt 0) + { + LogMsg "Retrying..." + } + if ($retryCount -eq 0) + { + Throw "Calling function - $($MyInvocation.MyCommand). Unable to Restart : $($vmData.RoleName)" + } + } + } + } + $recheckAgain = $true + LogMsg "Waiting until VMs restart..." + $jobCount = $restartJobs.Count + $completedJobsCount = 0 + While ($recheckAgain) + { + $recheckAgain = $false + $tempJobs = @() + foreach ($restartJob in $restartJobs) + { + if ($restartJob.State -eq "Completed") + { + $completedJobsCount += 1 + LogMsg "[$completedJobsCount/$jobCount] $($restartJob.Name) is done." + $out = Remove-Job -Id $restartJob.ID -Force -ErrorAction SilentlyContinue + } + else + { + $tempJobs += $restartJob + $recheckAgain = $true + } + } + $restartJobs = $tempJobs + Start-Sleep -Seconds 1 + } + + Remove-Item -Path "$env:TEMP\$($currentGUID).azurecontext" -Force -ErrorAction SilentlyContinue | Out-Null + + $isSSHOpened = isAllSSHPortsEnabledRG -AllVMDataObject $AllVMData + return $isSSHOpened +} + +Function GetTotalPhysicalDisks($FdiskOutput) +{ + $physicalDiskNames = ("sda","sdb","sdc","sdd","sde","sdf","sdg","sdh","sdi","sdj","sdk","sdl","sdm","sdn", + "sdo","sdp","sdq","sdr","sds","sdt","sdu","sdv","sdw","sdx","sdy","sdz", "sdaa", "sdab", "sdac", "sdad","sdae", "sdaf", "sdag", "sdah", "sdai") + $diskCount = 0 + foreach ($physicalDiskName in $physicalDiskNames) + { + if ($FdiskOutput -imatch "Disk /dev/$physicalDiskName") + { + $diskCount += 1 + } + } + return $diskCount +} + +Function GetNewPhysicalDiskNames($FdiskOutputBeforeAddingDisk, $FdiskOutputAfterAddingDisk) +{ + $availableDisksBeforeAddingDisk = "" + $availableDisksAfterAddingDisk = "" + $physicalDiskNames = ("sda","sdb","sdc","sdd","sde","sdf","sdg","sdh","sdi","sdj","sdk","sdl","sdm","sdn", + "sdo","sdp","sdq","sdr","sds","sdt","sdu","sdv","sdw","sdx","sdy","sdz", "sdaa", "sdab", "sdac", "sdad","sdae", "sdaf", "sdag", "sdah", "sdai") + foreach ($physicalDiskName in $physicalDiskNames) + { + if ($FdiskOutputBeforeAddingDisk -imatch "Disk /dev/$physicalDiskName") + { + if ( $availableDisksBeforeAddingDisk -eq "" ) + { + $availableDisksBeforeAddingDisk = "/dev/$physicalDiskName" + } + else + { + $availableDisksBeforeAddingDisk = $availableDisksBeforeAddingDisk + "^" + "/dev/$physicalDiskName" + } + } + } + foreach ($physicalDiskName in $physicalDiskNames) + { + if ($FdiskOutputAfterAddingDisk -imatch "Disk /dev/$physicalDiskName") + { + if ( $availableDisksAfterAddingDisk -eq "" ) + { + $availableDisksAfterAddingDisk = "/dev/$physicalDiskName" + } + else + { + $availableDisksAfterAddingDisk = $availableDisksAfterAddingDisk + "^" + "/dev/$physicalDiskName" + } + } + } + $newDisks = "" + foreach ($afterDisk in $availableDisksAfterAddingDisk.Split("^")) + { + if($availableDisksBeforeAddingDisk -imatch $afterDisk) + { + + } + else + { + if($newDisks -eq "") + { + $newDisks = $afterDisk + } + else + { + $newDisks = $newDisks + "^" + $afterDisk + } + } + } + return $newDisks +} + +Function PerformIOTestOnDisk($testVMObject, [string]$attachedDisk, [string]$diskFileSystem) +{ + $retValue = "Aborted" + $testVMSSHport = $testVMObject.sshPort + $testVMVIP = $testVMObject.ip + $testVMUsername = $testVMObject.user + $testVMPassword = $testVMObject.password + if ( $diskFileSystem -imatch "xfs" ) + { + $diskFileSystem = "xfs -f" + } + $isVMAlive = Test-TCP -testIP $testVMVIP -testport $testVMSSHport + if ($isVMAlive -eq "True") + { + $retValue = "FAIL" + $mountPoint = "/mnt/datadisk" + LogMsg "Performing I/O operations on $attachedDisk.." + $LogPath = "$LogDir\VerifyIO$($attachedDisk.Replace('/','-')).txt" + $dmesgBefore = RunLinuxCmd -username $testVMUsername -password $testVMPassword -ip $testVMVIP -port $testVMSSHport -command "dmesg" -runMaxAllowedTime 30 -runAsSudo + #CREATE A MOUNT DIRECTORY + $out = RunLinuxCmd -username $testVMUsername -password $testVMPassword -ip $testVMVIP -port $testVMSSHport -command "mkdir -p $mountPoint" -runAsSudo + $partitionNumber=1 + $PartitionDiskOut = RunLinuxCmd -username $testVMUsername -password $testVMPassword -ip $testVMVIP -port $testVMSSHport -command "./ManagePartitionOnDisk.sh -diskName $attachedDisk -create yes -forRaid no" -runAsSudo + $FormatDiskOut = RunLinuxCmd -username $testVMUsername -password $testVMPassword -ip $testVMVIP -port $testVMSSHport -command "time mkfs.$diskFileSystem $attachedDisk$partitionNumber" -runAsSudo -runMaxAllowedTime 2400 + $out = RunLinuxCmd -username $testVMUsername -password $testVMPassword -ip $testVMVIP -port $testVMSSHport -command "mount -o nobarrier $attachedDisk$partitionNumber $mountPoint" -runAsSudo + Add-Content -Value $formatDiskOut -Path $LogPath -Force + $ddOut = RunLinuxCmd -username $testVMUsername -password $testVMPassword -ip $testVMVIP -port $testVMSSHport -command "dd if=/dev/zero bs=1024 count=1000000 of=$mountPoint/file_1GB" -runAsSudo -runMaxAllowedTime 1200 + WaitFor -seconds 10 + Add-Content -Value $ddOut -Path $LogPath + try + { + $out = RunLinuxCmd -username $testVMUsername -password $testVMPassword -ip $testVMVIP -port $testVMSSHport -command "umount $mountPoint" -runAsSudo + } + catch + { + LogMsg "umount failed. Trying umount -l" + $out = RunLinuxCmd -username $testVMUsername -password $testVMPassword -ip $testVMVIP -port $testVMSSHport -command "umount -l $mountPoint" -runAsSudo + } + $dmesgAfter = RunLinuxCmd -username $testVMUsername -password $testVMPassword -ip $testVMVIP -port $testVMSSHport -command "dmesg" -runMaxAllowedTime 30 -runAsSudo + $addedLines = $dmesgAfter.Replace($dmesgBefore,$null) + LogMsg "Kernel Logs : $($addedLines.Replace('[32m','').Replace('','').Replace('',''))" -LinuxConsoleOuput + $retValue = "PASS" + } + else + { + LogError "VM is not Alive." + LogError "Aborting Test." + $retValue = "Aborted" + } + return $retValue +} + +Function RetryOperation($operation, $description, $expectResult=$null, $maxRetryCount=10, $retryInterval=10, [switch]$NoLogsPlease) +{ + $retryCount = 1 + + do + { + LogMsg "Attempt : $retryCount/$maxRetryCount : $description" -NoLogsPlease $NoLogsPlease + $ret = $null + $oldErrorActionValue = $ErrorActionPreference + $ErrorActionPreference = "Stop" + + try + { + $ret = Invoke-Command -ScriptBlock $operation + if ($expectResult -ne $null) + { + if ($ret -match $expectResult) + { + return $ret + } + else + { + $ErrorActionPreference = $oldErrorActionValue + $retryCount ++ + WaitFor -seconds $retryInterval + } + } + else + { + return $ret + } + } + catch + { + $retryCount ++ + WaitFor -seconds $retryInterval + if ( $retryCount -le $maxRetryCount ) + { + continue + } + } + finally + { + $ErrorActionPreference = $oldErrorActionValue + } + if ($retryCount -ge $maxRetryCount) + { + LogError "Opearation Failed." + break; + } + } while ($True) + + return $null +} + +Function GetFilePathsFromLinuxFolder ([string]$folderToSearch, $IpAddress, $SSHPort, $username, $password, $maxRetryCount=20, [string]$expectedFiles) +{ + $parentFolder = $folderToSearch.Replace("/" + $folderToSearch.Split("/")[($folderToSearch.Trim().Split("/").Count)-1],"") + $LogFilesPaths = "" + $LogFiles = "" + $retryCount = 1 + while (($LogFilesPaths -eq "") -and ($retryCount -le $maxRetryCount )) + { + LogMsg "Attempt $retryCount/$maxRetryCount : Getting all file paths inside $folderToSearch" + $lsOut = RunLinuxCmd -username $username -password $password -ip $IpAddress -port $SSHPort -command "ls -lR $parentFolder > /home/$user/listDir.txt" -runAsSudo -ignoreLinuxExitCode + RemoteCopy -downloadFrom $IpAddress -port $SSHPort -files "/home/$user/listDir.txt" -username $username -password $password -downloadTo $LogDir -download + $lsOut = Get-Content -Path "$LogDir\listDir.txt" -Force + Remove-Item "$LogDir\listDir.txt" -Force | Out-Null + foreach ($line in $lsOut.Split("`n") ) + { + $line = $line.Trim() + if ($line -imatch $parentFolder) + { + $currentFolder = $line.Replace(":","") + } + if ( ( ($line.Split(" ")[0][0]) -eq "-" ) -and ($currentFolder -imatch $folderToSearch) ) + { + while ($line -imatch " ") + { + $line = $line.Replace(" "," ") + } + $currentLogFile = $line.Split(" ")[8] + if ( $expectedFiles ) + { + if ( $expectedFiles.Split(",") -contains $currentLogFile ) + { + if ($LogFilesPaths) + { + $LogFilesPaths += "," + $currentFolder + "/" + $currentLogFile + $LogFiles += "," + $currentLogFile + } + else + { + $LogFilesPaths = $currentFolder + "/" + $currentLogFile + $LogFiles += $currentLogFile + } + LogMsg "Found Expected File $currentFolder/$currentLogFile" + } + else + { + LogMsg "Ignoring File $currentFolder/$currentLogFile" + } + } + else + { + if ($LogFilesPaths) + { + $LogFilesPaths += "," + $currentFolder + "/" + $currentLogFile + $LogFiles += "," + $currentLogFile + } + else + { + $LogFilesPaths = $currentFolder + "/" + $currentLogFile + $LogFiles += $currentLogFile + } + } + } + } + if ($LogFilesPaths -eq "") + { + WaitFor -seconds 10 + } + $retryCount += 1 + } + if ( !$LogFilesPaths ) + { + LogMsg "No files found in $folderToSearch" + } + return $LogFilesPaths, $LogFiles +} + +function ZipFiles( $zipfilename, $sourcedir ) +{ + $currentDir = (Get-Location).Path + $7z = (Get-ChildItem .\tools\7za.exe).FullName + $sourcedir = $sourcedir.Trim('\') + cd $sourcedir + $out = Invoke-Expression "$7z a -mx5 $currentDir\$zipfilename * -r" + cd $currentDir + if ($out -match "Everything is Ok") + { + Write-Host "$currentDir\$zipfilename created successfully." + } } \ No newline at end of file diff --git a/Libraries/Framework.psm1 b/Libraries/Framework.psm1 new file mode 100644 index 000000000..4eeca4182 --- /dev/null +++ b/Libraries/Framework.psm1 @@ -0,0 +1,445 @@ +function GetTestSummary($testCycle, [DateTime] $StartTime, [string] $xmlFilename, [string] $distro, $testSuiteResultDetails) +{ + <# + .Synopsis + Append the summary text from each VM into a single string. + + .Description + Append the summary text from each VM one long string. The + string includes line breaks so it can be display on a + console or included in an e-mail message. + + .Parameter xmlConfig + The parsed xml from the $xmlFilename file. + Type : [System.Xml] + + .Parameter startTime + The date/time the ICA test run was started + Type : [DateTime] + + .Parameter xmlFilename + The name of the xml file for the current test run. + Type : [String] + + .ReturnValue + A string containing all the summary message from all + VMs in the current test run. + + .Example + GetTestSummary $testCycle $myStartTime $myXmlTestFile + +#> + + $endTime = [Datetime]::Now.ToUniversalTime() + $testSuiteRunDuration= $endTime - $StartTime + $testSuiteRunDuration=$testSuiteRunDuration.Days.ToString() + ":" + $testSuiteRunDuration.hours.ToString() + ":" + $testSuiteRunDuration.minutes.ToString() + $str = "
Test Results Summary
" + $str += "ICA test run on " + $startTime + if ( $BaseOsImage ) + { + $str += "
Image under test " + $BaseOsImage + } + if ( $BaseOSVHD ) + { + $str += "
VHD under test " + $BaseOSVHD + } + if ( $ARMImage ) + { + $str += "
ARM Image under test " + "$($ARMImage.Publisher) : $($ARMImage.Offer) : $($ARMImage.Sku) : $($ARMImage.Version)" + } + $str += "
Total Executed TestCases " + $testSuiteResultDetails.totalTc + " (" + $testSuiteResultDetails.totalPassTc + " Pass" + ", " + $testSuiteResultDetails.totalFailTc + " Fail" + ", " + $testSuiteResultDetails.totalAbortedTc + " Abort)" + $str += "
Total Execution Time(dd:hh:mm) " + $testSuiteRunDuration.ToString() + $str += "
XML file: $xmlFilename

" + + # Add information about the host running ICA to the e-mail summary + $str += "
"
+    $str += $testCycle.emailSummary + "
" + $hostName = hostname + $str += "
Logs can be found at \\${hostname}\TestResults\" + $xmlFilename + "-" + $StartTime.ToString("yyyyMMdd-HHmmss") + "

" + $str += "
" + $plainTextSummary = $str + $strHtml = "" + + "Test Results Summary" + + "" + + "

Test Results Summary

" + $strHtml += "

ICA test run on - " + $startTime + "

" + if ( $BaseOsImage ) + { + $strHtml += '

Image under test - ' + "$BaseOsImage

" + } + if ( $BaseOSVHD ) + { + $strHtml += '

VHD under test - ' + "$BaseOsVHD

" + } + if ( $ARMImage ) + { + $strHtml += '

ARM Image under test - ' + "$($ARMImage.Publisher) : $($ARMImage.Offer) : $($ARMImage.Sku) : $($ARMImage.Version)

" + } + + $strHtml += '

Total Executed TestCases - ' + "$($testSuiteResultDetails.totalTc)" + '
' + '[ ' + $testSuiteResultDetails.totalPassTc + ' - PASS, ' + "$($testSuiteResultDetails.totalFailTc)" + '- FAIL, ' + "$($testSuiteResultDetails.totalAbortedTc)" +' - ABORTED ]

' + $strHtml += "

Total Execution Time(dd:hh:mm) " + $testSuiteRunDuration.ToString() + $strHtml += "

XML file: $xmlFilename

" + + # Add information about the host running ICA to the e-mail summary + $strHtml += "" + $strHtml += $testCycle.htmlSummary + $strHtml += "
" + + $strHtml += "" + + if (-not (Test-Path(".\temp\CI"))) { + mkdir ".\temp\CI" | Out-Null + } + + Set-Content ".\temp\CI\index.html" $strHtml + return $plainTextSummary, $strHtml +} + +function SendEmail([XML] $xmlConfig, $body) +{ + <# + .Synopsis + Send an e-mail message with test summary information. + + .Description + Collect the test summary information from each testcycle. Send an + eMail message with this summary information to emailList defined + in the xml config file. + + .Parameter xmlConfig + The parsed XML from the test xml file + Type : [System.Xml] + + .ReturnValue + none + + .Example + SendEmail $myConfig + #> + + $to = $xmlConfig.config.global.emailList.split(",") + $from = $xmlConfig.config.global.emailSender + $subject = $xmlConfig.config.global.emailSubject + " " + $testStartTime + $smtpServer = $xmlConfig.config.global.smtpServer + $fname = [System.IO.Path]::GetFilenameWithoutExtension($xmlConfigFile) + # Highlight the failed tests + $body = $body.Replace("Aborted", 'Aborted') + $body = $body.Replace("FAIL", 'Failed') + + Send-mailMessage -to $to -from $from -subject $subject -body $body -smtpserver $smtpServer -BodyAsHtml +} + +function Usage() +{ + write-host + write-host " Start automation: AzureAutomationManager.ps1 -xmlConfigFile -runTests -email -Distro -cycleName " + write-host + write-host " xmlConfigFile : Specifies the configuration for the test environment." + write-host " DistroName : Run tests on the distribution OS image defined in Azure->Deployment->Data->Distro" + write-host " -help : Displays this help message." + write-host +} +Function GetCurrentCycleData($xmlConfig, $cycleName) +{ + foreach ($Cycle in $xmlConfig.config.testCycles.Cycle ) + { + if($cycle.cycleName -eq $cycleName) + { + return $cycle + break + } + } + +} +Function ThrowException($Exception) +{ + $line = $Exception.InvocationInfo.ScriptLineNumber + $script_name = ($Exception.InvocationInfo.ScriptName).Replace($PWD,".") + $ErrorMessage = $Exception.Exception.Message + Write-Host "EXCEPTION : $ErrorMessage" + Write-Host "SOURCE : Line $line in script $script_name." + Throw "Calling function - $($MyInvocation.MyCommand)" +} + +<# +JUnit XML Report Schema: + http://windyroad.com.au/dl/Open%20Source/JUnit.xsd +Example: + Import-Module .\UtilLibs.psm1 -Force + + StartLogReport("$pwd/report.xml") + + $testsuite = StartLogTestSuite "CloudTesting" + + $testcase = StartLogTestCase $testsuite "BVT" "CloudTesting.BVT" + FinishLogTestCase $testcase + + $testcase = StartLogTestCase $testsuite "NETWORK" "CloudTesting.NETWORK" + FinishLogTestCase $testcase "FAIL" "NETWORK fail" "Stack trace: XXX" + + $testcase = StartLogTestCase $testsuite "VNET" "CloudTesting.VNET" + FinishLogTestCase $testcase "ERROR" "VNET error" "Stack trace: XXX" + + FinishLogTestSuite($testsuite) + + $testsuite = StartLogTestSuite "FCTesting" + + $testcase = StartLogTestCase $testsuite "BVT" "FCTesting.BVT" + FinishLogTestCase $testcase + + $testcase = StartLogTestCase $testsuite "NEGATIVE" "FCTesting.NEGATIVE" + FinishLogTestCase $testcase "FAIL" "NEGATIVE fail" "Stack trace: XXX" + + FinishLogTestSuite($testsuite) + + FinishLogReport + +report.xml: + + + + + Stack trace: XXX + + + Stack trace: XXX + + + + + + Stack trace: XXX + + + +#> + +[xml]$junitReport = $null +[object]$reportRootNode = $null +[string]$junitReportPath = "" +[bool]$isGenerateJunitReport=$False + +Function StartLogReport([string]$reportPath) +{ + if(!$junitReport) + { + $global:junitReport = new-object System.Xml.XmlDocument + $newElement = $global:junitReport.CreateElement("testsuites") + $global:reportRootNode = $global:junitReport.AppendChild($newElement) + + $global:junitReportPath = $reportPath + + $global:isGenerateJunitReport = $True + } + else + { + throw "CI report has been created." + } + + return $junitReport +} + +Function FinishLogReport([bool]$isFinal=$True) +{ + if(!$global:isGenerateJunitReport) + { + return + } + + $global:junitReport.Save($global:junitReportPath) + if($isFinal) + { + $global:junitReport = $null + $global:reportRootNode = $null + $global:junitReportPath = "" + $global:isGenerateJunitReport=$False + } +} + +Function StartLogTestSuite([string]$testsuiteName) +{ + if(!$global:isGenerateJunitReport) + { + return + } + + $newElement = $global:junitReport.CreateElement("testsuite") + $newElement.SetAttribute("name", $testsuiteName) + $newElement.SetAttribute("timestamp", [Datetime]::Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss")) + $newElement.SetAttribute("tests", 0) + $newElement.SetAttribute("failures", 0) + $newElement.SetAttribute("errors", 0) + $newElement.SetAttribute("time", 0) + $testsuiteNode = $global:reportRootNode.AppendChild($newElement) + + $timer = CIStartTimer + $testsuite = New-Object -TypeName PSObject + Add-Member -InputObject $testsuite -MemberType NoteProperty -Name testsuiteNode -Value $testsuiteNode -Force + Add-Member -InputObject $testsuite -MemberType NoteProperty -Name timer -Value $timer -Force + + return $testsuite +} + +Function FinishLogTestSuite([object]$testsuite) +{ + if(!$global:isGenerateJunitReport) + { + return + } + + $testsuite.testsuiteNode.Attributes["time"].Value = CIStopTimer $testsuite.timer + FinishLogReport $False +} + +Function StartLogTestCase([object]$testsuite, [string]$caseName, [string]$className) +{ + if(!$global:isGenerateJunitReport) + { + return + } + + $newElement = $global:junitReport.CreateElement("testcase") + $newElement.SetAttribute("name", $caseName) + $newElement.SetAttribute("classname", $classname) + $newElement.SetAttribute("time", 0) + + $testcaseNode = $testsuite.testsuiteNode.AppendChild($newElement) + + $timer = CIStartTimer + $testcase = New-Object -TypeName PSObject + Add-Member -InputObject $testcase -MemberType NoteProperty -Name testsuite -Value $testsuite -Force + Add-Member -InputObject $testcase -MemberType NoteProperty -Name testcaseNode -Value $testcaseNode -Force + Add-Member -InputObject $testcase -MemberType NoteProperty -Name timer -Value $timer -Force + return $testcase +} + +Function FinishLogTestCase([object]$testcase, [string]$result="PASS", [string]$message="", [string]$detail="") +{ + if(!$global:isGenerateJunitReport) + { + return + } + + $testcase.testcaseNode.Attributes["time"].Value = CIStopTimer $testcase.timer + + [int]$testcase.testsuite.testsuiteNode.Attributes["tests"].Value += 1 + if ($result -eq "FAIL") + { + $newChildElement = $global:junitReport.CreateElement("failure") + $newChildElement.InnerText = $detail + $newChildElement.SetAttribute("message", $message) + $testcase.testcaseNode.AppendChild($newChildElement) + + [int]$testcase.testsuite.testsuiteNode.Attributes["failures"].Value += 1 + } + + if ($result -eq "ERROR") + { + $newChildElement = $global:junitReport.CreateElement("error") + $newChildElement.InnerText = $detail + $newChildElement.SetAttribute("message", $message) + $testcase.testcaseNode.AppendChild($newChildElement) + + [int]$testcase.testsuite.testsuiteNode.Attributes["errors"].Value += 1 + } + FinishLogReport $False +} + +Function CIStartTimer() +{ + $timer = [system.diagnostics.stopwatch]::startNew() + return $timer +} + +Function CIStopTimer([System.Diagnostics.Stopwatch]$timer) +{ + $timer.Stop() + return [System.Math]::Round($timer.Elapsed.TotalSeconds, 2) + +} + +Function AddReproVMDetailsToHtmlReport() +{ + $reproVMHtmlText += "
Repro VMs: " + if ( $UserAzureResourceManager ) + { + foreach ( $vm in $allVMData ) + { + $reproVMHtmlText += "
ResourceGroup : $($vm.ResourceGroup), IP : $($vm.PublicIP), SSH : $($vm.SSHPort)" + } + } + else + { + foreach ( $vm in $allVMData ) + { + $reproVMHtmlText += "
ServiceName : $($vm.ServiceName), IP : $($vm.PublicIP), SSH : $($vm.SSHPort)" + } + } + return $reproVMHtmlText +} + +Function GetCurrentCycleData($xmlConfig, $cycleName) +{ + foreach ($Cycle in $xmlConfig.config.testCycles.Cycle ) + { + if($cycle.cycleName -eq $cycleName) + { + return $cycle + break + } + } + +} + +Function GetCurrentTestData($xmlConfig, $testName) +{ + foreach ($test in $xmlConfig.config.testsDefinition.test) + { + if ($test.testName -eq $testName) + { + LogMsg "Loading the test data for $($test.testName)" + Set-Variable -Name CurrentTestData -Value $test -Scope Global -Force + return $test + break + } + } +} + +Function RefineTestResult2 ($testResult) +{ + $i=0 + $tempResult = @() + foreach ($cmp in $testResult) + { + if(($cmp -eq "PASS") -or ($cmp -eq "FAIL") -or ($cmp -eq "ABORTED")) + { + $tempResult += $testResult[$i] + $tempResult += $testResult[$i+1] + $testResult = $tempResult + break + } + $i++; + } + return $testResult +} + +Function RefineTestResult1 ($tempResult) +{ + foreach ($new in $tempResult) + { + $lastObject = $new + } + $tempResultSplitted = $lastObject.Split(" ") + if($tempResultSplitted.Length > 1 ) + { + Write-Host "Test Result = $lastObject" -ForegroundColor Gray + } + $lastWord = ($tempResultSplitted.Length - 1) + + return $tempResultSplitted[$lastWord] +} \ No newline at end of file diff --git a/Libraries/Parser.psm1 b/Libraries/Parser.psm1 new file mode 100644 index 000000000..e69de29bb diff --git a/RunTests.ps1 b/RunTests.ps1 new file mode 100644 index 000000000..7fb800650 --- /dev/null +++ b/RunTests.ps1 @@ -0,0 +1,411 @@ +Param( + + #Do not use. Reserved for Jenkins use. + $BuildNumber=$env:BUILD_NUMBER, + + #Required + [string] $TestLocation="westeurope", + [string] $RGIdentifier = "TEST", + [string] $TestPlatform = "Azure", + [string] $ARMImageName = "Canonical UbuntuServer 16.04-LTS latest", + + #Optinal + [string] $OsVHD, #... Required if -ARMImageName is not provided. + [string] $TestCategory = "", + [string] $TestArea, + [string] $TestTag = "", + [string] $TestNames="VERIFY-DEPLOYMENT-PROVISION", + [switch] $Verbose, + + + #Swithces + [switch] $keepReproInact +) + +#Import the Functinos from Library Files. +Get-ChildItem .\Libraries -Recurse | Where-Object { $_.FullName.EndsWith(".psm1") } | ForEach-Object { Import-Module $_.FullName -Force -Global } +LogVerbose "Set-Variable -Name WorkingDirectory -Value (Get-Location).Path -Scope Global" + +try +{ + #region Validate Parameters + LogVerbose "Set-Variable -Name WorkingDirectory -Value (Get-Location).Path -Scope Global" + $ParameterErrors = @() + if ( !$TestPlatform ) + { + $ParameterErrors += "-TestPlatform is required." + } + if ( !$ARMImageName -and !$OsVHD ) + { + $ParameterErrors += "-ARMImageName <'Publisher Offer Sku Version'>/ -OsVHD <'VHD_Name.vhd'> is required" + } + if ( !$TestLocation) + { + $ParameterErrors += "-TestLocation is required" + } + if ( !$RGIdentifier ) + { + $ParameterErrors += "-RGIdentifier is required. This string will added to Resources created by Automation." + } + if ( $ParameterErrors.Count -gt 0) + { + $ParameterErrors | ForEach-Object { LogError $_ } + Throw "Paremeters are not valid." + } + else + { + LogMsg "Input parameters are valid" + } + #endregion + + if ($TestPlatform -eq "Azure") + { + #TBD Verify if the current PS session is authenticated. + #As of now, it expects that PS session is authenticated. + #We'll change this behaviour in upcoming commits. + } + + #region Static Global Variables + Set-Variable -Name WorkingDirectory -Value (Get-Location).Path -Scope Global + LogVerbose "Set-Variable -Name WorkingDirectory -Value (Get-Location).Path -Scope Global" + Set-Variable -Name shortRandomNumber -Value $(Get-Random -Maximum 99999 -Minimum 11111) -Scope Global + LogVerbose "Set-Variable -Name shortRandomNumber -Value $(Get-Random -Maximum 99999 -Minimum 11111) -Scope Global" + Set-Variable -Name shortRandomWord -Value $(-join ((65..90) | Get-Random -Count 4 | ForEach-Object {[char]$_})) -Scope Global + LogVerbose "Set-Variable -Name shortRandomWord -Value $(-join ((65..90) | Get-Random -Count 4 | ForEach-Object {[char]$_})) -Scope Global" + #endregion + + #region Runtime Global Variables + if ( $Verbose ) + { + $VerboseCommand = "-Verbose" + Set-Variable -Name VerboseCommand -Value "-Verbose" -Scope Global + } + else + { + Set-Variable -Name VerboseCommand -Value "" -Scope Global + } + + + #endregion + + #region Local Variables + $TestXMLs = Get-ChildItem -Path "$WorkingDirectory\XML\TestCases\*.xml" + $SetupTypeXMLs = Get-ChildItem -Path "$WorkingDirectory\XML\VMConfigurations\*.xml" + $allTests = @() + $ARMImage = $ARMImageName.Split(" ") + $xmlFile = "$WorkingDirectory\TestConfiguration.xml" + if ( $TestCategory -eq "All") + { + $TestCategory = "" + } + if ( $TestArea -eq "All") + { + $TestArea = "" + } + if ( $TestNames -eq "All") + { + $TestNames = "" + } + if ( $TestTag -eq "All") + { + $TestTag = $null + } + #endregion + + #Validate all XML files in working directory. + ValiateXMLs -ParentFolder $WorkingDirectory + + #region Collect Tests Data + if ( $TestPlatform -and !$TestCategory -and !$TestArea -and !$TestNames -and !$TestTag) + { + foreach ( $file in $TestXMLs.FullName) + { + $currentTests = ([xml]( Get-Content -Path $file)).TestCases + if ( $TestPlatform ) + { + foreach ( $test in $currentTests.test ) + { + if ($TestPlatform -eq $test.Platform ) + { + LogMsg "Collected $($test.TestName)" + $allTests += $test + } + } + } + } + } + elseif ( $TestPlatform -and $TestCategory -and (!$TestArea -or $TestArea -eq "default") -and !$TestNames -and !$TestTag) + { + foreach ( $file in $TestXMLs.FullName) + { + + $currentTests = ([xml]( Get-Content -Path $file)).TestCases + if ( $TestPlatform ) + { + foreach ( $test in $currentTests.test ) + { + if ( ($TestPlatform -eq $test.Platform ) -and $($TestCategory -eq $test.Category) ) + { + LogMsg "Collected $($test.TestName)" + $allTests += $test + } + } + } + } + } + elseif ( $TestPlatform -and $TestCategory -and ($TestArea -and $TestArea -ne "default") -and !$TestNames -and !$TestTag) + { + foreach ( $file in $TestXMLs.FullName) + { + + $currentTests = ([xml]( Get-Content -Path $file)).TestCases + if ( $TestPlatform ) + { + foreach ( $test in $currentTests.test ) + { + if ( ($TestPlatform -eq $test.Platform ) -and $($TestCategory -eq $test.Category) -and $($TestArea -eq $test.Area) ) + { + LogMsg "Collected $($test.TestName)" + $allTests += $test + } + } + } + } + } + elseif ( $TestPlatform -and $TestCategory -and $TestNames -and !$TestTag) + { + foreach ( $file in $TestXMLs.FullName) + { + + $currentTests = ([xml]( Get-Content -Path $file)).TestCases + if ( $TestPlatform ) + { + foreach ( $test in $currentTests.test ) + { + if ( ($TestPlatform -eq $test.Platform ) -and $($TestCategory -eq $test.Category) -and $($TestArea -eq $test.Area) -and ($TestNames.Split(",").Contains($test.TestName) ) ) + { + LogMsg "Collected $($test.TestName)" + $allTests += $test + } + } + } + } + } + elseif ( $TestPlatform -and !$TestCategory -and !$TestArea -and $TestNames -and !$TestTag) + { + foreach ( $file in $TestXMLs.FullName) + { + + $currentTests = ([xml]( Get-Content -Path $file)).TestCases + if ( $TestPlatform ) + { + foreach ( $test in $currentTests.test ) + { + if ( ($TestPlatform -eq $test.Platform ) -and ($TestNames.Split(",").Contains($test.TestName) ) ) + { + LogMsg "Collected $($test.TestName)" + $allTests += $test + } + } + } + } + } + elseif ( $TestPlatform -and !$TestCategory -and !$TestArea -and !$TestNames -and $TestTag) + { + foreach ( $file in $TestXMLs.FullName) + { + + $currentTests = ([xml]( Get-Content -Path $file)).TestCases + if ( $TestPlatform ) + { + foreach ( $test in $currentTests.test ) + { + if ( ($TestPlatform -eq $test.Platform ) -and ( $test.Tags.Split(",").Contains($TestTag) ) ) + { + LogMsg "Collected $($test.TestName)" + $allTests += $test + } + } + } + } + } + else + { + Throw "Invalid Test Selection" + } + #endregion + + #region Create Test XML + $SetupTypes = $allTests.SetupType | Sort-Object | Get-Unique + + $tab = @() + for ( $i = 0; $i -lt 30; $i++) + { + $currentTab = "" + for ( $j = 0; $j -lt $i; $j++) + { + $currentTab += "`t" + } + $tab += $currentTab + } + + + $GlobalConfiguration = [xml](Get-content .\XML\GlobalConfigurations.xml) + <########################################################################## + We're following the Indentation of the XML file to make XML creation easier. + ##########################################################################> + $xmlContent = ("$($tab[0])" + '') + $xmlContent += ("$($tab[0])" + "`n") + $xmlContent += ("$($tab[0])" + "$TestPlatform`n") + $xmlContent += ("$($tab[1])" + "`n") + + #region Add Subscription Details + $xmlContent += ("$($tab[2])" + "`n") + + foreach ( $line in $GlobalConfiguration.Global.Azure.Subscription.InnerXml.Replace("><",">`n<").Split("`n")) + { + $xmlContent += ("$($tab[3])" + "$line`n") + } + $xmlContent += ("$($tab[2])" + "$TestLocation`n") + $xmlContent += ("$($tab[2])" + "`n") + #endregion + + #region Database details + $xmlContent += ("$($tab[2])" + "`n") + foreach ( $line in $GlobalConfiguration.Global.Azure.ResultsDatabase.InnerXml.Replace("><",">`n<").Split("`n")) + { + $xmlContent += ("$($tab[3])" + "$line`n") + } + $xmlContent += ("$($tab[2])" + "`n") + #endregion + + #region Deployment details + $xmlContent += ("$($tab[2])" + "`n") + $xmlContent += ("$($tab[3])" + "`n") + $xmlContent += ("$($tab[4])" + "`n") + $xmlContent += ("$($tab[5])" + "$RGIdentifier`n") + $xmlContent += ("$($tab[5])" + "`n") + $xmlContent += ("$($tab[6])" + "" + "$($ARMImage[0])" + "`n") + $xmlContent += ("$($tab[6])" + "" + "$($ARMImage[1])" + "`n") + $xmlContent += ("$($tab[6])" + "" + "$($ARMImage[2])" + "`n") + $xmlContent += ("$($tab[6])" + "" + "$($ARMImage[3])" + "`n") + $xmlContent += ("$($tab[5])" + "`n") + $xmlContent += ("$($tab[5])" + "" + "$OsVHD" + "`n") + $xmlContent += ("$($tab[4])" + "`n") + $xmlContent += ("$($tab[4])" + "" + "$($GlobalConfiguration.Global.Azure.TestCredentials.LinuxUsername)" + "`n") + $xmlContent += ("$($tab[4])" + "" + "$($GlobalConfiguration.Global.Azure.TestCredentials.LinuxPassword)" + "`n") + $xmlContent += ("$($tab[3])" + "`n") + + foreach ( $file in $SetupTypeXMLs.FullName) + { + foreach ( $SetupType in $SetupTypes ) + { + $CurrentSetupType = ([xml]( Get-Content -Path $file)).TestSetup + if ( $CurrentSetupType.$SetupType -ne $null) + { + $SetupTypeElement = $CurrentSetupType.$SetupType + $xmlContent += ("$($tab[3])" + "<$SetupType>`n") + #$xmlContent += ("$($tab[4])" + "$($SetupTypeElement.InnerXml)`n") + foreach ( $line in $SetupTypeElement.InnerXml.Replace("><",">`n<").Split("`n")) + { + $xmlContent += ("$($tab[4])" + "$line`n") + } + + $xmlContent += ("$($tab[3])" + "`n") + } + } + } + $xmlContent += ("$($tab[2])" + "`n") + #endregion + $xmlContent += ("$($tab[1])" + "`n") + + + #region TestDefinition + $xmlContent += ("$($tab[1])" + "`n") + foreach ( $currentTest in $allTests) + { + $xmlContent += ("$($tab[2])" + "`n") + foreach ( $line in $currentTest.InnerXml.Replace("><",">`n<").Split("`n")) + { + $xmlContent += ("$($tab[3])" + "$line`n") + } + $xmlContent += ("$($tab[2])" + "`n") + } + $xmlContent += ("$($tab[1])" + "`n") + #endregion + + #region TestCycle + $xmlContent += ("$($tab[1])" + "`n") + $xmlContent += ("$($tab[2])" + "`n") + $xmlContent += ("$($tab[3])" + "TC-$shortRandomNumber`n") + foreach ( $currentTest in $allTests) + { + $line = $currentTest.TestName + $xmlContent += ("$($tab[3])" + "`n") + $xmlContent += ("$($tab[4])" + "$line`n") + $xmlContent += ("$($tab[3])" + "`n") + } + $xmlContent += ("$($tab[2])" + "`n") + $xmlContent += ("$($tab[1])" + "`n") + #endregion + $xmlContent += ("$($tab[0])" + "`n") + Set-Content -Value $xmlContent -Path $xmlFile -Force + try + { + $xmlConfig = [xml](Get-Content $xmlFile) + $xmlConfig.Save("$xmlFile") + LogMsg "Auto created $xmlFile validated successfully." + } + catch + { + Throw "Auto created $xmlFile is not valid." + } + + #endregion + + #region Download necessary tools. + mkdir -Path .\tools -ErrorAction SilentlyContinue | Out-Null + Import-Module BitsTransfer + if (!( Test-Path -Path .\tools\7za.exe )) + { + Write-Host "Downloading 7za.exe" + $out = Start-BitsTransfer -Source "https://github.com/iamshital/azure-linux-automation-support-files/raw/master/tools/7za.exe" | Out-Null + } + if (!( Test-Path -Path .\tools\dos2unix.exe )) + { + Write-Host "Downloading dos2unix.exe" + $out = Start-BitsTransfer -Source "https://github.com/iamshital/azure-linux-automation-support-files/raw/master/tools/dos2unix.exe" | Out-Null + } + if (!( Test-Path -Path .\tools\plink.exe )) + { + Write-Host "Downloading plink.exe" + $out = Start-BitsTransfer -Source "https://github.com/iamshital/azure-linux-automation-support-files/raw/master/tools/plink.exe" | Out-Null + } + if (!( Test-Path -Path .\tools\pscp.exe )) + { + Write-Host "Downloading pscp.exe" + $out = Start-BitsTransfer -Source "https://github.com/iamshital/azure-linux-automation-support-files/raw/master/tools/pscp.exe" | Out-Null + } + Move-Item -Path "*.exe" -Destination .\tools -ErrorAction SilentlyContinue -Force + #endregion + + LogMsg ".\AutomationManager.ps1 -xmlConfigFile '$xmlFile' -cycleName TC-$shortRandomNumber -RGIdentifier $RGIdentifier -runtests -UseAzureResourceManager" + .\AutomationManager.ps1 -xmlConfigFile "$xmlFile" -cycleName "TC-$shortRandomNumber" -RGIdentifier $RGIdentifier -runtests -UseAzureResourceManager -keepReproInact + + #TBD Analyse the test result + #TBD Archive the logs + #TBD Email the reports +} +catch +{ + $line = $_.InvocationInfo.ScriptLineNumber + $script_name = ($_.InvocationInfo.ScriptName).Replace($PWD,".") + $ErrorMessage = $_.Exception.Message + LogMsg "EXCEPTION : $ErrorMessage" + LogMsg "Source : Line $line in script $script_name." + $ExitCode = 1 +} +finally +{ + exit $ExitCode +} \ No newline at end of file diff --git a/Testscripts/Linux/BVT-IS-ROOT-PASSWORD-DELETED.py b/Testscripts/Linux/BVT-IS-ROOT-PASSWORD-DELETED.py new file mode 100644 index 000000000..d8013b4a5 --- /dev/null +++ b/Testscripts/Linux/BVT-IS-ROOT-PASSWORD-DELETED.py @@ -0,0 +1,19 @@ +#!/usr/bin/python + +from azuremodules import * + +def RunTest(): + UpdateState("TestRunning") + RunLog.info("Checking if root password is deleted or not...") + + passwd_output = Run("cat /etc/shadow | grep root") + root_passwd = passwd_output.split(":")[1] + if ('*' in root_passwd or '!' in root_passwd): + RunLog.info('root password is deleted in /etc/shadow.') + ResultLog.info('PASS') + else: + RunLog.error('root password not deleted.%s', passwd_output) + ResultLog.error('FAIL') + UpdateState("TestCompleted") + +RunTest() diff --git a/Testscripts/Linux/BVT-VERIFY-HOSTNAME.py b/Testscripts/Linux/BVT-VERIFY-HOSTNAME.py new file mode 100644 index 000000000..a010cc6b9 --- /dev/null +++ b/Testscripts/Linux/BVT-VERIFY-HOSTNAME.py @@ -0,0 +1,53 @@ +#!/usr/bin/python + +from azuremodules import * + + +import argparse +import sys +import time +import re + #for error checking +parser = argparse.ArgumentParser() + +parser.add_argument('-e', '--expected', help='specify expected hostname', required=True) + +args = parser.parse_args() + #if no value specified then stop +expectedHostname = args.expected + +def RunTest(expectedHost): + UpdateState("TestRunning") + if CheckHostName(expectedHost) and CheckFQDN(expectedHost): + ResultLog.info('PASS') + UpdateState("TestCompleted") + else: + ResultLog.error('FAIL') + UpdateState("TestCompleted") + +def CheckHostName(expectedHost): + RunLog.info("Checking hostname...") + output = Run("hostname") + if expectedHost.upper() in output.upper(): + RunLog.info('Hostname is set successfully to {0}'.format(expectedHost)) + return True + else: + RunLog.error('Hostname change failed. Current hostname : {0} Expected hostname : {1}'.format(output, expectedHost)) + return False + +def CheckFQDN(expectedHost): + RunLog.info("Checking fqdn...") + [current_distro, distro_version] = DetectDistro() + nslookupCmd = "nslookup {0}".format(expectedHost) + if current_distro == 'coreos': + nslookupCmd = "python nslookup.py -n {0}".format(expectedHost) + output = Run(nslookupCmd) + if re.search("server can't find", output) is None: + RunLog.info('nslookup successfully for: {0}'.format(expectedHost)) + return True + else: + RunLog.error("nslookup failed for: {0}, {1}".format(expectedHost, output)) + return False + + +RunTest(expectedHostname) diff --git a/Testscripts/Linux/CollectLogFile.sh b/Testscripts/Linux/CollectLogFile.sh new file mode 100644 index 000000000..e34d7410d --- /dev/null +++ b/Testscripts/Linux/CollectLogFile.sh @@ -0,0 +1,31 @@ +#!/bin/bash +export PATH="/sbin:/bin:/usr/sbin:/usr/bin" +dmesg > `hostname`-dmesg.txt +cp /var/log/waagent.log `hostname`-waagent.log.txt +uname -r > `hostname`-kernelVersion.txt +uptime -s > `hostname`-uptime.txt || echo "UPTIME_COMMAND_ERROR" > `hostname`-uptime.txt +modinfo hv_netvsc > `hostname`-lis.txt +release=`cat /etc/*release*` +if [ -f /etc/redhat-release ] ; then + echo "/etc/redhat-release detected" + if [[ "$release" =~ "Oracle" ]] ; then + cat /etc/os-release | grep ^PRETTY_NAME | sed 's/"//g' | sed 's/PRETTY_NAME=//g' > `hostname`-distroVersion.txt + else + cat /etc/redhat-release > `hostname`-distroVersion.txt + fi +elif [ -f /etc/SuSE-release ] ; then + echo "/etc/SuSE-release detected" + cat /etc/os-release | grep ^PRETTY_NAME | sed 's/"//g' | sed 's/PRETTY_NAME=//g' > `hostname`-distroVersion.txt +elif [[ "$release" =~ "UBUNTU" ]] || [[ "$release" =~ "Ubuntu" ]] || [[ "$release" =~ "Debian" ]]; then + NAME=`cat /etc/os-release | grep ^NAME= | sed 's/"//g' | sed 's/NAME=//g'` + VERSION=`cat /etc/os-release | grep ^VERSION= | sed 's/"//g' | sed 's/VERSION=//g'` + echo "$NAME $VERSION" > `hostname`-distroVersion.txt +elif [ -e /usr/share/clear/version ]; then + NAME=`cat /usr/lib/os-release | grep ^PRETTY_NAME | sed 's/"//g' | sed 's/PRETTY_NAME=//g'` + VERSION=`cat /usr/lib/os-release | grep ^VERSION= | sed 's/"//g' | sed 's/VERSION=//g'` + echo "$NAME $VERSION" > `hostname`-distroVersion.txt +else + echo "unknown" > `hostname`-distroVersion.txt + echo $release > `hostname`-unknownDistro.txt +fi +exit 0 \ No newline at end of file diff --git a/Testscripts/Linux/ConfigureSRIOV-workaround.sh b/Testscripts/Linux/ConfigureSRIOV-workaround.sh new file mode 100644 index 000000000..b9dc3219b --- /dev/null +++ b/Testscripts/Linux/ConfigureSRIOV-workaround.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux" /etc/{issue,*release,*version}` +bootLogs=`dmesg` +if [[ $bootLogs =~ "Data path switched to VF" ]]; +then + echo "DATAPATH_SWITCHED_TO_VF" +else + if [[ $DISTRO =~ "Ubuntu" ]]; + then + #A temporary workaround for SRIOV issue. + macAddr=`cat /sys/class/net/eth0/address` + echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"hv_netvsc\", ATTR{address}==\"${macAddr}\", NAME=\"eth0\"" > /etc/udev/rules.d/70-persistent-net.rules + echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"mlx4_core\", ATTR{address}==\"${macAddr}\", NAME=\"vf0\"" >> /etc/udev/rules.d/70-persistent-net.rules + #sed -i '/rename*/c\vf0' /etc/network/interfaces + echo "SYSTEM_RESTART_REQUIRED" + fi +fi +exit 0 \ No newline at end of file diff --git a/Testscripts/Linux/ConfigureSRIOV.sh b/Testscripts/Linux/ConfigureSRIOV.sh new file mode 100644 index 000000000..68fa36169 --- /dev/null +++ b/Testscripts/Linux/ConfigureSRIOV.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +#Reference: https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-create-vm-accelerated-networking +bootLogs=`dmesg` +if [[ $bootLogs =~ "Data path switched to VF" ]]; +then + echo "DATAPATH_SWITCHED_TO_VF" +else + wget https://raw.githubusercontent.com/torvalds/linux/master/tools/hv/bondvf.sh + chmod +x ./bondvf.sh + ./bondvf.sh + cp bondvf.sh /etc/init.d + update-rc.d bondvf.sh defaults + echo "SYSTEM_RESTART_REQUIRED" +fi +exit 0 \ No newline at end of file diff --git a/Testscripts/Linux/DetectLinuxDistro.sh b/Testscripts/Linux/DetectLinuxDistro.sh new file mode 100644 index 000000000..281fe0eec --- /dev/null +++ b/Testscripts/Linux/DetectLinuxDistro.sh @@ -0,0 +1,75 @@ +#!/bin/bash +#V-SHISAV@MICROSOFT.COM +# THIS SCRIPT DETECT FOLLOWING DISTROS: +# UBUNTU [VERSION INDEPENDANT] +# CENTOS [VERSION INDEPENDANT] +# SUSE LINUX ENTERPRISE SERVER [VERSION INDEPENDANT] +# OPENSUSE [VERSION INDEPENDANT] +# REDHAT +# ORACLELINUX +# FEDORA +DetectDistro() +{ +while echo $1 | grep ^- > /dev/null; do + eval $( echo $1 | sed 's/-//g' | tr -d '\012')=$2 + shift + shift +done + if [ -e /etc/debian_version ]; then + tmp=`cat /etc/*-release` + if [[ "$tmp" == *Ubuntu* ]]; then + echo "UBUNTU" + exitVal=0 + else + echo "DEBIAN" + exitVal=0 + fi + elif [ -e /etc/redhat-release ]; then + tmp=`cat /etc/redhat-release` + if [ -e /etc/oracle-release ]; then + tmp=`cat /etc/oracle-release` + if [[ "$tmp" == *Oracle* ]]; then + echo "ORACLELINUX" + exitVal=0 + else + echo "Unknown" + exitVal=1 + fi + elif [[ "$tmp" == *CentOS* ]]; then + echo "CENTOS" + exitVal=0 + elif [[ "$tmp" == *Fedora* ]]; then + echo "FEDORA" + exitVal=0 + elif [[ "$tmp" == *Red* ]]; then + echo "REDHAT" + exitVal=0 + else + echo "Unknown" + exitVal=1 + fi + elif [ -e /etc/SuSE-release ]; then + tmp=`cat /etc/SuSE-release` + if [[ "$tmp" == *Enterprise* ]]; then + echo "SLES" + exitVal=0 + elif [[ "$tmp" == *open* ]]; then + echo "SUSE" + exitVal=0 + else + echo "Unknown" + fi + elif [ -e /etc/os-release ]; then + tmp=`cat /etc/os-release` + if [[ "$tmp" == *coreos* ]]; then + echo "COREOS" + exitVal=0 + fi + elif [ -e /usr/share/clear/version ]; then + tmp=`cat /usr/share/clear/version` + echo "CLEARLINUX" + exitVal=0 + fi +return $exitVal +} +DetectDistro \ No newline at end of file diff --git a/Testscripts/Linux/LIS-LogCollector.sh b/Testscripts/Linux/LIS-LogCollector.sh new file mode 100644 index 000000000..ff2a37f37 --- /dev/null +++ b/Testscripts/Linux/LIS-LogCollector.sh @@ -0,0 +1,142 @@ +#!/bin/bash +#Author: Vijay Tripathi +Log() { + msg="echo $1" + cmd=$2 + file=$3 + format="echo "---------------------------------------------------"" + + $format >> $file + $msg >> $file + echo "Command Used:" $2 >> $3 + eval $cmd >> $file + $format >> $file + + 2>/dev/null +} + +intro() { +##Create the Directory in Which Logs would be stored +currtime=$(date +"%b%d%Y-%H-%M-%S"); +#hostnm=$(hostname) +hostnm="" +#dirname="LIS-Logs-"${hostnm}; +dirname="LIS-Logs" +mkdir $dirname; +} + +Collect_Waagent_Logs() { +echo "Collecting Waagent Details...." +Log "Collecting Waagent Details at" 'date' $dirname/Waagent.txt +Log "Waagent Process Running Status" 'ps -ef | grep waagent' $dirname/Waagent.txt +if [ -f /usr/share/oem/bin/waagent ] +then +Log "Waagent Version is" '/usr/share/oem/python/bin/python /usr/share/oem/bin/waagent --version' $dirname/Waagent.txt +else +Log "Waagent Version is" '/usr/sbin/waagent --version' $dirname/Waagent.txt +fi +Log "Root Device Timeout" 'cat /sys/block/sda/device/timeout' $dirname/Waagent.txt +if [[ $dist == *Debian* ]] || [[ $dist == *Ubuntu* ]] +then +Log "Waagent Package Details" 'dpkg -p walinuxagent' $dirname/Waagent.txt +else +Log "Waagent Package Details" 'rpm -qil WALinuxAgent' $dirname/Waagent.txt +fi +Log "Waagent.log file" 'cat /var/log/waagent.log' $dirname/Waagent.log +} + +Collect_OS_Logs() { +echo "Collection Operating System Logs....." +Log "Collection Operating System Details at" 'date' $dirname/OS.log +Log "Kernel Version" 'uname -a' $dirname/OS.log +Log "Distro Release Details" 'cat /etc/issue' $dirname/OS.log +Log "Additional Kernel Details" 'cat /proc/version' $dirname/OS.log +Log "Mount Points" 'mount' $dirname/OS.log +Log "System Limits" 'ulimit -a' $dirname/OS.log +#Log "NFS Shares on System" 'showmount -e' $dirname/OS.log +Log "Hosts File Details" 'cat /etc/hosts' $dirname/OS.log +Log "Locale Details" 'locale' $dirname/OS.log +Log "Running Process Details" 'ps -auwwx' $dirname/OS.log +if [ -e /boot/grub/grub.conf ]; then + Log "Grub File Details" 'cat /boot/grub/grub.conf' $dirname/grub.log +elif [ -e /boot/grub/menu.lst ]; then + Log "Grub File Details" 'cat /boot/grub/menu.lst' $dirname/grub.log +elif [ -e /etc/grub.conf ]; then + Log "Grub File Details" 'cat /etc/grub.conf' $dirname/grub.log +fi +Log "Enviornment Variables Settings" 'env' $dirname/OS.log +Log "Dmesg File Details" 'dmesg' $dirname/dmesg.txt +dist=`cat /etc/issue` +echo $dist +if [[ $dist == *Debian* ]] || [[ $dist == *Ubuntu* ]] +then +Log "Kernel Loaded Packages" 'dpkg -l | grep kernel' $dirname/KernelPackagess.txt +else +Log "Kernel Loaded Packages" 'rpm -qa | grep kernel' $dirname/KernelPackages.txt +fi +#Log "var log messages saved" 'cat /var/log/messages' $dirname/VarLogMessages.txt +Log "System has Been up since" 'uptime' $dirname/OS.log +echo "Operating system Log process finished..." +Log "I/O Scheduler Details" 'cat /sys/block/sda/queue/scheduler ' $dirname/OS.log +} + +Collect_LIS() { +echo "Collecting Microsoft Linux Integration Service Data..." +Log "LIS Modules Loaded" 'lsmod | grep vsc' $dirname/LISDetails.txt +vmbus=`lsmod | grep vmbus | cut -d' ' -f1` +Log "LIS Modules version Details" 'modinfo $vmbus' $dirname/LISDetails.txt +echo "Collecting Microsoft Linux Integration Service Data Finsished..." +} + +Collect_DiskandMemory() { +echo "Collecting Disk and Memory Data" +Log "Disk Partition Details" 'fdisk -l' $dirname/Disk.txt +Log "Filesystem details" 'df -k' $dirname/Disk.txt +Log "Additional Partition Details" 'cat /proc/partitions' $dirname/Disk.txt +Log "Memory Details" 'cat /proc/meminfo' $dirname/Memory.txt +Log "Scsi details" 'cat /proc/scsi/scsi' $dirname/Disk.txt +Log "Memory Usage Details in MB" 'free -m' $dirname/Memory.txt +Log "I/O Memory details" 'cat /proc/iomem' $dirname/Memory.txt +echo "Collecting Disk and Memory Data Finished..." +} + +Collect_Processor() { +echo "Collecting Processor Data..." +Log "Processor Details" 'cat /proc/cpuinfo' $dirname/Cpuinfo.txt +Log "Processor Count" 'cat /proc/cpuinfo | grep ^proc' $dirname/Cpuinfo.txt +Log "Interrurpts details" 'cat /proc/interrupts' $dirname/interrupts.txt +Log "List of loaded Modules" 'lsmod' $dirname/Modules.txt +Log "List of IO Ports" 'cat /proc/ioports' $dirname/IOports.txt +Log "Processor Real time activity" 'top -b -n 5' $dirname/Top.txt +Log "Processes consuming most amount of memory" 'ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10' $dirname/Top.txt +echo "Collecting Processor Data Finished..." +} + +Collect_Network() { +echo "Collecting Network Data..." +Log "Network Interface Details" 'ifconfig -a' $dirname/Network.txt +Log "Network Status Details by interface" 'netstat -i' $dirname/Network.txt +Log "Network Status Details of all sockets" 'netstat -a' $dirname/Network.txt +Log "Network Status Details Source and Destinations ips and ports" 'netstat -lan' $dirname/Network.txt +Log "Routing Table Details" 'route' $dirname/Route.txt +echo "Collecting Network Data Finished..." +} + +Create_Compr_Logs() { +echo "Compressing Logs" +tar -czf $dirname.tgz $dirname/* +} + +Upload_Logs() { +return; + +} +intro +Collect_OS_Logs +Collect_Waagent_Logs +Collect_LIS +Collect_DiskandMemory +Collect_Processor +Collect_Network +Create_Compr_Logs + diff --git a/Testscripts/Linux/azuremodules.py b/Testscripts/Linux/azuremodules.py new file mode 100644 index 000000000..566a3da35 --- /dev/null +++ b/Testscripts/Linux/azuremodules.py @@ -0,0 +1,847 @@ +#!/usr/bin/python +##################################################################################################################################### +# THIS FILE CONTAINS ALL THE FUNCTIONS USED IN PYTHON TEST FILES... HANDLE WITH CARE... +# FOR ANY QUERY - V-SHISAV@MICROSOFT.COM +# DO NOT DELETE ANY STATEMENT FROM THE FUNCTION EVEN IF IT IS COMMENTED!!! BECAUSE I'M TRACKING, WHAT I'M DOING... +##################################################################################################################################### + +import subprocess +import logging +import string +import os +import time +import os.path +import array +import linecache +import sys +import re + +try: + import commands +except ImportError: + import subprocess as commands + +py_ver_str = sys.version +print(sys.version) + +#THIS LOG WILL COLLECT ALL THE LOGS THAT ARE RUN WHILE THE TEST IS GOING ON... +RunLog = logging.getLogger("RuntimeLog : ") +WRunLog = logging.FileHandler('Runtime.log','w') +RunFormatter = logging.Formatter('%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') +WRunLog.setFormatter(RunFormatter) +RunLog.setLevel(logging.DEBUG) +RunScreen = logging.StreamHandler() +RunScreen.setFormatter(RunFormatter) +#RunLog.addHandler(RunScreen) +RunLog.addHandler(WRunLog) + +#This will collect Result from every test case : +ResultLog = logging.getLogger("Result : ") +WResultLog = logging.FileHandler('Summary.log','w') +#ResultFormatter = logging.Formatter('%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') +ResultFormatter = logging.Formatter('%(message)s') +WResultLog.setFormatter(ResultFormatter) +ResultLog.setLevel(logging.DEBUG) +ResultScreen = logging.StreamHandler() +ResultScreen.setFormatter(ResultFormatter) +#ResultLog.addHandler(ResultScreen) +ResultLog.addHandler(WResultLog) + +def UpdateRepos(current_distro): + RunLog.info ("\nUpdating the repositoriy information...") + if (current_distro.find("ubuntu") != -1) or (current_distro.find("debian") != -1): + #method 'RunUpdate': fix deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe + RunUpdate("apt-get update") + elif (current_distro.find("rhel") != -1) or (current_distro.find("Oracle") != -1) or (current_distro.find('centos') != -1): + RunUpdate("yum -y update") + elif (current_distro.find("opensuse") != -1) or (current_distro.find("SUSE") != -1) or (current_distro.find("sles") != -1): + RunUpdate("zypper --non-interactive --gpg-auto-import-keys update") + else: + RunLog.info("Repo upgradation failed on:"+current_distro) + return False + + RunLog.info ("Updating the repositoriy information... [done]") + return True + +def DownloadUrl(url, destination_folder, output_file=None): + cmd = "wget -P "+destination_folder+" "+url+ " 2>&1" + if output_file is not None: + cmd = "wget {0} -O {1} 2>&1".format(url, output_file) + + rtrn = Run(cmd) + + if(rtrn.rfind("wget: command not found") != -1): + InstallPackage("wget") + rtrn = Run(cmd) + + if( rtrn.rfind("100%") != -1): + return True + else: + RunLog.info (rtrn) + return False + +def DetectDistro(): + distribution = 'unknown' + version = 'unknown' + + RunLog.info("Detecting Distro ") + output = Run("cat /etc/*-release") + outputlist = re.split("\n", output) + + for line in outputlist: + line = re.sub('"', '', line) + if (re.match(r'^ID=(.*)',line,re.M|re.I) ): + matchObj = re.match( r'^ID=(.*)', line, re.M|re.I) + distribution = matchObj.group(1) + elif (re.match(r'^VERSION_ID=(.*)',line,re.M|re.I) ): + matchObj = re.match( r'^VERSION_ID=(.*)', line, re.M|re.I) + version = matchObj.group(1) + + if(distribution.strip() == "ol"): + distribution = 'Oracle' + + if(distribution == 'unknown'): + # Finding the Distro + for line in outputlist: + if (re.match(r'.*Ubuntu.*',line,re.M|re.I) ): + distribution = 'ubuntu' + break + elif (re.match(r'.*SUSE Linux.*',line,re.M|re.I)): + distribution = 'SUSE' + break + elif (re.match(r'.*openSUSE.*',line,re.M|re.I)): + distribution = 'opensuse' + break + elif (re.match(r'.*centos.*',line,re.M|re.I)): + distribution = 'centos' + break + elif (re.match(r'.*Oracle.*',line,re.M|re.I)): + distribution = 'Oracle' + break + elif (re.match(r'.*Red Hat.*',line,re.M|re.I)): + distribution = 'rhel' + break + elif (re.match(r'.*Fedora.*',line,re.M|re.I)): + distribution = 'fedora' + break + return [distribution, version] + +def FileGetContents(filename): + with open(filename) as f: + return f.read() + +def ExecMultiCmdsLocalSudo(cmd_list): + f = open('/tmp/temp_script.sh','w') + for line in cmd_list: + f.write(line+'\n') + f.close() + Run ("chmod +x /tmp/temp_script.sh") + Run ("/tmp/temp_script.sh 2>&1 > /tmp/exec_multi_cmds_local_sudo.log") + return FileGetContents("/tmp/exec_multi_cmds_local_sudo.log") + +def DetectLinuxDistro(): + if os.path.isfile("/etc/redhat-release"): + return (True, "RedHat") + if os.path.isfile("/etc/lsb-release") and "Ubuntu" in GetFileContents("/etc/lsb-release"): + return (True, "Ubuntu") + if os.path.isfile("/etc/debian_version"): + return (True, "Debian") + if os.path.isfile("/etc/SuSE-release"): + return (True, "Suse") + return (False, "Unknown") + +def IsUbuntu(): + cmd = "cat /etc/issue" + tmp=Run(cmd) + return ("Ubuntu" in tmp) + +def ParseWalaConf2Dict(walaconfpath): + d = None + if os.path.exists(walaconfpath): + d={} + lines = GetFileContentsByLines(walaconfpath) + configs_list = [x.strip().split()[0] for x in lines if not x.startswith('#') and not x.startswith('\n')] + for x in configs_list: + try: + k,v=x.split('=') + d.setdefault(k,v) + except Exception as e: + pass + else: + RunLog.error("%s is not exists, please check." % walaconfpath) + return d + +def GetWalaConfPath(): + if os.path.exists("/etc/lsb-release") and int(Run("cat /etc/lsb-release | grep -i coreos | wc -l")) > 0: + return "/usr/share/oem/waagent.conf" + else: + return "/etc/waagent.conf" + +def GetResourceDiskMountPoint(): + walacfg_path = GetWalaConfPath() + walacfg_dict = ParseWalaConf2Dict(walacfg_path) + + if os.path.exists('/var/log/cloud-init.log') and os.path.islink('/var/lib/cloud/instance'): + RunLog.info('ResourceDisk handled by cloud-init.') + return '/mnt' + else: + RunLog.info("ResourceDisk handled by waagent.") + return walacfg_dict['ResourceDisk.MountPoint'] + +def RunGetOutput(cmd): + try: + proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) + retval = proc.communicate() + output = retval[0] + + output = unicode(output, + encoding='utf-8', + errors="backslashreplace") + except subprocess.CalledProcessError as e: + output = unicode(e.output, + encoding='utf-8', + errors="backslashreplace") + return e.returncode, output + return 0, output + +def Run(cmd): + proc=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) + proc.wait() + op = proc.stdout.read() + RunLog.debug(op) + code=proc.returncode + if int(code) !=0: + exception = 1 + else: + #ensure type str return + if py_ver_str[0] == '3': + op = op.decode('utf-8') + return op + if exception == 1: + str_code = str(code) + return op +#use method communicate() instead of wait() +#This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe +#such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that. +def RunUpdate(cmd): + proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) + retval = proc.communicate() + op = retval[0] + RunLog.debug(op) + code = proc.returncode + if int(code) !=0: + exception = 1 + else: + if py_ver_str[0] == '3': + op = op.decode('utf-8') + return op + if exception == 1: + str_code = str(code) + return op + +def JustRun(cmd): + return commands.getoutput(cmd) + +def UpdateState(testState): + stateFile = open('state.txt', 'w') + stateFile.write(testState) + stateFile.close() + +def GetFileContents(filepath): + file = None + try: + file = open(filepath) + except: + return None + if file == None: + return None + try: + return file.read() + finally: + file.close() + + +#----------------------------------------------------------------------------------------------------------------------------------------------------- +# Instlaltion routines + +def YumPackageInstall(package): + RunLog.info(("\nyum_package_install: " + package)) + output = Run("yum install -y "+package) + outputlist = re.split("\n", output) + + for line in outputlist: + #Package installed successfully + if (re.match(r'Complete!', line, re.M|re.I)): + RunLog.info((package+": package installed successfully.\n"+line)) + return True + #package is already installed + elif (re.match(r'.* already installed and latest version', line, re.M|re.I)): + RunLog.info((package + ": package is already installed.\n"+line)) + return True + elif (re.match(r'^Nothing to do', line, re.M|re.I)): + RunLog.info((package + ": package already installed.\n"+line)) + return True + #Package installation failed + elif (re.match(r'^Error: Nothing to do', line, re.M|re.I)): + break + #package is not found on the repository + elif (re.match(r'^No package '+ re.escape(package)+ r' available', line, re.M|re.I)): + break + + #Consider package installation failed if non of the above matches. + RunLog.error((package + ": package installation failed!\n" +output)) + return False + +def AptgetPackageInstall(package,dbpasswd = "root"): + RunLog.info("Installing Package: " + package) + # Identify the package for Ubuntu + # We Haven't installed mysql-secure_installation for Ubuntu Distro + if (package == 'mysql-server'): + RunLog.info( "apt-get function package:" + package) + cmds = ("export DEBIAN_FRONTEND=noninteractive","echo mysql-server mysql-server/root_password select " + dbpasswd + " | debconf-set-selections", "echo mysql-server mysql-server/root_password_again select " + dbpasswd + "| debconf-set-selections", "apt-get install -y mysql-server") + output = ExecMultiCmdsLocalSudo(cmds) + else: + cmds = ("export DEBIAN_FRONTEND=noninteractive", "apt-get install -y "+package) + output = ExecMultiCmdsLocalSudo(cmds) + + outputlist = re.split("\n", output) + + unpacking = False + setting_up = False + + for line in outputlist: + #package is already installed + if (re.match(re.escape(package) + r' is already the newest version', line, re.M|re.I)): + RunLog.info(package + ": package is already installed."+line) + return True + #package installation check 1 + elif (re.match(r'Unpacking.*'+ re.escape(package) + r'.*', line, re.M|re.I)): + unpacking = True + #package installation check 2 + elif (re.match(r'Setting up '+ re.escape(package) + r" \(.*" , line, re.M|re.I)): + setting_up = True + #Package installed successfully + if (setting_up and unpacking): + RunLog.info(package+": package installed successfully.") + return True + #package is not found on the repository + elif (re.match(r'E: Unable to locate package '+ re.escape(package), line, re.M|re.I)): + break + #package installation failed due to server unavailability + elif (re.match(r'E: Unable to fetch some archives', line, re.M|re.I)): + break + + #Consider package installation failed if non of the above matches. + RunLog.info(package + ": package installation failed!\n") + RunLog.info("Error log: "+output) + return False + +def ZypperPackageInstall(package): + RunLog.info( "\nzypper_package_install: " + package) + + output = Run("zypper --non-interactive in "+package) + outputlist = re.split("\n", output) + + for line in outputlist: + #Package or package dependencies installed successfully + if (re.match(r'.*Installing: '+r'.*done', line, re.M|re.I)): + RunLog.info((package+": package installed successfully.\n"+line)) + return True + #package or provider of package is already installed + elif (re.match(r'.*\''+re.escape(package)+r'\' is already installed', line, re.M|re.I)): + RunLog.info((package + ": package is already installed.\n"+line)) + return True + #package is not found on the repository + elif (re.match(r'^No provider of \''+ re.escape(package) + r'\' found', line, re.M|re.I)): + break + + #Consider package installation failed if non of the above matches. + RunLog.error((package + ": package installation failed!\n"+output)) + return False + +def ZypperPackageRemove(package): + RunLog.info( "\nzypper_package_remove: " + package) + + output = Run("zypper --non-interactive remove "+package) + outputlist = re.split("\n", output) + + for line in outputlist: + #Package removed successfully + if (re.match(r'.*Removing '+re.escape(package)+r'.*done', line, re.M|re.I)): + RunLog.info((package+": package removed successfully.\n"+line)) + return True + #package is not installed + elif (re.match(r'\''+re.escape(package)+r'\' is not installed', line, re.M|re.I)): + RunLog.info((package + ": package is not installed.\n"+line)) + return True + #package is not found on the repository + elif (re.match(r'\''+re.escape(package)+r'\' not found in package names', line, re.M|re.I)): + return True + + #Consider package remove failed if non of the above matches. + RunLog.error((package + ": package remove failed!\n"+output)) + return False + +def InstallPackage(package): + RunLog.info( "\nInstall_package: "+package) + [current_distro, distro_version] = DetectDistro() + if (("ubuntu" in current_distro) or ("Debian" in current_distro)): + return AptgetPackageInstall(package) + elif (("rhel" in current_distro) or ("Oracle" in current_distro) or ("centos" in current_distro) or ("fedora" in current_distro)): + return YumPackageInstall(package) + elif (("SUSE" in current_distro) or ("opensuse" in current_distro) or ("sles" in current_distro)): + return ZypperPackageInstall(package) + else: + RunLog.error((package + ": package installation failed!")) + RunLog.info((current_distro + ": Unrecognised Distribution OS Linux found!")) + return False + +def InstallDeb(file_path): + RunLog.info( "\nInstalling package: "+file_path) + output = Run("dpkg -i "+file_path+" 2>&1") + RunLog.info(output) + outputlist = re.split("\n", output) + + for line in outputlist: + #package is already installed + if(re.match("installation successfully completed", line, re.M|re.I)): + RunLog.info(file_path + ": package installed successfully."+line) + return True + + RunLog.info(file_path+": Installation failed"+output) + return False + +def InstallRpm(file_path, package_name): + RunLog.info( "\nInstalling package: "+file_path) + output = Run("rpm -ivh --nodeps "+file_path+" 2>&1") + RunLog.info(output) + outputlist = re.split("\n", output) + package = re.split("/", file_path )[-1] + matchObj = re.match( r'(.*?)\.rpm', package, re.M|re.I) + package = matchObj.group(1) + + for line in outputlist: + #package is already installed + if (re.match(r'.*package'+re.escape(package) + r'.*is already installed', line, re.M|re.I)): + RunLog.info(file_path + ": package is already installed."+line) + return True + elif(re.match(re.escape(package) + r'.*######', line, re.M|re.I)): + RunLog.info(package + ": package installed successfully."+line) + return True + elif(re.match(re.escape(package_name) + r'.*######', line, re.M|re.I)): + RunLog.info(package + ": package installed successfully."+line) + return True + + RunLog.info(file_path+": Installation failed"+output) + return False + +#----------------------------------------------------------------------------------------------------------------------------------------------------- + +# iperf server + +def GetServerCommand(): + import argparse + import sys + #for error checking + validPlatformValues = ["532","540","541", "542", "550"] + parser = argparse.ArgumentParser() + + parser.add_argument('-u', '--udp', help='switch : starts the server in udp data packets listening mode.', choices=['yes', 'no'] ) + parser.add_argument('-p', '--port', help='specifies which port should be used', required=True, type= int) + parser.add_argument('-m', '--maxsegdisplay', help='Maximum Segment Size display ', choices=['yes', 'no']) + parser.add_argument('-M', '--maxsegset', help='Maximum Segment Size Settings', type = int) + parser.add_argument('-i', '--interval', help='specifies frequency of the output to be displyed on screen', type= int, required = True) + args = parser.parse_args() + #if no value specified then stop + command = 'iperf -s' + ' -i' + str(args.interval) + ' -p' + str(args.port) + if args.udp == 'yes': + command = command + ' -u' + if args.maxsegset != None: + command = command + ' -M' + str(args.maxsegset) + if args.maxsegdisplay == 'yes': + command = command + ' -m' + + finalCommand = 'nohup ' + command + ' > iperf-server.txt &' + return finalCommand + +#_________________________________________________________________________________________________________________________________________________ + +def StopServer(): + RunLog.info("Killing iperf server if running ..") + temp = Run("killall iperf") + +def StartServer(server): + StopServer() + RunLog.info("Starting iperf server..") + temp = Run(server) + tmp = Run("sleep 1") + #print(output) + iperfstatus = open('iperf-server.txt', 'r') + output = iperfstatus.read() + #print output + RunLog.info("Checking if server is started..") + if ("listening" in output) : + str_out = str.split(output) + #len_out = len(str_out) + for each in str_out : + #print(each) + if each == "listening" : + iperfPID = Run('pidof iperf') + RunLog.info("Server started successfully. PID : %s", iperfPID) + Run('echo "yes" > isServerStarted.txt') + #UpdateState('TestCompleted') + + else : + RunLog.error('Server Failed to start..') + Run("echo yes > isServerStarted.txt") + UpdateState('Aborted') + +#_______________________________________________________________________________________________________________________________________________ + +def AnalyseClientUpdateResult(): + iperfstatus = open('iperf-client.txt', 'r') + output = iperfstatus.read() + #print output + Failure = 0 + RunLog.info("Checking if client was connected to server..") + if ("connected" in output) : + if ("TestInComplete" in output): + RunLog.error('Client was successfully connected but, iperf process failed to exit.') + Failure = Failure + 1 + if("failed" in output): + RunLog.error("Client connected with some failed connections!") + Failure = Failure + 1 + if("error" in output): + RunLog.error("There were some errors in the connections.") + Failure = Failure + 1 + + if("refused" in output): + RunLog.error("some connections were refused.") + Failure = Failure + 1 + + if(Failure == 0): + RunLog.info("Client was successfully connected to server") + ResultLog.info("PASS") + UpdateState("TestCompleted") + else: + ResultLog.info("FAIL") + UpdateState("TestCompleted") + + else: + if("No address associated" in output): + RunLog.error('Client was not connected to server.') + RunLog.error("No address associated with hostname") + ResultLog.info('FAIL') + UpdateState("TestCompleted") + + elif("Connection refused" in output): + RunLog.error('Client was not connected to server.') + RunLog.error("Connection refused by the server.") + ResultLog.info('FAIL') + UpdateState("TestCompleted") + + + + elif("Name or service not known" in output): + RunLog.error('Client was not connected to server.') + RunLog.error("Name or service not known.") + ResultLog.info('FAIL') + UpdateState("TestCompleted") + + + else: + RunLog.error('Client was not connected to server.') + RunLog.error("Unlisted error. Check logs for more information...!") + ResultLog.info('FAIL') + UpdateState("TestCompleted") + + +#________________________________________________________________________________________________________________________________________________ + +def isProcessRunning(processName): + temp = 'ps -ef' + outProcess = Run(temp) + ProcessCount = outProcess.count('iperf -c') + if (ProcessCount > 0): + return "True" + else: + return "False" + +#________________________________________________________________________________________________________________________________________________ +# +# +# VNET Library.. + + +#DECLARE GLOBAL VARIBALES HERE FIRST AND THEN ADD THEM TO SetVnetGlobalParametesrs() +vnetDomain_db_filepath = '' +vnetDomain_rev_filepath = '' +dns_server_ip = '' +resolv_conf_filepath = '' +hosts_filepath = '' +def SetVnetGlobalParameters(): + import argparse + import sys + parser = argparse.ArgumentParser() + parser.add_argument('-d', '--dns_server_ip', help='DNS server IP address',required=True) + parser.add_argument('-D', '--vnetDomain_db_filepath', help='VNET Domain db filepath', required=True) + parser.add_argument('-r', '--vnetDomain_rev_filepath', help='VNET rev filepath',required=True) + parser.add_argument('-R', '--resolv_conf_filepath', help='resolv.conf filepath', required=True) + parser.add_argument('-h', '--hosts_filepath', help='hosts filepath',required = True) + args = parser.parse_args() + global dns_server_ip + global vnetDomain_db_filepath + global vnetDomain_rev_filepath + global resolv_conf_filepath + global hosts_filepath + vnetDomain_db_filepath = str(args.vnetDomain_db_filepath) + vnetDomain_rev_filepath = str(args.vnetDomain_rev_filepath) + dns_server_ip = str(args.dns_server_ip) + resolv_conf_filepath = str(args.resolv_conf_filepath) + hosts_filepath = str(args.hosts_filepath) + +def GetFileContentsByLines(filepath): + file = None + try: + file = open(filepath, 'r') + except: + return None + if file == None: + return None + try: + file_lines = file.readlines() + return file_lines + finally: + file.close() + +def RemoveStringMatchLinesFromFile(filepath, matchString): + try: + old_file_lines = GetFileContentsByLines(filepath) + NewFile = open(filepath,'w') + for eachLine in old_file_lines: + if not matchString in eachLine : + NewFile.writelines(eachLine) +#By the end of this for loop, Selected lines will be removed. + else: + print("removed %s from %s" % ( eachLine.replace('\n',''), filepath)) + NewFile.close() + except: + print ('File : %s not found.' % filepath) + +def ReplaceStringMatchLinesFromFile(filepath, matchString, newLine): + try: + old_file_lines = GetFileContentsByLines(filepath) + NewFile = open(filepath,'w') + for eachLine in old_file_lines: + if matchString in eachLine : + if '\n' in newLine: + NewFile.writelines(newLine) + else : + NewFile.writelines('%s\n' % newLine) + else : + NewFile.writelines(eachLine) + NewFile.close() + except: + print ('File : %s not found.' % filepath) + +def GetStringMatchCount(filepath, matchString): + #try: + NewFile = open(filepath,'r') + NewFile.close() + matchCount = 0 + file_lines = GetFileContentsByLines(filepath) + for eachLine in file_lines: + if matchString in eachLine : + matchCount = matchCount + 1 + return matchCount + #except: + print ('File : %s not found.' % filepath) + +def RemoveICAVMsFromDBfile(vnetDomain_db_filepath): + matchString = 'ICA-' + RemoveStringMatchLinesFromFile(vnetDomain_db_filepath,matchString) + +def RemoveICAVMsFromREVfile(vnetDomain_rev_filepath): + matchString = 'ICA-' + RemoveStringMatchLinesFromFile(vnetDomain_rev_filepath,matchString) + + +def RetryOperation(operation, description, expectResult=None, maxRetryCount=18, retryInterval=10): + retryCount = 1 + + while True: + RunLog.info("Attempt : %s : %s", retryCount, description) + ret = None + + try: + ret = Run(operation) + if (expectResult and (ret.strip() == expectResult)) or (expectResult == None): + return ret + except: + RunLog.info("Retrying Operation") + + if retryCount >= maxRetryCount: + break + retryCount += 1 + time.sleep(retryInterval) + if(expectResult != None): + return ret + return None + +def AppendTextToFile(filepath,textString): + #THIS FUNCTION DONES NOT CREATES ANY FILE. THE FILE MUST PRESENT AT THE SPECIFIED LOCATION. + try: + fileToEdit = open ( filepath , 'r' ) + fileToEdit.close() + fileToEdit = open ( filepath , 'a' ) + if not '\n' in textString: + fileToEdit.write(textString) + else: + fileToEdit.writelines(textString) + fileToEdit.close() + except: + print('File %s not found' % filepath) + + +def AddICAVMsToDnsServer(HostnameDIP,vnetDomain_db_filepath,vnetDomain_rev_filepath): + #SetVnetGlobalParameters() + vnetDomain=(vnetDomain_db_filepath.split("/"))[len((vnetDomain_db_filepath.split("/")))-1].replace(".db","") + #PARSE THE VM DETAILS FIRST. + separatedVMs = HostnameDIP.split('^') + vmCounter = 0 + successCount = 0 + for eachVM in separatedVMs: + vmCounter = vmCounter + 1 + eachVMdata = eachVM.split(':') + eachVMHostname = eachVMdata[0] + eachVMDIP = eachVMdata[1] + lastDigitofVMDIP = eachVMDIP.split('.')[3] + vnetDomainDBstring = '%s\tIN\tA\t%s\n' % (eachVMHostname,eachVMDIP) + print(vnetDomainDBstring.replace('\n','')) + AppendTextToFile(vnetDomain_db_filepath,vnetDomainDBstring) + vnetDomainREVstring = '%s\tIN\tPTR\t%s.%s.\n' % (lastDigitofVMDIP,eachVMHostname,vnetDomain) + AppendTextToFile(vnetDomain_rev_filepath,vnetDomainREVstring) + print(vnetDomainREVstring.replace('\n','')) + isDBFileEntry = GetStringMatchCount(vnetDomain_db_filepath,vnetDomainDBstring) + isREVFileEntry = GetStringMatchCount(vnetDomain_rev_filepath,vnetDomainREVstring) + if isDBFileEntry >= 1 and isREVFileEntry >= 1: + print (vnetDomain_db_filepath + " file edited for " + eachVMDIP + " : " + eachVMHostname) + print (vnetDomain_rev_filepath + " file edited for " + eachVMDIP + " : " + eachVMHostname) + successCount = successCount + 1 + else: + if isDBFileEntry != 1: + print ("Failed to edit " + vnetDomain_db_filepath + " for " + eachVMDIP + " : " + eachVMHostname) + if isREVFileEntry != 1: + print ("Failed to edit " + vnetDomain_rev_filepath + " for " + eachVMDIP + " : " + eachVMHostname) + if successCount == vmCounter: + return 0 + else: + return 1 + +def RemoteUpload(hostIP, hostPassword, hostUsername, hostPort, filesToUpload, remoteLocation): + import paramiko +# print ('%s %s' % (hostIP,hostPort)) + transport = paramiko.Transport((hostIP,int(hostPort))) + try: + print('Connecting to %s'% hostIP), + transport.connect(username = hostUsername, password = hostPassword) + print('...Connected.') + try: + sftp = paramiko.SFTPClient.from_transport(transport) + filesToUpload = filesToUpload.split(',') + for eachFile in filesToUpload : + eachFileName = eachFile.split('/') +# print eachFileName + eachFileNameLength = len(eachFileName) +# print eachFileNameLength + exactFileName = eachFileName[eachFileNameLength-1] +# print exactFileName + if remoteLocation[-1] == '/': + newFile = "%s%s" % (remoteLocation,exactFileName) + else: + newFile = "%s/%s" % (remoteLocation,exactFileName) +# print ("%s - %s" % (eachFile, newFile)) + try: + print ("Uploading %s to %s" % (eachFile, newFile)), + sftp.put(eachFile, newFile) + print ('...OK!') + except: + print('...Error!') + transport.close() + except: + print("Failed to upload to %s" % hostIP) + + except: + print("...Failed!") + +def RemoteDownload(hostIP, hostPassword, hostUsername, hostPort, filesToDownload, localLocation): + import paramiko +# print ('%s %s' % (hostIP,hostPort)) + transport = paramiko.Transport((hostIP,int(hostPort))) + try: + print('Connecting to %s'% hostIP), + transport.connect(username = hostUsername, password = hostPassword) + print('...Connected.') + try: + sftp = paramiko.SFTPClient.from_transport(transport) + filesToDownload = filesToDownload.split(',') + for eachFile in filesToDownload : + eachFileName = eachFile.split('/') +# print eachFileName + eachFileNameLength = len(eachFileName) +# print eachFileNameLength + exactFileName = eachFileName[eachFileNameLength-1] +# print exactFileName + if localLocation[-1] == '/': + newFile = "%s%s" % (localLocation,exactFileName) + else: + newFile = "%s/%s" % (localLocation,exactFileName) +# print ("%s - %s" % (eachFile, newFile)) + try: + print ("Downloading %s to %s" % (eachFile, newFile)), + sftp.get(eachFile, newFile) + print ('...OK!') + except: + print('...Error!') + transport.close() + except: + print("Failed to Download to %s" % hostIP) + + except: + print("...Failed!") + + +def ConfigureResolvConf(resolv_conf_filepath,dns_server_ip,vnetDomain): + isDnsEntry = GetStringMatchCount(resolv_conf_filepath,dns_server_ip) + hostName = JustRun('hostname') + if isDnsEntry == 1: + domainReplaceString="search " + vnetDomain + ReplaceStringMatchLinesFromFile(resolv_conf_filepath,'search',domainReplaceString) + isDnsNameEntry = GetStringMatchCount(resolv_conf_filepath,domainReplaceString) + if isDnsNameEntry == 1: + print('Added string "search ' + vnetDomain + '" to ' + resolv_conf_filepath) + return 0 + else : + print('Failed to add string "search ' + vnetDomain + '" to ' + resolv_conf_filepath) + return 1 + else: + print('DNS server IP is not present in ' + resolv_conf_filepath + ' file') + return 2 + +def ConfigureHostsFile(hosts_filepath): + hostName = JustRun('hostname') + AppendTextToFile(hosts_filepath,"127.0.0.1 %s\n" % hostName) + isHostsEdited = GetStringMatchCount(hosts_filepath, hostName) + if isHostsEdited >= 1: + print('Added string "127.0.0.1 ' + hostName + '" to ' + hosts_filepath) + return 0 + else : + print('Failed to Add string "127.0.0.1 ' + hostName + '" to ' + hosts_filepath) + return 1 + +def GetOSDisk(): + resourceDiskPartition = JustRun("grep -i '%s' /etc/mtab | awk '{print $1;}' | tr -d '\n'" % GetResourceDiskMountPoint()) + if 'sda' in resourceDiskPartition: + return 'sdb' + else : + return 'sda' diff --git a/Testscripts/Linux/azuremodules.sh b/Testscripts/Linux/azuremodules.sh new file mode 100644 index 000000000..8aaa8012f --- /dev/null +++ b/Testscripts/Linux/azuremodules.sh @@ -0,0 +1,395 @@ +#!/bin/bash +# +# This script is library for shell scripts used in Azure Linux Automation. +# Author: Srikanth Myakam +# Email : v-srm@microsoft.com +# +# + +function get_lis_version () +{ + lis_version=`modinfo hv_vmbus | grep "^version:"| awk '{print $2}'` + if [ "$lis_version" == "" ] + then + lis_version="Default_LIS" + fi + echo $lis_version +} + +function get_host_version () +{ + dmesg | grep "Host Build" | sed "s/.*Host Build://"| awk '{print $1}'| sed "s/;//" +} + +function check_exit_status () +{ + exit_status=$? + message=$1 + + if [ $exit_status -ne 0 ]; then + echo "$message: Failed (exit code: $exit_status)" + if [ "$2" == "exit" ] + then + exit $exit_status + fi + else + echo "$message: Success" + fi +} + +function detect_linux_ditribution_version() +{ + local distro_version="Unknown" + if [ -f /etc/centos-release ] ; then + distro_version=`cat /etc/centos-release | sed s/.*release\ // | sed s/\ .*//` + elif [ -f /etc/oracle-release ] ; then + distro_version=`cat /etc/oracle-release | sed s/.*release\ // | sed s/\ .*//` + elif [ -f /etc/redhat-release ] ; then + distro_version=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//` + elif [ -f /etc/os-release ] ; then + distro_version=`cat /etc/os-release|sed 's/"//g'|grep "VERSION_ID="| sed 's/VERSION_ID=//'| sed 's/\r//'` + fi + echo $distro_version +} + +function detect_linux_ditribution() +{ + local linux_ditribution=`cat /etc/*release*|sed 's/"//g'|grep "^ID="| sed 's/ID=//'` + local temp_text=`cat /etc/*release*` + if [ "$linux_ditribution" == "" ] + then + if echo "$temp_text" | grep -qi "ol"; then + linux_ditribution='Oracle' + elif echo "$temp_text" | grep -qi "Ubuntu"; then + linux_ditribution='Ubuntu' + elif echo "$temp_text" | grep -qi "SUSE Linux"; then + linux_ditribution='SUSE' + elif echo "$temp_text" | grep -qi "openSUSE"; then + linux_ditribution='OpenSUSE' + elif echo "$temp_text" | grep -qi "centos"; then + linux_ditribution='CentOS' + elif echo "$temp_text" | grep -qi "Oracle"; then + linux_ditribution='Oracle' + elif echo "$temp_text" | grep -qi "Red Hat"; then + linux_ditribution='RHEL' + else + linux_ditribution='unknown' + fi + fi + echo "$(echo "$linux_ditribution" | sed 's/.*/\u&/')" +} + +function updaterepos() +{ + ditribution=$(detect_linux_ditribution) + case "$ditribution" in + Oracle|RHEL|CentOS) + yum makecache + ;; + + Ubuntu) + apt-get update + ;; + SUSE|openSUSE|sles) + zypper refresh + ;; + + *) + echo "Unknown ditribution" + return 1 + esac +} + +function install_rpm () +{ + package_name=$1 + rpm -ivh --nodeps $package_name + check_exit_status "install_rpm $package_name" +} + +function install_deb () +{ + package_name=$1 + dpkg -i $package_name + apt-get install -f + check_exit_status "install_deb $package_name" +} + +function apt_get_install () +{ + package_name=$1 + DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes $package_name + check_exit_status "apt_get_install $package_name" +} + +function yum_install () +{ + package_name=$1 + yum install -y $package_name + check_exit_status "yum_install $package_name" +} + +function zypper_install () +{ + package_name=$1 + zypper --non-interactive in $package_name + check_exit_status "zypper_install $package_name" +} + +function install_package () +{ + local package_name=$@ + ditribution=$(detect_linux_ditribution) + for i in "${package_name[@]}" + do + case "$ditribution" in + Oracle|RHEL|CentOS) + yum_install "$package_name" + ;; + + Ubuntu) + apt_get_install "$package_name" + ;; + + SUSE|OpenSUSE|sles) + zypper_install "$package_name" + ;; + + *) + echo "Unknown ditribution" + return 1 + esac + done +} + +function creat_partitions () +{ + disk_list=($@) + echo "Creating partitions on ${disk_list[@]}" + + count=0 + while [ "x${disk_list[count]}" != "x" ] + do + echo ${disk_list[$count]} + (echo n; echo p; echo 2; echo; echo; echo t; echo fd; echo w;) | fdisk ${disk_list[$count]} + count=$(( $count + 1 )) + done +} + +function remove_partitions () +{ + disk_list=($@) + echo "Creating partitions on ${disk_list[@]}" + + count=0 + while [ "x${disk_list[count]}" != "x" ] + do + echo ${disk_list[$count]} + (echo p; echo d; echo w;) | fdisk ${disk_list[$count]} + count=$(( $count + 1 )) + done +} + +function create_raid_and_mount() +{ +# Creats RAID using unused data disks attached to the VM. + if [[ $# == 3 ]] + then + local deviceName=$1 + local mountdir=$2 + local format=$3 + else + local deviceName="/dev/md1" + local mountdir=/data-dir + local format="ext4" + fi + + local uuid="" + local list="" + + echo "IO test setup started.." + list=(`fdisk -l | grep 'Disk.*/dev/sd[a-z]' |awk '{print $2}' | sed s/://| sort| grep -v "/dev/sd[ab]$" `) + + lsblk + install_package mdadm + echo "--- Raid $deviceName creation started ---" + (echo y)| mdadm --create $deviceName --level 0 --raid-devices ${#list[@]} ${list[@]} + check_exit_status "$deviceName Raid creation" + + time mkfs -t $format $deviceName + check_exit_status "$deviceName Raid format" + + mkdir $mountdir + uuid=`blkid $deviceName| sed "s/.*UUID=\"//"| sed "s/\".*\"//"` + echo "UUID=$uuid $mountdir $format defaults 0 2" >> /etc/fstab + mount $deviceName $mountdir + check_exit_status "RAID ($deviceName) mount on $mountdir as $format" +} + +function remote_copy () +{ + remote_path="~" + + while echo $1 | grep -q ^-; do + eval $( echo $1 | sed 's/^-//' )=$2 + shift + shift + done + + if [[ `which sshpass` == "" ]] + then + echo "sshpass not installed\n Installing now..." + install_package "sshpass" + fi + + if [ "x$host" == "x" ] || [ "x$user" == "x" ] || [ "x$passwd" == "x" ] || [ "x$filename" == "x" ] ; then + echo "Usage: remote_copy -user -passwd -host -filename -remote_path -cmd " + return + fi + + if [ "$cmd" == "get" ] || [ "x$cmd" == "x" ]; then + source_path="$user@$host:$remote_path/$filename" + destination_path="." + elif [ "$cmd" == "put" ]; then + source_path=$filename + destination_path=$user@$host:$remote_path/ + fi + + status=`sshpass -p $passwd scp -o StrictHostKeyChecking=no $source_path $destination_path 2>&1` + echo $status +} + +function remote_exec () +{ + while echo $1 | grep -q ^-; do + eval $( echo $1 | sed 's/^-//' )=$2 + shift + shift + done + cmd=$@ + if [[ `which sshpass` == "" ]] + then + echo "sshpass not installed\n Installing now..." + install_package "sshpass" + fi + + if [ "x$host" == "x" ] || [ "x$user" == "x" ] || [ "x$passwd" == "x" ] || [ "x$cmd" == "x" ] ; then + echo "Usage: remote_exec -user -passwd -host " + return + fi + + status=`sshpass -p $passwd ssh -t -o StrictHostKeyChecking=no $user@$host $cmd 2>&1` + echo $status +} + +function set_user_password { + # This routine can set root or any user's password. + if [[ $# == 3 ]] + then + user=$1 + user_password=$2 + sudo_password=$3 + else + echo "Usage: user user_password sudo_password" + return -1 + fi + + hash=$(openssl passwd -1 $user_password) + + string=`echo $sudo_password | sudo -S cat /etc/shadow | grep $user` + + if [ "x$string" == "x" ] + then + echo "$user not found in /etc/shadow" + return -1 + fi + + IFS=':' read -r -a array <<< "$string" + line="${array[0]}:$hash:${array[2]}:${array[3]}:${array[4]}:${array[5]}:${array[6]}:${array[7]}:${array[8]}" + + echo $sudo_password | sudo -S sed -i "s#^${array[0]}.*#$line#" /etc/shadow + + if [ `echo $sudo_password | sudo -S cat /etc/shadow| grep $line|wc -l` != "" ] + then + echo "Password set succesfully" + else + echo "failed to set password" + fi +} + +function collect_VM_properties () +{ +# This routine collects the information in .csv format. +# Anyone can expand this with useful details. +# Better if it can collect details without su permission. + + local output_file=$1 + + if [ "x$output_file" == "x" ] + then + output_file="VM_properties.csv" + fi + + echo "" > $output_file + echo ",OS type,"`detect_linux_ditribution` `detect_linux_ditribution_version` >> $output_file + echo ",Kernel version,"`uname -r` >> $output_file + echo ",LIS Version,"`get_lis_version` >> $output_file + echo ",Host Version,"`get_host_version` >> $output_file + echo ",Total CPU cores,"`nproc` >> $output_file + echo ",Total Memory,"`free -h|grep Mem|awk '{print $2}'` >> $output_file + echo ",Resource disks size,"`lsblk|grep "^sdb"| awk '{print $4}'` >> $output_file + echo ",Data disks attached,"`lsblk | grep "^sd" | awk '{print $1}' | sort | grep -v "sd[ab]$" | wc -l` >> $output_file + echo ",eth0 MTU,"`ifconfig eth0|grep MTU|sed "s/.*MTU:\(.*\) .*/\1/"` >> $output_file + echo ",eth1 MTU,"`ifconfig eth1|grep MTU|sed "s/.*MTU:\(.*\) .*/\1/"` >> $output_file +} + +function keep_cmd_in_startup () +{ + testcommand=$* + startup_files="/etc/rc.d/rc.local /etc/rc.local /etc/SuSE-release" + count=0 + for file in $startup_files + do + if [[ -f $file ]] + then + if ! grep -q "${testcommand}" $file + then + sed "/^\s*exit 0/i ${testcommand}" $file -i + if ! grep -q "${testcommand}" $file + then + echo $testcommand >> $file + fi + echo "Added $testcommand >> $file" + ((count++)) + fi + fi + done + if [ $count == 0 ] + then + echo "Cannot find $startup_files files" + fi +} + +function remove_cmd_from_startup () +{ + testcommand=$* + startup_files="/etc/rc.d/rc.local /etc/rc.local /etc/SuSE-release" + count=0 + for file in $startup_files + do + if [[ -f $file ]] + then + if grep -q "${testcommand}" $file + then + sed "s/${testcommand}//" $file -i + ((count++)) + echo "Removed $testcommand from $file" + fi + fi + done + if [ $count == 0 ] + then + echo "Cannot find $testcommand in $startup_files files" + fi +} + diff --git a/Testscripts/Linux/customKernelInstall.sh b/Testscripts/Linux/customKernelInstall.sh new file mode 100644 index 000000000..323ca18d9 --- /dev/null +++ b/Testscripts/Linux/customKernelInstall.sh @@ -0,0 +1,251 @@ +#!/bin/bash + +####################################################################### +# +# Linux on Hyper-V and Azure Test Code, ver. 1.0.0 +# Copyright (c) Microsoft Corporation +# +# All rights reserved. +# Licensed under the Apache License, Version 2.0 (the ""License""); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +# ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR +# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. +# +# See the Apache Version 2.0 License for specific language governing +# permissions and limitations under the License. +# +####################################################################### + +####################################################################### +# +# +# +# Description: +####################################################################### + +#HOW TO PARSE THE ARGUMENTS.. SOURCE - http://stackoverflow.com/questions/4882349/parsing-shell-script-arguments + +while echo $1 | grep ^- > /dev/null; do + eval $( echo $1 | sed 's/-//g' | tr -d '\012')=$2 + shift + shift +done +# +# Constants/Globals +# +ICA_TESTRUNNING="TestRunning" # The test is running +ICA_TESTCOMPLETED="TestCompleted" # The test completed successfully +ICA_TESTABORTED="TestAborted" # Error during the setup of the test +ICA_TESTFAILED="TestFailed" # Error occurred during the test + +####################################################################### +# +# LogMsg() +# +####################################################################### + +if [ -z "$customKernel" ]; then + echo "Please mention -customKernel next" + exit 1 +fi +if [ -z "$logFolder" ]; then + logFolder="~" + echo "-logFolder is not mentioned. Using ~" +else + echo "Using Log Folder $logFolder" +fi + +LogMsg() +{ + echo `date "+%b %d %Y %T"` : "${1}" # Add the time stamp to the log message + echo "${1}" >> $logFolder/build-customKernel.txt +} + +UpdateTestState() +{ + echo "${1}" > $logFolder/state.txt +} + + +touch $logFolder/build-customKernel.txt + +CheckInstallLockUbuntu() +{ + dpkgPID=$(pidof dpkg) + if [ $? -eq 0 ];then + LogMsg "Another install is in progress. Waiting 10 seconds." + sleep 10 + CheckInstallLockUbuntu + else + LogMsg "No lock on dpkg present." + fi +} + + +InstallKernel() +{ + sleep 10 + if [ "${customKernel}" == "linuxnext" ]; then + kernelSource="https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git" + sourceDir="linux-next" + elif [ "${customKernel}" == "proposed" ]; then + DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux" /etc/{issue,*release,*version}` + if [[ $DISTRO =~ "Xenial" ]]; + then + LogMsg "Enabling proposed repositry..." + echo "deb http://archive.ubuntu.com/ubuntu/ xenial-proposed restricted main multiverse universe" >> /etc/apt/sources.list + rm -rf /etc/apt/preferences.d/proposed-updates + LogMsg "Installing linux-image-generic from proposed repository." + apt -y update >> $logFolder/build-customKernel.txt 2>&1 + apt -y --fix-missing upgrade >> $logFolder/build-customKernel.txt 2>&1 + kernelInstallStatus=$? + elif [[ $DISTRO =~ "Trusty" ]]; + then + LogMsg "Enabling proposed repositry..." + echo "deb http://archive.ubuntu.com/ubuntu/ trusty-proposed restricted main multiverse universe" >> /etc/apt/sources.list + rm -rf /etc/apt/preferences.d/proposed-updates + LogMsg "Installing linux-image-generic from proposed repository." + apt -y update >> $logFolder/build-customKernel.txt 2>&1 + apt -y --fix-missing upgrade >> $logFolder/build-customKernel.txt 2>&1 + kernelInstallStatus=$? + fi + UpdateTestState $ICA_TESTCOMPLETED + if [ $kernelInstallStatus -ne 0 ]; then + LogMsg "CUSTOM_KERNEL_FAIL" + UpdateTestState $ICA_TESTFAILED + else + LogMsg "CUSTOM_KERNEL_SUCCESS" + UpdateTestState $ICA_TESTCOMPLETED + fi + elif [ "${customKernel}" == "latest" ]; then + DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux" /etc/{issue,*release,*version}` + if [[ $DISTRO =~ "Ubuntu" ]]; + then + LogMsg "Installing linux-image-generic from repository." + apt -y update >> $logFolder/build-customKernel.txt 2>&1 + apt -y --fix-missing upgrade >> $logFolder/build-customKernel.txt 2>&1 + LogMsg "Installing linux-image-generic from proposed repository." + apt -y update >> $logFolder/build-customKernel.txt 2>&1 + apt -y --fix-missing upgrade >> $logFolder/build-customKernel.txt 2>&1 + kernelInstallStatus=$? + fi + UpdateTestState $ICA_TESTCOMPLETED + if [ $kernelInstallStatus -ne 0 ]; then + LogMsg "CUSTOM_KERNEL_FAIL" + UpdateTestState $ICA_TESTFAILED + else + LogMsg "CUSTOM_KERNEL_SUCCESS" + UpdateTestState $ICA_TESTCOMPLETED + fi + elif [ "${customKernel}" == "netnext" ]; then + kernelSource="https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git" + sourceDir="net-next" + elif [[ $customKernel == *.deb ]]; then + LogMsg "Custom Kernel:$customKernel" + apt-get update + if [[ $customKernel =~ "http" ]];then + CheckInstallLockUbuntu + apt-get install wget + LogMsg "Debian package web link detected. Downloading $customKernel" + wget $customKernel + LogMsg "Installing ${customKernel##*/}" + dpkg -i "${customKernel##*/}" >> $logFolder/build-customKernel.txt 2>&1 + kernelInstallStatus=$? + else + CheckInstallLockUbuntu + prefix="localfile:" + LogMsg "Installing ${customKernel#$prefix}" + dpkg -i "${customKernel#$prefix}" >> $logFolder/build-customKernel.txt 2>&1 + kernelInstallStatus=$? + fi + + UpdateTestState $ICA_TESTCOMPLETED + if [ $kernelInstallStatus -ne 0 ]; then + LogMsg "CUSTOM_KERNEL_FAIL" + UpdateTestState $ICA_TESTFAILED + else + LogMsg "CUSTOM_KERNEL_SUCCESS" + UpdateTestState $ICA_TESTCOMPLETED + fi + elif [[ $customKernel == *.rpm ]]; then + LogMsg "Custom Kernel:$customKernel" + + if [[ $customKernel =~ "http" ]];then + yum -y install wget + LogMsg "RPM package web link detected. Downloading $customKernel" + wget $customKernel + LogMsg "Installing ${customKernel##*/}" + rpm -ivh "${customKernel##*/}" >> $logFolder/build-customKernel.txt 2>&1 + kernelInstallStatus=$? + else + prefix="localfile:" + LogMsg "Installing ${customKernel#$prefix}" + rpm -ivh "${customKernel#$prefix}" >> $logFolder/build-customKernel.txt 2>&1 + kernelInstallStatus=$? + + fi + UpdateTestState $ICA_TESTCOMPLETED + if [ $kernelInstallStatus -ne 0 ]; then + LogMsg "CUSTOM_KERNEL_FAIL" + UpdateTestState $ICA_TESTFAILED + else + LogMsg "CUSTOM_KERNEL_SUCCESS" + UpdateTestState $ICA_TESTCOMPLETED + grub2-set-default 0 + fi + fi + if [[ ${customKernel} == "linuxnext" ]] || [[ ${customKernel} == "netnext" ]]; then + LogMsg "Custom Kernel:$customKernel" + chmod +x $logFolder/DetectLinuxDistro.sh + LinuxDistro=`$logFolder/DetectLinuxDistro.sh` + if [ $LinuxDistro == "SLES" -o $LinuxDistro == "SUSE" ]; then + #zypper update + zypper --non-interactive install git-core make tar gcc bc patch dos2unix wget xz + #TBD + elif [ $LinuxDistro == "CENTOS" -o $LinuxDistro == "REDHAT" -o $LinuxDistro == "FEDORA" -o $LinuxDistro == "ORACLELINUX" ]; then + #yum update + yum install -y git make tar gcc bc patch dos2unix wget xz + #TBD + elif [ $LinuxDistro == "UBUNTU" ]; then + unset UCF_FORCE_CONFFOLD + export UCF_FORCE_CONFFNEW=YES + export DEBIAN_FRONTEND=noninteractive + ucf --purge /etc/kernel-img.conf + export DEBIAN_FRONTEND=noninteractive + LogMsg "Updating distro..." + CheckInstallLockUbuntu + apt-get update + LogMsg "Installing packages git make tar gcc bc patch dos2unix wget ..." + apt-get install -y git make tar gcc bc patch dos2unix wget >> $logFolder/build-customKernel.txt 2>&1 + LogMsg "Installing kernel-package ..." + apt-get -o Dpkg::Options::="--force-confnew" -y install kernel-package >> $logFolder/build-customKernel.txt 2>&1 + rm -rf linux-next + LogMsg "Downloading kernel source..." + git clone ${kernelSource} >> $logFolder/build-customKernel.txt 2>&1 + cd ${sourceDir} + #Download kernel build shell script... + wget https://raw.githubusercontent.com/simonxiaoss/linux_performance_test/master/git_bisect/build-ubuntu.sh + chmod +x build-ubuntu.sh + #Start installing kernel + LogMsg "Building and Installing kernel..." + ./build-ubuntu.sh >> $logFolder/build-customKernel.txt 2>&1 + kernelInstallStatus=$? + if [ $kernelInstallStatus -eq 0 ]; then + LogMsg "CUSTOM_KERNEL_SUCCESS" + UpdateTestState $ICA_TESTFAILED + else + LogMsg "CUSTOM_KERNEL_FAIL" + UpdateTestState $ICA_TESTFAILED + fi + fi + fi + UpdateTestState $ICA_TESTCOMPLETED + return $kernelInstallStatus +} +InstallKernel +exit 0 diff --git a/Testscripts/Linux/customLISInstall.sh b/Testscripts/Linux/customLISInstall.sh new file mode 100644 index 000000000..7a1ddc968 --- /dev/null +++ b/Testscripts/Linux/customLISInstall.sh @@ -0,0 +1,166 @@ +#!/bin/bash + +####################################################################### +# +# Description: It install the LIS using given LIS source file (.tar.gz or lis-next) +# Usage: ./customLISInstall.sh -customLIS lisnext or tar file link -LISbranch a specific branch or default is master +# Author: Sivakanth Rebba +# Email : v-sirebb@microsoft.com +# +####################################################################### + +#HOW TO PARSE THE ARGUMENTS.. SOURCE - http://stackoverflow.com/questions/4882349/parsing-shell-script-arguments + +while echo $1 | grep ^- > /dev/null; do + eval $( echo $1 | sed 's/-//g' | tr -d '\012')=$2 + shift + shift +done +# +# Constants/Globals +# +ICA_TESTRUNNING="TestRunning" # The test is running +ICA_TESTCOMPLETED="TestCompleted" # The test completed successfully +ICA_TESTABORTED="TestAborted" # Error during the setup of the test +ICA_TESTFAILED="TestFailed" # Error occurred during the test + +####################################################################### +# +# LogMsg() +# +####################################################################### +LogMsg() +{ + echo `date "+%b %d %Y %T"` : "${1}" # Add the time stamp to the log message + echo "${1}" >> ~/build-customLIS.txt +} + +UpdateTestState() +{ + echo "${1}" > ~/state.txt +} + +if [ -z "$customLIS" ]; then + echo "Please mention -customLIS next" + exit 1 +fi +if [ -z "$LISbranch" ]; then + echo "Not mentioned LIS branch, Use Master branch" + LISbranch="master" +fi +touch ~/build-customLIS.txt + +#Detect Distro and it's version +DistroName="Unknown" +DistroVersion="Unknown" +if [ -f /etc/redhat-release ] ; then + DistroName='REDHAT' + DistroVersion=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//` +elif [ -f /etc/centos-release ] ; then + DistroName==`cat /etc/centos-release | sed s/^\ // |sed s/\ .*//` + DistroName='CENTOS' + DistroVersion=`cat /etc/centos-release | sed s/.*release\ // | sed s/\ .*//` +elif [ -f /etc/SuSE-release ] ; then + DistroName=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//` + DistroVersion=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //` +elif [ -f /etc/debian_version ] ; then + DistroName="Debian `cat /etc/debian_version`" + DistroVersion="" +fi +if [ -f /etc/UnitedLinux-release ] ; then + DistroName="${DistroName}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]" +fi +LogMsg "*****OS Info*****" +cat /etc/*-release >> ~/build-customLIS.txt 2>&1 +LogMsg "*****Kernen Info*****" +uname -r >> ~/build-customLIS.txt 2>&1 +LogMsg "*****LIS Info*****" +modinfo hv_vmbus >> ~/build-customLIS.txt 2>&1 +kernel=`uname -r` +if [ "${customLIS}" == "lisnext" ]; then + LISSource="https://github.com/LIS/lis-next.git" + sourceDir="lis-next" +elif [ "${customLIS}" == "netnext" ]; then + LISSource="https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git" + sourceDir="net-next" +elif [[ $customLIS == *.rpm ]]; then + LogMsg "Custom LIS:$customLIS" + sed -i '/^exclude/c\#exclude' /etc/yum.conf + yum install -y wget tar + LogMsg "Debian package web link detected. Downloading $customLIS" + wget $customLIS + LogMsg "Installing ${customLIS##*/}" + rpm -ivh "${customLIS##*/}" >> ~/build-customLIS.txt 2>&1 + LISInstallStatus=$? + UpdateTestState $ICA_TESTCOMPLETED + if [ $LISInstallStatus -ne 0 ]; then + LogMsg "CUSTOM_LIS_FAIL" + UpdateTestState $ICA_TESTFAILED + else + LogMsg "CUSTOM_LIS_SUCCESS" + UpdateTestState $ICA_TESTCOMPLETED + fi + exit 0 +elif [[ $customLIS == *.tar.gz ]]; then + LogMsg "Custom LIS:$customLIS" + sed -i '/^exclude/c\#exclude' /etc/yum.conf + yum install -y git make tar gcc bc patch dos2unix wget xz >> ~/build-customLIS.txt 2>&1 + LogMsg "LIS tar file web link detected. Downloading $customLIS" + wget $customLIS + LogMsg "Extracting ${customLIS##*/}" + tar -xvzf "${customLIS##*/}" + LogMsg "Installing ${customLIS##*/}" + cd LISISO + ./install.sh >> ~/build-customLIS.txt 2>&1 + LISInstallStatus=$? + UpdateTestState $ICA_TESTCOMPLETED + modinfo hv_vmbus >> ~/build-customLIS.txt 2>&1 + if [ $LISInstallStatus -ne 0 ]; then + LogMsg "CUSTOM_LIS_FAIL" + UpdateTestState $ICA_TESTFAILED + else + LogMsg "CUSTOM_LIS_SUCCESS" + UpdateTestState $ICA_TESTCOMPLETED + fi + exit 0 +fi +LogMsg "Custom LIS:$customLIS" + +if [ $DistroName == "SLES" -o $DistroName == "SUSE" ]; then + zypper --non-interactive install git-core make tar gcc bc patch dos2unix wget xz + LogMsg "LIS doesn't support for $DistroName distro..." +elif [ $DistroName == "CENTOS" -o $DistroName == "REDHAT" -o $DistroName == "FEDORA" -o $DistroName == "ORACLELINUX" ]; then + LogMsg "Installing packages git make tar gcc bc patch dos2unix wget ..." + sed -i '/^exclude/c\#exclude' /etc/yum.conf + yum install -y git make tar gcc bc patch dos2unix wget xz >> ~/build-customLIS.txt 2>&1 + LogMsg "Downloading LIS source from ${LISSource}..." + git clone ${LISSource} >> ~/build-customLIS.txt 2>&1 + cd ${sourceDir} + git checkout ${LISbranch} + LogMsg "Downloaded LIS from this ${LISbranch} branch..." + if [[ $DistroVersion == *"5."* ]]; then + LISsourceDir=hv-rhel5.x/hv + elif [[ $DistroVersion == *"6."* ]]; then + LISsourceDir=hv-rhel6.x/hv + elif [[ $DistroVersion == *"7."* ]]; then + LISsourceDir=hv-rhel7.x/hv + fi + cd $LISsourceDir + LISDir=`pwd` + LogMsg "Installing kernel-devel-${kernel} for LIS..." + yum install -y "https://konkasoftpackages.blob.core.windows.net/linuxbinaries/kernel-devel-${kernel}.rpm" ~/build-customLIS.txt 2>&1 + LogMsg "LIS is installing from this ${LISDir} branch..." + ./*-hv-driver-install >> ~/build-customLIS.txt 2>&1 + if [ $? -ne 0 ]; then + LogMsg "CUSTOM_LIS_FAIL" + UpdateTestState $ICA_TESTFAILED + exit 0 + fi +elif [ $DistroName == "UBUNTU" ]; then + LogMsg "LIS doesn't support for $DistroName distro..." +fi +UpdateTestState $ICA_TESTCOMPLETED +sleep 10 +LogMsg "CUSTOM_LIS_SUCCESS" +sleep 10 +exit 0 diff --git a/Testscripts/Linux/nslookup.py b/Testscripts/Linux/nslookup.py new file mode 100644 index 000000000..f039b18f9 --- /dev/null +++ b/Testscripts/Linux/nslookup.py @@ -0,0 +1,12 @@ +#!/usr/bin/python + +import argparse +import sys +import socket + +parser = argparse.ArgumentParser() + +parser.add_argument('-n', '--hostname', help='hostname or fqdn', required=True) +args = parser.parse_args() + +print socket.gethostbyname(args.hostname) \ No newline at end of file diff --git a/Testscripts/Linux/perf_fio.sh b/Testscripts/Linux/perf_fio.sh new file mode 100644 index 000000000..49d9d84d2 --- /dev/null +++ b/Testscripts/Linux/perf_fio.sh @@ -0,0 +1,346 @@ +#!/bin/bash +# +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# +# Sample script to run sysbench. +# In this script, we want to bench-mark device IO performance on a mounted folder. +# You can adapt this script to other situations easily like for stripe disks as RAID0. +# The only thing to keep in mind is that each different configuration you're testing +# must log its output to a different directory. +# + +HOMEDIR="/root" +LogMsg() +{ + echo "[$(date +"%x %r %Z")] ${1}" + echo "[$(date +"%x %r %Z")] ${1}" >> "${HOMEDIR}/runlog.txt" +} +LogMsg "Sleeping 10 seconds.." +sleep 10 + +#export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/oem/bin:/usr/share/oem/python/bin:/opt/bin +CONSTANTS_FILE="$HOMEDIR/constants.sh" +ICA_TESTRUNNING="TestRunning" # The test is running +ICA_TESTCOMPLETED="TestCompleted" # The test completed successfully +ICA_TESTABORTED="TestAborted" # Error during the setup of the test +ICA_TESTFAILED="TestFailed" # Error occurred during the test +touch ./fioTest.log + +if [ -e ${CONSTANTS_FILE} ]; then + . ${CONSTANTS_FILE} +else + errMsg="Error: missing ${CONSTANTS_FILE} file" + LogMsg "${errMsg}" + UpdateTestState $ICA_TESTABORTED + exit 10 +fi + + +UpdateTestState() +{ + echo "${1}" > $HOMEDIR/state.txt +} + +InstallFIO() { + DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux\|clear-linux-os" /etc/{issue,*release,*version} /usr/lib/os-release` + + if [[ $DISTRO =~ "Ubuntu" ]] || [[ $DISTRO =~ "Debian" ]]; + then + LogMsg "Detected UBUNTU/Debian. Installing required packages" + until dpkg --force-all --configure -a; sleep 10; do echo 'Trying again...'; done + apt-get update + apt-get install -y pciutils gawk mdadm + apt-get install -y wget sysstat blktrace bc fio + if [ $? -ne 0 ]; then + LogMsg "Error: Unable to install fio" + exit 1 + fi + mount -t debugfs none /sys/kernel/debug + + elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 6" ]]; + then + LogMsg "Detected RHEL 6.x; Installing required packages" + rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm + yum -y --nogpgcheck install wget sysstat mdadm blktrace libaio fio + mount -t debugfs none /sys/kernel/debug + + elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 7" ]]; + then + LogMsg "Detected RHEL 7.x; Installing required packages" + rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + yum -y --nogpgcheck install wget sysstat mdadm blktrace libaio fio + mount -t debugfs none /sys/kernel/debug + + elif [[ $DISTRO =~ "CentOS Linux release 6" ]] || [[ $DISTRO =~ "CentOS release 6" ]]; + then + LogMsg "Detected CentOS 6.x; Installing required packages" + rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm + yum -y --nogpgcheck install wget sysstat mdadm blktrace libaio fio + mount -t debugfs none /sys/kernel/debug + + elif [[ $DISTRO =~ "CentOS Linux release 7" ]]; + then + LogMsg "Detected CentOS 7.x; Installing required packages" + rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + yum -y --nogpgcheck install wget sysstat mdadm blktrace libaio fio + mount -t debugfs none /sys/kernel/debug + + elif [[ $DISTRO =~ "SUSE Linux Enterprise Server 12" ]]; + then + LogMsg "Detected SLES12. Installing required packages" + zypper addrepo http://download.opensuse.org/repositories/benchmark/SLE_12_SP2_Backports/benchmark.repo + zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys refresh + zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys remove gettext-runtime-mini-0.19.2-1.103.x86_64 + zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys install sysstat + zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys install grub2 + zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys install wget mdadm blktrace libaio1 fio + elif [[ $DISTRO =~ "clear-linux-os" ]]; + then + LogMsg "Detected Clear Linux OS. Installing required packages" + swupd bundle-add dev-utils-dev sysadmin-basic performance-tools os-testsuite-phoronix network-basic openssh-server dev-utils os-core os-core-dev + + else + LogMsg "Unknown Distro" + UpdateTestState "TestAborted" + UpdateSummary "Unknown Distro, test aborted" + return 1 + fi +} + +RunFIO() +{ + UpdateTestState ICA_TESTRUNNING + FILEIO="--size=${fileSize} --direct=1 --ioengine=libaio --filename=fiodata --overwrite=1 " + + #################################### + #All run config set here + # + + #Log Config + + mkdir $HOMEDIR/FIOLog/jsonLog + mkdir $HOMEDIR/FIOLog/iostatLog + mkdir $HOMEDIR/FIOLog/blktraceLog + + #LOGDIR="${HOMEDIR}/FIOLog" + JSONFILELOG="${LOGDIR}/jsonLog" + IOSTATLOGDIR="${LOGDIR}/iostatLog" + BLKTRACELOGDIR="${LOGDIR}/blktraceLog" + LOGFILE="${LOGDIR}/fio-test.log.txt" + + #redirect blktrace files directory + Resource_mount=$(mount -l | grep /sdb1 | awk '{print$3}') + blk_base="${Resource_mount}/blk-$(date +"%m%d%Y-%H%M%S")" + mkdir $blk_base + # + # + #Test config + # + # + + #All possible values for file-test-mode are randread randwrite read write + #modes='randread randwrite read write' + iteration=0 + #startThread=1 + #startIO=8 + #numjobs=1 + + #Max run config + #ioruntime=300 + #maxThread=1024 + #maxIO=8 + io_increment=128 + + #################################### + echo "Test log created at: ${LOGFILE}" + echo "===================================== Starting Run $(date +"%x %r %Z") ================================" + echo "===================================== Starting Run $(date +"%x %r %Z") script generated 2/9/2015 4:24:44 PM ================================" >> $LOGFILE + + chmod 666 $LOGFILE + echo "Preparing Files: $FILEIO" + echo "Preparing Files: $FILEIO" >> $LOGFILE + LogMsg "Preparing Files: $FILEIO" + # Remove any old files from prior runs (to be safe), then prepare a set of new files. + rm fiodata + echo "--- Kernel Version Information ---" >> $LOGFILE + uname -a >> $LOGFILE + cat /proc/version >> $LOGFILE + cat /etc/*-release >> $LOGFILE + echo "--- PCI Bus Information ---" >> $LOGFILE + lspci >> $LOGFILE + echo "--- Drive Mounting Information ---" >> $LOGFILE + mount >> $LOGFILE + echo "--- Disk Usage Before Generating New Files ---" >> $LOGFILE + df -h >> $LOGFILE + fio --cpuclock-test >> $LOGFILE + fio $FILEIO --readwrite=read --bs=1M --runtime=1 --iodepth=128 --numjobs=8 --name=prepare + echo "--- Disk Usage After Generating New Files ---" >> $LOGFILE + df -h >> $LOGFILE + echo "=== End Preparation $(date +"%x %r %Z") ===" >> $LOGFILE + LogMsg "Preparing Files: $FILEIO: Finished." + #################################### + #Trigger run from here + for testmode in $modes; do + io=$startIO + while [ $io -le $maxIO ] + do + Thread=$startThread + while [ $Thread -le $maxThread ] + do + if [ $Thread -ge 8 ] + then + numjobs=8 + else + numjobs=$Thread + fi + iostatfilename="${IOSTATLOGDIR}/iostat-fio-${testmode}-${io}K-${Thread}td.txt" + nohup iostat -x 5 -t -y > $iostatfilename & + #capture blktrace output during test + #LogMsg "INFO: start blktrace for 40 sec on device sdd and sdf" + #blk_operation="${blk_base}/blktrace-fio-${testmode}-${io}K-${Thread}td/" + #mkdir $blk_operation + #blktrace -w 40 -d /dev/sdf -D $blk_operation & + #blktrace -w 40 -d /dev/sdm -D $blk_operation & + echo "-- iteration ${iteration} ----------------------------- ${testmode} test, ${io}K bs, ${Thread} threads, ${numjobs} jobs, 5 minutes ------------------ $(date +"%x %r %Z") ---" >> $LOGFILE + LogMsg "Running ${testmode} test, ${io}K bs, ${Thread} threads ..." + jsonfilename="${JSONFILELOG}/fio-result-${testmode}-${io}K-${Thread}td.json" + fio $FILEIO --readwrite=$testmode --bs=${io}K --runtime=$ioruntime --iodepth=$Thread --numjobs=$numjobs --output-format=json --output=$jsonfilename --name="iteration"${iteration} >> $LOGFILE + #fio $FILEIO --readwrite=$testmode --bs=${io}K --runtime=$ioruntime --iodepth=$Thread --numjobs=$numjobs --name="iteration"${iteration} --group_reporting >> $LOGFILE + iostatPID=`ps -ef | awk '/iostat/ && !/awk/ { print $2 }'` + kill -9 $iostatPID + Thread=$(( Thread*2 )) + iteration=$(( iteration+1 )) + done + io=$(( io * io_increment )) + done + done + #################################### + echo "===================================== Completed Run $(date +"%x %r %Z") script generated 2/9/2015 4:24:44 PM ================================" >> $LOGFILE + rm fiodata + + compressedFileName="${HOMEDIR}/FIOTest-$(date +"%m%d%Y-%H%M%S").tar.gz" + LogMsg "INFO: Please wait...Compressing all results to ${compressedFileName}..." + tar -cvzf $compressedFileName $LOGDIR/ + + echo "Test logs are located at ${LOGDIR}" + UpdateTestState ICA_TESTCOMPLETED +} + + +CreateRAID0() +{ + disks=$(ls -l /dev | grep sd[c-z]$ | awk '{print $10}') + #disks=(`fdisk -l | grep 'Disk.*/dev/sd[a-z]' |awk '{print $2}' | sed s/://| sort| grep -v "/dev/sd[ab]$" `) + + LogMsg "INFO: Check and remove RAID first" + mdvol=$(cat /proc/mdstat | grep "active raid" | awk {'print $1'}) + if [ -n "$mdvol" ]; then + echo "/dev/${mdvol} already exist...removing first" + umount /dev/${mdvol} + mdadm --stop /dev/${mdvol} + mdadm --remove /dev/${mdvol} + mdadm --zero-superblock /dev/sd[c-z][1-5] + fi + + LogMsg "INFO: Creating Partitions" + count=0 + for disk in ${disks} + do + echo "formatting disk /dev/${disk}" + (echo d; echo n; echo p; echo 1; echo; echo; echo t; echo fd; echo w;) | fdisk /dev/${disk} + count=$(( $count + 1 )) + sleep 1 + done + LogMsg "INFO: Creating RAID of ${count} devices." + sleep 1 + mdadm --create ${mdVolume} --level 0 --raid-devices ${count} /dev/sd[c-z][1-5] + sleep 1 + time mkfs -t $1 -F ${mdVolume} + mkdir ${mountDir} + sleep 1 + mount -o nobarrier ${mdVolume} ${mountDir} + if [ $? -ne 0 ]; then + LogMsg "Error: Unable to create raid" + exit 1 + else + LogMsg "${mdVolume} mounted to ${mountDir} successfully." + fi + + #LogMsg "INFO: adding fstab entry" + #echo "${mdVolume} ${mountDir} ext4 defaults 1 1" >> /etc/fstab +} + +CreateLVM() +{ + disks=$(ls -l /dev | grep sd[c-z]$ | awk '{print $10}') + #disks=(`fdisk -l | grep 'Disk.*/dev/sd[a-z]' |awk '{print $2}' | sed s/://| sort| grep -v "/dev/sd[ab]$" `) + + #LogMsg "INFO: Check and remove LVM first" + vgExist=$(vgdisplay) + if [ -n "$vgExist" ]; then + umount ${mountDir} + lvremove -A n -f /dev/${vggroup}/lv1 + vgremove ${vggroup} -f + fi + + LogMsg "INFO: Creating Partition" + count=0 + for disk in ${disks} + do + echo "formatting disk /dev/${disk}" + (echo d; echo n; echo p; echo 1; echo; echo; echo t; echo fd; echo w;) | fdisk /dev/${disk} + count=$(( $count + 1 )) + done + + LogMsg "INFO: Creating LVM with all data disks" + pvcreate /dev/sd[c-z][1-5] + vgcreate ${vggroup} /dev/sd[c-z][1-5] + lvcreate -l 100%FREE -i 12 -I 64 ${vggroup} -n lv1 + time mkfs -t $1 -F /dev/${vggroup}/lv1 + mkdir ${mountDir} + mount -o nobarrier /dev/${vggroup}/lv1 ${mountDir} + if [ $? -ne 0 ]; then + LogMsg "Error: Unable to create LVM " + exit 1 + fi + + #LogMsg "INFO: adding fstab entry" + #echo "${mdVolume} ${mountDir} ext4 defaults 1 1" >> /etc/fstab +} + +############################################################ +# Main body +############################################################ + +HOMEDIR=$HOME +mv $HOMEDIR/FIOLog/ $HOMEDIR/FIOLog-$(date +"%m%d%Y-%H%M%S")/ +mkdir $HOMEDIR/FIOLog +LOGDIR="${HOMEDIR}/FIOLog" +DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux" /etc/{issue,*release,*version}` +if [[ $DISTRO =~ "SUSE Linux Enterprise Server 12" ]]; +then + mdVolume="/dev/md/mdauto0" +else + mdVolume="/dev/md0" +fi +vggroup="vg1" +mountDir="/data" +cd ${HOMEDIR} + +InstallFIO + +#Creating RAID before triggering test +CreateRAID0 ext4 +#CreateLVM ext4 + +#Run test from here +LogMsg "*********INFO: Starting test execution*********" +cd ${mountDir} +mkdir sampleDIR +RunFIO +LogMsg "*********INFO: Script execution reach END. Completed !!!*********" diff --git a/Testscripts/Linux/perf_iperf3.sh b/Testscripts/Linux/perf_iperf3.sh new file mode 100644 index 000000000..e90dc9a90 --- /dev/null +++ b/Testscripts/Linux/perf_iperf3.sh @@ -0,0 +1,295 @@ +#!/bin/bash + +####################################################################### +# +# Linux on Hyper-V and Azure Test Code, ver. 1.0.0 +# Copyright (c) Microsoft Corporation +# +# All rights reserved. +# Licensed under the Apache License, Version 2.0 (the ""License""); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +# ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR +# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. +# +# See the Apache Version 2.0 License for specific language governing +# permissions and limitations under the License. +# +####################################################################### + +####################################################################### +# +# perf_IPERF3.sh +# Author : SHITAL SAVEKAR +# +# Description: +# Download and run IPERF3 network performance tests. +# This script needs to be run on client VM. +# +# Supported Distros: +# Ubuntu 16.04 +####################################################################### + +CONSTANTS_FILE="./constants.sh" +ICA_TESTRUNNING="TestRunning" # The test is running +ICA_TESTCOMPLETED="TestCompleted" # The test completed successfully +ICA_TESTABORTED="TestAborted" # Error during the setup of the test +ICA_TESTFAILED="TestFailed" # Error occurred during the test +touch ./IPERF3Test.log + +InstallIPERF3() +{ + DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux\|clear-linux-os" /etc/{issue,*release,*version} /usr/lib/os-release` + if [[ $DISTRO =~ "Ubuntu" ]]; + then + + LogMsg "Detected Ubuntu" + ssh ${1} "until dpkg --force-all --configure -a; sleep 10; do echo 'Trying again...'; done" + ssh ${1} "apt-get update" + ssh ${1} "apt-get -y install iperf3 sysstat bc psmisc" + if [ $IPversion -eq 6 ]; then + scp ConfigureUbuntu1604IPv6.sh ${1}: + ssh ${1} "chmod +x ConfigureUbuntu1604IPv6.sh" + ssh ${1} "./ConfigureUbuntu1604IPv6.sh" + fi + elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 6" ]] || [[ $DISTRO =~ "CentOS Linux release 6" ]] || [[ $DISTRO =~ "CentOS release 6" ]]; + then + LogMsg "Detected Redhat/CentOS 6.x" + ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm" + ssh ${1} "yum -y --nogpgcheck install iperf3 sysstat bc psmisc" + ssh ${1} "iptables -F" + + elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 7" ]] || [[ $DISTRO =~ "CentOS Linux release 7" ]]; + then + LogMsg "Detected Redhat/CentOS 7.x" + ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm" + ssh ${1} "yum -y --nogpgcheck install iperf3 sysstat bc psmisc" + ssh ${1} "iptables -F" + elif [[ $DISTRO =~ "clear-linux-os" ]]; + then + LogMsg "Detected Clear Linux OS. Installing required packages" + ssh ${1} "swupd bundle-add dev-utils-dev sysadmin-basic performance-tools os-testsuite-phoronix network-basic openssh-server dev-utils os-core os-core-dev" + ssh ${1} "iptables -F" + + else + LogMsg "Unknown Distro" + UpdateTestState "TestAborted" + UpdateSummary "Unknown Distro, test aborted" + return 1 + fi +} + + +LogMsg() +{ + echo `date "+%b %d %Y %T"` : "${1}" # Add the time stamp to the log message + echo "${1}" >> ./IPERF3Test.log +} + +UpdateTestState() +{ + echo "${1}" > ./state.txt +} + +if [ -e ${CONSTANTS_FILE} ]; then + source ${CONSTANTS_FILE} +else + errMsg="Error: missing ${CONSTANTS_FILE} file" + LogMsg "${errMsg}" + UpdateTestState $ICA_TESTABORTED + exit 10 +fi + +if [ ! ${server} ]; then + errMsg="Please add/provide value for server in constants.sh. server=" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi +if [ ! ${client} ]; then + errMsg="Please add/provide value for client in constants.sh. client=" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi + +if [ ! ${testDuration} ]; then + errMsg="Please add/provide value for testDuration in constants.sh. testDuration=60" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi + +if [ ! ${testType} ]; then + errMsg="Please add/provide value for testType in constants.sh. testType=tcp/udp" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi + +if [ ! ${max_parallel_connections_per_instance} ]; then + errMsg="Please add/provide value for max_parallel_connections_per_instance in constants.sh. max_parallel_connections_per_instance=60" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi + +if [ ! ${connections} ]; then + errMsg="Please add/provide value for connections in constants.sh. connections=(1 2 4 8 ....)" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi + +if [ ! ${bufferLengths} ]; then + errMsg="Please add/provide value for bufferLengths in constants.sh. bufferLengths=(1 8). Note buffer lenghs are in Bytest" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi + +if [ ! ${IPversion} ]; then + errMsg="Please add/provide value for IPversion in constants.sh. IPversion=4/6." + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi + +if [ $IPversion -eq 6 ]; then + if [ ! ${serverIpv6} ]; then + errMsg="Please add/provide value for serverIpv6 in constants.sh" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 + fi + if [ ! ${clientIpv6} ]; then + errMsg="Please add/provide value for clientIpv6 in constants.sh." + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 + fi + +fi + + +#connections=(64 128) +#BufferLenghts are in Bytes +#max_parallel_connections_per_instance=64 +#Make & build IPERF3 on client and server Machine + +LogMsg "Configuring client ${client}..." +InstallIPERF3 ${client} + +LogMsg "Configuring server ${server}..." +InstallIPERF3 ${server} + +ssh ${server} "rm -rf iperf-server-*" +ssh ${client} "rm -rf iperf-client-*" +ssh ${client} "rm -rf iperf-server-*" + + +#connections=(1 2 4 8 16 32 64 128 256 512 1024) +#BufferLenghts are in K +#bufferLenghs=(1 8) + +for current_buffer in "${bufferLengths[@]}" + do + for current_test_connections in "${connections[@]}" + do + if [ $current_test_connections -lt $max_parallel_connections_per_instance ] + then + num_threads_P=$current_test_connections + num_threads_n=1 + else + num_threads_P=$max_parallel_connections_per_instance + num_threads_n=$(($current_test_connections / $num_threads_P)) + fi + + ssh ${server} "killall iperf3" + ssh ${client} "killall iperf3" + LogMsg "Starting $num_threads_n iperf3 server instances on $server.." + startPort=750 + currentPort=$startPort + currentIperfInstanses=0 + while [ $currentIperfInstanses -lt $num_threads_n ] + do + currentIperfInstanses=$(($currentIperfInstanses+1)) + serverCommand="iperf3 -s -1 -J -i10 -f g -p ${currentPort} > iperf-server-${testType}-IPv${IPversion}-buffer-${current_buffer}-conn-$current_test_connections-instance-${currentIperfInstanses}.txt 2>&1" + ssh ${server} $serverCommand & + LogMsg "Executed: $serverCommand" + currentPort=$(($currentPort+1)) + sleep 0.1 + done + + LogMsg "$num_threads_n iperf server instances started on $server.." + sleep 5 + LogMsg "Starting client.." + startPort=750 + currentPort=$startPort + currentIperfInstanses=0 + if [ $IPversion -eq 4 ]; then + testServer=$server + else + testServer=$serverIpv6 + fi + #ssh ${client} "./sar-top.sh ${testDuration} $current_test_connections root" & + #ssh ${server} "./sar-top.sh ${testDuration} $current_test_connections root" & + while [ $currentIperfInstanses -lt $num_threads_n ] + do + currentIperfInstanses=$(($currentIperfInstanses+1)) + + if [[ "$testType" == "udp" ]]; + then + clientCommand="iperf3 -c $testServer -u -b 0 -J -f g -i10 -l ${current_buffer} -t ${testDuration} -p ${currentPort} -P $num_threads_P -${IPversion} > iperf-client-${testType}-IPv${IPversion}-buffer-${current_buffer}-conn-$current_test_connections-instance-${currentIperfInstanses}.txt 2>&1" + fi + if [[ "$testType" == "tcp" ]]; + then + clientCommand="iperf3 -c $testServer -b 0 -J -f g -i10 -l ${current_buffer} -t ${testDuration} -p ${currentPort} -P $num_threads_P -${IPversion} > iperf-client-${testType}-IPv${IPversion}-buffer-${current_buffer}-conn-$current_test_connections-instance-${currentIperfInstanses}.txt 2>&1" + fi + + ssh ${client} $clientCommand & + LogMsg "Executed: $clientCommand" + currentPort=$(($currentPort+1)) + sleep 0.1 + done + LogMsg "Iperf3 running buffer ${current_buffer}Bytes $num_threads_P X $num_threads_n ..." + sleep ${testDuration} + timeoutSeconds=900 + sleep 5 + var=`ps -C "iperf3 -c" --no-headers | wc -l` + echo $var + while [[ $var -gt 0 ]]; + do + timeoutSeconds=`expr $timeoutSeconds - 1` + if [ $timeoutSeconds -eq 0 ]; then + LogMsg "Iperf3 running buffer ${current_buffer}K $num_threads_P X $num_threads_n. Timeout." + LogMsg "killing all iperf3 client threads." + killall iperf3 + sleep 1 + else + sleep 1 + var=`ps -C "iperf3 -c" --no-headers | wc -l` + LogMsg "Iperf3 running buffer ${current_buffer}K $num_threads_P X $num_threads_n. Waiting to finish $var instances." + fi + done + #Sleep extra 5 seconds. + sleep 5 + LogMsg "Iperf3 Finished buffer ${current_buffer} $num_threads_P X $num_threads_n ..." + done +done +scp ${server}:iperf-server-* ./ +UpdateTestState ICA_TESTCOMPLETED diff --git a/Testscripts/Linux/perf_lagscope.sh b/Testscripts/Linux/perf_lagscope.sh new file mode 100644 index 000000000..db97e1085 --- /dev/null +++ b/Testscripts/Linux/perf_lagscope.sh @@ -0,0 +1,189 @@ +#!/bin/bash + +####################################################################### +# +# Linux on Hyper-V and Azure Test Code, ver. 1.0.0 +# Copyright (c) Microsoft Corporation +# +# All rights reserved. +# Licensed under the Apache License, Version 2.0 (the ""License""); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +# ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR +# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. +# +# See the Apache Version 2.0 License for specific language governing +# permissions and limitations under the License. +# +####################################################################### + +####################################################################### +# +# perf_lagscope.sh +# Author : SHITAL SAVEKAR +# +# Description: +# Download and run lagscope latency tests. +# This script needs to be run on client VM. +# +# Supported Distros: +# Ubuntu 16.04 +####################################################################### + +CONSTANTS_FILE="./constants.sh" +ICA_TESTRUNNING="TestRunning" # The test is running +ICA_TESTCOMPLETED="TestCompleted" # The test completed successfully +ICA_TESTABORTED="TestAborted" # Error during the setup of the test +ICA_TESTFAILED="TestFailed" # Error occurred during the test +touch ./lagscopeTest.log + + +InstallLAGSCOPE() { + DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux\|clear-linux-os" /etc/{issue,*release,*version} /usr/lib/os-release` + + if [[ $DISTRO =~ "Ubuntu" ]]; + then + LogMsg "Detected UBUNTU" + LogMsg "Configuring ${1} for lagscope test..." + ssh ${1} "until dpkg --force-all --configure -a; sleep 10; do echo 'Trying again...'; done" + ssh ${1} "apt-get update" + ssh ${1} "apt-get -y install libaio1 sysstat git bc make gcc" + ssh ${1} "rm -rf lagscope" + ssh ${1} "git clone https://github.com/Microsoft/lagscope" + ssh ${1} "cd lagscope/src && make && make install" + + elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 6" ]]; + then + LogMsg "Detected Redhat 6.x" + ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm" + ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc" + ssh ${1} "yum -y --nogpgcheck install gcc-c++" + + ssh ${1} "wget http://ftp.heanet.ie/mirrors/gnu/libc/glibc-2.14.1.tar.gz" + ssh ${1} "tar xvf glibc-2.14.1.tar.gz" + ssh ${1} "mv glibc-2.14.1 glibc-2.14 && cd glibc-2.14 && mkdir build && cd build && ../configure --prefix=/opt/glibc-2.14 && make && make install && export LD_LIBRARY_PATH=/opt/glibc-2.14/lib:$LD_LIBRARY_PATH" + + ssh ${1} "rm -rf lagscope" + ssh ${1} "git clone https://github.com/Microsoft/lagscope" + ssh ${1} "cd lagscope/src && make && make install" + ssh ${1} "iptables -F" + + elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 7" ]]; + then + LogMsg "Detected Redhat 7.x" + ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm" + ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc" + ssh ${1} "rm -rf lagscope" + ssh ${1} "git clone https://github.com/Microsoft/lagscope" + ssh ${1} "cd lagscope/src && make && make install" + ssh ${1} "iptables -F" + + elif [[ $DISTRO =~ "CentOS Linux release 6" ]]; + then + LogMsg "Detected CentOS 6.x" + ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm" + ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc" + ssh ${1} "yum -y --nogpgcheck install gcc-c++" + ssh ${1} "rm -rf lagscope" + ssh ${1} "git clone https://github.com/Microsoft/lagscope" + ssh ${1} "cd lagscope/src && make && make install" + ssh ${1} "iptables -F" + + elif [[ $DISTRO =~ "CentOS Linux release 7" ]]; + then + LogMsg "Detected CentOS 7.x" + ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm" + ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc" + ssh ${1} "rm -rf lagscope" + ssh ${1} "git clone https://github.com/Microsoft/lagscope" + ssh ${1} "cd lagscope/src && make && make install" + ssh ${1} "iptables -F" + + elif [[ $DISTRO =~ "SUSE Linux Enterprise Server 12" ]]; + then + LogMsg "Detected SLES12" + ssh ${1} "zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys remove gettext-runtime-mini*" + ssh ${1} "zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys install sysstat git bc make gcc grub2" + ssh ${1} "rm -rf lagscope" + ssh ${1} "git clone https://github.com/Microsoft/lagscope" + ssh ${1} "cd lagscope/src && make && make install" + ssh ${1} "iptables -F" + elif [[ $DISTRO =~ "clear-linux-os" ]]; + then + LogMsg "Detected Clear Linux OS. Installing required packages" + ssh ${1} "swupd bundle-add dev-utils-dev sysadmin-basic performance-tools os-testsuite-phoronix network-basic openssh-server dev-utils os-core os-core-dev" + ssh ${1} "iptables -F" + + else + LogMsg "Unknown Distro" + UpdateTestState "TestAborted" + UpdateSummary "Unknown Distro, test aborted" + return 1 + fi +} +LogMsg() +{ + echo `date "+%b %d %Y %T"` : "${1}" # Add the time stamp to the log message + echo "${1}" >> ./ntttcpTest.log +} + +UpdateTestState() +{ + echo "${1}" > ./state.txt +} + +if [ -e ${CONSTANTS_FILE} ]; then + source ${CONSTANTS_FILE} +else + errMsg="Error: missing ${CONSTANTS_FILE} file" + LogMsg "${errMsg}" + UpdateTestState $ICA_TESTABORTED + exit 10 +fi + +if [ ! ${server} ]; then + errMsg="Please add/provide value for server in constants.sh. server=" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi +if [ ! ${client} ]; then + errMsg="Please add/provide value for client in constants.sh. client=" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi + +if [ ! ${pingIteration} ]; then + errMsg="Please add/provide value for pingIteration in constants.sh. pingIteration=1000000" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi + +#Make & build ntttcp on client and server Machine + +LogMsg "Configuring client ${client}..." +InstallLAGSCOPE ${client} + +LogMsg "Configuring server ${server}..." +InstallLAGSCOPE ${server} + +#Now, start the ntttcp client on client VM. + +LogMsg "Now running Lagscope test" +LogMsg "Starting server." +ssh root@${server} "lagscope -r -D" +sleep 1 +LogMsg "lagscope client running..." +ssh root@${client} "lagscope -s${server} -i0 -n${pingIteration} -H > lagscope-n${pingIteration}-output.txt" +LogMsg "Test finsished." +UpdateTestState ICA_TESTCOMPLETED + diff --git a/Testscripts/Linux/perf_ntttcp.sh b/Testscripts/Linux/perf_ntttcp.sh new file mode 100644 index 000000000..b0b19229f --- /dev/null +++ b/Testscripts/Linux/perf_ntttcp.sh @@ -0,0 +1,222 @@ +#!/bin/bash + +####################################################################### +# +# Linux on Hyper-V and Azure Test Code, ver. 1.0.0 +# Copyright (c) Microsoft Corporation +# +# All rights reserved. +# Licensed under the Apache License, Version 2.0 (the ""License""); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +# ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR +# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. +# +# See the Apache Version 2.0 License for specific language governing +# permissions and limitations under the License. +# +####################################################################### + +####################################################################### +# +# perf_ntttcp.sh +# Author : SHITAL SAVEKAR +# +# Description: +# Download and run ntttcp network performance tests. +# This script needs to be run on client VM. +# +# Supported Distros: +# Ubuntu 16.04 +####################################################################### + +CONSTANTS_FILE="./constants.sh" +ICA_TESTRUNNING="TestRunning" # The test is running +ICA_TESTCOMPLETED="TestCompleted" # The test completed successfully +ICA_TESTABORTED="TestAborted" # Error during the setup of the test +ICA_TESTFAILED="TestFailed" # Error occurred during the test +touch ./ntttcpTest.log + + +InstallNTTTCP() { + DISTRO=`grep -ihs "buntu\|Suse\|Fedora\|Debian\|CentOS\|Red Hat Enterprise Linux\|clear-linux-os" /etc/{issue,*release,*version} /usr/lib/os-release` + + if [[ $DISTRO =~ "Ubuntu" ]]; + then + LogMsg "Detected UBUNTU" + LogMsg "Configuring ${1} for ntttcp test..." + ssh ${1} "until dpkg --force-all --configure -a; sleep 10; do echo 'Trying again...'; done" + ssh ${1} "apt-get update" + ssh ${1} "apt-get -y install libaio1 sysstat git bc make gcc dstat psmisc" + ssh ${1} "git clone https://github.com/Microsoft/ntttcp-for-linux.git" + ssh ${1} "cd ntttcp-for-linux/ && git checkout 7a5017b00a603cfaf2ae2a83a6d6b688b2f9dbaa" + ssh ${1} "cd ntttcp-for-linux/src/ && make && make install" + ssh ${1} "cp ntttcp-for-linux/src/ntttcp ." + ssh ${1} "rm -rf lagscope" + ssh ${1} "git clone https://github.com/Microsoft/lagscope" + ssh ${1} "cd lagscope/src && make && make install" + + elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 6" ]]; + then + LogMsg "Detected Redhat 6.x" + ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm" + ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc dstat psmisc" + ssh ${1} "yum -y --nogpgcheck install gcc-c++" + + ssh ${1} "wget http://ftp.heanet.ie/mirrors/gnu/libc/glibc-2.14.1.tar.gz" + ssh ${1} "tar xvf glibc-2.14.1.tar.gz" + ssh ${1} "mv glibc-2.14.1 glibc-2.14 && cd glibc-2.14 && mkdir build && cd build && ../configure --prefix=/opt/glibc-2.14 && make && make install && export LD_LIBRARY_PATH=/opt/glibc-2.14/lib:$LD_LIBRARY_PATH" + + ssh ${1} "git clone https://github.com/Microsoft/ntttcp-for-linux.git" + ssh ${1} "cd ntttcp-for-linux/ && git checkout 7a5017b00a603cfaf2ae2a83a6d6b688b2f9dbaa" + + ssh ${1} "cd ntttcp-for-linux/src/ && make && make install" + ssh ${1} "cp ntttcp-for-linux/src/ntttcp ." + ssh ${1} "rm -rf lagscope" + ssh ${1} "git clone https://github.com/Microsoft/lagscope" + ssh ${1} "cd lagscope/src && make && make install" + ssh ${1} "iptables -F" + + elif [[ $DISTRO =~ "Red Hat Enterprise Linux Server release 7" ]]; + then + LogMsg "Detected Redhat 7.x" + ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm" + ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc dstat psmisc" + ssh ${1} "git clone https://github.com/Microsoft/ntttcp-for-linux.git" + ssh ${1} "cd ntttcp-for-linux/ && git checkout 7a5017b00a603cfaf2ae2a83a6d6b688b2f9dbaa" + ssh ${1} "cd ntttcp-for-linux/src/ && make && make install" + ssh ${1} "cp ntttcp-for-linux/src/ntttcp ." + ssh ${1} "rm -rf lagscope" + ssh ${1} "git clone https://github.com/Microsoft/lagscope" + ssh ${1} "cd lagscope/src && make && make install" + ssh ${1} "iptables -F" + + elif [[ $DISTRO =~ "CentOS Linux release 6" ]] || [[ $DISTRO =~ "CentOS release 6" ]]; + then + LogMsg "Detected CentOS 6.x" + ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm" + ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc dstat psmisc" + ssh ${1} "yum -y --nogpgcheck install gcc-c++" + ssh ${1} "git clone https://github.com/Microsoft/ntttcp-for-linux.git" + ssh ${1} "cd ntttcp-for-linux/ && git checkout 7a5017b00a603cfaf2ae2a83a6d6b688b2f9dbaa" + ssh ${1} "cd ntttcp-for-linux/src/ && make && make install" + ssh ${1} "cp ntttcp-for-linux/src/ntttcp ." + ssh ${1} "rm -rf lagscope" + ssh ${1} "git clone https://github.com/Microsoft/lagscope" + ssh ${1} "cd lagscope/src && make && make install" + ssh ${1} "iptables -F" + + elif [[ $DISTRO =~ "CentOS Linux release 7" ]]; + then + LogMsg "Detected CentOS 7.x" + ssh ${1} "rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm" + ssh ${1} "yum -y --nogpgcheck install libaio1 sysstat git bc make gcc dstat psmisc" + ssh ${1} "git clone https://github.com/Microsoft/ntttcp-for-linux.git" + ssh ${1} "cd ntttcp-for-linux/ && git checkout 7a5017b00a603cfaf2ae2a83a6d6b688b2f9dbaa" + ssh ${1} "cd ntttcp-for-linux/src/ && make && make install" + ssh ${1} "cp ntttcp-for-linux/src/ntttcp ." + ssh ${1} "rm -rf lagscope" + ssh ${1} "git clone https://github.com/Microsoft/lagscope" + ssh ${1} "cd lagscope/src && make && make install" + ssh ${1} "iptables -F" + + elif [[ $DISTRO =~ "SUSE Linux Enterprise Server 12" ]]; + then + LogMsg "Detected SLES12" + ssh ${1} "zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys remove gettext-runtime-mini*" + ssh ${1} "zypper --no-gpg-checks --non-interactive --gpg-auto-import-keys install sysstat git bc make gcc grub2 dstat psmisc" + ssh ${1} "git clone https://github.com/Microsoft/ntttcp-for-linux.git" + ssh ${1} "cd ntttcp-for-linux/ && git checkout 7a5017b00a603cfaf2ae2a83a6d6b688b2f9dbaa" + ssh ${1} "cd ntttcp-for-linux/src/ && make && make install" + ssh ${1} "cp ntttcp-for-linux/src/ntttcp ." + ssh ${1} "rm -rf lagscope" + ssh ${1} "git clone https://github.com/Microsoft/lagscope" + ssh ${1} "cd lagscope/src && make && make install" + ssh ${1} "iptables -F" + elif [[ $DISTRO =~ "clear-linux-os" ]]; + then + LogMsg "Detected Clear Linux OS. Installing required packages" + ssh ${1} "swupd bundle-add dev-utils-dev sysadmin-basic performance-tools os-testsuite-phoronix network-basic openssh-server dev-utils os-core os-core-dev" + ssh ${1} "iptables -F" + + else + LogMsg "Unknown Distro" + UpdateTestState "TestAborted" + UpdateSummary "Unknown Distro, test aborted" + return 1 + fi +} +LogMsg() +{ + echo `date "+%b %d %Y %T"` : "${1}" # Add the time stamp to the log message + echo "${1}" >> ./ntttcpTest.log +} + +UpdateTestState() +{ + echo "${1}" > ./state.txt +} + +if [ -e ${CONSTANTS_FILE} ]; then + source ${CONSTANTS_FILE} +else + errMsg="Error: missing ${CONSTANTS_FILE} file" + LogMsg "${errMsg}" + UpdateTestState $ICA_TESTABORTED + exit 10 +fi + +if [ ! ${server} ]; then + errMsg="Please add/provide value for server in constants.sh. server=" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi +if [ ! ${client} ]; then + errMsg="Please add/provide value for client in constants.sh. client=" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi + +if [ ! ${testDuration} ]; then + errMsg="Please add/provide value for testDuration in constants.sh. testDuration=60" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi + +if [ ! ${nicName} ]; then + errMsg="Please add/provide value for nicName in constants.sh. nicName=eth0/bond0" + LogMsg "${errMsg}" + echo "${errMsg}" >> ./summary.log + UpdateTestState $ICA_TESTABORTED + exit 1 +fi +#Make & build ntttcp on client and server Machine + +LogMsg "Configuring client ${client}..." +InstallNTTTCP ${client} + +LogMsg "Configuring server ${server}..." +InstallNTTTCP ${server} + +#Now, start the ntttcp client on client VM. + +ssh root@${client} "wget https://raw.githubusercontent.com/iamshital/linux_performance_test/master/run_ntttcp-for-linux/run-ntttcp-and-tcping.sh" +ssh root@${client} "wget https://raw.githubusercontent.com/iamshital/linux_performance_test/master/run_ntttcp-for-linux/report-ntttcp-and-tcping.sh" +ssh root@${client} "chmod +x run-ntttcp-and-tcping.sh && chmod +x report-ntttcp-and-tcping.sh" +LogMsg "Now running NTTTCP test" +ssh root@${client} "rm -rf ntttcp-test-logs" +ssh root@${client} "./run-ntttcp-and-tcping.sh ntttcp-test-logs ${server} root ${testDuration} ${nicName} '$testConnections'" +ssh root@${client} "./report-ntttcp-and-tcping.sh ntttcp-test-logs '$testConnections'" +ssh root@${client} "cp ntttcp-test-logs/* ." + +UpdateTestState ICA_TESTCOMPLETED \ No newline at end of file diff --git a/Testscripts/Windows/BVT-IS-ROOT-PASSWORD-DELETED.ps1 b/Testscripts/Windows/BVT-IS-ROOT-PASSWORD-DELETED.ps1 new file mode 100644 index 000000000..8c640c59a --- /dev/null +++ b/Testscripts/Windows/BVT-IS-ROOT-PASSWORD-DELETED.ps1 @@ -0,0 +1,54 @@ +$result = "" +$testResult = "" +$resultArr = @() + +$isDeployed = DeployVMS -setupType $currentTestData.setupType -Distro $Distro -xmlConfig $xmlConfig +if ($isDeployed) +{ + try + { + RemoteCopy -uploadTo $AllVMData.PublicIP -port $AllVMData.SSHPort -files $currentTestData.files -username $user -password $password -upload + $out = RunLinuxCmd -username $user -password $password -ip $AllVMData.PublicIP -port $AllVMData.SSHPort -command "chmod +x *" -runAsSudo + + LogMsg "Executing : $($currentTestData.testScript)" + RunLinuxCmd -username $user -password $password -ip $AllVMData.PublicIP -port $AllVMData.SSHPort -command "$python_cmd $($currentTestData.testScript)" -runAsSudo + RunLinuxCmd -username $user -password $password -ip $AllVMData.PublicIP -port $AllVMData.SSHPort -command "mv Runtime.log $($currentTestData.testScript).log" -runAsSudo + RemoteCopy -download -downloadFrom $AllVMData.PublicIP -files "/home/$user/state.txt, /home/$user/Summary.log, /home/$user/$($currentTestData.testScript).log" -downloadTo $LogDir -port $AllVMData.SSHPort -username $user -password $password + $testResult = Get-Content $LogDir\Summary.log + $testStatus = Get-Content $LogDir\state.txt + LogMsg "Test result : $testResult" + + if ($testStatus -eq "TestCompleted") + { + LogMsg "Test Completed" + } + } + + catch + { + $ErrorMessage = $_.Exception.Message + LogMsg "EXCEPTION : $ErrorMessage" + } + Finally + { + 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 \ No newline at end of file diff --git a/Testscripts/Windows/BVT-VERIFY-DEPLOYMENT-PROVISION.ps1 b/Testscripts/Windows/BVT-VERIFY-DEPLOYMENT-PROVISION.ps1 new file mode 100644 index 000000000..b496bac14 --- /dev/null +++ b/Testscripts/Windows/BVT-VERIFY-DEPLOYMENT-PROVISION.ps1 @@ -0,0 +1,72 @@ +$result = "" +$testResult = "" +$resultArr = @() + +$isDeployed = DeployVMS -setupType $currentTestData.setupType -Distro $Distro -xmlConfig $xmlConfig +if ($isDeployed) +{ + try + { + LogMsg "Check 1: Checking call tracess again after 30 seconds sleep" + Start-Sleep 30 + $noIssues = CheckKernelLogs -allVMData $allVMData + if ($noIssues) + { + $RestartStatus = RestartAllDeployments -allVMData $allVMData + if($RestartStatus -eq "True") + { + LogMsg "Check 2: Checking call tracess again after Reboot > 30 seconds sleep" + Start-Sleep 30 + $noIssues = CheckKernelLogs -allVMData $allVMData + if ($noIssues) + { + LogMsg "Test Result : PASS." + $testResult = "PASS" + } + else + { + LogMsg "Test Result : FAIL." + $testResult = "FAIL" + } + } + else + { + LogMsg "Test Result : FAIL." + $testResult = "FAIL" + } + } + else + { + LogMsg "Test Result : FAIL." + $testResult = "FAIL" + } + } + catch + { + $ErrorMessage = $_.Exception.Message + LogMsg "EXCEPTION : $ErrorMessage" + } + Finally + { + $metaData = "" + if (!$testResult) + { + $testResult = "Aborted" + } + $resultArr += $testResult + } +} + +else +{ + $testResult = "FAIL" + $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 diff --git a/Testscripts/Windows/BVT-VERIFY-HOSTNAME.ps1 b/Testscripts/Windows/BVT-VERIFY-HOSTNAME.ps1 new file mode 100644 index 000000000..bece4f298 --- /dev/null +++ b/Testscripts/Windows/BVT-VERIFY-HOSTNAME.ps1 @@ -0,0 +1,63 @@ +$result = "" +$testResult = "" +$resultArr = @() + +$isDeployed = DeployVMS -setupType $currentTestData.setupType -Distro $Distro -xmlConfig $xmlConfig +if ($isDeployed) +{ + try + { + $hs1VIP = $AllVMData.PublicIP + $hs1vm1sshport = $AllVMData.SSHPort + $hs1ServiceUrl = $AllVMData.URL + $hs1vm1Dip = $AllVMData.InternalIP + $hs1vm1Hostname = $AllVMData.RoleName + + RemoteCopy -uploadTo $hs1VIP -port $hs1vm1sshport -files $currentTestData.files -username $user -password $password -upload + RunLinuxCmd -username $user -password $password -ip $hs1VIP -port $hs1vm1sshport -command "chmod +x *" -runAsSudo + + + LogMsg "Executing : $($currentTestData.testScript)" + RunLinuxCmd -username $user -password $password -ip $hs1VIP -port $hs1vm1sshport -command "$python_cmd $($currentTestData.testScript) -e $hs1vm1Hostname" -runAsSudo + RunLinuxCmd -username $user -password $password -ip $hs1VIP -port $hs1vm1sshport -command "mv Runtime.log $($currentTestData.testScript).log" -runAsSudo + RemoteCopy -download -downloadFrom $hs1VIP -files "/home/$user/state.txt, /home/$user/Summary.log, /home/$user/$($currentTestData.testScript).log" -downloadTo $LogDir -port $hs1vm1sshport -username $user -password $password + $testResult = Get-Content $LogDir\Summary.log + $testStatus = Get-Content $LogDir\state.txt + LogMsg "Test result : $testResult" + + if ($testStatus -eq "TestCompleted") + { + LogMsg "Test Completed" + } + } + + catch + { + $ErrorMessage = $_.Exception.Message + LogMsg "EXCEPTION : $ErrorMessage" + } + Finally + { + $metaData = "" + if (!$testResult) + { + $testResult = "Aborted" + } + $resultArr += $testResult +#$resultSummary += CreateResultSummary -testResult $testResult -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 diff --git a/Testscripts/Windows/PERF-NETWORK-TCP-LATENCY-MULTICONNECTION-LAGSCOPE.ps1 b/Testscripts/Windows/PERF-NETWORK-TCP-LATENCY-MULTICONNECTION-LAGSCOPE.ps1 new file mode 100644 index 000000000..3f3864326 --- /dev/null +++ b/Testscripts/Windows/PERF-NETWORK-TCP-LATENCY-MULTICONNECTION-LAGSCOPE.ps1 @@ -0,0 +1,230 @@ +$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 "SERVER VM details :" + LogMsg " RoleName : $($serverVMData.RoleName)" + LogMsg " Public IP : $($serverVMData.PublicIP)" + LogMsg " SSH Port : $($serverVMData.SSHPort)" + + # + # 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" + Set-Content -Value "#Generated by Azure Automation." -Path $constantsFile + Add-Content -Value "server=$($serverVMData.InternalIP)" -Path $constantsFile + Add-Content -Value "client=$($clientVMData.InternalIP)" -Path $constantsFile + foreach ( $param in $currentTestData.TestParameters.param) + { + if ($param -imatch "pingIteration") + { + $pingIteration=$param.Trim().Replace("pingIteration=","") + } + Add-Content -Value "$param" -Path $constantsFile + } + LogMsg "constanst.sh created successfully..." + LogMsg (Get-Content -Path $constantsFile) + #endregion + + + #region EXECUTE TEST + $myString = @" +cd /root/ +./perf_lagscope.sh &> lagscopeConsoleLogs.txt +. azuremodules.sh +collect_VM_properties +"@ + Set-Content "$LogDir\StartLagscopeTest.sh" $myString + RemoteCopy -uploadTo $clientVMData.PublicIP -port $clientVMData.SSHPort -files ".\$constantsFile,.\Testscripts\Linux\azuremodules.sh,.\Testscripts\Linux\perf_lagscope.sh,.\$LogDir\StartLagscopeTest.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/StartLagscopeTest.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 lagscopeConsoleLogs.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 "lagscope-n$pingIteration-output.txt" + RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "VM_properties.csv" + + $testSummary = $null + $lagscopeReportLog = Get-Content -Path "$LogDir\lagscope-n$pingIteration-output.txt" + LogMsg $lagscopeReportLog + + try + { + $matchLine= (Select-String -Path "$LogDir\lagscope-n$pingIteration-output.txt" -Pattern "Average").Line + $minimumLat = $matchLine.Split(",").Split("=").Trim().Replace("us","")[1] + $maximumLat = $matchLine.Split(",").Split("=").Trim().Replace("us","")[3] + $averageLat = $matchLine.Split(",").Split("=").Trim().Replace("us","")[5] + + $resultSummary += CreateResultSummary -testResult $minimumLat -metaData "Minimum Latency" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + $resultSummary += CreateResultSummary -testResult $maximumLat -metaData "Maximum Latency" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + $resultSummary += CreateResultSummary -testResult $averageLat -metaData "Average Latency" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + } + catch + { + $resultSummary += CreateResultSummary -testResult "Error in parsing logs." -metaData "LAGSCOPE" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + } + #endregion + + 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,",""} + $IPVersion = "IPv4" + $ProtocolType = "TCP" + if($EnableAcceleratedNetworking) + { + $DataPath = "SRIOV" + } + else + { + $DataPath = "Synthetic" + } + $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,DataPath,MaxLatency_us,AverageLatency_us,MinLatency_us,Latency95Percentile_us,Latency99Percentile_us) VALUES " + + #Percentile Values are not calculated yet. will be added in future. + $Latency95Percentile_us = 0 + $Latency99Percentile_us = 0 + + $SQLQuery += "('$TestCaseName','$(Get-Date -Format yyyy-MM-dd)','$HostType','$HostBy','$HostOS','$GuestOSType','$GuestDistro','$GuestSize','$KernelVersion','$IPVersion','$ProtocolType','$DataPath','$maximumLat','$averageLat','$minimumLat','$Latency95Percentile_us','$Latency99Percentile_us')," + + $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 = "LAGSCOPE 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 diff --git a/Testscripts/Windows/PERF-NETWORK-TCP-THROUGHPUT-MULTICONNECTION-NTTTCP.ps1 b/Testscripts/Windows/PERF-NETWORK-TCP-THROUGHPUT-MULTICONNECTION-NTTTCP.ps1 new file mode 100644 index 000000000..b020b098e --- /dev/null +++ b/Testscripts/Windows/PERF-NETWORK-TCP-THROUGHPUT-MULTICONNECTION-NTTTCP.ps1 @@ -0,0 +1,279 @@ +$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 "SERVER VM details :" + LogMsg " RoleName : $($serverVMData.RoleName)" + LogMsg " Public IP : $($serverVMData.PublicIP)" + LogMsg " SSH Port : $($serverVMData.SSHPort)" + + # + # 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 + + if($EnableAcceleratedNetworking) + { + $DataPath = "SRIOV" + LogMsg "Getting SRIOV NIC Name." + $clientNicName = (RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "route | grep '^default' | grep -o '[^ ]*$'").Trim() + LogMsg "CLIENT SRIOV NIC: $clientNicName" + $serverNicName = (RunLinuxCmd -ip $clientVMData.PublicIP -port $serverVMData.SSHPort -username "root" -password $password -command "route | grep '^default' | grep -o '[^ ]*$'").Trim() + LogMsg "SERVER SRIOV NIC: $serverNicName" + if ( $serverNicName -eq $clientNicName) + { + $nicName = $clientNicName + } + else + { + Throw "Server and client SRIOV NICs are not same." + } + } + else + { + $DataPath = "Synthetic" + LogMsg "Getting Active NIC Name." + $clientNicName = (RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "route | grep '^default' | grep -o '[^ ]*$'").Trim() + LogMsg "CLIENT NIC: $clientNicName" + $serverNicName = (RunLinuxCmd -ip $clientVMData.PublicIP -port $serverVMData.SSHPort -username "root" -password $password -command "route | grep '^default' | grep -o '[^ ]*$'").Trim() + LogMsg "SERVER NIC: $serverNicName" + if ( $serverNicName -eq $clientNicName) + { + $nicName = $clientNicName + } + else + { + Throw "Server and client NICs are not same." + } + } + + LogMsg "Generating constansts.sh ..." + $constantsFile = "$LogDir\constants.sh" + Set-Content -Value "#Generated by Azure Automation." -Path $constantsFile + Add-Content -Value "server=$($serverVMData.InternalIP)" -Path $constantsFile + Add-Content -Value "client=$($clientVMData.InternalIP)" -Path $constantsFile + Add-Content -Value "nicName=$nicName" -Path $constantsFile + foreach ( $param in $currentTestData.TestParameters.param) + { + Add-Content -Value "$param" -Path $constantsFile + } + LogMsg "constanst.sh created successfully..." + LogMsg (Get-Content -Path $constantsFile) + #endregion + + + #region EXECUTE TEST + $myString = @" +cd /root/ +./perf_ntttcp.sh &> ntttcpConsoleLogs.txt +. azuremodules.sh +collect_VM_properties +"@ + Set-Content "$LogDir\StartNtttcpTest.sh" $myString + RemoteCopy -uploadTo $clientVMData.PublicIP -port $clientVMData.SSHPort -files ".\$constantsFile,.\Testscripts\Linux\azuremodules.sh,.\Testscripts\Linux\perf_ntttcp.sh,.\$LogDir\StartNtttcpTest.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/StartNtttcpTest.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 -2 ntttcpConsoleLogs.txt | head -1" + 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/ntttcpConsoleLogs.txt" + RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "lagscope-ntttcp-*" + RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "ntttcp-sender-p*" + RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "mpstat-sender-p*" + RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "dstat-sender-p*" + RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "sar-sender-p*" + RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "report.log" + RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "VM_properties.csv" + + $testSummary = $null + $ntttcpReportLog = Get-Content -Path "$LogDir\report.log" + foreach ( $line in $ntttcpReportLog ) + { + if ( $line -imatch "test_connections" ) + { + continue; + } + try + { + $uploadResults = $true + $test_connections = $line.Trim().Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Split(" ")[0] + $throughput_gbps = $line.Trim().Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Split(" ")[1] + $cycle_per_byte = $line.Trim().Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Split(" ")[2] + $average_tcp_latency = $line.Trim().Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Replace(" "," ").Split(" ")[3] + $metadata = "Connections=$test_connections" + $connResult = "throughput=$throughput_gbps`Gbps cyclePerBytet=$cycle_per_byte Avg_TCP_lat=$average_tcp_latency" + $resultSummary += CreateResultSummary -testResult $connResult -metaData $metaData -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + if ([string]$throughput_gbps -imatch "0.00") + { + $uploadResults = $false + $testResult = "FAIL" + } + } + catch + { + $resultSummary += CreateResultSummary -testResult "Error in parsing logs." -metaData "NTTTCP" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + } + } + #endregion + + 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") -and $uploadResults ) + { + 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 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,",""} + $IPVersion = "IPv4" + $ProtocolType = "TCP" + $connectionString = "Server=$dataSource;uid=$user; pwd=$password;Database=$database;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;" + $LogContents = Get-Content -Path "$LogDir\report.log" + $SQLQuery = "INSERT INTO $dataTableName (TestCaseName,TestDate,HostType,HostBy,HostOS,GuestOSType,GuestDistro,GuestSize,KernelVersion,IPVersion,ProtocolType,DataPath,NumberOfConnections,Throughput_Gbps,Latency_ms) VALUES " + + for($i = 1; $i -lt $LogContents.Count; $i++) + { + $Line = $LogContents[$i].Trim() -split '\s+' + $SQLQuery += "('$TestCaseName','$(Get-Date -Format yyyy-MM-dd)','$HostType','$HostBy','$HostOS','$GuestOSType','$GuestDistro','$GuestSize','$KernelVersion','$IPVersion','$ProtocolType','$DataPath',$($Line[0]),$($Line[1]),$($Line[2]))," + } + $SQLQuery = $SQLQuery.TrimEnd(',') + LogMsg $SQLQuery + if ($uploadResults) + { + $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 + { + LogErr "Uploading the test results cancelled due to zero throughput for some connections!!" + $testResult = "FAIL" + } + + } + else + { + LogMsg "Invalid database details. Failed to upload result to database!" + } + LogMsg "Test result : $testResult" + } + catch + { + $ErrorMessage = $_.Exception.Message + LogMsg "EXCEPTION : $ErrorMessage" + } + Finally + { + $metaData = "NTTTCP 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 diff --git a/Testscripts/Windows/PERF-NETWORK-UDP-THROUGHPUT-MULTICONNECTION-IPERF3.ps1 b/Testscripts/Windows/PERF-NETWORK-UDP-THROUGHPUT-MULTICONNECTION-IPERF3.ps1 new file mode 100644 index 000000000..5bee1b9eb --- /dev/null +++ b/Testscripts/Windows/PERF-NETWORK-UDP-THROUGHPUT-MULTICONNECTION-IPERF3.ps1 @@ -0,0 +1,435 @@ +$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.InternalIP)" + LogMsg " SSH Port : $($clientVMData.SSHPort)" + LogMsg "SERVER VM details :" + LogMsg " RoleName : $($serverVMData.RoleName)" + LogMsg " Public IP : $($serverVMData.InternalIP)" + LogMsg " SSH Port : $($serverVMData.SSHPort)" + + # + # 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 + + if($EnableAcceleratedNetworking) + { + $DataPath = "SRIOV" + LogMsg "Getting SRIOV NIC Name." + $clientNicName = (RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "route | grep '^default' | grep -o '[^ ]*$'").Trim() + LogMsg "CLIENT SRIOV NIC: $clientNicName" + $serverNicName = (RunLinuxCmd -ip $clientVMData.PublicIP -port $serverVMData.SSHPort -username "root" -password $password -command "route | grep '^default' | grep -o '[^ ]*$'").Trim() + LogMsg "SERVER SRIOV NIC: $serverNicName" + if ( $serverNicName -eq $clientNicName) + { + $nicName = $clientNicName + } + else + { + Throw "Server and client SRIOV NICs are not same." + } + } + else + { + $DataPath = "Synthetic" + LogMsg "Getting Active NIC Name." + $clientNicName = (RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "route | grep '^default' | grep -o '[^ ]*$'").Trim() + LogMsg "CLIENT NIC: $clientNicName" + $serverNicName = (RunLinuxCmd -ip $clientVMData.PublicIP -port $serverVMData.SSHPort -username "root" -password $password -command "route | grep '^default' | grep -o '[^ ]*$'").Trim() + LogMsg "SERVER NIC: $serverNicName" + if ( $serverNicName -eq $clientNicName) + { + $nicName = $clientNicName + } + else + { + Throw "Server and client NICs are not same." + } + } + + LogMsg "Generating constansts.sh ..." + $constantsFile = "$LogDir\constants.sh" + Set-Content -Value "#Generated by Azure Automation." -Path $constantsFile + Add-Content -Value "server=$($serverVMData.InternalIP)" -Path $constantsFile + Add-Content -Value "client=$($clientVMData.InternalIP)" -Path $constantsFile + foreach ( $param in $currentTestData.TestParameters.param) + { + Add-Content -Value "$param" -Path $constantsFile + if ($param -imatch "bufferLengths=") + { + $testBuffers= $param.Replace("bufferLengths=(","").Replace(")","").Split(" ") + } + if ($param -imatch "connections=" ) + { + $testConnections = $param.Replace("connections=(","").Replace(")","").Split(" ") + } + } + LogMsg "constanst.sh created successfully..." + LogMsg (Get-Content -Path $constantsFile) + #endregion + + + #region EXECUTE TEST + $myString = @" +cd /root/ +./perf_iperf3.sh &> iperf3udpConsoleLogs.txt +. azuremodules.sh +collect_VM_properties +"@ + Set-Content "$LogDir\Startiperf3udpTest.sh" $myString + RemoteCopy -uploadTo $clientVMData.PublicIP -port $clientVMData.SSHPort -files ".\$constantsFile,.\Testscripts\Linux\azuremodules.sh,.\Testscripts\Linux\perf_iperf3.sh,.\$LogDir\Startiperf3udpTest.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/Startiperf3udpTest.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 iperf3udpConsoleLogs.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/iperf3udpConsoleLogs.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-udp*" + RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $iperf3LogDir -files "iperf-server-udp*" + RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "VM_properties.csv" + + $testSummary = $null + + #region START UDP ANALYSIS + $clientfolder = $iperf3LogDir + $serverfolder = $iperf3LogDir + + #clientData + $files = Get-ChildItem -Path $clientfolder + $FinalClientThroughputArr=@() + $FinalServerThroughputArr=@() + $FinalClientUDPLossArr=@() + $FinalServerUDPLossArr=@() + $FinalServerClientUDPResultObjArr = @() + + function GetUDPDataObject() + { + $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 + Add-Member -InputObject $objNode -MemberType NoteProperty -Name ServerRxGbps -Value $null -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name ThroughputDropPercent -Value $null -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name ClientUDPLoss -Value $null -Force + Add-Member -InputObject $objNode -MemberType NoteProperty -Name ServerUDPLoss -Value $null -Force + return $objNode + } + + foreach ( $Buffer in $testBuffers ) + { + foreach ( $connection in $testConnections ) + { + $currentResultObj = GetUDPDataObject + + $currentConnectionClientTxGbps = 0 + $currentConnectionClientTxGbpsArr = @() + $currentConnectionClientUDPLoss = 0 + $currentConnectionClientUDPLossArr = @() + + $currentConnectionserverTxGbps = 0 + $currentConnectionserverTxGbpsArr = @() + $currentConnectionserverUDPLoss = 0 + $currentConnectionserverUDPLossArr = @() + + foreach ( $file in $files ) + { + #region Get Client data... + if ( $file.Name -imatch "iperf-client-udp-IPv4-buffer-$($Buffer)-conn-$connection-instance-*" ) + { + $currentInstanceclientJsonText = $null + $currentInstanceclientJsonObj = $null + $currentInstanceClientPacketLoss = @() + $currentInstanceClientThroughput = $null + $fileName = $file.Name + try + { + $currentInstanceclientJsonText = ([string]( Get-Content "$clientfolder\$fileName")).Replace("-nan","0") + $errorLines = (Select-String -Path $clientfolder\$fileName -Pattern "warning") + if ($errorLines) + { + foreach ($errorLine in $errorLines) + { + $currentInstanceclientJsonText = $currentInstanceclientJsonText.Replace($errorLine.Line,'') + } + } + $currentInstanceclientJsonObj = ConvertFrom-Json -InputObject $currentInstanceclientJsonText + } + catch + { + LogErr " $fileName : RETURNED NULL" + } + if ( $currentInstanceclientJsonObj.end.sum.lost_percent -or $currentInstanceserverJsonObj.end.sum.packets) + { + $currentConnectionClientUDPLossArr += $currentInstanceclientJsonObj.end.sum.lost_percent + + $currentConnCurrentInstanceAllIntervalThroughputArr = @() + foreach ( $interval in $currentInstanceclientJsonObj.intervals ) + { + $currentConnCurrentInstanceAllIntervalThroughputArr += $interval.sum.bits_per_second + } + $currentInstanceClientThroughput = (((($currentConnCurrentInstanceAllIntervalThroughputArr | Measure-Object -Average).Average))/1000000000) + $outOfOrderPackats = ([regex]::Matches($currentInstanceclientJsonText, "OUT OF ORDER" )).count + if ( $outOfOrderPackats -gt 0 ) + { + LogErr " $fileName : ERROR: $outOfOrderPackats PACKETS ARRIVED OUT OF ORDER" + } + LogMsg " $fileName : Data collected successfully." + } + else + { + $currentInstanceClientThroughput = $null + #Write-Host " $($currentJsonObj.error) $currentFileClientThroughput " + } + if($currentInstanceClientThroughput) + { + $currentConnectionClientTxGbpsArr += $currentInstanceClientThroughput + } + } + #endregion + + #region Get Server data... + if ( $file.Name -imatch "iperf-server-udp-IPv4-buffer-$($Buffer)-conn-$connection-instance-*" ) + { + $currentInstanceserverJsonText = $null + $currentInstanceserverJsonObj = $null + $currentInstanceserverPacketLoss = @() + $currentInstanceserverThroughput = $null + $fileName = $file.Name + try + { + $currentInstanceserverJsonText = ([string]( Get-Content "$serverfolder\$fileName")).Replace("-nan","0") + $currentInstanceserverJsonObj = ConvertFrom-Json -InputObject $currentInstanceserverJsonText + } + catch + { + LogErr " $fileName : RETURNED NULL" + } + if ( $currentInstanceserverJsonObj.end.sum.lost_percent -or $currentInstanceserverJsonObj.end.sum.packets ) + { + $currentConnectionserverUDPLossArr += $currentInstanceserverJsonObj.end.sum.lost_percent + + $currentConnCurrentInstanceAllIntervalThroughputArr = @() + foreach ( $interval in $currentInstanceserverJsonObj.intervals ) + { + $currentConnCurrentInstanceAllIntervalThroughputArr += $interval.sum.bits_per_second + } + $currentInstanceserverThroughput = (((($currentConnCurrentInstanceAllIntervalThroughputArr | Measure-Object -Average).Average))/1000000000) + + $outOfOrderPackats = ([regex]::Matches($currentInstanceserverJsonText, "OUT OF ORDER" )).count + if ( $outOfOrderPackats -gt 0 ) + { + LogErr " $fileName : ERROR: $outOfOrderPackats PACKETS ARRIVED OUT OF ORDER" + } + LogMsg " $fileName : Data collected successfully." + } + else + { + $currentInstanceserverThroughput = $null + LogErr " $fileName : $($currentInstanceserverJsonObj.error)" + } + if($currentInstanceserverThroughput) + { + $currentConnectionserverTxGbpsArr += $currentInstanceserverThroughput + } + } + #endregion + } + + $currentConnectionClientTxGbps = [math]::Round((($currentConnectionClientTxGbpsArr | Measure-Object -Average).Average),2) + $currentConnectionClientUDPLoss = [math]::Round((($currentConnectionClientUDPLossArr | Measure-Object -Average).Average),2) + Write-Host "Client: $Buffer . $connection . $currentConnectionClientTxGbps .$currentConnectionClientUDPLoss" + $FinalClientThroughputArr += $currentConnectionClientTxGbps + $FinalClientUDPLossArr += $currentConnectionClientUDPLoss + + $currentConnectionserverTxGbps = [math]::Round((($currentConnectionserverTxGbpsArr | Measure-Object -Average).Average),2) + $currentConnectionserverUDPLoss = [math]::Round((($currentConnectionserverUDPLossArr | Measure-Object -Average).Average),2) + Write-Host "Server: $Buffer . $connection . $currentConnectionserverTxGbps .$currentConnectionserverUDPLoss" + $FinalServerThroughputArr += $currentConnectionserverTxGbps + $FinalServerUDPLossArr += $currentConnectionserverUDPLoss + $currentResultObj.BufferSize = $Buffer/1024 + $currentResultObj.Connections = $connection + $currentResultObj.ClientTxGbps = $currentConnectionClientTxGbps + $currentResultObj.ClientUDPLoss = $currentConnectionClientUDPLoss + if ( $currentConnectionClientTxGbps -ne 0 ) + { + if ( $currentConnectionClientTxGbps -ge $currentConnectionserverTxGbps ) + { + $currentResultObj.ThroughputDropPercent = [math]::Round(((($currentConnectionClientTxGbps-$currentConnectionserverTxGbps)*100)/$currentConnectionClientTxGbps),2) + } + else + { + $currentResultObj.ThroughputDropPercent = 0 + } + } + else + { + $currentResultObj.ThroughputDropPercent = 0 + } + $currentResultObj.ServerRxGbps = $currentConnectionserverTxGbps + $currentResultObj.ServerUDPLoss = $currentConnectionserverUDPLoss + $FinalServerClientUDPResultObjArr += $currentResultObj + Write-Host "-------------------------------" + } + } + + + #endregion + + foreach ( $udpResultObject in $FinalServerClientUDPResultObjArr ) + { + $connResult="ClientTxGbps=$($udpResultObject.ClientTxGbps) ServerRxGbps=$($udpResultObject.ServerRxGbps) UDPLoss=$($udpResultObject.ClientUDPLoss)%" + $metaData = "Buffer=$($udpResultObject.BufferSize)K Connections=$($udpResultObject.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 to DB STARTED.." + $dataSource = $xmlConfig.config.Azure.database.server + $dbuser = $xmlConfig.config.Azure.database.user + $dbpassword = $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 $dbuser -And $dbpassword -And $database -And $dataTableName) + { + $GuestDistro = cat "$LogDir\VM_properties.csv" | Select-String "OS type"| %{$_ -replace ",OS type,",""} + 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,",""} + $IPVersion = "IPv4" + $ProtocolType = $($currentTestData.TestType) + + $connectionString = "Server=$dataSource;uid=$dbuser; pwd=$dbpassword;Database=$database;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;" + $SQLQuery = "INSERT INTO $dataTableName (TestCaseName,TestDate,HostType,HostBy,HostOS,GuestOSType,GuestDistro,GuestSize,KernelVersion,IPVersion,ProtocolType,DataPath,SendBufSize_KBytes,NumberOfConnections,TxThroughput_Gbps,RxThroughput_Gbps,DatagramLoss) VALUES " + + foreach ( $udpResultObject in $FinalServerClientUDPResultObjArr ) + { + $SQLQuery += "('$TestCaseName','$(Get-Date -Format yyyy-MM-dd)','$HostType','$HostBy','$HostOS','$GuestOSType','$GuestDistro','$GuestSize','$KernelVersion','$IPVersion','UDP','$DataPath','$($udpResultObject.BufferSize)','$($udpResultObject.Connections)','$($udpResultObject.ClientTxGbps)','$($udpResultObject.ServerRxGbps)','$($udpResultObject.ClientUDPLoss)')," + } + + $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 to DB DONE!!" + } + else + { + LogMsg "Invalid database details. Failed to upload result to database!" + } + } + catch + { + $ErrorMessage = $_.Exception.Message + LogMsg "EXCEPTION : $ErrorMessage" + } + Finally + { + $metaData = "iperf3udp 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 diff --git a/Testscripts/Windows/PERF-STORAGE-MULTIDISK-RAID0-FIO.ps1 b/Testscripts/Windows/PERF-STORAGE-MULTIDISK-RAID0-FIO.ps1 new file mode 100644 index 000000000..e1332bc2d --- /dev/null +++ b/Testscripts/Windows/PERF-STORAGE-MULTIDISK-RAID0-FIO.ps1 @@ -0,0 +1,247 @@ +$result = "" +$testResult = "" +$resultArr = @() + +$isDeployed = DeployVMS -setupType $currentTestData.setupType -Distro $Distro -xmlConfig $xmlConfig +if ($isDeployed) +{ + try + { + $testVMData = $allVMData + ProvisionVMsForLisa -allVMData $allVMData -installPackagesOnRoleNames "none" + LogMsg "Generating constansts.sh ..." + $constantsFile = "$LogDir\constants.sh" + Set-Content -Value "#Generated by Azure Automation." -Path $constantsFile + foreach ( $param in $currentTestData.TestParameters.param) + { + Add-Content -Value "$param" -Path $constantsFile + LogMsg "$param added to constants.sh" + if ( $param -imatch "startThread" ) + { + $startThread = [int]($param.Replace("startThread=","")) + } + if ( $param -imatch "maxThread" ) + { + $maxThread = [int]($param.Replace("maxThread=","")) + } + } + LogMsg "constanst.sh created successfully..." + #endregion + + #region EXECUTE TEST + $myString = @" +chmod +x perf_fio.sh +./perf_fio.sh &> fioConsoleLogs.txt +. azuremodules.sh +collect_VM_properties +"@ + + $myString2 = @" +wget https://konkaciwestus1.blob.core.windows.net/scriptfiles/JSON.awk +wget https://konkaciwestus1.blob.core.windows.net/scriptfiles/gawk +wget https://konkaciwestus1.blob.core.windows.net/scriptfiles/fio_jason_parser.sh +chmod +x *.sh +cp fio_jason_parser.sh gawk JSON.awk /root/FIOLog/jsonLog/ +cd /root/FIOLog/jsonLog/ +./fio_jason_parser.sh +cp perf_fio.csv /root +chmod 666 /root/perf_fio.csv +"@ + Set-Content "$LogDir\StartFioTest.sh" $myString + Set-Content "$LogDir\ParseFioTestLogs.sh" $myString2 + RemoteCopy -uploadTo $testVMData.PublicIP -port $testVMData.SSHPort -files ".\$constantsFile,.\Testscripts\Linux\azuremodules.sh,.\Testscripts\Linux\perf_fio.sh,.\$LogDir\StartFioTest.sh,.\$LogDir\ParseFioTestLogs.sh" -username "root" -password $password -upload + RemoteCopy -uploadTo $testVMData.PublicIP -port $testVMData.SSHPort -files $currentTestData.files -username "root" -password $password -upload + $out = RunLinuxCmd -ip $testVMData.PublicIP -port $testVMData.SSHPort -username "root" -password $password -command "chmod +x *.sh" -runAsSudo + $testJob = RunLinuxCmd -ip $testVMData.PublicIP -port $testVMData.SSHPort -username "root" -password $password -command "./StartFioTest.sh" -RunInBackground -runAsSudo + + #endregion + + #region MONITOR TEST + while ( (Get-Job -Id $testJob).State -eq "Running" ) + { + $currentStatus = RunLinuxCmd -ip $testVMData.PublicIP -port $testVMData.SSHPort -username "root" -password $password -command "tail -1 runlog.txt"-runAsSudo + LogMsg "Current Test Staus : $currentStatus" + WaitFor -seconds 20 + } + + $finalStatus = RunLinuxCmd -ip $testVMData.PublicIP -port $testVMData.SSHPort -username "root" -password $password -command "cat state.txt" + RemoteCopy -downloadFrom $testVMData.PublicIP -port $testVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "FIOTest-*.tar.gz" + RemoteCopy -downloadFrom $testVMData.PublicIP -port $testVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "VM_properties.csv" + + $testSummary = $null + + #endregion + + 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") + { + $out = RunLinuxCmd -ip $testVMData.PublicIP -port $testVMData.SSHPort -username "root" -password $password -command "/root/ParseFioTestLogs.sh" + RemoteCopy -downloadFrom $testVMData.PublicIP -port $testVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "perf_fio.csv" + 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" + $resultSummary += CreateResultSummary -testResult $testResult -metaData "" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + + try + { + foreach($line in (Get-Content "$LogDir\perf_fio.csv")) + { + if ( $line -imatch "Max IOPS of each mode" ) + { + $maxIOPSforMode = $true + $maxIOPSforBlockSize = $false + $fioData = $false + } + if ( $line -imatch "Max IOPS of each BlockSize" ) + { + $maxIOPSforMode = $false + $maxIOPSforBlockSize = $true + $fioData = $false + } + if ( $line -imatch "Iteration,TestType,BlockSize" ) + { + $maxIOPSforMode = $false + $maxIOPSforBlockSize = $false + $fioData = $true + } + if ( $maxIOPSforMode ) + { + Add-Content -Value $line -Path $LogDir\maxIOPSforMode.csv + } + if ( $maxIOPSforBlockSize ) + { + Add-Content -Value $line -Path $LogDir\maxIOPSforBlockSize.csv + } + if ( $fioData ) + { + Add-Content -Value $line -Path $LogDir\fioData.csv + } + } + $maxIOPSforModeCsv = Import-Csv -Path $LogDir\maxIOPSforMode.csv + $maxIOPSforBlockSizeCsv = Import-Csv -Path $LogDir\maxIOPSforBlockSize.csv + $fioDataCsv = Import-Csv -Path $LogDir\fioData.csv + + + LogMsg "Uploading the test results.." + $dataSource = $xmlConfig.config.Azure.database.server + $DBuser = $xmlConfig.config.Azure.database.user + $DBpassword = $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 $DBuser -And $DBpassword -And $database -And $dataTableName) + { + $GuestDistro = cat "$LogDir\VM_properties.csv" | Select-String "OS type"| %{$_ -replace ",OS type,",""} + 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 = $testVMData.InstanceSize + $KernelVersion = cat "$LogDir\VM_properties.csv" | Select-String "Kernel version"| %{$_ -replace ",Kernel version,",""} + + $connectionString = "Server=$dataSource;uid=$DBuser; pwd=$DBpassword;Database=$database;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;" + + $SQLQuery = "INSERT INTO $dataTableName (TestCaseName,TestDate,HostType,HostBy,HostOS,GuestOSType,GuestDistro,GuestSize,KernelVersion,DiskSetup,BlockSize_KB,QDepth,seq_read_iops,seq_read_lat_usec,rand_read_iops,rand_read_lat_usec,seq_write_iops,seq_write_lat_usec,rand_write_iops,rand_write_lat_usec) VALUES " + + for ( $QDepth = $startThread; $QDepth -le $maxThread; $QDepth *= 2 ) + { + $seq_read_iops = ($fioDataCsv | where { $_.TestType -eq "read" -and $_.Threads -eq "$QDepth"} | Select ReadIOPS).ReadIOPS + $seq_read_lat_usec = ($fioDataCsv | where { $_.TestType -eq "read" -and $_.Threads -eq "$QDepth"} | Select MaxOfReadMeanLatency).MaxOfReadMeanLatency + + $rand_read_iops = ($fioDataCsv | where { $_.TestType -eq "randread" -and $_.Threads -eq "$QDepth"} | Select ReadIOPS).ReadIOPS + $rand_read_lat_usec = ($fioDataCsv | where { $_.TestType -eq "randread" -and $_.Threads -eq "$QDepth"} | Select MaxOfReadMeanLatency).MaxOfReadMeanLatency + + $seq_write_iops = ($fioDataCsv | where { $_.TestType -eq "write" -and $_.Threads -eq "$QDepth"} | Select WriteIOPS).WriteIOPS + $seq_write_lat_usec = ($fioDataCsv | where { $_.TestType -eq "write" -and $_.Threads -eq "$QDepth"} | Select MaxOfWriteMeanLatency).MaxOfWriteMeanLatency + + $rand_write_iops = ($fioDataCsv | where { $_.TestType -eq "randwrite" -and $_.Threads -eq "$QDepth"} | Select WriteIOPS).WriteIOPS + $rand_write_lat_usec= ($fioDataCsv | where { $_.TestType -eq "randwrite" -and $_.Threads -eq "$QDepth"} | Select MaxOfWriteMeanLatency).MaxOfWriteMeanLatency + + $BlockSize_KB= (($fioDataCsv | where { $_.Threads -eq "$QDepth"} | Select BlockSize)[0].BlockSize).Replace("K","") + + $SQLQuery += "('$TestCaseName','$(Get-Date -Format yyyy-MM-dd)','$HostType','$HostBy','$HostOS','$GuestOSType','$GuestDistro','$GuestSize','$KernelVersion','RAID0:12xP30','$BlockSize_KB','$QDepth','$seq_read_iops','$seq_read_lat_usec','$rand_read_iops','$rand_read_lat_usec','$seq_write_iops','$seq_write_lat_usec','$rand_write_iops','$rand_write_lat_usec')," + LogMsg "Collected performace data for $QDepth QDepth." + } + + $SQLQuery = $SQLQuery.TrimEnd(',') + Write-Host $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 + LogErr "EXCEPTION : $ErrorMessage" + } + + + } + catch + { + $ErrorMessage = $_.Exception.Message + LogMsg "EXCEPTION : $ErrorMessage" + } + Finally + { + $metaData = "NTTTCP 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 diff --git a/Testscripts/Windows/VERIFY-NVIDIA-CUDA-DRIVER-INSTALLATION.ps1 b/Testscripts/Windows/VERIFY-NVIDIA-CUDA-DRIVER-INSTALLATION.ps1 new file mode 100644 index 000000000..6817a64ff --- /dev/null +++ b/Testscripts/Windows/VERIFY-NVIDIA-CUDA-DRIVER-INSTALLATION.ps1 @@ -0,0 +1,207 @@ +$result = "" +$testResult = "" +$resultArr = @() + +Set-Variable -Name OverrideVMSize -Value $currentTestData.OverrideVMSize -Scope Global +$isDeployed = DeployVMS -setupType $currentTestData.setupType -Distro $Distro -xmlConfig $xmlConfig +if ($isDeployed) +{ + try + { + $testResult = $null + $clientVMData = $allVMData + #region CONFIGURE VM FOR N SERIES GPU TEST + LogMsg "Test VM details :" + LogMsg " RoleName : $($clientVMData.RoleName)" + LogMsg " Public IP : $($clientVMData.PublicIP)" + LogMsg " SSH Port : $($clientVMData.SSHPort)" + # + # 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 + + #region Install N-Vidia Drivers and reboot. + $myString = @" +cd /root/ +./GPU_Test.sh -logFolder /root &> GPUConsoleLogs.txt +. azuremodules.sh +collect_VM_properties +"@ + $StartScriptName = "StartGPUDriverInstall.sh" + Set-Content "$LogDir\$StartScriptName" $myString + RemoteCopy -uploadTo $clientVMData.PublicIP -port $clientVMData.SSHPort -files ".\Testscripts\Linux\azuremodules.sh,.\Testscripts\Linux\GPU_Test.sh,.\$LogDir\$StartScriptName" -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/$StartScriptName" -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 GPUConsoleLogs.txt" + LogMsg "Current Test Staus : $currentStatus" + WaitFor -seconds 20 + } + + RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "VM_properties.csv" + RemoteCopy -downloadFrom $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -download -downloadTo $LogDir -files "GPUConsoleLogs.txt" + + + $GPUDriverInstallLogs = RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "cat GPU_Test_Logs.txt" + + if ($GPUDriverInstallLogs -imatch "GPU_DRIVER_INSTALLATION_SUCCESSFUL") + { + #Reboot VM. + LogMsg "*********************************************************" + LogMsg "GPU Drivers installed successfully. Restarting VM now..." + LogMsg "*********************************************************" + $restartStatus = RestartAllDeployments -allVMData $clientVMData + if ($restartStatus -eq "True") + { + if (($clientVMData.InstanceSize -eq "Standard_NC6") -or ($clientVMData.InstanceSize -eq "Standard_NC6s_v2") -or ($clientVMData.InstanceSize -eq "Standard_NV6")) + { + $expectedCount = 1 + } + elseif (($clientVMData.InstanceSize -eq "Standard_NC12") -or ($clientVMData.InstanceSize -eq "Standard_NC12s_v2") -or ($clientVMData.InstanceSize -eq "Standard_NV12")) + { + $expectedCount = 2 + } + elseif (($clientVMData.InstanceSize -eq "Standard_NC24") -or ($clientVMData.InstanceSize -eq "Standard_NC24s_v2") -or ($clientVMData.InstanceSize -eq "Standard_NV24")) + { + $expectedCount = 4 + } + elseif (($clientVMData.InstanceSize -eq "Standard_NC24r") -or ($clientVMData.InstanceSize -eq "Standard_NC24rs_v2")) + { + $expectedCount = 4 + } + LogMsg "Test VM Size: $($clientVMData.InstanceSize). Expected GPU Adapters : $expectedCount" + $errorCount = 0 + #Adding sleep of 180 seconds, giving time to load nvidia drivers. + LogMsg "Waiting 3 minutes. (giving time to load nvidia drivers)" + Start-Sleep -Seconds 180 + #region PCI Express pass-through + $PCIExpress = RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "lsvmbus" -ignoreLinuxExitCode + Set-Content -Value $PCIExpress -Path $LogDir\PIC-Express-pass-through.txt -Force + if ( (Select-String -Path $LogDir\PIC-Express-pass-through.txt -Pattern "PCI Express pass-through").Matches.Count -eq $expectedCount ) + { + LogMsg "Expected `"PCI Express pass-through`" count: $expectedCount. Observed Count: $expectedCount" + $resultSummary += CreateResultSummary -testResult "PASS" -metaData "PCI Express pass-through" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + } + else + { + $errorCount += 1 + LogErr "Error in lsvmbus Outoput." + LogErr "$PCIExpress" + $resultSummary += CreateResultSummary -testResult "FAIL" -metaData "PCI Express pass-through" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + } + #endregion + + #region lspci + $lspci = RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "lspci" -ignoreLinuxExitCode + Set-Content -Value $lspci -Path $LogDir\lspci.txt -Force + if ( (Select-String -Path $LogDir\lspci.txt -Pattern "NVIDIA Corporation").Matches.Count -eq $expectedCount ) + { + LogMsg "Expected `"3D controller: NVIDIA Corporation`" count: $expectedCount. Observed Count: $expectedCount" + $resultSummary += CreateResultSummary -testResult "PASS" -metaData "lspci" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + } + else + { + $errorCount += 1 + LogErr "Error in lspci Outoput." + LogErr "$lspci" + $resultSummary += CreateResultSummary -testResult "FAIL" -metaData "lspci" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + } + + #endregion + + #region PCI lshw -c video + $lshw = RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "lshw -c video" -ignoreLinuxExitCode + Set-Content -Value $lshw -Path $LogDir\lshw-c-video.txt -Force + if ( ((Select-String -Path $LogDir\lshw-c-video.txt -Pattern "product: NVIDIA Corporation").Matches.Count -eq $expectedCount) -or ((Select-String -Path $LogDir\lshw-c-video.txt -Pattern "vendor: NVIDIA Corporation").Matches.Count -eq $expectedCount) ) + { + LogMsg "Expected Display adapters: $expectedCount. Observed adapters: $expectedCount" + $resultSummary += CreateResultSummary -testResult "PASS" -metaData "lshw -c video" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + } + else + { + $errorCount += 1 + LogErr "Error in display adapters." + LogErr "$lshw" + $resultSummary += CreateResultSummary -testResult "FAIL" -metaData "lshw -c video" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + } + + #endregion + + #region PCI nvidia-smi + $nvidiasmi = RunLinuxCmd -ip $clientVMData.PublicIP -port $clientVMData.SSHPort -username "root" -password $password -command "nvidia-smi" -ignoreLinuxExitCode + Set-Content -Value $nvidiasmi -Path $LogDir\nvidia-smi.txt -Force + if ( (Select-String -Path $LogDir\nvidia-smi.txt -Pattern "Tesla ").Matches.Count -eq $expectedCount ) + { + LogMsg "Expected Tesla count: $expectedCount. Observed count: $expectedCount" + $resultSummary += CreateResultSummary -testResult "PASS" -metaData "nvidia-smi" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + } + else + { + $errorCount += 1 + LogErr "Error in nvidia-smi." + LogErr "$nvidiasmi" + $resultSummary += CreateResultSummary -testResult "FAIL" -metaData "nvidia-smi" -checkValues "PASS,FAIL,ABORTED" -testName $currentTestData.testName + } + #endregion + } + else + { + LogErr "Unable to connect to test VM after restart" + $testResult = "FAIL" + } + } + else + { + + } + #endregion + + if ( ($errorCount -ne 0)) + { + LogErr "Test failed. : $summary." + $testResult = "FAIL" + } + elseif ( $errorCount -eq 0) + { + LogMsg "Test Completed." + $testResult = "PASS" + } + LogMsg "Test result : $testResult" + LogMsg "Test Completed" + } + catch + { + $ErrorMessage = $_.Exception.Message + LogMsg "EXCEPTION : $ErrorMessage" + } + Finally + { + $metaData = "GPU Verification" + 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 diff --git a/Tools/7za.exe b/Tools/7za.exe new file mode 100644 index 000000000..7f6bf86bc Binary files /dev/null and b/Tools/7za.exe differ diff --git a/Tools/Deleteme.txt b/Tools/Deleteme.txt new file mode 100644 index 000000000..e69de29bb diff --git a/Tools/dos2unix.exe b/Tools/dos2unix.exe new file mode 100644 index 000000000..7f2df21a1 Binary files /dev/null and b/Tools/dos2unix.exe differ diff --git a/Tools/plink.exe b/Tools/plink.exe new file mode 100644 index 000000000..ed861e2b1 Binary files /dev/null and b/Tools/plink.exe differ diff --git a/Tools/pscp.exe b/Tools/pscp.exe new file mode 100644 index 000000000..07a8ffb09 Binary files /dev/null and b/Tools/pscp.exe differ diff --git a/Utilities/AddAzureRmAccountFromSecretsFile.ps1 b/Utilities/AddAzureRmAccountFromSecretsFile.ps1 new file mode 100644 index 000000000..a0d5add2e --- /dev/null +++ b/Utilities/AddAzureRmAccountFromSecretsFile.ps1 @@ -0,0 +1,74 @@ +<# +.SYNOPSIS + This script authenticates PS sessing using Azure principal account. + +.DESCRIPTION + This script authenticates PS sessing using Azure principal account. + +.PARAMETER -customSecretsFilePath + Type: string + Required: Optinal. + +.INPUTS + AzureSecrets.xml file. If you are running this script in Jenkins, then make sure to add a secret file with ID: Azure_Secrets_File + If you are running the file locally, then pass secrets file path to -customSecretsFilePath parameter. + +.NOTES + Version: 1.0 + Author: Shital Savekar + Creation Date: 14th December 2017 + Purpose/Change: Initial script development + +.EXAMPLE + .\AddAzureRmAccountFromSecretsFile.ps1 -customSecretsFilePath .\AzureSecrets.xml +#> + +param +( + [string]$customSecretsFilePath = $null +) + +#---------------------------------------------------------[Initializations]-------------------------------------------------------- + +if ( $customSecretsFilePath ) { + $secretsFile = $customSecretsFilePath + Write-Host "Using provided secrets file: $($secretsFile | Split-Path -Leaf)" +} +if ($env:Azure_Secrets_File) { + $secretsFile = $env:Azure_Secrets_File + Write-Host "Using predefined secrets file: $($secretsFile | Split-Path -Leaf) in Jenkins Global Environments." +} +if ( $secretsFile -eq $null ) { + Write-Host "ERROR: Azure Secrets file not found in Jenkins / user not provided -customSecretsFilePath" -ForegroundColor Red -BackgroundColor Black + exit 1 +} + +#---------------------------------------------------------[Script Start]-------------------------------------------------------- + +if ( Test-Path $secretsFile ) { + Write-Host "$($secretsFile | Split-Path -Leaf) found." + Write-Host "---------------------------------" + Write-Host "Authenticating Azure PS session.." + $xmlSecrets = [xml](Get-Content $secretsFile) + $ClientID = $xmlSecrets.secrets.SubscriptionServicePrincipalClientID + $TenantID = $xmlSecrets.secrets.SubscriptionServicePrincipalTenantID + $Key = $xmlSecrets.secrets.SubscriptionServicePrincipalKey + $pass = ConvertTo-SecureString $key -AsPlainText -Force + $mycred = New-Object System.Management.Automation.PSCredential ($ClientID, $pass) + $out = Add-AzureRmAccount -ServicePrincipal -Tenant $TenantID -Credential $mycred + $subIDSplitted = ($xmlSecrets.secrets.SubscriptionID).Split("-") + $selectedSubscription = Select-AzureRmSubscription -SubscriptionId $xmlSecrets.secrets.SubscriptionID + if ( $selectedSubscription.Subscription.Id -eq $xmlSecrets.secrets.SubscriptionID ) { + Write-Host "Current Subscription : $($subIDSplitted[0])-xxxx-xxxx-xxxx-$($subIDSplitted[4])." + Write-Host "---------------------------------" + } + else { + Write-Host "There was error selecting $($subIDSplitted[0])-xxxx-xxxx-xxxx-$($subIDSplitted[4])." + Write-Host "---------------------------------" + } +} +else { + Write-Host "$($secretsFile | Spilt-Path -Leaf) file is not added in Jenkins Global Environments OR it is not bound to 'Azure_Secrets_File' variable." -ForegroundColor Red -BackgroundColor Black + Write-Host "Aborting."-ForegroundColor Red -BackgroundColor Black + exit 1 +} \ No newline at end of file diff --git a/Utilities/Deleteme.txt b/Utilities/Deleteme.txt new file mode 100644 index 000000000..e69de29bb diff --git a/XML/GlobalConfigurations.xml b/XML/GlobalConfigurations.xml index 62df28b96..01b8b4fd9 100644 --- a/XML/GlobalConfigurations.xml +++ b/XML/GlobalConfigurations.xml @@ -1,7 +1,7 @@ - 2cd20493-fe97-42ef-9ace-ab95b63d82c4 + xxxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxx YOUR_SUBSCRIPTION_NAME https://management.core.windows.net AzureCloud @@ -17,7 +17,7 @@ YOUR_USERNAME - Skynet@is@c0ming + xxxxxxxxxxxxxxxxxxxxxxxxx \ No newline at end of file diff --git a/XML/TestCases/FunctionalTests.xml b/XML/TestCases/FunctionalTests.xml index c84c1de99..2eef7ad6d 100644 --- a/XML/TestCases/FunctionalTests.xml +++ b/XML/TestCases/FunctionalTests.xml @@ -1,15 +1,54 @@ VERIFY-NVIDIA-CUDA-DRIVER-FOR-NC6-VM - ICA-N-Series-GPU-TEST.ps1 + VERIFY-NVIDIA-CUDA-DRIVER-INSTALLATION.ps1 SingleVM Standard_NC6 SOME,TEXTS,NEEDS,TO,BE,PRESENT,HERE,FOR,PRINTING,TEST,SUMMARY - .\remote-scripts\azuremodules.sh + .\Testscripts\Linux\azuremodules.sh Azure Functional default gpu,pci_hyperv - Functional_001 + Functional_GPU_001 + + VERIFY-NVIDIA-CUDA-DRIVER-FOR-NC12-VM + VERIFY-NVIDIA-CUDA-DRIVER-INSTALLATION.ps1 + SingleVM + Standard_NC12 + SOME,TEXTS,NEEDS,TO,BE,PRESENT,HERE,FOR,PRINTING,TEST,SUMMARY + .\Testscripts\Linux\azuremodules.sh + Azure + Functional + default + gpu,pci_hyperv + Functional_GPU_002 + + + VERIFY-NVIDIA-CUDA-DRIVER-FOR-NC24-VM + VERIFY-NVIDIA-CUDA-DRIVER-INSTALLATION.ps1 + SingleVM + Standard_NC24 + SOME,TEXTS,NEEDS,TO,BE,PRESENT,HERE,FOR,PRINTING,TEST,SUMMARY + .\Testscripts\Linux\azuremodules.sh + Azure + Functional + default + gpu,pci_hyperv + Functional_GPU_003 + + + VERIFY-NVIDIA-CUDA-DRIVER-FOR-NC24r-VM + VERIFY-NVIDIA-CUDA-DRIVER-INSTALLATION.ps1 + SingleVM + Standard_NC24r + SOME,TEXTS,NEEDS,TO,BE,PRESENT,HERE,FOR,PRINTING,TEST,SUMMARY + .\Testscripts\Linux\azuremodules.sh + Azure + Functional + default + gpu,pci_hyperv + Functional_GPU_004 + \ No newline at end of file diff --git a/XML/TestCases/PerformanceTests.xml b/XML/TestCases/PerformanceTests.xml index a8100a316..dda0aa489 100644 --- a/XML/TestCases/PerformanceTests.xml +++ b/XML/TestCases/PerformanceTests.xml @@ -1,11 +1,11 @@ - PERF-NETWORK-TCP-MULTICONNECTION + PERF-NETWORK-TCP-THROUGHPUT-MULTICONNECTION - ICA-PERF-NTTTCP-TEST.ps1 + PERF-NETWORK-TCP-THROUGHPUT-MULTICONNECTION-NTTTCP.ps1 M1S1 This-tag-will-be-removed - .\remote-scripts\azuremodules.sh + .\Testscripts\Linux\azuremodules.sh testDuration=300 testConnections="1 2 4 8 16 32 64 128 256 512 1024 2048 4096 6144 8192 10240" @@ -13,8 +13,90 @@ Azure Performance Network - tcp,network - Perf_001 + tcp,network,hv_netvsc + Perf_Network_001 - + + PERF-NETWORK-TCP-LATENCY-MULTICONNECTION + + PERF-NETWORK-TCP-LATENCY-MULTICONNECTION-LAGSCOPE.ps1 + M1S1 + This-tag-will-be-removed + .\Testscripts\Linux\azuremodules.sh + + pingIteration=1000000 + + Azure + Performance + Network + tcp,network,hv_netvsc + Perf_Network_002 + + + PERF-NETWORK-UDP-THROUGHPUT-MULTICONNECTION + + PERF-NETWORK-UDP-THROUGHPUT-MULTICONNECTION-IPERF3.ps1 + M1S1 + This-tag-will-be-removed + .\Testscripts\Linux\azuremodules.sh + + testDuration=300 + testType=udp + max_parallel_connections_per_instance=64 + connections=(1 2 4 8 16 32 64 128 256 512 1024) + bufferLengths=(1024 8192) + IPversion=4 + + Azure + Performance + Network + udp,network,hv_netvsc + Perf_Network_003 + + + PERF-STORAGE-4K-IO + + PERF-STORAGE-MULTIDISK-RAID0-FIO.ps1 + DS14DISK12 + This-tag-will-be-removed + .\Testscripts\Linux\azuremodules.sh + + modes='randread randwrite read write' + startThread=1 + maxThread=1024 + startIO=4 + numjobs=1 + ioruntime=300 + maxIO=4 + fileSize=1023G + + Azure + Performance + Storage + hv_storvsc,storage + Perf_Storage_001 + + + PERF-STORAGE-1024K-IO + + PERF-STORAGE-MULTIDISK-RAID0-FIO.ps1 + DS14DISK12 + This-tag-will-be-removed + .\Testscripts\Linux\azuremodules.sh + + modes='randread randwrite read write' + startThread=1 + maxThread=1024 + startIO=4 + numjobs=1 + ioruntime=300 + maxIO=1024 + fileSize=1023G + + Azure + Performance + Storage + hv_storvsc,storage + Perf_Storage_002 + \ No newline at end of file diff --git a/XML/TestCases/RegressionTests.xml b/XML/TestCases/RegressionTests.xml index 85bad59e9..cdad31d97 100644 --- a/XML/TestCases/RegressionTests.xml +++ b/XML/TestCases/RegressionTests.xml @@ -1,37 +1,3 @@ - - VERIFY-DEPLOYMENT-PROVISION - BVT-VERIFY-DEPLOYMENT-PROVISION.ps1 - - SingleVM - Azure - Regression - default - bvt - Regression_001 - - - VERIFY-HOSTNAME - BVT-VERIFY-HOSTNAME.py - BVT-VERIFY-HOSTNAME.ps1 - .\remote-scripts\nslookup.py,.\remote-scripts\BVT-VERIFY-HOSTNAME.py,.\remote-scripts\azuremodules.py - SingleVM - Azure - Regression - default - bvt - Regression_002 - - - VERIFY-ROOT-PASSWORD-DELETED - BVT-IS-ROOT-PASSWORD-DELETED.py - BVT-IS-ROOT-PASSWORD-DELETED.ps1 - .\remote-scripts\BVT-IS-ROOT-PASSWORD-DELETED.py,.\remote-scripts\azuremodules.py - SingleVM - Azure - Regression - default - bvt - Regression_003 - + \ No newline at end of file diff --git a/XML/TestCases/SmokeTests.xml b/XML/TestCases/SmokeTests.xml index bd9826b6b..442ec5d9d 100644 --- a/XML/TestCases/SmokeTests.xml +++ b/XML/TestCases/SmokeTests.xml @@ -14,7 +14,7 @@ VERIFY-HOSTNAME BVT-VERIFY-HOSTNAME.py BVT-VERIFY-HOSTNAME.ps1 - .\remote-scripts\nslookup.py,.\remote-scripts\BVT-VERIFY-HOSTNAME.py,.\remote-scripts\azuremodules.py + .\Testscripts\Linux\nslookup.py,.\Testscripts\Linux\BVT-VERIFY-HOSTNAME.py,.\Testscripts\Linux\azuremodules.py SingleVM Azure Smoke @@ -26,7 +26,7 @@ VERIFY-ROOT-PASSWORD-DELETED BVT-IS-ROOT-PASSWORD-DELETED.py BVT-IS-ROOT-PASSWORD-DELETED.ps1 - .\remote-scripts\BVT-IS-ROOT-PASSWORD-DELETED.py,.\remote-scripts\azuremodules.py + .\Testscripts\Linux\BVT-IS-ROOT-PASSWORD-DELETED.py,.\Testscripts\Linux\azuremodules.py SingleVM Azure Smoke diff --git a/XML/TestCases/StressTests.xml b/XML/TestCases/StressTests.xml index 0fa0a9805..cdad31d97 100644 --- a/XML/TestCases/StressTests.xml +++ b/XML/TestCases/StressTests.xml @@ -1,19 +1,3 @@ - - PERF-NETWORK-TCP-MULTICONNECTION - - ICA-PERF-NTTTCP-TEST.ps1 - M1S1 - This-tag-will-be-removed - .\remote-scripts\azuremodules.sh - - testDuration=300 - testConnections="1 2 4 8 16 32 64 128 256 512 1024 2048 4096 6144 8192 10240" - - Azure - Stress - Network - tcp,network - Stress_001 - + \ No newline at end of file diff --git a/XML/VMConfigurations/PerformanceTestsConfigurations.xml b/XML/VMConfigurations/PerformanceTestsConfigurations.xml index 082c2a5d2..8653777a9 100644 --- a/XML/VMConfigurations/PerformanceTestsConfigurations.xml +++ b/XML/VMConfigurations/PerformanceTestsConfigurations.xml @@ -26,101 +26,6 @@ - - NO - - - - Standard_G5 - Standard_G5 - - - SSH - tcp - 22 - 22 - - - TCPtest - tcp - 750 - 750 - False - - - UDPtest - udp - 990 - 990 - False - - - - - - Standard_G5 - Standard_G5 - - - SSH - tcp - 22 - 222 - - - TCPtest - tcp - 1750 - 1750 - False - - - UDPtest - udp - 1990 - 1990 - False - - - - - - - - NO - - - - Standard_D14 - Standard_D14 - - - SSH - tcp - 22 - 22 - - - - - - Standard_D14 - Standard_D14 - - - SSH - tcp - 22 - 222 - - - - - NO @@ -333,504 +238,5 @@ - - - NO - - - - Standard_A8 - Standard_A8 - server-vm - - SSH - tcp - 22 - 1111 - - - - - - Standard_A8 - Standard_A8 - client-vm - - SSH - tcp - 22 - 1112 - - - - - - - NO - - - - Standard_A9 - Standard_A9 - server-vm - - SSH - tcp - 22 - 1111 - - - - - - Standard_A9 - Standard_A9 - client-vm - - SSH - tcp - 22 - 1112 - - - - - - - NO - - - - Standard_H16r - Standard_H16r - server-vm - - SSH - tcp - 22 - 1111 - - - - - - Standard_H16r - Standard_H16r - client-vm - - SSH - tcp - 22 - 1112 - - - - - - - NO - - - - Standard_H16mr - Standard_H16mr - server-vm - - SSH - tcp - 22 - 1111 - - - - - - Standard_H16mr - Standard_H16mr - client-vm - - SSH - tcp - 22 - 1112 - - - - - - - - NO - - - - Standard_G5 - Standard_G5 - master - - SSH - tcp - 22 - 1111 - - - - - - Standard_G5 - Standard_G5 - slave1 - - SSH - tcp - 22 - 1112 - - - - - - Standard_G5 - Standard_G5 - slave2 - - SSH - tcp - 22 - 1113 - - - - - - Standard_G5 - Standard_G5 - slave3 - - SSH - tcp - 22 - 1114 - - - - - - Standard_G5 - Standard_G5 - slave4 - - SSH - tcp - 22 - 1115 - - - - - - Standard_G5 - Standard_G5 - slave5 - - SSH - tcp - 22 - 1116 - - - - - - - NO - - - - Large - Standard_D2 - master-vm - - SSH - tcp - 22 - 1111 - - - - - - Large - Standard_D2 - slave-vm-1 - - SSH - tcp - 22 - 1112 - - - - - - Large - Standard_D2 - slave-vm-2 - - SSH - tcp - 22 - 1113 - - - - - - Large - Standard_D2 - slave-vm-3 - - SSH - tcp - 22 - 1114 - - - - - - Large - Standard_D2 - slave-vm-4 - - SSH - tcp - 22 - 1115 - - - - - - Large - Standard_D2 - slave-vm-5 - - SSH - tcp - 22 - 1116 - - - - - - Large - Standard_D2 - slave-vm-6 - - SSH - tcp - 22 - 1117 - - - - - - Large - Standard_D2 - slave-vm-7 - - SSH - tcp - 22 - 1118 - - - - - - Large - Standard_D2 - slave-vm-8 - - SSH - tcp - 22 - 1119 - - - - - - Large - Standard_D2 - slave-vm-9 - - SSH - tcp - 22 - 11110 - - - - - - Large - Standard_D2 - slave-vm-10 - - SSH - tcp - 22 - 11111 - - - - - - Large - Standard_D2 - slave-vm-11 - - SSH - tcp - 22 - 11112 - - - - - - Large - Standard_D2 - slave-vm-12 - - SSH - tcp - 22 - 11113 - - - - - - Large - Standard_D2 - slave-vm-13 - - SSH - tcp - 22 - 11114 - - - - - - Large - Standard_D2 - slave-vm-14 - - SSH - tcp - 22 - 11115 - - - - - - Large - Standard_D2 - slave-vm-15 - - SSH - tcp - 22 - 11116 - - - - - - - NO - - - - Standard_GS5 - Standard_GS5 - server-vm - - SSH - tcp - 22 - 1111 - - - 0 - 1023 - None - - - - - Standard_GS5 - Standard_GS5 - client-vm - - SSH - tcp - 22 - 1112 - - - - - - NO - - - - Standard_G5 - Standard_G5 - Server1 - - SSH - tcp - 22 - 1111 - - - - - - Standard_G5 - Standard_G5 - Server2 - - SSH - tcp - 22 - 1112 - - - - - - Standard_G5 - Standard_G5 - Client - - SSH - tcp - 22 - 1113 - - - - - + diff --git a/XML/VMConfigurations/RegressionTestsConfigurations.xml b/XML/VMConfigurations/RegressionTestsConfigurations.xml index ac259dff4..c081f8bab 100644 --- a/XML/VMConfigurations/RegressionTestsConfigurations.xml +++ b/XML/VMConfigurations/RegressionTestsConfigurations.xml @@ -1,38 +1,2 @@ - - NO - - - - Standard_DS1 - Standard_DS1 - - - SSH - tcp - 22 - 22 - - - - - - - NO - - - - Standard_DS1 - Standard_DS1 - - - SSH - tcp - 22 - 22 - - - - - diff --git a/XML/VMConfigurations/StressTestsConfigurations.xml b/XML/VMConfigurations/StressTestsConfigurations.xml index 5c5c8783a..7e2cd6e97 100644 --- a/XML/VMConfigurations/StressTestsConfigurations.xml +++ b/XML/VMConfigurations/StressTestsConfigurations.xml @@ -1,29 +1,2 @@ - - - NO - - - Standard_D15_v2 - server-vm - - SSH - tcp - 22 - 1111 - - - - - Standard_D15_v2 - client-vm - - SSH - tcp - 22 - 1112 - - - - - +