Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arcbox 3.0 workstream - task 915 Pester tests #2336

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 74 additions & 3 deletions azure_jumpstart_arcbox/artifacts/ArcServersLogonScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ $Env:ArcBoxDir = "C:\ArcBox"
$Env:ArcBoxLogsDir = "$Env:ArcBoxDir\Logs"
$Env:ArcBoxVMDir = "$Env:ArcBoxDir\Virtual Machines"
$Env:ArcBoxIconDir = "$Env:ArcBoxDir\Icons"
$Env:ArcBoxTestsDir = "$Env:ArcBoxDir\Tests"
$agentScript = "$Env:ArcBoxDir\agentScript"

# Set variables to execute remote powershell scripts on guest VMs
Expand Down Expand Up @@ -40,6 +41,27 @@ foreach ($key in $keys) {
}
}

# Create Windows Terminal desktop shortcut
$WshShell = New-Object -comObject WScript.Shell
$WinTerminalPath = (Get-ChildItem "C:\Program Files\WindowsApps" -Recurse | Where-Object { $_.name -eq "wt.exe" }).FullName
$Shortcut = $WshShell.CreateShortcut("$Env:USERPROFILE\Desktop\Windows Terminal.lnk")
$Shortcut.TargetPath = $WinTerminalPath
$shortcut.WindowStyle = 3
$shortcut.Save()

# Configure Windows Terminal as the default terminal application
$registryPath = "HKCU:\Console\%%Startup"

if (Test-Path $registryPath) {
Set-ItemProperty -Path $registryPath -Name "DelegationConsole" -Value "{2EACA947-7F5F-4CFA-BA87-8F7FBEEFBE69}"
Set-ItemProperty -Path $registryPath -Name "DelegationTerminal" -Value "{E12CFF52-A866-4C77-9A90-F570A7AA2C6B}"
} else {
New-Item -Path $registryPath -Force | Out-Null
Set-ItemProperty -Path $registryPath -Name "DelegationConsole" -Value "{2EACA947-7F5F-4CFA-BA87-8F7FBEEFBE69}"
Set-ItemProperty -Path $registryPath -Name "DelegationTerminal" -Value "{E12CFF52-A866-4C77-9A90-F570A7AA2C6B}"
}


################################################
# Setup Hyper-V server before deploying VMs for each flavor
################################################
Expand Down Expand Up @@ -482,11 +504,60 @@ Write-Host "Creating deployment logs bundle"
7z a $Env:ArcBoxLogsDir\LogsBundle-"$RandomString".zip $Env:ArcBoxLogsDir\*.log
}'

# Changing to Jumpstart ArcBox wallpaper
#Changing to Jumpstart ArcBox wallpaper

Write-Header "Changing wallpaper"

$wallpaperPath = "$Env:ArcBoxDir\wallpaper.png"
Set-JSDesktopBackground -ImagePath $wallpaperPath
# bmp file is required for BGInfo
Convert-JSImageToBitMap -SourceFilePath "$Env:ArcBoxDir\wallpaper.png" -DestinationFilePath "$Env:ArcBoxDir\wallpaper.bmp"

Set-JSDesktopBackground -ImagePath "$Env:ArcBoxDir\wallpaper.bmp"

Write-Header "Running tests to verify infrastructure"

Invoke-Pester -Path "$Env:ArcBoxTestsDir\common.tests.ps1" -Output Detailed -PassThru -OutVariable tests_common
$tests_passed = $tests_common.Passed.Count
$tests_failed = $tests_common.Failed.Count

