qa_robusta 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/.autotest +23 -0
  2. data/.gemtest +0 -0
  3. data/History.txt +6 -0
  4. data/Manifest.txt +101 -0
  5. data/README.txt +48 -0
  6. data/Rakefile +18 -0
  7. data/bin/qa_robusta +14 -0
  8. data/common/Rakefile +95 -0
  9. data/common/conf/monkey_patch.yaml +8 -0
  10. data/common/conf/monkey_patch.yaml.ex +10 -0
  11. data/common/lib/array.rb +9 -0
  12. data/common/lib/cache.rb +12 -0
  13. data/common/lib/constants.rb +35 -0
  14. data/common/lib/error_defns.rb +13 -0
  15. data/common/lib/format_html_tmp.html +34 -0
  16. data/common/lib/formatters.rb +18 -0
  17. data/common/lib/gem_helpers.rb +29 -0
  18. data/common/lib/gems/.svn/entries +43 -0
  19. data/common/lib/gems/cache/.svn/entries +28 -0
  20. data/common/lib/gems/doc/.svn/entries +28 -0
  21. data/common/lib/gems/gems/.svn/entries +28 -0
  22. data/common/lib/gems/installed/.svn/entries +40 -0
  23. data/common/lib/gems/installed/cache/.svn/entries +28 -0
  24. data/common/lib/gems/installed/doc/.svn/entries +28 -0
  25. data/common/lib/gems/installed/gems/.svn/entries +28 -0
  26. data/common/lib/gems/installed/specifications/.svn/entries +28 -0
  27. data/common/lib/gems/specifications/.svn/entries +28 -0
  28. data/common/lib/gen_suite_doc.rb +52 -0
  29. data/common/lib/load_test_data.rb +18 -0
  30. data/common/lib/monkey_patch.rb +149 -0
  31. data/common/lib/navigate_mech.rb +79 -0
  32. data/common/lib/update_element.rb +12 -0
  33. data/common/monkey_patches/mechanize.rb +589 -0
  34. data/common/monkey_patches/table.rb +363 -0
  35. data/common/monkey_patches/telnet.rb +420 -0
  36. data/common/monkey_patches/unit.rb +538 -0
  37. data/demo/demo_site.rb +38 -0
  38. data/demo/public/javascripts/jquery-1.6.2.min.js +18 -0
  39. data/demo/views/index.erb +35 -0
  40. data/lib/monkey_patch.rb +26 -0
  41. data/lib/qa_robusta.rb +3 -0
  42. data/mechanize_interface/conf/app.yaml +10 -0
  43. data/mechanize_interface/lib/agent.rb +18 -0
  44. data/mechanize_interface/lib/app_require.rb +19 -0
  45. data/mechanize_interface/lib/get_page.rb +20 -0
  46. data/mechanize_interface/lib/login.rb +30 -0
  47. data/mechanize_interface/lib/navigation_paths.rb +12 -0
  48. data/mechanize_interface/test/lib/mech_unit_test.rb +19 -0
  49. data/qa_observer/conf/dev_users.yaml +9 -0
  50. data/qa_observer/conf/development.yaml +3 -0
  51. data/qa_observer/conf/qa_observer_links.yaml +10 -0
  52. data/qa_observer/generators/site/site_generator.rb +61 -0
  53. data/qa_observer/generators/site/templates/base_urls.yaml.erb +6 -0
  54. data/qa_observer/generators/site/templates/create_flow.rb.erb +54 -0
  55. data/qa_observer/generators/site/templates/elements.rb.erb +61 -0
  56. data/qa_observer/generators/site/templates/html_elements.yaml +22 -0
  57. data/qa_observer/generators/site/templates/navigate.rb +32 -0
  58. data/qa_observer/generators/site/templates/reports.rb +7 -0
  59. data/qa_observer/generators/site/templates/users_list.yaml +21 -0
  60. data/qa_observer/generators/test_case/templates/test_case.rb.erb +62 -0
  61. data/qa_observer/generators/test_case/test_case_generator.rb +29 -0
  62. data/qa_observer/lib/doc.rb +103 -0
  63. data/qa_observer/lib/env_details.rb +2 -0
  64. data/qa_observer/lib/error_defns.rb +3 -0
  65. data/qa_observer/lib/form_helpers.rb +52 -0
  66. data/qa_observer/lib/reports.rb +7 -0
  67. data/qa_observer/lib/requires.rb +23 -0
  68. data/qa_observer/lib/system_test.rb +146 -0
  69. data/qa_observer/lib/test_extention.rb +29 -0
  70. data/qa_observer/lib/update_element.rb +12 -0
  71. data/qa_observer/lib/watir.rb +42 -0
  72. data/qa_observer/script/destroy +14 -0
  73. data/qa_observer/script/generate +14 -0
  74. data/qa_observer/sites/demo/conf/base_urls.yaml +6 -0
  75. data/qa_observer/sites/demo/conf/html_elements.yaml +22 -0
  76. data/qa_observer/sites/demo/conf/remote_machine.yaml +12 -0
  77. data/qa_observer/sites/demo/conf/users_list.yaml +21 -0
  78. data/qa_observer/sites/demo/elements/demo_elements.rb +9 -0
  79. data/qa_observer/sites/demo/flows/demo_flows.rb +37 -0
  80. data/qa_observer/sites/demo/helpers/.placeholder +0 -0
  81. data/qa_observer/sites/demo/lib/navigate.rb +32 -0
  82. data/qa_observer/sites/demo/lib/reports.rb +7 -0
  83. data/qa_observer/sites/demo/results/.placeholder +0 -0
  84. data/qa_observer/sites/demo/results/images/.placeholder +0 -0
  85. data/qa_observer/sites/demo/test_cases/home_page.rb +106 -0
  86. data/qa_observer/suites/demo_lg_chrome/lg.yaml +11 -0
  87. data/qa_observer/suites/demo_md_chrome/md.yaml +11 -0
  88. data/qa_observer/suites/demo_sm_chrome/sm.yaml +11 -0
  89. data/qa_observer/suites/init.rb +41 -0
  90. data/qa_observer/test_runner.rb +125 -0
  91. data/remote_unix/helpers/constants.rb +8 -0
  92. data/remote_unix/helpers/out_xforms.rb +48 -0
  93. data/remote_unix/lib/common.rb +52 -0
  94. data/remote_unix/lib/error_defn.rb +4 -0
  95. data/remote_unix/lib/general_unix.rb +308 -0
  96. data/remote_unix/lib/network_commands.rb +41 -0
  97. data/remote_unix/lib/network_info.rb +98 -0
  98. data/remote_unix/lib/postfix_commands.rb +87 -0
  99. data/remote_unix/lib/postfix_info.rb +30 -0
  100. data/remote_unix/lib/requires.rb +25 -0
  101. data/remote_unix/lib/scp.rb +22 -0
  102. data/remote_unix/lib/ssh.rb +46 -0
  103. data/test/test_qa_robusta.rb +8 -0
  104. metadata +219 -0
