summaryrefslogtreecommitdiff
path: root/lib/oxidized/input
diff options
context:
space:
mode:
authorElvin Efendi <elvin.efendiyev@gmail.com>2015-11-13 11:19:20 -0500
committerElvin Efendi <elvin.efendiyev@gmail.com>2015-11-13 11:19:20 -0500
commit5a2364e50620b825d5325bfbbc5d0f3d8578e25f (patch)
tree0e985374cc7b4bd8111c012072c39218335881ef /lib/oxidized/input
parent1400b842f6dc61e662ce15f72f578a55126ffc06 (diff)
parentf2da63369fcb754e3715091cc4fd2f93db42106e (diff)
Merge pull request #2 from Shopify/testing-refactoring
Testing refactoring
Diffstat (limited to 'lib/oxidized/input')
-rw-r--r--lib/oxidized/input/cli.rb3
-rw-r--r--lib/oxidized/input/ftp.rb4
-rw-r--r--lib/oxidized/input/ssh.rb18
-rw-r--r--lib/oxidized/input/telnet.rb4
4 files changed, 15 insertions, 14 deletions
diff --git a/lib/oxidized/input/cli.rb b/lib/oxidized/input/cli.rb
index 22d188c..731b459 100644
--- a/lib/oxidized/input/cli.rb
+++ b/lib/oxidized/input/cli.rb
@@ -1,6 +1,7 @@
module Oxidized
class Input
module CLI
+ attr_reader :node
def initialize
@post_login = []
@@ -10,7 +11,7 @@ module Oxidized
def get
connect_cli
- d = @node.model.get
+ d = node.model.get
disconnect
d
end
diff --git a/lib/oxidized/input/ftp.rb b/lib/oxidized/input/ftp.rb
index 70db60c..a3d7ac8 100644
--- a/lib/oxidized/input/ftp.rb
+++ b/lib/oxidized/input/ftp.rb
@@ -18,7 +18,7 @@ module Oxidized
def connect node
@node = node
@node.model.cfg['ftp'].each { |cb| instance_exec(&cb) }
- @log = File.open(Oxidized::Config::Crash + "-#{@node.ip}-ftp", 'w') if CFG.input.debug?
+ @log = File.open(Oxidized::Config::Crash + "-#{@node.ip}-ftp", 'w') if Oxidized.config.input.debug?
@ftp = Net::FTP.new @node.ip, @node.auth[:username], @node.auth[:password]
connected?
end
@@ -47,7 +47,7 @@ module Oxidized
@ftp.close
#rescue Errno::ECONNRESET, IOError
ensure
- @log.close if CFG.input.debug?
+ @log.close if Oxidized.config.input.debug?
end
end
diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb
index 21fb02c..e45adb6 100644
--- a/lib/oxidized/input/ssh.rb
+++ b/lib/oxidized/input/ssh.rb
@@ -19,11 +19,11 @@ module Oxidized
@node = node
@output = ''
@node.model.cfg['ssh'].each { |cb| instance_exec(&cb) }
- secure = CFG.input.ssh.secure
- @log = File.open(Oxidized::Config::Crash + "-#{@node.ip}-ssh", 'w') if CFG.input.debug?
+ secure = Oxidized.config.input.ssh.secure
+ @log = File.open(Oxidized::Config::Crash + "-#{@node.ip}-ssh", 'w') if Oxidized.config.input.debug?
port = vars(:ssh_port) || 22
@ssh = Net::SSH.start @node.ip, @node.auth[:username], :port => port.to_i,
- :password => @node.auth[:password], :timeout => CFG.timeout,
+ :password => @node.auth[:password], :timeout => Oxidized.config.timeout,
:paranoid => secure,
:auth_methods => %w(none publickey password keyboard-interactive),
:number_of_password_prompts => 0
@@ -42,8 +42,8 @@ module Oxidized
@ssh and not @ssh.closed?
end
- def cmd cmd, expect=@node.prompt
- Log.debug "SSH: #{cmd} @ #{@node.name}"
+ def cmd cmd, expect=node.prompt
+ Log.debug "SSH: #{cmd} @ #{node.name}"
if @exec
@ssh.exec! cmd
else
@@ -64,17 +64,17 @@ module Oxidized
def disconnect
disconnect_cli
# if disconnect does not disconnect us, give up after timeout
- Timeout::timeout(CFG.timeout) { @ssh.loop }
+ Timeout::timeout(Oxidized.config.timeout) { @ssh.loop }
rescue Errno::ECONNRESET, Net::SSH::Disconnect, IOError
ensure
- @log.close if CFG.input.debug?
+ @log.close if Oxidized.config.input.debug?
(@ssh.close rescue true) unless @ssh.closed?
end
def shell_open ssh
@ses = ssh.open_channel do |ch|
ch.on_data do |_ch, data|
- @log.print data if CFG.input.debug?
+ @log.print data if Oxidized.config.input.debug?
@output << data
@output = @node.model.expects @output
end
@@ -109,7 +109,7 @@ module Oxidized
end
def expect regexp
- Timeout::timeout(CFG.timeout) do
+ Timeout::timeout(Oxidized.config.timeout) do
@ssh.loop(0.1) do
sleep 0.1
not @output.match regexp
diff --git a/lib/oxidized/input/telnet.rb b/lib/oxidized/input/telnet.rb
index bf0140c..b92d703 100644
--- a/lib/oxidized/input/telnet.rb
+++ b/lib/oxidized/input/telnet.rb
@@ -8,7 +8,7 @@ module Oxidized
def connect node
@node = node
- @timeout = CFG.timeout
+ @timeout = Oxidized.config.timeout
@node.model.cfg['telnet'].each { |cb| instance_exec(&cb) }
port = vars(:telnet_port) || 23
@@ -16,7 +16,7 @@ module Oxidized
'Port' => port.to_i,
'Timeout' => @timeout,
'Model' => @node.model }
- opt['Output_log'] = Oxidized::Config::Crash + "-#{@node.ip}-telnet" if CFG.input.debug?
+ opt['Output_log'] = Oxidized::Config::Crash + "-#{@node.ip}-telnet" if Oxidized.config.input.debug?
@telnet = Net::Telnet.new opt
if @node.auth[:username] and @node.auth[:username].length > 0