switch ($env:flavor) {
'DevOps' {
Invoke-Pester -Path "$Env:ArcBoxTestsDir\devops.tests.ps1" -Output Detailed -PassThru -OutVariable tests_devops
$tests_passed = $tests_passed + $tests_devops.Passed.Count
$tests_failed = $tests_failed + $tests_devops.Failed.Count
}
'DataOps' {
Invoke-Pester -Path "$Env:ArcBoxTestsDir\dataops.tests.ps1" -Output Detailed -Output Detailed -PassThru -OutVariable tests_dataops
$tests_passed = $tests_passed + $tests_dataops.Passed.Count
$tests_failed = $tests_failed + $tests_dataops.Failed.Count
}
'ITPro' {
Invoke-Pester -Path "$Env:ArcBoxTestsDir\itpro.tests.ps1" -Output Detailed -PassThru -OutVariable tests_itpro
$tests_passed = $tests_passed + $tests_itpro.Passed.Count
$tests_failed = $tests_failed + $tests_itpro.Failed.Count
}
'Full' {
Invoke-Pester -Path "$Env:ArcBoxTestsDir\devops.tests.ps1" -Output Detailed -PassThru -OutVariable tests_devops
$tests_passed = $tests_passed + $tests_devops.Passed.Count
$tests_failed = $tests_failed + $tests_devops.Failed.Count

Invoke-Pester -Path "$Env:ArcBoxTestsDir\dataops.tests.ps1" -Output Detailed -PassThru -OutVariable tests_dataops
$tests_passed = $tests_passed + $tests_dataops.Passed.Count
$tests_failed = $tests_failed + $tests_dataops.Failed.Count

Invoke-Pester -Path "$Env:ArcBoxTestsDir\itpro.tests.ps1" -Output Detailed -PassThru -OutVariable tests_itpro
$tests_passed = $tests_passed + $tests_itpro.Passed.Count
$tests_failed = $tests_failed + $tests_itpro.Failed.Count
}
}

Write-Output "Tests succeeded: $tests_passed"
Write-Output "Tests failed: $tests_failed"

Write-Header "Adding deployment test results to wallpaper using BGInfo"

Set-Content 'C:\Windows\Temp\arcbox-tests-succeeded.txt' $tests_passed
Set-Content 'C:\Windows\Temp\arcbox-tests-failed.txt' $tests_failed

bginfo.exe $Env:ArcBoxTestsDir\arcbox-bginfo.bgi /timer:0 /NOLICPROMPT

Stop-Transcript
7 changes: 7 additions & 0 deletions azure_jumpstart_arcbox/artifacts/Bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ $Env:ArcBoxKVDir = "$Env:ArcBoxDir\KeyVault"
$Env:ArcBoxGitOpsDir = "$Env:ArcBoxDir\GitOps"
$Env:ArcBoxIconDir = "$Env:ArcBoxDir\Icons"
$Env:agentScript = "$Env:ArcBoxDir\agentScript"
$Env:ArcBoxTestsDir = "$Env:ArcBoxDir\Tests"
$Env:ToolsDir = "C:\Tools"
$Env:tempDir = "C:\Temp"
$Env:ArcBoxDataOpsDir = "$Env:ArcBoxDir\DataOps"
Expand All @@ -96,6 +97,7 @@ New-Item -Path $Env:ToolsDir -ItemType Directory -Force
New-Item -Path $Env:tempDir -ItemType directory -Force
New-Item -Path $Env:agentScript -ItemType directory -Force
New-Item -Path $Env:ArcBoxDataOpsDir -ItemType directory -Force
New-Item -Path $Env:ArcBoxTestsDir -ItemType directory -Force

Start-Transcript -Path $Env:ArcBoxLogsDir\Bootstrap.log

Expand Down Expand Up @@ -167,6 +169,8 @@ Invoke-WebRequest ($templateBaseUrl + "artifacts/dsc/common.dsc.yml") -OutFile $
Invoke-WebRequest ($templateBaseUrl + "artifacts/dsc/dataops.dsc.yml") -OutFile $Env:ArcBoxDscDir\dataops.dsc.yml
Invoke-WebRequest ($templateBaseUrl + "artifacts/dsc/devops.dsc.yml") -OutFile $Env:ArcBoxDscDir\devops.dsc.yml
Invoke-WebRequest ($templateBaseUrl + "artifacts/dsc/itpro.dsc.yml") -OutFile $Env:ArcBoxDscDir\itpro.dsc.yml
Invoke-WebRequest ($templateBaseUrl + "artifacts/tests/arcbox-bginfo.bgi") -OutFile $Env:ArcBoxTestsDir\arcbox-bginfo.bgi
Invoke-WebRequest ($templateBaseUrl + "artifacts/tests/common.tests.ps1") -OutFile $Env:ArcBoxTestsDir\common.tests.ps1
Invoke-WebRequest ($templateBaseUrl + "artifacts/WinGet.ps1") -OutFile $Env:ArcBoxDir\WinGet.ps1
Invoke-WebRequest ($templateBaseUrl + "../tests/GHActionDeploy.ps1") -OutFile "$Env:ArcBoxDir\GHActionDeploy.ps1"
Invoke-WebRequest ($templateBaseUrl + "../tests/OpenSSHDeploy.ps1") -OutFile "$Env:ArcBoxDir\OpenSSHDeploy.ps1"
Expand Down Expand Up @@ -200,6 +204,7 @@ if ($flavor -eq "Full" -Or $flavor -eq "ITPro") {
Invoke-WebRequest ($templateBaseUrl + "artifacts/ArcSQLManualOnboarding.ps1") -OutFile $Env:ArcBoxDir\ArcSQLManualOnboarding.ps1
Invoke-WebRequest ($templateBaseUrl + "artifacts/installArcAgentSQLUser.ps1") -OutFile $Env:ArcBoxDir\installArcAgentSQLUser.ps1
Invoke-WebRequest ($templateBaseUrl + "artifacts/testDefenderForSQL.ps1") -OutFile $Env:ArcBoxDir\testDefenderForSQL.ps1
Invoke-WebRequest ($templateBaseUrl + "artifacts/tests/itpro.tests.ps1") -OutFile $Env:ArcBoxTestsDir\itpro.tests.ps1
}

