Skip to content

Commit

Permalink
Windows testing and pipeline enhancements (#110)
Browse files Browse the repository at this point in the history
* Initial code changes for windows testing and pipeline enhancements

* Added test cases for windows node

* Updated e2e-test-pipeline.yml

* Updated pipelines according to templates

* Address pipeline related issues

* Address pipeline related issues #2

* Address pipeline related issues #3

* Address pipeline related issues #4

* Address pipeline related issues #5

* Removed code added for debugging

* Address pipeline related issues #6

* Import windows-test in initialization script

* Fixed group name for linuxandwindows test group

* Updated linuxandwindows pipeline
  • Loading branch information
ag17sep authored May 11, 2023
1 parent 7016f38 commit 5eb5d4e
Show file tree
Hide file tree
Showing 8 changed files with 485 additions and 16 deletions.
35 changes: 35 additions & 0 deletions .pipeline/e2e-test-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# E2E pipeline for AKS Iot

trigger: none

resources:
repositories:
- repository: AksEdge
type: github
endpoint: AksEdge-GithubConnection
name: Azure/AKS-Edge
ref: $(Build.SourceBranch)


# Reference the MSI pipelines

parameters:
- name: TestGroup
displayName: Test Group to execute
type: string
default: LinuxOffline
values:
- LinuxOffline
- LinuxOnline
- LinuxAndWindows
- All
jobs:
- template: templates/matrix-generator.yml
parameters:
TestGroup: ${{ parameters.TestGroup }}
- ${{ if or( eq(parameters.TestGroup, 'All'), eq(parameters.TestGroup, 'LinuxOffline')) }}:
- template: templates/e2e-linuxoffline.yml
- ${{ if or( eq(parameters.TestGroup, 'All'), eq(parameters.TestGroup, 'LinuxOnline')) }}:
- template: templates/e2e-linuxonline.yml
- ${{ if or( eq(parameters.TestGroup, 'All'), eq(parameters.TestGroup, 'LinuxAndWindows')) }}:
- template: templates/e2e-linuxandwindows.yml
103 changes: 103 additions & 0 deletions .pipeline/templates/e2e-linuxandwindows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
jobs:
- job: aidescript_e2e_test_linuxandwindows
dependsOn:
- mtrxgenerator
displayName: Run E2E Linux And Windows Offline Test Suite
pool: 1es-aksiot-windows-x64-ltsc-2021-test-pool
timeoutInMinutes: 60
condition: eq(dependencies.mtrxgenerator.outputs['mtrx.LinuxAndWindows'], 'true')

steps:
- checkout: AksEdge
path: self
clean: true
fetchDepth: 1

- powershell: |
$CheckInstaller = Get-WmiObject -Class Win32_Product | where Name -match "AKS Edge Essentials - (K8s|K3s)"
$Module = Get-Module -ListAvailable -Name AksEdge
if ($CheckInstaller -ne $Null -Or $Module -ne $Null)
{
Write-Error "AksEdge is already installed on this agent"
Exit 1
}
Write-Host "AksEdge is not installed on this agent"
$freememInMB = ((Get-CimInstance -Class Win32_OperatingSystem).FreePhysicalMemory / 1024)
$freememInMBRounded = [Math]::Round($freememInMB)
if ($freememInMbRounded -lt 4096)
{
Write-Error "The host does not have enough resources to install and run AksEdge"
Exit 1
}
Write-Host "The host has $freememInMBRounded free memory, AksEdge can be installed on it"
$PSConfiguration = Get-ExecutionPolicy
if ($PSConfiguration -ne "Bypass" -and $PSConfiguration -ne "Unrestricted")
{
Write-Error "The host current powershell configuration is $PSConfiguration, expected configuration is Bypass or Unrestricted"
Exit 1
}
Write-Host "The host current powershell configuration is $PSConfiguration"
$SSHCheck = (Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Client*').State
$HyperVHyperVisor = (Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-Hypervisor -Online).State
$HyperV = (Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online).State
$HyperVMngPowershell = (Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-Management-PowerShell -Online).State
if ($SSHCheck -ne "Installed" -Or $HyperVHyperVisor -ne "Enabled" -Or $HyperV -ne "Enabled" -Or $HyperVMngPowershell -ne "Enabled")
{
Write-Error "Not all software modules are installed, the software modules that are needed are: OpenSSH.Client, Microsoft-Hyper-V-Hypervisor, Microsoft-Hyper-V, Microsoft-Hyper-V-Management-PowerShell."
Exit 1
}
Write-Host "All the software modules are installed: OpenSSH.Client, Microsoft-Hyper-V-Hypervisor, Microsoft-Hyper-V, Microsoft-Hyper-V-Management-PowerShell."
displayName: 'Validating agent state'
- powershell: |
Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force
$modules = Get-Module -ListAvailable
Write-Host "Modules available are"
Write-Host $modules
$psgallery = Get-PSRepository | Where-Object { $_.Name -like "PSGallery" }
if ($psgallery.InstallationPolicy -ine "Trusted") {
# Do this always as by default PSGallery is untrusted.
# See alternate means to force install rather than making this trusted.
Write-Host "Setting PSGallery as Trusted Source"
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
}
else { Write-Host "PSGallery is trusted" -ForegroundColor Green }
displayName: 'Enabling PS Reposiotory access to install required module'
- powershell: |
$LogFile = 'e2e_junit.xml'
$TestPath = "$(Agent.BuildDirectory)\self\tests"
$WindowsConfig = [PSCustomObject]@{
"CpuCount"= 4
"MemoryInMB"= 4096
"DataSizeInGB"= 20
}
$AksEdgeConfigFilePath = "$(Agent.BuildDirectory)\self\tools\aksedge-config.json"
$AksEdgeConfig = Get-Content -Raw $AksEdgeConfigFilePath | ConvertFrom-Json
Add-Member -InputObject $AksEdgeConfig.Machines[0] -MemberType NoteProperty -Name WindowsNode -Value $WindowsConfig
$AksEdgeConfig | ConvertTo-Json | Out-File $AksEdgeConfigFilePath
$JsonConfigFilePath = "$(Agent.BuildDirectory)\self\tools\aide-userconfig.json"
$JsonTestParameters = Get-Content -Raw $JsonConfigFilePath | ConvertFrom-Json
$JsonTestParameters.AksEdgeConfigFile = $AksEdgeConfigFilePath
$JsonTestParameters | ConvertTo-Json -Depth 4 | Out-File $JsonConfigFilePath
Write-Host "Executing tests from $TestPath, Results at $LogFile"
Get-ChildItem -Path $TestPath
& c:\windows\system32\windowspowershell\v1.0\powershell.exe -File "$TestPath\e2e.ps1" -LogFile $LogFile -JsonConfigFilePath $JsonConfigFilePath -IncludeGroup BasicLinuxAndWindowsNodeOffline
Copy-Item -Path $LogFile -Destination "$(Build.ArtifactStagingDirectory)\e2e_junit.xml"
Copy-Item -Path $TestPath\Logs-*.zip -Destination "$(Build.ArtifactStagingDirectory)\$E2E-Logs.zip"
displayName: 'Run e2e.ps1'
- task: PublishTestResults@2
inputs:
testResultsFormat: JUnit
testResultsFiles: '$(Build.ArtifactStagingDirectory)/e2e_junit.xml'
testRunTitle: 'AideScripts E2E Test Pass'
displayName: 'Publish E2E Test Results'
93 changes: 93 additions & 0 deletions .pipeline/templates/e2e-linuxoffline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
jobs:
- job: aidescript_e2e_test_linuxoffline
dependsOn:
- mtrxgenerator
displayName: Run E2E Linux Offline Test Suite
pool: 1es-aksiot-windows-x64-ltsc-2021-test-pool
timeoutInMinutes: 60
condition: eq(dependencies.mtrxgenerator.outputs['mtrx.LinuxNodeOffline'], 'true')


steps:
- checkout: AksEdge
path: self
clean: true
fetchDepth: 1

- powershell: |
$CheckInstaller = Get-WmiObject -Class Win32_Product | where Name -match "AKS Edge Essentials - (K8s|K3s)"
$Module = Get-Module -ListAvailable -Name AksEdge
if ($CheckInstaller -ne $Null -Or $Module -ne $Null)
{
Write-Error "AksEdge is already installed on this agent"
Exit 1
}
Write-Host "AksEdge is not installed on this agent"
$freememInMB = ((Get-CimInstance -Class Win32_OperatingSystem).FreePhysicalMemory / 1024)
$freememInMBRounded = [Math]::Round($freememInMB)
if ($freememInMbRounded -lt 4096)
{
Write-Error "The host does not have enough resources to install and run AksEdge"
Exit 1
}
Write-Host "The host has $freememInMBRounded free memory, AksEdge can be installed on it"
$PSConfiguration = Get-ExecutionPolicy
if ($PSConfiguration -ne "Bypass" -and $PSConfiguration -ne "Unrestricted")
{
Write-Error "The host current powershell configuration is $PSConfiguration, expected configuration is Bypass or Unrestricted"
Exit 1
}
Write-Host "The host current powershell configuration is $PSConfiguration"
$SSHCheck = (Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Client*').State
$HyperVHyperVisor = (Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-Hypervisor -Online).State
$HyperV = (Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online).State
$HyperVMngPowershell = (Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-Management-PowerShell -Online).State
if ($SSHCheck -ne "Installed" -Or $HyperVHyperVisor -ne "Enabled" -Or $HyperV -ne "Enabled" -Or $HyperVMngPowershell -ne "Enabled")
{
Write-Error "Not all software modules are installed, the software modules that are needed are: OpenSSH.Client, Microsoft-Hyper-V-Hypervisor, Microsoft-Hyper-V, Microsoft-Hyper-V-Management-PowerShell."
Exit 1
}
Write-Host "All the software modules are installed: OpenSSH.Client, Microsoft-Hyper-V-Hypervisor, Microsoft-Hyper-V, Microsoft-Hyper-V-Management-PowerShell."
displayName: 'Validating agent state'
- powershell: |
Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force
$modules = Get-Module -ListAvailable
Write-Host "Modules available are"
Write-Host $modules
$psgallery = Get-PSRepository | Where-Object { $_.Name -like "PSGallery" }
if ($psgallery.InstallationPolicy -ine "Trusted") {
# Do this always as by default PSGallery is untrusted.
# See alternate means to force install rather than making this trusted.
Write-Host "Setting PSGallery as Trusted Source"
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
}
else { Write-Host "PSGallery is trusted" -ForegroundColor Green }
displayName: 'Enabling PS Reposiotory access to install required module'
- powershell: |
$LogFile = 'e2e_junit.xml'
$TestPath = "$(Agent.BuildDirectory)\self\tests"
$JsonConfigFilePath = "$(Agent.BuildDirectory)\self\tools\aide-userconfig.json"
$JsonTestParameters = Get-Content -Raw $JsonConfigFilePath | ConvertFrom-Json
$JsonTestParameters.AksEdgeConfigFile = "$(Agent.BuildDirectory)\self\tools\aksedge-config.json"
$JsonTestParameters | ConvertTo-Json | Out-File $JsonConfigFilePath
Write-Host "Executing tests from $TestPath, Results at $LogFile"
Get-ChildItem -Path $TestPath
& c:\windows\system32\windowspowershell\v1.0\powershell.exe -File "$TestPath\e2e.ps1" -LogFile $LogFile -JsonConfigFilePath $JsonConfigFilePath -IncludeGroup BasicLinuxNodeOffline
Copy-Item -Path $LogFile -Destination "$(Build.ArtifactStagingDirectory)\e2e_junit.xml"
Copy-Item -Path $TestPath\Logs-*.zip -Destination "$(Build.ArtifactStagingDirectory)\$E2E-Logs.zip"
displayName: 'Run e2e.ps1'
- task: PublishTestResults@2
inputs:
testResultsFormat: JUnit
testResultsFiles: '$(Build.ArtifactStagingDirectory)/e2e_junit.xml'
testRunTitle: 'AideScripts E2E Test Pass'
displayName: 'Publish E2E Test Results'
25 changes: 10 additions & 15 deletions azure-pipelines.yml → .pipeline/templates/e2e-linuxonline.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
trigger: none

resources:
repositories:
- repository: AksEdge
type: github
endpoint: AksEdge-GithubConnection
name: Azure/AKS-Edge
ref: $(Build.SourceBranch)

jobs:
- job: aidescript_e2e_test
displayName: Run E2E Aide Test Script
- job: aidescript_e2e_test_linuxonline
displayName: Run E2E Linux Online Test Suite
dependsOn:
- mtrxgenerator
pool: 1es-aksiot-windows-x64-ltsc-2021-test-pool
timeoutInMinutes: 60
condition: eq(dependencies.mtrxgenerator.outputs['mtrx.LinuxNodeOnline'], 'true')


steps:
- checkout: AksEdge
Expand Down Expand Up @@ -91,15 +85,16 @@ jobs:
}
'CustomLocationOID' = '51dfe1e8-70c6-4de5-a08e-e18aff23d815'
}
$JsonTestParameters = Get-Content -Raw "$(Agent.BuildDirectory)\self\tools\aide-userconfig.json" | ConvertFrom-Json
$JsonConfigFilePath = "$(Agent.BuildDirectory)\self\tools\aide-userconfig.json"
$JsonTestParameters = Get-Content -Raw $JsonConfigFilePath | ConvertFrom-Json
$JsonTestParameters.AksEdgeConfigFile = "$(Agent.BuildDirectory)\self\tools\aksedge-config.json"
$JsonTestParameters.Azure = New-Object psobject -Property $AzureConfig
$JsonTestParameters | ConvertTo-Json | Out-File "$(Agent.BuildDirectory)\self\tools\aide-userconfig.json"
$JsonTestParameters | ConvertTo-Json | Out-File "$JsonConfigFilePath"
Write-Host "Executing tests from $TestPath, Results at $LogFile"
Get-ChildItem -Path $TestPath
& c:\windows\system32\windowspowershell\v1.0\powershell.exe -File "$TestPath\e2e.ps1" -All -LogFile $LogFile
& c:\windows\system32\windowspowershell\v1.0\powershell.exe -File "$TestPath\e2e.ps1" -LogFile $LogFile -JsonConfigFilePath $JsonConfigFilePath -IncludeGroup BasicLinuxNodeOnline
Copy-Item -Path $LogFile -Destination "$(Build.ArtifactStagingDirectory)\e2e_junit.xml"
Copy-Item -Path $TestPath\Logs-*.zip -Destination "$(Build.ArtifactStagingDirectory)\$E2E-Logs.zip"
displayName: 'Run e2e.ps1'
Expand Down
45 changes: 45 additions & 0 deletions .pipeline/templates/matrix-generator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Template for the matrix generator

parameters:
- name: TestGroup
displayName: Test Group to execute

jobs:
- job: mtrxgenerator
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
clean: true
fetchDepth: 1
- bash: |
# Use the json file to get the values of params passed to the MSI pipeline
# Install jq
sudo apt-get update
sudo apt-get install jq -y
LinuxNodeOnline='false'
LinuxNodeOffline='false'
LinuxAndWindows='false'
if [ "${{ parameters.TestGroup }}" == "All" ]; then
LinuxNodeOnline='true'
LinuxNodeOffline='true'
LinuxAndWindows='true'
elif [ "${{ parameters.TestGroup }}" == "LinuxOffline" ]; then
LinuxNodeOffline='true'
elif [ "${{ parameters.TestGroup }}" == "LinuxOnline" ]; then
LinuxNodeOnline='true'
elif [ "${{ parameters.TestGroup }}" == "LinuxAndWindows" ]; then
LinuxAndWindows='true'
fi
echo "LinuxOffline: $LinuxNodeOffline"
echo "LinuxOnline: $LinuxNodeOnline"
echo "LinuxAndWindows: $LinuxAndWindows"
echo "##vso[task.setVariable variable=LinuxNodeOffline;isOutput=true]$LinuxNodeOffline"
echo "##vso[task.setVariable variable=LinuxNodeOnline;isOutput=true]$LinuxNodeOnline"
echo "##vso[task.setVariable variable=LinuxAndWindows;isOutput=true]$LinuxAndWindows"
name: mtrx
Loading

0 comments on commit 5eb5d4e

Please sign in to comment.