Implemented new runner & dealt with issues regarding facts resource
This commit is contained in:
parent
08e132a4d2
commit
fc56af0621
@ -22,6 +22,11 @@ module RubyQA
|
||||
@gather_command = ""
|
||||
end
|
||||
|
||||
def [](key)
|
||||
@data[key]
|
||||
end
|
||||
|
||||
|
||||
# TODO: Create validate_host method to replace REQUIREMENTS for a bit more flexiblity on
|
||||
# determining if a host is valid for this resource to be added to it.
|
||||
|
||||
@ -57,16 +62,26 @@ module RubyQA
|
||||
## Gathers the facts from the remote machine via the facter utility
|
||||
class Facts < Resource
|
||||
require 'json'
|
||||
|
||||
REQUIREMENTS = {}
|
||||
def initialize (host)
|
||||
super host
|
||||
@name = 'facts'
|
||||
@gather_command = "facter -j"
|
||||
@gather_command = "sudo puppet facts"
|
||||
end
|
||||
|
||||
def parse (output)
|
||||
@data = JSON.load(output)
|
||||
|
||||
# TODO: Find a better way of doing this.
|
||||
## Only reason this exists is becuase when doing the command over telnet some extra special characters get added
|
||||
## to the beginning of the opening bracket. Only quick way I found to remove it is to just split, reasssign
|
||||
## & join it back into a string.
|
||||
if @host.client.is_a? Telnet_Runner
|
||||
output_lines = output.split(/\n/)
|
||||
output_lines[0]='{'
|
||||
output = output_lines.join("\n")
|
||||
end
|
||||
|
||||
@data = JSON.parse(output)
|
||||
end
|
||||
end
|
||||
|
||||
@ -91,5 +106,4 @@ module RubyQA
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -39,7 +39,7 @@ module RubyQA
|
||||
if @data[:password].empty?
|
||||
raise "Password was not provided for host"
|
||||
end
|
||||
new_command = <<EOT
|
||||
sudo_command = <<EOT
|
||||
if [[ $UID -ne 0 ]]; then
|
||||
command_file=/tmp/sudo-command-$(date +%Y-%m-%d_%H-%M)
|
||||
cat >$command_file <<EOF
|
||||
@ -49,13 +49,15 @@ echo "#{@data[:password]}" | sudo -S /bin/bash $command_file 2>/dev/null
|
||||
rm $command_file
|
||||
else
|
||||
#{command}
|
||||
fi
|
||||
fi > sudo-output
|
||||
EOT
|
||||
run_command(new_command)
|
||||
run_command(sudo_command)
|
||||
run_command('cat sudo-output')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
require 'net/ssh'
|
||||
class SSH_Runner < CommandRunner
|
||||
def initialize_runner
|
||||
begin
|
||||
@ -73,6 +75,44 @@ EOT
|
||||
def run_command(command)
|
||||
@client.exec!(command).strip
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
class Telnet_Runner < CommandRunner
|
||||
require 'net/ssh/telnet'
|
||||
LOGIN_HANDLER=nil
|
||||
TELNET_OPTS={
|
||||
"Timeout" => 10,
|
||||
"Prompt" => /[$:#]/
|
||||
}
|
||||
def initialize_runner
|
||||
begin
|
||||
@client = Net::SSH::Telnet.new( "Host" => @data[:ip], "Username" => @data[:user], "Password" => @data[:password])
|
||||
# Since this is telnet, it doesn't filter out command sequences, so we have to set the PS1/prompt to something
|
||||
# that is easily matched for filtering purposes
|
||||
@client.cmd({"String" => "PS1='<filter_line>'; PROMPT_COMMANDS='';", "Match" => /filter_line/})
|
||||
rescue SocketError
|
||||
raise "Failed to make ssh client for #{@data[:hostname]}"
|
||||
end
|
||||
end
|
||||
|
||||
def run_command(command)
|
||||
output = ""
|
||||
|
||||
## Doing intitial command (doesn't send white-space/newline)
|
||||
lines = Array.new
|
||||
filter_regex=/(^|#{command}|^\n$)/
|
||||
|
||||
output = @client.cmd({"String" => command, "Waittime" => 100, "Match" => /filter_line/})
|
||||
|
||||
# Have to clean output since telnet session will return all output, both stdin & stdout.
|
||||
output = output.split(/\n/).reject do |line|
|
||||
line.match?(/filter_line/) || line.match(/#{command}/)
|
||||
end.join("\n")
|
||||
|
||||
output
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
RubyQA Test Report
|
||||
|
||||
QA Date: <%= Time.now.strftime("%Y/%m/%d %l:%M:%S %Z") %>
|
||||
QA Date: <%= Time.now.strftime("%Y/%m/%d %l:%M:%S %p %Z") %>
|
||||
QA Runner: <%= ENV['USER'] %>
|
||||
QA Tests: <%= Manager.tests.count %>
|
||||
<% Manager.tests.each do |test| -%>
|
||||
@ -8,7 +8,7 @@ QA Tests: <%= Manager.tests.count %>
|
||||
<% end -%>
|
||||
QA Hosts:
|
||||
<% Manager.hosts.each do |host| -%>
|
||||
- <%= host.name %> (<%= host.data[:ip] %>)
|
||||
- <%= host.name %> (<%= host[:ip] %>)
|
||||
<% end -%>
|
||||
|
||||
###############
|
||||
|
Loading…
Reference in New Issue
Block a user