# DevOps
Expand All @@ -215,6 +220,7 @@ if ($flavor -eq "DevOps") {
Invoke-WebRequest ($templateBaseUrl + "artifacts/gitops_scripts/ResetBookstore.ps1") -OutFile $Env:ArcBoxGitOpsDir\ResetBookstore.ps1
Invoke-WebRequest ($templateBaseUrl + "artifacts/icons/arc.ico") -OutFile $Env:ArcBoxIconDir\arc.ico
Invoke-WebRequest ($templateBaseUrl + "artifacts/icons/bookstore.ico") -OutFile $Env:ArcBoxIconDir\bookstore.ico
Invoke-WebRequest ($templateBaseUrl + "artifacts/tests/devops.tests.ps1") -OutFile $Env:ArcBoxTestsDir\devops.tests.ps1
}

# DataOps
Expand All @@ -240,6 +246,7 @@ if ($flavor -eq "DataOps") {
Invoke-WebRequest ($templateBaseUrl + "artifacts/installArcAgent.ps1") -OutFile $Env:ArcBoxDir\agentScript\installArcAgent.ps1
Invoke-WebRequest ($templateBaseUrl + "artifacts/installArcAgentSQLSP.ps1") -OutFile $Env:ArcBoxDir\agentScript\installArcAgentSQLSP.ps1
Invoke-WebRequest ($templateBaseUrl + "artifacts/testDefenderForSQL.ps1") -OutFile $Env:ArcBoxDir\testDefenderForSQL.ps1
Invoke-WebRequest ($templateBaseUrl + "artifacts/tests/dataops.tests.ps1") -OutFile $Env:ArcBoxTestsDir\dataops.tests.ps1
}

# Full
Expand Down
6 changes: 6 additions & 0 deletions azure_jumpstart_arcbox/artifacts/WinGet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ Start-Transcript -Path $logFilePath -Force -ErrorAction SilentlyContinue
Install-PSResource -Name Microsoft.WinGet.DSC -Scope AllUsers -Quiet -AcceptLicense -TrustRepository -Prerelease

# Install DSC resources required for ArcBox
Install-PSResource -Name DSCR_Font -Scope AllUsers -Quiet -AcceptLicense -TrustRepository
Install-PSResource -Name HyperVDsc -Scope AllUsers -Quiet -AcceptLicense -TrustRepository -Prerelease

# Install WinGet CLI
$null = Repair-WinGetPackageManager -AllUsers

Write-Header 'Installing WinGet packages and DSC configurations'
$winget = Join-Path -Path $env:LOCALAPPDATA -ChildPath Microsoft\WindowsApps\winget.exe

# Windows Terminal needs to be installed per user, while WinGet Configuration runs as SYSTEM. Hence, this package is installed in the logon script.
& $winget install Microsoft.WindowsTerminal --version 1.18.3181.0 -s winget

# Apply WinGet Configuration files
& $winget configure --file C:\ArcBox\DSC\common.dsc.yml --accept-configuration-agreements --disable-interactivity

