From b24da8c380d9fc1a7b6c867455bbc59f0cda604d Mon Sep 17 00:00:00 2001 From: Jeroen van Ingen Date: Mon, 8 Oct 2018 12:37:23 +0200 Subject: [PATCH] Add tests for peth_port_ifindex in Juniper.pm --- lib/SNMP/Info/Layer3/Juniper.pm | 2 +- xt/lib/Test/SNMP/Info/Layer3/Juniper.pm | 27 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/SNMP/Info/Layer3/Juniper.pm b/lib/SNMP/Info/Layer3/Juniper.pm index 8b961f62..342da78c 100644 --- a/lib/SNMP/Info/Layer3/Juniper.pm +++ b/lib/SNMP/Info/Layer3/Juniper.pm @@ -664,7 +664,7 @@ sub peth_port_ifindex { # Only the power status from the first member in a virtual chassis is reported. foreach my $i ( keys %$i_descr ) { # Juniper's port numbering is PHYS-FPC/PIC/PORT, only looking at PIC 0 - if ($i_descr->{$i} =~ m/^(fe|ge|xe|et)-([0-9]+)\/([0]+)\/([0-9]+)$/) { + if ($i_descr->{$i} =~ m/^(fe|ge|xe|et)-(\d+)\/(0)\/(\d+)$/) { # Juniper port numbering begins at 0, but for PowerEthernet it begins at 1 my $mod = $2+1; my $port = $4+1; diff --git a/xt/lib/Test/SNMP/Info/Layer3/Juniper.pm b/xt/lib/Test/SNMP/Info/Layer3/Juniper.pm index 92ab3910..4837d975 100644 --- a/xt/lib/Test/SNMP/Info/Layer3/Juniper.pm +++ b/xt/lib/Test/SNMP/Info/Layer3/Juniper.pm @@ -79,8 +79,20 @@ sub setup : Tests(setup) { '_e_contents_type' => 1, '_jnxContainersWithin' => 1, + # For PoE port mapping test + '_i_description' => 1, 'store' => { + 'peth_port_status' => {'1.1' => 'searching', '1.2' => 'otherFault', '1.3' => 'deliveringPower'}, + 'i_index' => {504 => 504, 505 => 505, 506 => 506, 507 => 507, 508 => 508, 509 => 509}, + 'i_description' => { + 504 => 'ge-0/0/0', + 505 => 'ge-0/0/0.0', + 506 => 'ge-0/0/1', + 507 => 'ge-0/0/1.0', + 508 => 'ge-0/0/2', + 509 => 'ge-0/0/2.0', + }, 'jnxExVlanPortAccessMode' => {'2.514' => 'access', '7.513' => 'trunk'}, 'jnx_v_name' => {2 => 'default', 3 => 'management'}, 'jnx_v_index' => {2 => 0, 3 => 120}, @@ -854,4 +866,19 @@ sub e_parent : Tests(3) { cmp_deeply($test->{info}->e_parent(), {}, q(No data returns empty hash)); } +sub peth_port_ifindex : Tests(3) { + my $test = shift; + + can_ok($test->{info}, 'peth_port_ifindex'); + + my $expected = {'1.1' => 504, '1.2' => 506, '1.3' => 508}; + + cmp_deeply($test->{info}->peth_port_ifindex(), + $expected, q(POE port 'ifIndex' mapping returns expected values)); + + $test->{info}->clear_cache(); + cmp_deeply($test->{info}->peth_port_ifindex(), + {}, q(No data returns empty hash)); +} + 1;