fix: Set-PveHaRule requires mandatory Type parameter

PVE 9 API requires 'type' on PUT /cluster/ha/rules/{rule} even for
updates. Added mandatory Type parameter with ValidateSet for
node-affinity and resource-affinity.

Updated integration test and Pester unit tests to pass -Type.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Clint Branham
2026-03-25 17:52:23 -05:00
parent d43387806e
commit 514ce3fc1b
3 changed files with 17 additions and 3 deletions
@@ -19,6 +19,11 @@ namespace PSProxmoxVE.Cmdlets.HA
HelpMessage = "HA rule ID.")]
public string Rule { get; set; } = string.Empty;
/// <summary>Rule type (required by PVE API on update).</summary>
[Parameter(Mandatory = true, Position = 1, HelpMessage = "HA rule type: node-affinity or resource-affinity.")]
[ValidateSet("node-affinity", "resource-affinity")]
public string Type { get; set; } = string.Empty;
/// <summary>Rule state.</summary>
[Parameter(Mandatory = false, HelpMessage = "Rule state: enabled or disabled.")]
[ValidateSet("enabled", "disabled")]
@@ -42,7 +47,7 @@ namespace PSProxmoxVE.Cmdlets.HA
var service = new HaService();
var data = new Dictionary<string, string>();
var data = new Dictionary<string, string> { ["type"] = Type };
if (State != null) data["state"] = State;
if (Comment != null) data["comment"] = Comment;
if (Properties != null)
+10 -1
View File
@@ -736,6 +736,15 @@ Describe 'Set-PveHaRule' -Tag 'Unit' {
$isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory }
$isMandatory | Should -Not -BeNullOrEmpty
}
It 'Should have mandatory Type parameter with ValidateSet' {
Skip-IfMissing 'Set-PveHaRule'
$p = $script:Cmd.Parameters['Type']
$p | Should -Not -BeNullOrEmpty
$isMandatory = $p.ParameterSets.Values | Where-Object { $_.IsMandatory }
$isMandatory | Should -Not -BeNullOrEmpty
$vsAttr = $p.Attributes | Where-Object { $_ -is [System.Management.Automation.ValidateSetAttribute] }
$vsAttr | Should -Not -BeNullOrEmpty
}
It 'Should have optional State parameter with ValidateSet' {
Skip-IfMissing 'Set-PveHaRule'
$p = $script:Cmd.Parameters['State']
@@ -762,7 +771,7 @@ Describe 'Set-PveHaRule' -Tag 'Unit' {
Context 'Without active session' {
It 'Should throw when no session is active' {
Skip-IfMissing 'Set-PveHaRule'
{ Set-PveHaRule -Rule 'rule1' -ErrorAction Stop -Confirm:$false } |
{ Set-PveHaRule -Rule 'rule1' -Type 'node-affinity' -ErrorAction Stop -Confirm:$false } |
Should -Throw '*No active Proxmox VE session*'
}
}
@@ -360,7 +360,7 @@ Describe 'Cluster Config & HA Lifecycle — Integration' -Tag 'Integration' {
return
}
{ Set-PveHaRule -Rule 'pester-rule-1' `
{ Set-PveHaRule -Rule 'pester-rule-1' -Type 'node-affinity' `
-Comment 'Updated by Pester' `
-Confirm:$false `
-ErrorAction Stop } | Should -Not -Throw