From c268f57fd64e009694b6c91561b51cd6e5f9b360 Mon Sep 17 00:00:00 2001 From: staley1975 Date: Sat, 18 Nov 2023 09:28:46 -0600 Subject: [PATCH] Convert snmp params to uppercase. Added tests --- PowerArubaCP/Public/NetworkDevice.ps1 | 4 +- Tests/integration/NetworkDevice.Tests.ps1 | 54 +++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/PowerArubaCP/Public/NetworkDevice.ps1 b/PowerArubaCP/Public/NetworkDevice.ps1 index d527aab..8b96cfa 100644 --- a/PowerArubaCP/Public/NetworkDevice.ps1 +++ b/PowerArubaCP/Public/NetworkDevice.ps1 @@ -140,7 +140,7 @@ function Add-ArubaCPNetworkDevice { throw "If snmp_version is specified, community_string is mandatory." } $snmp_read = @{ - snmp_version = $snmp_version + snmp_version = $snmp_version.ToUpper() community_string = $community_string zone_name = "default" } @@ -385,7 +385,7 @@ function Set-ArubaCPNetworkDevice { throw "If snmp_version is specified, community_string is mandatory." } $snmp_read = @{ - snmp_version = $snmp_version + snmp_version = $snmp_version.ToUpper() community_string = $community_string zone_name = "default" } diff --git a/Tests/integration/NetworkDevice.Tests.ps1 b/Tests/integration/NetworkDevice.Tests.ps1 index cdddd3f..37cc46b 100644 --- a/Tests/integration/NetworkDevice.Tests.ps1 +++ b/Tests/integration/NetworkDevice.Tests.ps1 @@ -403,6 +403,60 @@ Describe "Remove Network Device" { } +Describe "Add Network Device" { + + It "Add Network Device with snmp v2c" { + Add-ArubaCPNetworkDevice -name pester_SW6 -ip_address 192.0.2.6 -radius_secret MySecurePassword -vendor Cisco -snmp_version v2c -community_string myString + $nad = Get-ArubaCPNetworkDevice -name pester_SW6 + $nad.name | Should -Be "pester_SW6" + $nad.ip_address | Should -Be "192.0.2.6" + $nad.vendor_name | Should -Be "Cisco" + $nad.snmp_read.snmp_version | Should -Be "v2c" + $nad.snmp_read.zone_name | Should -Be "default" + # community_string is always empty + } + + It "Add Network Device with snmp v1" { + Add-ArubaCPNetworkDevice -name pester_SW6 -ip_address 192.0.2.6 -radius_secret MySecurePassword -vendor Cisco -snmp_version v1 -community_string myString + $nad = Get-ArubaCPNetworkDevice -name pester_SW6 + $nad.name | Should -Be "pester_SW6" + $nad.ip_address | Should -Be "192.0.2.6" + $nad.vendor_name | Should -Be "Cisco" + $nad.snmp_read.snmp_version | Should -Be "v1" + $nad.snmp_read.zone_name | Should -Be "default" + # community_string is always empty + } + + It "Add Network Device with snmp v2c then change it to v1" { + Add-ArubaCPNetworkDevice -name pester_SW6 -ip_address 192.0.2.6 -radius_secret MySecurePassword -vendor Cisco -snmp_version v2c -community_string myString + Get-ArubaCPNetworkDevice -name pester_SW6 | Set-ArubaCPNetworkDevice -snmp_version v1 -community_string myString + $nad = Get-ArubaCPNetworkDevice -name pester_SW6 + $nad.name | Should -Be "pester_SW6" + $nad.ip_address | Should -Be "192.0.2.6" + $nad.vendor_name | Should -Be "Cisco" + $nad.snmp_read.snmp_version | Should -Be "v1" + $nad.snmp_read.zone_name | Should -Be "default" + # community_string is always empty + } + + It "Add Network Device with snmp v1 then change it to v2c" { + Add-ArubaCPNetworkDevice -name pester_SW6 -ip_address 192.0.2.6 -radius_secret MySecurePassword -vendor Cisco -snmp_version v1 -community_string myString + Get-ArubaCPNetworkDevice -name pester_SW6 | Set-ArubaCPNetworkDevice -snmp_version v2c -community_string myString + $nad = Get-ArubaCPNetworkDevice -name pester_SW6 + $nad.name | Should -Be "pester_SW6" + $nad.ip_address | Should -Be "192.0.2.6" + $nad.vendor_name | Should -Be "Cisco" + $nad.snmp_read.snmp_version | Should -Be "v2c" + $nad.snmp_read.zone_name | Should -Be "default" + # community_string is always empty + } + + AfterEach { + Get-ArubaCPNetworkDevice -name pester_SW6 | Remove-ArubaCPNetworkDevice -confirm:$false + } + +} + AfterAll { Disconnect-ArubaCP -confirm:$false } \ No newline at end of file