From 988b1446b0d654ce45556c003bb3a6532714d721 Mon Sep 17 00:00:00 2001 From: Clint Branham Date: Wed, 25 Mar 2026 09:23:06 -0500 Subject: [PATCH] fix: use root@pam for cluster node removal in integration tests Remove-PveClusterConfigNode requires root@pam (not API token). Fixed both the test context and AfterAll cleanup to connect with root@pam credentials before attempting node removal. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../ClusterConfig.Integration.Tests.ps1 | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/PSProxmoxVE.Tests/Integration/ClusterConfig.Integration.Tests.ps1 b/tests/PSProxmoxVE.Tests/Integration/ClusterConfig.Integration.Tests.ps1 index e086043..fa22f77 100644 --- a/tests/PSProxmoxVE.Tests/Integration/ClusterConfig.Integration.Tests.ps1 +++ b/tests/PSProxmoxVE.Tests/Integration/ClusterConfig.Integration.Tests.ps1 @@ -108,16 +108,18 @@ BeforeAll { AfterAll { # Best-effort cleanup — each step may fail if cluster state is partial - if ($script:ClusterCreated) { - # Try to discover node B name and remove it from the cluster - if ($script:NodeBName) { - try { - Write-Warning "Cleanup: removing node '$($script:NodeBName)' from cluster..." - Remove-PveClusterConfigNode -Node $script:NodeBName -Confirm:$false -ErrorAction Stop - } - catch { - Write-Warning "Cleanup: failed to remove node B from cluster: $_" - } + if ($script:ClusterCreated -and $script:NodeBName -and $script:Password) { + try { + # Reconnect as root@pam for privileged cleanup + $secPw = ConvertTo-SecureString $script:Password -AsPlainText -Force + $cred = New-Object System.Management.Automation.PSCredential('root@pam', $secPw) + Connect-PveServer -Server $script:Host_ -Port $script:Port -Credential $cred -SkipCertificateCheck + + Write-Warning "Cleanup: removing node '$($script:NodeBName)' from cluster..." + Remove-PveClusterConfigNode -Node $script:NodeBName -Confirm:$false -ErrorAction Stop + } + catch { + Write-Warning "Cleanup: failed to remove node B from cluster: $_" } } @@ -430,11 +432,13 @@ Describe 'Cluster Config & HA Lifecycle — Integration' -Tag 'Integration' { return } - # Ensure we are connected to node A + # Ensure we are connected to node A as root@pam (node removal requires it) + $secPw = ConvertTo-SecureString $script:Password -AsPlainText -Force + $cred = New-Object System.Management.Automation.PSCredential('root@pam', $secPw) Connect-PveServer ` -Server $script:Host_ ` -Port $script:Port ` - -ApiToken $script:ApiToken ` + -Credential $cred ` -SkipCertificateCheck { Remove-PveClusterConfigNode -Node $script:NodeBName -Confirm:$false -ErrorAction Stop } |