Skip to content

Commit

Permalink
catch detect failing to parse json (#243)
Browse files Browse the repository at this point in the history
* catch detect failing to parse json

This may happen if the exit code is incorrect or the results get scrambled

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>

* remove variable assignment

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
  • Loading branch information
arlimus authored and jerryaldrichiii committed Feb 5, 2018
1 parent c3c20d3 commit a26a2b9
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/train/platforms/detect/specifications/os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ def self.load
cmd = @backend.run_command('show version | json')
if cmd.exit_status == 0 && !cmd.stdout.empty?
require 'json'
eos_ver = JSON.parse(cmd.stdout)
@platform[:release] = eos_ver['version']
@platform[:arch] = eos_ver['architecture']
true
begin
eos_ver = JSON.parse(cmd.stdout)
@platform[:release] = eos_ver['version']
@platform[:arch] = eos_ver['architecture']
true
rescue JSON::ParserError
nil
end
end
}
plat.name('arista_eos_bash').title('Arista EOS Bash Shell').in_family('arista_eos')
Expand All @@ -58,10 +62,14 @@ def self.load
cmd = @backend.run_command('FastCli -p 15 -c "show version | json"')
if cmd.exit_status == 0 && !cmd.stdout.empty?
require 'json'
eos_ver = JSON.parse(cmd.stdout)
@platform[:release] = eos_ver['version']
@platform[:arch] = eos_ver['architecture']
true
begin
eos_ver = JSON.parse(cmd.stdout)
@platform[:release] = eos_ver['version']
@platform[:arch] = eos_ver['architecture']
true
rescue JSON::ParserError
nil
end
end
end
}
Expand Down

0 comments on commit a26a2b9

Please sign in to comment.