mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-09-04 03:05:32 +00:00
2dff02f2bd
PveNetwork already deserialised bridge_vlan_aware as BridgeVlanAware, so a VLAN-aware bridge could be read back but never created or changed. Both write paths now take a -BridgeVlanAware switch. Clearing the flag does not use bridge_vlan_aware=0. PVE merges the supplied keys onto the stored stanza and accepts that 0 without acting on it, so the obvious form is a silent no-op: an integration run against PVE 9 issued it and Get-PveNetwork still reported 1. The endpoint's delete list is what actually removes the key. The API schema advertises a plain boolean and gives no hint of this, which is why the behaviour is pinned by an integration test rather than inferred. Set-PveNetwork guards the switch on BoundParameters so an update that omits it leaves the flag alone; the create path follows the existing -Autostart form. Only bridge_vlan_aware is added. bridge_vids is an independent parameter that PVE defaults to 2-4094, and the issue asks only for the flag. Coverage: the integration suite pins create, disable, re-enable, and that an unrelated Set leaves the flag alone -- that last one kills a mutant that drops the BoundParameters guard, which every other test survives. A model test pins the read path the assertions depend on. The Pester unit tests assert only parameter metadata; the defect is server-side, so nothing offline can catch it. Closes #92
276 lines
9.8 KiB
PowerShell
276 lines
9.8 KiB
PowerShell
#Requires -Module Pester
|
|
<#
|
|
.SYNOPSIS
|
|
Pester 5 tests for network cmdlets:
|
|
Get-PveNetwork, New-PveNetwork, Set-PveNetwork,
|
|
Remove-PveNetwork, Invoke-PveNetworkApply.
|
|
|
|
All tests are fully offline — no live Proxmox VE target is required.
|
|
If a cmdlet is not yet compiled the test is marked Skipped.
|
|
#>
|
|
|
|
BeforeAll {
|
|
. $PSScriptRoot/../_TestHelper.ps1
|
|
|
|
$script:Availability = @{}
|
|
foreach ($name in @('Get-PveNetwork', 'New-PveNetwork', 'Set-PveNetwork',
|
|
'Remove-PveNetwork', 'Invoke-PveNetworkApply')) {
|
|
$script:Availability[$name] = $null -ne (Get-Command $name -ErrorAction SilentlyContinue)
|
|
}
|
|
|
|
function Skip-IfMissing([string]$Name) {
|
|
if (-not $script:Availability[$Name]) {
|
|
Set-ItResult -Skipped -Because "$Name is not yet implemented in this build"
|
|
}
|
|
}
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Manifest contract
|
|
# ---------------------------------------------------------------------------
|
|
Describe 'Network cmdlets — manifest declarations' {
|
|
BeforeAll {
|
|
$manifestPath = Join-Path (Get-Module PSProxmoxVE).ModuleBase 'PSProxmoxVE.psd1'
|
|
$script:Manifest = if (Test-Path $manifestPath) { Import-PowerShellDataFile $manifestPath } else { $null }
|
|
}
|
|
|
|
It "<cmdName> should be declared in CmdletsToExport" -TestCases @(
|
|
@{ cmdName = 'Get-PveNetwork' }
|
|
@{ cmdName = 'New-PveNetwork' }
|
|
@{ cmdName = 'Set-PveNetwork' }
|
|
@{ cmdName = 'Remove-PveNetwork' }
|
|
@{ cmdName = 'Invoke-PveNetworkApply' }
|
|
) {
|
|
if ($null -eq $script:Manifest) { Set-ItResult -Skipped -Because 'Manifest not found'; return }
|
|
$script:Manifest.CmdletsToExport | Should -Contain $cmdName
|
|
}
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Get-PveNetwork
|
|
# ---------------------------------------------------------------------------
|
|
Describe 'Get-PveNetwork' {
|
|
|
|
BeforeAll { $script:Cmd = Get-Command 'Get-PveNetwork' -ErrorAction SilentlyContinue }
|
|
|
|
Context 'Command existence' {
|
|
It 'Should be available after module import' {
|
|
Skip-IfMissing 'Get-PveNetwork'
|
|
$script:Cmd | Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Should be a CmdletInfo (binary cmdlet)' {
|
|
Skip-IfMissing 'Get-PveNetwork'
|
|
$script:Cmd.CommandType | Should -Be 'Cmdlet'
|
|
}
|
|
}
|
|
|
|
Context 'Parameter metadata' {
|
|
It 'Should have Node parameter (Mandatory — network is always node-specific)' {
|
|
Skip-IfMissing 'Get-PveNetwork'
|
|
$script:Cmd.Parameters.ContainsKey('Node') | Should -BeTrue
|
|
}
|
|
|
|
It 'Should have Iface parameter (optional filter)' {
|
|
Skip-IfMissing 'Get-PveNetwork'
|
|
$script:Cmd.Parameters.ContainsKey('Iface') | Should -BeTrue
|
|
}
|
|
|
|
It 'Should have Type parameter (optional filter by interface type)' {
|
|
Skip-IfMissing 'Get-PveNetwork'
|
|
$script:Cmd.Parameters.ContainsKey('Type') | Should -BeTrue
|
|
}
|
|
|
|
It 'Should have Session parameter' {
|
|
Skip-IfMissing 'Get-PveNetwork'
|
|
$script:Cmd.Parameters.ContainsKey('Session') | Should -BeTrue
|
|
}
|
|
}
|
|
|
|
Context 'Without active session' {
|
|
It 'Should throw when no session is active' {
|
|
Skip-IfMissing 'Get-PveNetwork'
|
|
{ Get-PveNetwork -Node 'pve-node1' -ErrorAction Stop } |
|
|
Should -Throw '*No active Proxmox VE session*'
|
|
}
|
|
}
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# New-PveNetwork
|
|
# ---------------------------------------------------------------------------
|
|
Describe 'New-PveNetwork' {
|
|
|
|
BeforeAll { $script:Cmd = Get-Command 'New-PveNetwork' -ErrorAction SilentlyContinue }
|
|
|
|
Context 'Command existence' {
|
|
It 'Should be available after module import' {
|
|
Skip-IfMissing 'New-PveNetwork'
|
|
$script:Cmd | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
|
|
Context 'ShouldProcess support' {
|
|
It 'Should support WhatIf' {
|
|
Skip-IfMissing 'New-PveNetwork'
|
|
$script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
|
|
}
|
|
}
|
|
|
|
Context 'VLAN-aware bridge' {
|
|
It 'Should expose BridgeVlanAware as a switch' {
|
|
Skip-IfMissing 'New-PveNetwork'
|
|
$script:Cmd.Parameters.ContainsKey('BridgeVlanAware') | Should -BeTrue
|
|
$script:Cmd.Parameters['BridgeVlanAware'].ParameterType |
|
|
Should -Be ([System.Management.Automation.SwitchParameter])
|
|
}
|
|
}
|
|
|
|
Context 'Required parameters' {
|
|
It 'Node should be Mandatory' {
|
|
Skip-IfMissing 'New-PveNetwork'
|
|
$isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Iface should be Mandatory' {
|
|
Skip-IfMissing 'New-PveNetwork'
|
|
$isMandatory = $script:Cmd.Parameters['Iface'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Type should be Mandatory' {
|
|
Skip-IfMissing 'New-PveNetwork'
|
|
$isMandatory = $script:Cmd.Parameters['Type'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Set-PveNetwork
|
|
# ---------------------------------------------------------------------------
|
|
Describe 'Set-PveNetwork' {
|
|
|
|
BeforeAll { $script:Cmd = Get-Command 'Set-PveNetwork' -ErrorAction SilentlyContinue }
|
|
|
|
Context 'Command existence' {
|
|
It 'Should be available after module import' {
|
|
Skip-IfMissing 'Set-PveNetwork'
|
|
$script:Cmd | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
|
|
Context 'ShouldProcess support' {
|
|
It 'Should support WhatIf' {
|
|
Skip-IfMissing 'Set-PveNetwork'
|
|
$script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
|
|
}
|
|
}
|
|
|
|
Context 'VLAN-aware bridge' {
|
|
It 'Should expose BridgeVlanAware as a switch' {
|
|
Skip-IfMissing 'Set-PveNetwork'
|
|
$script:Cmd.Parameters.ContainsKey('BridgeVlanAware') | Should -BeTrue
|
|
$script:Cmd.Parameters['BridgeVlanAware'].ParameterType |
|
|
Should -Be ([System.Management.Automation.SwitchParameter])
|
|
}
|
|
}
|
|
|
|
Context 'Required parameters' {
|
|
It 'Node should be Mandatory' {
|
|
Skip-IfMissing 'Set-PveNetwork'
|
|
$isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Iface should be Mandatory' {
|
|
Skip-IfMissing 'Set-PveNetwork'
|
|
$isMandatory = $script:Cmd.Parameters['Iface'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Remove-PveNetwork
|
|
# ---------------------------------------------------------------------------
|
|
Describe 'Remove-PveNetwork' {
|
|
|
|
BeforeAll { $script:Cmd = Get-Command 'Remove-PveNetwork' -ErrorAction SilentlyContinue }
|
|
|
|
Context 'Command existence' {
|
|
It 'Should be available after module import' {
|
|
Skip-IfMissing 'Remove-PveNetwork'
|
|
$script:Cmd | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
|
|
Context 'ShouldProcess / ConfirmImpact' {
|
|
It 'Should support WhatIf' {
|
|
Skip-IfMissing 'Remove-PveNetwork'
|
|
$script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
|
|
}
|
|
|
|
It 'Should declare ConfirmImpact High' {
|
|
Skip-IfMissing 'Remove-PveNetwork'
|
|
$attr = $script:Cmd.ImplementingType.GetCustomAttributes(
|
|
[System.Management.Automation.CmdletAttribute], $false) |
|
|
Select-Object -First 1
|
|
$attr.ConfirmImpact | Should -Be ([System.Management.Automation.ConfirmImpact]::High)
|
|
}
|
|
}
|
|
|
|
Context 'Required parameters' {
|
|
It 'Node should be Mandatory' {
|
|
Skip-IfMissing 'Remove-PveNetwork'
|
|
$isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
|
|
It 'Iface should be Mandatory' {
|
|
Skip-IfMissing 'Remove-PveNetwork'
|
|
$isMandatory = $script:Cmd.Parameters['Iface'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Invoke-PveNetworkApply
|
|
# ---------------------------------------------------------------------------
|
|
Describe 'Invoke-PveNetworkApply' {
|
|
|
|
BeforeAll { $script:Cmd = Get-Command 'Invoke-PveNetworkApply' -ErrorAction SilentlyContinue }
|
|
|
|
Context 'Command existence' {
|
|
It 'Should be available after module import' {
|
|
Skip-IfMissing 'Invoke-PveNetworkApply'
|
|
$script:Cmd | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
|
|
Context 'ShouldProcess support' {
|
|
It 'Should support WhatIf' {
|
|
Skip-IfMissing 'Invoke-PveNetworkApply'
|
|
$script:Cmd.Parameters.ContainsKey('WhatIf') | Should -BeTrue
|
|
}
|
|
}
|
|
|
|
Context 'Required parameters' {
|
|
It 'Node should be Mandatory' {
|
|
Skip-IfMissing 'Invoke-PveNetworkApply'
|
|
$isMandatory = $script:Cmd.Parameters['Node'].ParameterSets.Values |
|
|
Where-Object { $_.IsMandatory }
|
|
$isMandatory | Should -Not -BeNullOrEmpty
|
|
}
|
|
}
|
|
}
|