@@ -0,0 +1,125 @@
1
+ base = File.expand_path(File.dirname(__FILE__))
2
+ require "#{base}/../common/lib/gem_helpers"
3
+ GemHelpers.update_gem_path "#{base}/../common/gems/installed"
4
+ require 'platform_helpers'
5
+ require 'getoptions'
6
+ require 'hpricot'
7
+ require "#{base}/lib/doc"
8
+
9
+ def usage(msg=nil)
10
+ usage = <<-EOF
11
+ Usage: test_runner.rb --site=<site_name>
12
+ --file_name=<ruby test case file>
13
+ --execute_methods=all | list,of,methods,to,execute
14
+ --browser=<ie|firefox>
15
+ --environment=<name such as production|test|dev>
16
+ --format=junit --> this is an optional and used for CI systems
17
+
18
+ where --site_name base directory name to a site defined under qa_observer/sites
19
+
20
+
21
+ EOF
22
+ puts usage
23
+ end
24
+
25
+ opt = GetOptions.new(%w(help site=s file_name=s execute_methods=s browser:s environment=s format:s proxy:s))
26
+
27
+ supported_browsers = ['ie', 'firefox', 'chrome']
28
+
29
+ unless opt.site && opt.execute_methods && opt.file_name &&
30
+ opt.environment
31
+ if opt.browser
32
+ supported_browsers.include?(opt.browser)
33
+ raise ArgumentError, usage
34
+ end
35
+ raise ArgumentError, usage
36
+ else
37
+
38
+ if opt.proxy
39
+ tmp_split = opt.proxy.split(':')
40
+ if tmp_split.length != 2
41
+ raise ArgumentError, '--proxy option requires format host:port'
42
+ end
43
+
44
+ PROXY = { :enabled => true,
45
+ :host => tmp_split[0],
46
+ :port => tmp_split[1] }
47
+ else
48
+ PROXY = { :enabled => false,
49
+ :host => nil,
50
+ :port => nil }
51
+
52
+ end
53
+
54
+ base = File.expand_path(File.dirname(__FILE__))
55
+
56
+ $qa_observer_client = base
57
+ $run_on_browser = opt.browser
58
+ $environment = opt.environment.to_sym
59
+ $standalone = false
60
+ TEST_CASE_DIR = "#{base}/sites/#{opt.site}/test_cases"
61
+
62
+ if opt.file_name
63
+ file = "#{TEST_CASE_DIR}/#{opt.file_name}"
64
+ raise ArgumentError, "Could not fine file: #{file} unless" unless File.exists?(file)
65
+ else
66
+ puts "FIXME: need to impl"
67
+ end
68
+ end
69
+
70
+ content = File.readlines(file).to_s
71
+
72
+ method_names = TCDoc.method_names_from_file(content)
73
+
74
+ if opt.execute_methods == 'all'
75
+ $job = {:methods => method_names}
76
+ else
77
+ $job = {:methods => opt.execute_methods.split(',')}
78
+ end
79
+
80
+ if opt.format == 'junit'
81
+ $junit_format = true
82
+
83
+ reqs = <<-EOF
84
+ puts "Calling modified code"
85
+ puts "$qa_observer_client set from test_runner: \#{$qa_observer_client}"
86
+ base = File.expand_path(File.dirname(__FILE__))
87
+
88
+ $qa_observer_client = '#{base}'
89
+ $junit_format = true
90
+ $run_on_browser = '#{opt.browser}'
91
+ $environment = :#{opt.environment.to_sym}
92
+ $standalone = false
93
+ TEST_CASE_DIR = '#{base}/sites/#{opt.site}/test_cases'
94
+ PROXY = #{PROXY.inspect}
95
+
96
+ EOF
97
+
98
+ content = File.read(file)
99
+
100
+ # lets add reqs after base in orig_content
101
+ content.gsub!("base = File.expand_path(File.dirname(__FILE__))", reqs)
102
+
103
+ tmp_file = "#{file}_#{Time.now.tv_sec}"
104
+
105
+ fd = File.open(tmp_file, 'w+')
106
+ fd.puts content.to_s
107
+ fd.close
108
+ results=`ruby #{tmp_file}`
109
+
110
+ FileUtils.rm_f tmp_file
111
+
112
+ else
113
+ load file
114
+ end
115
+
116
+ if $junit_format
117
+
118
+ FileUtils.mkdir 'junit_results' unless File.directory?('junit_results')
119
+
120
+ junit_xml = results.to_s.scan(/<JUNIT>(.*)<\/JUNIT>/m)
121
+
122
+ fd = File.open("junit_results/#{$current_test_class}_#{$current_test_method}_#{Time.to_md5}.xml", 'w+')
123
+ fd.puts junit_xml
124
+ fd.close
125
+ end
@@ -0,0 +1,8 @@
1
+ module Constants
2
+ module NFS
3
+ EXPORT_FILE='/etc/exports'
4
+ end
5
+ module FileTransfer
6
+ NUM_RETRIES = 1
7
+ end
8
+ end
@@ -0,0 +1,48 @@
1
+ module RemoteUnix
2
+ # outputer to parse output from echoed commands piped into script/console
3
+ class RailsConsoleOutput
4
+ attr_reader :unparsed
5
+ def initialize(out)
6
+ @unparsed = out
7
+ end
8
+ # given a generic output item from script/console such as:
9
+ # some prior items
10
+ # => [id1, id2, id3]
11
+ # transform the string to array
12
+
13
+ # when we have STDOUT comming back from ssh session in format
14
+ # [1,2,3] translate the string to a ruby Array obj
15
+ def to_a
16
+ unless @unparsed.grep(/.*\[.*\]/).nitems > 0
17
+ raise ArgumentError, "Tried to convert output to_a when not in correct format"
18
+ end
19
+ @unparsed.to_s.split(/\n/).to_s.split('=>').last.gsub(/[\[\]" ]/, '').split('>>').first.split(',')
20
+ end
21
+
22
+ def format
23
+ out = @unparsed.to_s.split(/\n/).to_s.split('=>').last.gsub(/[\[\] "]/, '').split('>>')
24
+
25
+ unless out.nitems > 0
26
+ return nil
27
+ end
28
+ # if we get here we found a result to return
29
+ out.first
30
+ end
31
+ end
32
+
33
+ class GenericShellOutput
34
+ # return an array for the output executed excluding any other
35
+ # control information, such as command executed or shell prompt
36
+ def self.to_lines(out, command_executed)
37
+ lines = out.first[command_executed.length..out.first.length].split(/\n/)
38
+
39
+ # empty array elem from stripping out command executed, deleting
40
+ lines.delete_at(0)
41
+
42
+ # last item will be shell prompt, delete
43
+ lines.delete_at(lines.length-1)
44
+ lines
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,52 @@
1
+ module RemoteUnix
2
+ module Common
3
+ def set_platform
4
+ @platform = {}
5
+ nav_path = [
6
+ {:execute => "uname -a",
7
+ :expected_output => /linux/i, :timeout => 1}
8
+ ]
9
+
10
+ uname = @ssh.navigate(nav_path).last.grep(/linux/i).first
11
+ uname_split = uname.split(' ')[2].split(".").last
12
+
13
+ # RHEL/CentOS
14
+ if uname_split =~ /el[0-5]/
15
+ @platform[:distro] = 'RH'
16
+ @platform[:prompt] = "]#"
17
+ @platform[:iscsi_packages] = ['iscsi-initiator-utils', 'sg3_utils.i386']
18
+ @platform[:install_iscsi_cmd] = "yum install -y"
19
+ # debian based
20
+ elsif uname =~ /ubuntu/i
21
+ @platform[:distro] = 'DEB'
22
+ @platform[:prompt] = "$"
23
+ @platform[:iscsi_packages] = ['open-iscsi', 'iscsitarget']
24
+ @platform[:install_iscsi_cmd] = "sudo apt-get install -y"
25
+
26
+ # TODO: check for /etc/redhat-release
27
+ # can't detec for SL as custom kernel without RH in uname -a
28
+ else
29
+ @platform[:distro] = 'DEB'
30
+ @platform[:prompt] = "#"
31
+ @platform[:iscsi_packages] = ['open-iscsi', 'iscsitarget']
32
+ @platform[:install_iscsi_cmd] = "apt-get install -y"
33
+
34
+ nav_path = [
35
+ {:execute => "if [ -f /etc/redhat-release ] ; then echo \"RH\"; else echo \"DEB\"; fi",
36
+ :timeout => 2}
37
+ ]
38
+
39
+ version = @ssh.navigate(nav_path).last.grep(/linux/i).first
40
+
41
+ if version =~ /RH/
42
+ @platform[:distro] = 'RH'
43
+ elsif version =~ /DEB/
44
+ @platform[:distro] = 'DEB'
45
+ end
46
+ end
47
+ @expected_prompt = Regexp.escape(@platform[:prompt].to_s)
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,4 @@
1
+ class RemoteUnixError < StandardError ; end
2
+ class LockedUserError < StandardError ; end
3
+ class FileNotFoundError < StandardError ; end
4
+ class FileTransferError < StandardError ; end
@@ -0,0 +1,308 @@
1
+ module RemoteUnix
2
+ # commands which return information such as initiator name
3
+ class GeneralUnix
4
+ include Common
5
+ def initialize(params={})
6
+ @host = params[:host]
7
+ @user = params[:user]
8
+ @password = params[:password]
9
+ @ssh = SSH.new(@host, @user, @password)
10
+ set_platform
11
+ end
12
+
13
+ def is_alive?(host)
14
+ ping_out = `ping -c 5 #{host}`
15
+ if ping_out =~ /100% packet loss/
16
+ return false
17
+ else
18
+ return true
19
+ end
20
+ end
21
+
22
+ def wait_till_alive(host, to=15)
23
+ timeout(to) {
24
+ while !is_alive?(host)
25
+ sleep 0.3
26
+ end
27
+ }
28
+ end
29
+
30
+ def wait_till_dead(host, to=15)
31
+ timeout(to) {
32
+ while is_alive?(host)
33
+ sleep 0.3
34
+ end
35
+ }
36
+ end
37
+
38
+ # if we don't care about results and just want to exex a remote command
39
+ def exec(cmd)
40
+ nav_path = [{:execute => cmd, :timeout => 1}]
41
+
42
+ begin
43
+ @ssh.navigate(nav_path)
44
+ rescue => e
45
+ puts "IGNORE: #{e}"
46
+ end
47
+
48
+ end
49
+
50
+ def get_num_lines_in_file(file)
51
+ nav_path = [{:execute => "wc -l #{file}", :timeout => 1}]
52
+
53
+ begin
54
+ return GenericShellOutput.to_lines(@ssh.navigate(nav_path),
55
+ nav_path.first[:execute]).pp.split(' ').first.to_i
56
+ rescue => e
57
+ puts "IGNORE: #{e}"
58
+ end
59
+
60
+ end
61
+
62
+ def ls(item)
63
+ nav_path = [{:execute => "ls #{item}", :timeout => 1}]
64
+ begin
65
+ content = RemoteUnix::GenericShellOutput.to_lines(@ssh.navigate(nav_path), nav_path.first[:execute])
66
+ rescue => e
67
+ puts "IGNORE: #{e}"
68
+ end
69
+ content
70
+ end
71
+
72
+ # assumes standard /etc/init.d/* start|stop|restart
73
+ def service(params={})
74
+ valid_commands = ['start', 'stop', 'restart']
75
+
76
+ unless params.has_key?(:name) && params.has_key?(:command)
77
+ raise ArgumentError
78
+ end
79
+
80
+ raise ArgumentError unless valid_commands.include?(params[:command])
81
+
82
+ nav_path = [{:execute => "/etc/init.d/#{params[:name]} #{params[:command]}", :timeout => 2}]
83
+
84
+ begin
85
+ @ssh.navigate(nav_path)
86
+ rescue => e
87
+ puts "IGNORE: #{e}"
88
+ end
89
+
90
+ end
91
+
92
+ # :ip --> host where the NFS export resides
93
+ # :share
94
+ # :mount_point --> local mount point
95
+ def mount_nfs(params={})
96
+
97
+ unless params.has_key?(:ip) && params.has_key?(:mount_point)
98
+ raise ArgumentError
99
+ end
100
+
101
+ nav_path = [{:execute => "mount #{params[:ip]}:#{params[:share]} #{params[:mount_point]}", :timeout => 1}]
102
+
103
+ begin
104
+ @ssh.navigate(nav_path)
105
+ rescue => e
106
+ puts "IGNORE: #{e}"
107
+ end
108
+
109
+ end
110
+
111
+ # return an array of content from remote file
112
+ def get_file_content(file)
113
+ unless file_exists?(file)
114
+ raise FileNotFoundError, "Could not find file #{file}"
115
+ end
116
+
117
+ nav_path = [{:execute => "cat #{file}", :timeout => 1}]
118
+ begin
119
+ content = RemoteUnix::GenericShellOutput.to_lines(@ssh.navigate(nav_path), nav_path.first[:execute])
120
+ rescue => e
121
+ puts "IGNORE: #{e}"
122
+ end
123
+ content
124
+ end
125
+
126
+ def put_file_content(file, content)
127
+ tmp=''
128
+
129
+ # if content passed in by array, assumes each array elem is a line in a file
130
+ # and add \n
131
+ if content.kind_of?(Array)
132
+ content.each { |i| tmp += "#{i}\n" }
133
+ end
134
+ content = tmp
135
+
136
+ tmp_file = "#{Time.now}"
137
+ fd = File.open(tmp_file, 'w+')
138
+
139
+ fd.puts content
140
+ fd.close
141
+
142
+ SCP::Upload.new(@host, @user, @password, tmp_file, file )
143
+ FileUtils.rm_f tmp_file
144
+
145
+ end
146
+
147
+ def flush_iptables
148
+ nav_path = [{:execute => "iptables -X", :timeout => 1},
149
+ {:execute => "iptables -F", :timeout => 1}]
150
+ begin
151
+ @ssh.navigate(nav_path)
152
+ rescue => e
153
+ puts "IGNORE: #{e}"
154
+ end
155
+
156
+ end
157
+
158
+ # params[:path] --> path to add to /etc/exports
159
+ # params[:allowed_host] --> string of host to allow access to the share (optional)
160
+ # not impl yet but will be added in future version as well
161
+ # as an additional param for options
162
+ def add_nfs_export(params={})
163
+ raise ArgumentError unless params.has_key?(:path)
164
+
165
+ begin
166
+ content = get_file_content(Constants::NFS::EXPORT_FILE)
167
+ rescue FileNotFoundError => e
168
+ content = []
169
+ end
170
+
171
+ updated_content = []
172
+ ops = '*(rw,sync)'
173
+
174
+ # if content already contains a share path lets delete old and add new
175
+ updated_content = delete_nfs_export(params[:path], content)
176
+
177
+ # append out path to the updated content
178
+ updated_content << "#{params[:path]} #{ops}"
179
+
180
+ # write content to exprts
181
+ put_file_content(Constants::NFS::EXPORT_FILE, updated_content)
182
+
183
+ service(:name => 'nfs', :command => 'restart')
184
+ sleep 0.75
185
+
186
+ # reread exports so it's active
187
+ nav_path = [{:execute => "/usr/sbin/exportfs -ra", :timeout => 1}]
188
+
189
+ begin
190
+ @ssh.navigate(nav_path)
191
+ rescue => e
192
+ puts "IGNORE: #{e}"
193
+ end
194
+
195
+ end
196
+
197
+ def delete_nfs_export(path, content=nil)
198
+ content = get_file_content(Constants::NFS::EXPORT_FILE) unless content
199
+
200
+ # if the path exists delete, else no need to perform additional cycles
201
+ if content.pp =~ /#{path}/
202
+ updated_content = []
203
+ ops = '*(rw,sync)'
204
+
205
+ # if content already contains a share path lets delete old and add new
206
+ content.each { |line|
207
+ updated_content << line unless line =~ /#{path}/
208
+ }
209
+
210
+ put_file_content(Constants::NFS::EXPORT_FILE, updated_content)
211
+
212
+ return updated_content
213
+ else
214
+ return content
215
+ end
216
+
217
+ end
218
+
219
+ def md5sum(file)
220
+ nav_path = [{:execute => "md5sum #{file}", :timeout => 1}]
221
+ begin
222
+ sum = RemoteUnix::GenericShellOutput.to_lines(@ssh.navigate(nav_path), nav_path.first[:execute]).first.split(' ').first
223
+ rescue => e
224
+ puts "IGNORE: #{e}"
225
+ end
226
+ sum
227
+ end
228
+
229
+ def rm_rf(loc)
230
+ nav_path = [{:execute => "rm -rf #{loc}", :timeout => 1}]
231
+ begin
232
+ out = RemoteUnix::GenericShellOutput.to_lines(@ssh.navigate(nav_path), nav_path.first[:execute])
233
+ rescue => e
234
+ puts "IGNORE: #{e}"
235
+ end
236
+ out
237
+ end
238
+
239
+ def reboot
240
+ nav_path = [{:execute => "shutdown -r now", :timeout => 1}]
241
+ begin
242
+ puts RemoteUnix::GenericShellOutput.to_lines(@ssh.navigate(nav_path), nav_path.first[:execute]).pp
243
+ rescue => e
244
+ puts "IGNORE: #{e}"
245
+ end
246
+ end
247
+
248
+ def date
249
+ date = {}
250
+ nav_path = [{:execute => "date", :timeout => 1}]
251
+ begin
252
+ tmp = RemoteUnix::GenericShellOutput.to_lines(@ssh.navigate(nav_path), nav_path.first[:execute]).pp
253
+
254
+ rescue => e
255
+ puts "IGNORE: #{e}"
256
+ end
257
+ Time.parse(tmp)
258
+ end
259
+
260
+ def hostname
261
+ nav_path = [{:execute => "hostname", :timeout => 1}]
262
+ begin
263
+ hostname = RemoteUnix::GenericShellOutput.to_lines(@ssh.navigate(nav_path), nav_path.first[:execute]).pp
264
+ rescue => e
265
+ puts "IGNORE: #{e}"
266
+ end
267
+ hostname
268
+ end
269
+
270
+ def file_exists?(file)
271
+ nav_path = [{:execute => "if [ -f #{file} ] ; then echo 'FOUND'; else echo 'NOT_FOUND'; fi", :timeout => 1}]
272
+ begin
273
+ out = RemoteUnix::GenericShellOutput.to_lines(@ssh.navigate(nav_path), nav_path.first[:execute]).pp
274
+ rescue => e
275
+ puts "IGNORE: #{e}"
276
+ end
277
+ if out == "FOUND"
278
+ return true
279
+ elsif out == "NOT_FOUND"
280
+ return false
281
+ else
282
+ raise ArgumentError, "Couldn't find file #{file}"
283
+ end
284
+
285
+ end
286
+
287
+ def redhat_release
288
+ nav_path = [{:execute => "cat /etc/redhat-release", :timeout => 1}]
289
+ begin
290
+ out = RemoteUnix::GenericShellOutput.to_lines(@ssh.navigate(nav_path), nav_path.first[:execute]).pp
291
+ rescue => e
292
+ puts "IGNORE: #{e}"
293
+ end
294
+ out
295
+ end
296
+
297
+ def kernel_version
298
+ nav_path = [{:execute => "uname -a", :timeout => 1}]
299
+ begin
300
+ out = RemoteUnix::GenericShellOutput.to_lines(@ssh.navigate(nav_path), nav_path.first[:execute]).pp
301
+ rescue => e
302
+ puts "IGNORE: #{e}"
303
+ end
304
+ out.split(' ')[2]
305
+ end
306
+
307
+ end
308
+ end