blib/lib/App/Netdisco/Worker/Plugin/Location.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 55 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package App::Netdisco::Worker::Plugin::Location;
2  
3 use Dancer ':syntax';
4 use App::Netdisco::Worker::Plugin;
5 use aliased 'App::Netdisco::Worker::Status';
6  
7 use App::Netdisco::Transport::SNMP;
8  
9 register_worker({ phase => 'check' }, sub {
10 return Status->error('Missing device (-d).')
11 unless defined shift->device;
12 return Status->done('Location is able to run');
13 });
14  
15 register_worker({ phase => 'main', driver => 'snmp' }, sub {
16 my ($job, $workerconf) = @_;
17 my ($device, $data) = map {$job->$_} qw/device extra/;
18  
19 # update pseudo devices directly in database
20 unless ($device->is_pseudo()) {
21 # snmp connect using rw community
22 my $snmp = App::Netdisco::Transport::SNMP->writer_for($device)
23 or return Status->defer("failed to connect to $device to update location");
24  
25 my $rv = $snmp->set_location($data);
26  
27 if (!defined $rv) {
28 return Status->error(
29 "failed to set location on $device: ". ($snmp->error || ''));
30 }
31  
32 # confirm the set happened
33 $snmp->clear_cache;
34 my $new_data = ($snmp->location || '');
35 if ($new_data ne $data) {
36 return Status->error("verify of location failed on $device: $new_data");
37 }
38 }
39  
40 # update netdisco DB
41 $device->update({location => $data});
42  
43 return Status->done("Updated location on $device to [$data]");
44 });
45  
46 true;