From e291e0b773a5112b85d7f50b5253ef2baf0e61ec Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 4 Sep 2013 08:15:42 +0100 Subject: [PATCH] Fixes for poor entity-mib implementations. Squashed commit of the following: commit aec8628f15801c42374414b13597f2d66ce98748 Author: Eric A. Miller Date: Tue Sep 3 19:31:05 2013 -0400 another try at fixing duplicate pos commit 7ab021a6adecdf32056ba96c3e1388b639e7cf2b Author: Eric A. Miller Date: Mon Sep 2 22:38:05 2013 -0400 alternate fix for dupe pos commit cae64c8fd882fd091446b93a6c8dc7163e9c0e91 Author: Oliver Gorwits Date: Mon Sep 2 22:05:45 2013 +0100 alternative building of modules tree using splice for dupe pos commit 980e45211b062c8717ff57625ad4d7b80f942886 Author: Oliver Gorwits Date: Mon Sep 2 22:05:19 2013 +0100 fix for updating pos "column" value --- Netdisco/lib/App/Netdisco/Util/Web.pm | 19 +++++++------------ .../App/Netdisco/Web/Plugin/Device/Modules.pm | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Util/Web.pm b/Netdisco/lib/App/Netdisco/Util/Web.pm index d5ee3085..11f88cf0 100644 --- a/Netdisco/lib/App/Netdisco/Util/Web.pm +++ b/Netdisco/lib/App/Netdisco/Util/Web.pm @@ -125,29 +125,24 @@ input arg is module list. sub sort_modules { my $input = shift; - my %modules; foreach my $module (@$input) { $modules{$module->index}{module} = $module; if ($module->parent) { - # Next wrong: some things have weird pos' + # Example # index | description | type | parent | class | pos #-------+----------------------------------------+---------------------+--------+---------+----- # 1 | Cisco Aironet 1200 Series Access Point | cevChassisAIRAP1210 | 0 | chassis | -1 # 3 | PowerPC405GP Ethernet | cevPortFEIP | 1 | port | -1 # 2 | 802.11G Radio | cevPortUnknown | 1 | port | 0 - $module->pos = 0 if ($module->pos < 0); - # this is wrong. a given parent can - # have multiple items at a single pos value. - # (HP may have gotten this wrong, but that's - # reality...) - if ($module->pos) { - ${$modules{$module->parent}{children}{$module->class}}[$module->pos] = $module->index; - } else { - push(@{$modules{$module->parent}{children}{$module->class}}, $module->index); - } + # Some devices do not implement correctly, so given parent + # can have multiple items within the same class at a single pos + # value. However, the database results are sorted by 1) parent + # 2) class 3) pos 4) index so we should just be able to push onto + # the array and ordering be preserved. + push(@{$modules{$module->parent}{children}{$module->class}}, $module->index); } else { push(@{$modules{root}}, $module->index); } diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Modules.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Modules.pm index df1bf61f..9917d59f 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Modules.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Device/Modules.pm @@ -15,7 +15,7 @@ ajax '/ajax/content/device/modules' => require_login sub { my $device = schema('netdisco')->resultset('Device') ->search_for_device($q) or send_error('Bad device', 400); - my @set = $device->modules->search({}, {order_by => { -asc => [qw/parent pos index/] }}); + my @set = $device->modules->search({}, {order_by => { -asc => [qw/parent class pos index/] }}); # sort modules (empty set would be a 'no records' msg) my $results = &App::Netdisco::Util::Web::sort_modules( \@set );