switch ($env:flavor) {
Expand Down
18 changes: 7 additions & 11 deletions azure_jumpstart_arcbox/artifacts/dsc/common.dsc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,90 +6,86 @@ properties:
id: git
directives:
description: Install Git
allowPrerelease: true
settings:
id: Git.Git
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: vscode
directives:
description: Install Visual Studio Code
allowPrerelease: true
settings:
id: Microsoft.VisualStudioCode
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: AzureCLI
directives:
description: Install Azure CLI
allowPrerelease: true
settings:
id: Microsoft.AzureCLI
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: PowerShell7
directives:
description: Install PowerShell 7
allowPrerelease: true
settings:
id: Microsoft.PowerShell
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: kubectl
directives:
description: Install kubectl
allowPrerelease: true
settings:
id: Kubernetes.kubectl
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: edge
directives:
description: Install Microsoft Edge
allowPrerelease: true
settings:
id: Microsoft.Edge
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: azcopy
directives:
description: Install azcopy
allowPrerelease: true
settings:
id: Microsoft.Azure.AZCopy.10
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: DotNetSDK7
directives:
description: Install Microsoft DotNet SDK 7
allowPrerelease: true
settings:
id: Microsoft.DotNet.SDK.7
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: helm
directives:
description: Install Helm
allowPrerelease: true
settings:
id: Helm.Helm
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: Microsoft.Sysinternals.BGInfo
directives:
description: Install Sysinternals BGInfo
allowPrerelease: true
settings:
id: Microsoft.Sysinternals.BGInfo
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: OpenSSL
directives:
description: Install OpenSSL
allowPrerelease: true
settings:
id: FireDaemon.OpenSSL
source: winget
- resource: DSCR_Font/cFont
id: CascadiaMono
directives:
description: Install font CascadiaMono
settings:
FontName: Cascadia Mono
FontFile: C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.18.3181.0_x64__8wekyb3d8bbwe\CascadiaMono.ttf
- resource: PSDscResources/WindowsFeature
id: Hyper-V
directives:
Expand Down
6 changes: 0 additions & 6 deletions azure_jumpstart_arcbox/artifacts/dsc/dataops.dsc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,41 @@ properties:
id: kubectl
directives:
description: Install kubectl
allowPrerelease: true
settings:
id: Kubernetes.kubectl
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: kubectx
directives:
description: Install kubectx
allowPrerelease: true
settings:
id: ahmetb.kubectx
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: DotNetSDK7
directives:
description: Install Microsoft DotNet SDK 7
allowPrerelease: true
settings:
id: Microsoft.DotNet.SDK.7
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: SQLServerManagementStudio
directives:
description: Install Microsoft SQL Server Management Studio
allowPrerelease: true
settings:
id: Microsoft.SQLServerManagementStudio
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: Microsoft.Azure.DataCLI
directives:
description: Install Microsoft Azure Data CLI
allowPrerelease: true
settings:
id: Microsoft.Azure.DataCLI
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: Microsoft.AzureDataStudio
directives:
description: Install Microsoft Azure Data Studio
allowPrerelease: true
settings:
id: Microsoft.AzureDataStudio
source: winget
Expand Down
4 changes: 0 additions & 4 deletions azure_jumpstart_arcbox/artifacts/dsc/devops.dsc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,27 @@ properties:
id: kubectl
directives:
description: Install kubectl
allowPrerelease: true
settings:
id: Kubernetes.kubectl
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: kubectx
directives:
description: Install kubectx
allowPrerelease: true
settings:
id: ahmetb.kubectx
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: DotNetSDK7
directives:
description: Install Microsoft DotNet SDK 7
allowPrerelease: true
settings:
id: Microsoft.DotNet.SDK.7
source: winget
- resource: Microsoft.WinGet.DSC/WinGetPackage
id: helm
directives:
description: Install Helm
allowPrerelease: true
settings:
id: Helm.Helm
source: winget
Expand Down
1 change: 0 additions & 1 deletion azure_jumpstart_arcbox/artifacts/dsc/itpro.dsc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ properties:
id: terraform
directives:
description: Install Terraform
allowPrerelease: true
settings:
id: Hashicorp.Terraform
source: winget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Azure.Arc.Jumpstart.Common.psm1'

# Version number of this module.
ModuleVersion = '0.0.1'
ModuleVersion = '0.0.4'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -69,7 +69,7 @@ Description = 'Common functions for Azure Arc Jumpstart'
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Set-JSDesktopBackground'
FunctionsToExport = 'Set-JSDesktopBackground','Convert-JSImageToBitMap'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = ''
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function Convert-JSImageToBitMap {
param (
$SourceFilePath,
$DestinationFilePath
)
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$file = Get-Item $SourceFilePath
$convertfile = new-object System.Drawing.Bitmap($file.Fullname)
$convertfile.Save($DestinationFilePath, "bmp")
}
Binary file not shown.
Loading