beaker 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +8 -8
  2. data/bin/beaker +1 -1
  3. data/lib/beaker.rb +1 -1
  4. data/lib/beaker/cli.rb +15 -35
  5. data/lib/beaker/host_prebuilt_steps.rb +335 -0
  6. data/lib/beaker/hypervisor.rb +53 -4
  7. data/lib/beaker/hypervisor/aixer.rb +2 -2
  8. data/lib/beaker/hypervisor/blimper.rb +5 -5
  9. data/lib/beaker/hypervisor/fusion.rb +3 -3
  10. data/lib/beaker/hypervisor/solaris.rb +2 -2
  11. data/lib/beaker/hypervisor/vagrant.rb +6 -16
  12. data/lib/beaker/hypervisor/vcloud.rb +6 -6
  13. data/lib/beaker/hypervisor/vcloud_pooled.rb +4 -4
  14. data/lib/beaker/hypervisor/vsphere.rb +3 -3
  15. data/lib/beaker/network_manager.rb +51 -37
  16. data/lib/beaker/options/presets.rb +1 -0
  17. data/lib/beaker/shared.rb +2 -2
  18. data/lib/beaker/shared/host_role_parser.rb +36 -0
  19. data/lib/beaker/version.rb +1 -1
  20. data/spec/beaker/host_prebuilt_steps_spec.rb +421 -0
  21. data/spec/beaker/hypervisor/google_compute.rb +23 -0
  22. data/spec/beaker/hypervisor/vagrant_spec.rb +5 -4
  23. data/spec/beaker/hypervisor/vcloud_pooled_spec.rb +2 -2
  24. data/spec/beaker/hypervisor/vcloud_spec.rb +2 -2
  25. data/spec/beaker/hypervisor/vsphere_spec.rb +2 -2
  26. data/spec/beaker/options/parser_spec.rb +1 -1
  27. data/spec/beaker/shared/host_role_parser_spec.rb +58 -0
  28. metadata +10 -18
  29. data/lib/beaker/shared/host_handler.rb +0 -51
  30. data/lib/beaker/utils.rb +0 -7
  31. data/lib/beaker/utils/ntp_control.rb +0 -57
  32. data/lib/beaker/utils/repo_control.rb +0 -90
  33. data/lib/beaker/utils/setup_helper.rb +0 -66
  34. data/lib/beaker/utils/validator.rb +0 -36
  35. data/spec/beaker/shared/host_handler_spec.rb +0 -104
  36. data/spec/beaker/utils/ntp_control_spec.rb +0 -70
  37. data/spec/beaker/utils/repo_control_spec.rb +0 -168
  38. data/spec/beaker/utils/setup_helper_spec.rb +0 -82
  39. data/spec/beaker/utils/validator_spec.rb +0 -91
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODYxYzQzYzY0MzQ5MmQ5ZDQ1ODNiMzNjYzhkYmNkNTQ1ZTAxNDIzZg==
4
+ MmRhZWZiYzAyYjBlYWU1NjQ4ZTJiY2Q2YjY2MjIzZDQ3OTU2ODhjMQ==
5
5
  data.tar.gz: !binary |-
6
- YzU4NjI5MzAxMWNlOWFlYWMyNzI5YWRiMzEwNjA5YjZhNDFhN2ZmYg==
6
+ MzY2M2M5M2UxM2U2NmQ3MmI0Y2UwNDk3ZmM0MDYxMjAzZWY2ZjM1Mg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjUzZjA3MmMwYzU0Njg3MzBjNWZhMGNjZmVmYzRiNzc1MjMxMjQ3Y2ZkZDYz
10
- YzgzNGVhNzMzNDQ1ZTkyYTgwNDQ2OGQ0YjVhZTlmZDQ1MTIzODQ5MzEyZmY5
11
- YmEwYTExZjk2ZGE0ZjA0NDVhMGNmZmMzZDI0NzM3MTc5ODA3ZDM=
9
+ OWZhMmJiMTE1NzJiOGQ0YWNhNTAwMDI2NzM2Njc0YTc4MDdhOWNkM2Y2MDRm
10
+ MjFjYmY3Y2NhZDU5YmZiODAxOWZhMzE2ZDJjMDVkZTAyZjc3YTdhMjZhYjNl
11
+ ZjcyMDJiNDE2NzBmYzUwYjM3OTY3YjFkODg4ZjM5MjVmNGNkOTk=
12
12
  data.tar.gz: !binary |-
13
- NzBiMGNmNTMwOGMwMzc5MGMzNWFkZmI0YTIyNjIwMDZlNmQzZWMyZTQyMDMy
14
- MTk2NDgwMDkyZDdlZWNhNzkyNmEyNzhlYWE4MWIzZWVkNTFiMjU4OTZlMjMy
15
- ZmRlZmE3MTkyNGZkZmJlMzFkNjk3MmQ0NzMwOTU3MjAyODYyYjY=
13
+ M2Y3MWYwYTBkNWJkMmQ0ZjJiMGUwYWIzNmZiODVlYTFiYTliOTU1MDY5NzRl
14
+ NmNlMDZjMzNlNjQ1NzM2N2U1NGYxZGFlYTNjY2NkNjA1ODE3YmY3OTMxMWI0
15
+ NWZjNTBlZjE2ZWRiMGYxODkyNjUyZTUyODA5ZWJlMmZlYTZkNzc=
data/bin/beaker CHANGED
@@ -5,5 +5,5 @@ require 'beaker'
5
5
 
6
6
  Beaker::CLI.new.execute!
7
7
 
8
- puts "systest completed successfully, thanks."
8
+ puts "Beaker completed successfully, thanks."
9
9
  exit 0
data/lib/beaker.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems' unless defined?(Gem)
2
2
  module Beaker
3
3
 
4
- %w( version platform utils test_suite result command options network_manager cli ).each do |lib|
4
+ %w( version platform test_suite result command options network_manager cli ).each do |lib|
5
5
  begin
6
6
  require "beaker/#{lib}"
7
7
  rescue LoadError
data/lib/beaker/cli.rb CHANGED
@@ -44,48 +44,26 @@ module Beaker
44
44
  end
45
45
  end
46
46
 
47
+ #Provision, validate and configure all hosts as defined in the hosts file
47
48
  def provision
48
49
  begin
49
50
  @hosts = []
50
51
  @network_manager = Beaker::NetworkManager.new(@options, @logger)
51
52
  @hosts = @network_manager.provision
53
+ @network_manager.validate
54
+ @network_manager.configure
52
55
  rescue => e
53
56
  report_and_raise(@logger, e, "CLI.provision")
54
57
  end
55
58
  end
56
59
 
57
- def validate
58
- begin
59
- #validation phase
60
- Beaker::Utils::Validator.validate(@hosts, @logger)
61
- rescue => e
62
- report_and_raise(@logger, e, "CLI.validate")
63
- end
64
- end
65
-
66
- def setup
67
- @ntp_controller = Beaker::Utils::NTPControl.new(@options, @hosts)
68
- @setup = Beaker::Utils::SetupHelper.new(@options, @hosts)
69
- @repo_controller = Beaker::Utils::RepoControl.new(@options, @hosts)
70
- setup_steps = [[:timesync, "Sync time on hosts", Proc.new {@ntp_controller.timesync}],
71
- [:root_keys, "Sync keys to hosts" , Proc.new {@setup.sync_root_keys}],
72
- [:repo_proxy, "Proxy packaging repositories on ubuntu, debian and solaris-11", Proc.new {@repo_controller.proxy_config}],
73
- [:add_el_extras, "Add Extra Packages for Enterprise Linux (EPEL) repository to el-* hosts", Proc.new {@repo_controller.add_el_extras}],
74
- [:add_master_entry, "Update /etc/hosts on master with master's ip", Proc.new {@setup.add_master_entry}]]
75
- begin
76
- #setup phase
77
- setup_steps.each do |step|
78
- if (not @options.has_key?(step[0])) or @options[step[0]]
79
- @logger.notify ""
80
- @logger.notify "Setup: #{step[1]}"
81
- step[2].call
82
- end
83
- end
84
- rescue => e
85
- report_and_raise(@logger, e, "CLI.setup")
86
- end
87
- end
88
-
60
+ #Run Beaker tests.
61
+ #
62
+ # - provision hosts (includes validation and configuration)
63
+ # - run pre-suite
64
+ # - run tests
65
+ # - run post-suite
66
+ # - cleanup hosts
89
67
  def execute!
90
68
 
91
69
  if !@execute
@@ -98,8 +76,6 @@ module Beaker
98
76
  end
99
77
 
100
78
  provision
101
- validate
102
- setup
103
79
 
104
80
  errored = false
105
81
 
@@ -142,7 +118,11 @@ module Beaker
142
118
  end
143
119
  end
144
120
 
145
- def run_suite(suite_name, failure_strategy = false)
121
+ #Run the provided test suite
122
+ #@param [Symbol] suite_name The test suite to execute
123
+ #@param [String] failure_strategy How to proceed after a test failure, 'fast' = stop running tests immediately, 'slow' =
124
+ # continue to execute tests.
125
+ def run_suite(suite_name, failure_strategy = :slow)
146
126
  if (@options[suite_name].empty?)
147
127
  @logger.notify("No tests to run for suite '#{suite_name.to_s}'")
148
128
  return
@@ -0,0 +1,335 @@
1
+ %w(command).each do |lib|
2
+ begin
3
+ require "beaker/#{lib}"
4
+ rescue LoadError
5
+ require File.expand_path(File.join(File.dirname(__FILE__), lib))
6
+ end
7
+ end
8
+
9
+ module Beaker
10
+ #Provides convienience methods for commonly run actions on hosts
11
+ module HostPrebuiltSteps
12
+ NTPSERVER = 'pool.ntp.org'
13
+ SLEEPWAIT = 5
14
+ TRIES = 5
15
+ PACKAGES = ['curl']
16
+ UNIX_PACKAGES = ['ntpdate']
17
+ SLES_PACKAGES = ['ntp']
18
+ ETC_HOSTS_PATH = "/etc/hosts"
19
+ ETC_HOSTS_PATH_SOLARIS = "/etc/inet/hosts"
20
+ ROOT_KEYS_SCRIPT = "https://raw.github.com/puppetlabs/puppetlabs-sshkeys/master/templates/scripts/manage_root_authorized_keys"
21
+ ROOT_KEYS_SYNC_CMD = "curl -k -o - #{ROOT_KEYS_SCRIPT} | %s"
22
+ APT_CFG = %q{ Acquire::http::Proxy "http://proxy.puppetlabs.net:3128/"; }
23
+ IPS_PKG_REPO="http://solaris-11-internal-repo.delivery.puppetlabs.net"
24
+
25
+ #Run timesync on the provided hosts
26
+ # @param [Host, Array<Host>, String, Symbol] host One or more hosts to act upon
27
+ # @param [Hash{Symbol=>String}] opts Options to alter execution.
28
+ # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
29
+ def timesync host, opts
30
+ logger = opts[:logger]
31
+ if host.is_a? Array
32
+ host.map { |h| timesync(h, opts) }
33
+ else
34
+ logger.notify "Update system time sync for '#{host.name}'"
35
+ if host['platform'].include? 'windows'
36
+ # The exit code of 5 is for Windows 2008 systems where the w32tm /register command
37
+ # is not actually necessary.
38
+ host.exec(Command.new("w32tm /register"), :acceptable_exit_codes => [0,5])
39
+ host.exec(Command.new("net start w32time"), :acceptable_exit_codes => [0,2])
40
+ host.exec(Command.new("w32tm /config /manualpeerlist:#{NTPSERVER} /syncfromflags:manual /update"))
41
+ host.exec(Command.new("w32tm /resync"))
42
+ logger.notify "NTP date succeeded on #{host}"
43
+ else
44
+ case
45
+ when host['platform'] =~ /solaris-10/
46
+ ntp_command = "sleep 10 && ntpdate -w #{NTPSERVER}"
47
+ when host['platform'] =~ /sles-/
48
+ ntp_command = "sntp #{NTPSERVER}"
49
+ else
50
+ ntp_command = "ntpdate -t 20 #{NTPSERVER}"
51
+ end
52
+ success=false
53
+ try = 0
54
+ until try >= TRIES do
55
+ try += 1
56
+ if host.exec(Command.new(ntp_command), :acceptable_exit_codes => (0..255)).exit_code == 0
57
+ success=true
58
+ break
59
+ end
60
+ sleep SLEEPWAIT
61
+ end
62
+ if success
63
+ logger.notify "NTP date succeeded on #{host} after #{try} tries"
64
+ else
65
+ raise "NTP date was not successful after #{try} tries"
66
+ end
67
+ end
68
+ end
69
+ rescue => e
70
+ report_and_raise(logger, e, "timesync (--ntp)")
71
+ end
72
+
73
+ #Validate that hosts are prepared to be used as SUTs, if packages are missing attempt to
74
+ #install them. Verifies the presence of {HostPrebuiltSteps::PACKAGES} on all hosts and
75
+ #{HostPrebuiltSteps::UNIX_PACKAGES} on unix platform hosts.
76
+ # @param [Host, Array<Host>, String, Symbol] host One or more hosts to act upon
77
+ # @param [Hash{Symbol=>String}] opts Options to alter execution.
78
+ # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
79
+ def validate_host host, opts
80
+ logger = opts[:logger]
81
+ if host.is_a? Array
82
+ host.map { |h| validate_host(h, opts) }
83
+ else
84
+ PACKAGES.each do |pkg|
85
+ if not host.check_for_package pkg
86
+ host.install_package pkg
87
+ end
88
+ end
89
+ case
90
+ when host['platform'] =~ /sles-/
91
+ SLES_PACKAGES.each do |pkg|
92
+ if not host.check_for_package pkg
93
+ host.install_package pkg
94
+ end
95
+ end
96
+
97
+ when host['platform'] !~ /(windows)|(aix)|(solaris)/
98
+ UNIX_PACKAGES.each do |pkg|
99
+ if not host.check_for_package pkg
100
+ host.install_package pkg
101
+ end
102
+ end
103
+ end
104
+ end
105
+ rescue => e
106
+ report_and_raise(logger, e, "validate")
107
+ end
108
+
109
+ #Update /etc/hosts on the master node to include a rule for lookup of the master by name/ip.
110
+ # @param [Host, Array<Host>, String, Symbol] host One or more hosts to act upon
111
+ # @param [Hash{Symbol=>String}] opts Options to alter execution.
112
+ # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
113
+ def add_master_entry hosts, opts
114
+ logger = opts[:logger]
115
+ master = only_host_with_role(hosts, :master)
116
+ logger.notify "Add Master entry to /etc/hosts on #{master.name}"
117
+ if master["hypervisor"] and master["hypervisor"] =~ /vagrant/
118
+ logger.debug "Don't update master entry on vagrant masters"
119
+ return
120
+ end
121
+ logger.debug "Get ip address of Master #{master}"
122
+ if master['platform'].include? 'solaris'
123
+ stdout = master.exec(Command.new("ifconfig -a inet| awk '/broadcast/ {print $2}' | cut -d/ -f1 | head -1")).stdout
124
+ else
125
+ stdout = master.exec(Command.new("ip a|awk '/global/{print$2}' | cut -d/ -f1 | head -1")).stdout
126
+ end
127
+ ip=stdout.chomp
128
+
129
+ path = ETC_HOSTS_PATH
130
+ if master['platform'].include? 'solaris'
131
+ path = ETC_HOSTS_PATH_SOLARIS
132
+ end
133
+
134
+ logger.debug "Update %s on #{master}" % path
135
+ # Preserve the mode the easy way...
136
+ master.exec(Command.new("cp %s %s.old" % [path, path]))
137
+ master.exec(Command.new("cp %s %s.new" % [path, path]))
138
+ master.exec(Command.new("grep -v '#{ip} #{master}' %s > %s.new" % [path, path]))
139
+ master.exec(Command.new("echo '#{ip} #{master}' >> %s.new" % path))
140
+ master.exec(Command.new("mv %s.new %s" % [path, path]))
141
+ rescue => e
142
+ report_and_raise(logger, e, "add_master_entry")
143
+ end
144
+
145
+ #Install a set of authorized keys using {HostPrebuiltSteps::ROOT_KEYS_SCRIPT}. This is a
146
+ #convenience method to allow for easy login to hosts after they have been provisioned with
147
+ #Beaker.
148
+ # @param [Host, Array<Host>, String, Symbol] host One or more hosts to act upon
149
+ # @param [Hash{Symbol=>String}] opts Options to alter execution.
150
+ # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
151
+ def sync_root_keys host, opts
152
+ # JJM This step runs on every system under test right now. We're anticipating
153
+ # issues on Windows and maybe Solaris. We will likely need to filter this step
154
+ # but we're deliberately taking the approach of "assume it will work, fix it
155
+ # when reality dictates otherwise"
156
+ logger = opts[:logger]
157
+ if host.is_a? Array
158
+ host.map { |h| sync_root_keys(h, opts) }
159
+ else
160
+ logger.notify "Sync root authorized_keys from github on #{host.name}"
161
+ # Allow all exit code, as this operation is unlikely to cause problems if it fails.
162
+ if host['platform'].include? 'solaris'
163
+ host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "bash"), :acceptable_exit_codes => (0..255))
164
+ else
165
+ host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "env PATH=/usr/gnu/bin:$PATH bash"), :acceptable_exit_codes => (0..255))
166
+ end
167
+ end
168
+ rescue => e
169
+ report_and_raise(logger, e, "sync_root_keys")
170
+ end
171
+
172
+ #Determine the Extra Packages for Enterprise Linux URL for the provided Enterprise Linux host.
173
+ # @param [Host] host One host to act upon
174
+ # @return [String] The URL for EPL for the provided host
175
+ # @raise [Exception] Raises an error if the host provided's platform != /el-(5|6)/
176
+ def epel_info_for! host
177
+ version = host['platform'].match(/el-(\d+)/)
178
+ if not version
179
+ raise "epel_info_for! not available for #{host.name} on platform #{host['platform']}"
180
+ end
181
+ version = version[1]
182
+ if version == '6'
183
+ pkg = 'epel-release-6-8.noarch.rpm'
184
+ url = "http://mirror.itc.virginia.edu/fedora-epel/6/i386/#{pkg}"
185
+ elsif version == '5'
186
+ pkg = 'epel-release-5-4.noarch.rpm'
187
+ url = "http://archive.linux.duke.edu/pub/epel/5/i386/#{pkg}"
188
+ else
189
+ raise "epel_info_for! does not support el version #{version}, on #{host.name}"
190
+ end
191
+ return url
192
+ end
193
+
194
+ #Run 'apt-get update' on the provided host or hosts. If the platform of the provided host is not
195
+ #ubuntu or debian do nothing.
196
+ # @param [Host, Array<Host>, String, Symbol] host One or more hosts to act upon
197
+ def apt_get_update host
198
+ if host.is_a? Array
199
+ host.map { |h| apt_get_update(h) }
200
+ else
201
+ if host[:platform] =~ /(ubuntu)|(debian)/
202
+ host.exec(Command.new("apt-get -y -f -m update"))
203
+ end
204
+ end
205
+ end
206
+
207
+ #Create a file on host or hosts at the provided file path with the provided file contents.
208
+ # @param [Host, Array<Host>, String, Symbol] host One or more hosts to act upon
209
+ # @param [String] file_path The path at which the new file will be created on the host or hosts.
210
+ # @param [String] file_content The contents of the file to be created on the host or hosts.
211
+ def copy_file_to_remote(host, file_path, file_content)
212
+ if host.is_a? Array
213
+ host.map { |h| copy_file_to_remote(h, file_path, file_contents) }
214
+ else
215
+ Tempfile.open 'beaker' do |tempfile|
216
+ File.open(tempfile.path, 'w') {|file| file.puts file_content }
217
+
218
+ host.do_scp_to(tempfile.path, file_path, @options)
219
+ end
220
+ end
221
+ end
222
+
223
+ #Alter apt configuration on ubuntu and debian host or hosts to internal Puppet Labs
224
+ # proxy {HostPrebuiltSteps::APT_CFG} proxy, alter pkg on solaris-11 host or hosts
225
+ # to point to interal Puppetlabs proxy {HostPrebuiltSteps::IPS_PKG_REPO}. Do nothing
226
+ # on non-ubuntu, debian or solaris-11 platform host or hosts.
227
+ # @param [Host, Array<Host>, String, Symbol] host One or more hosts to act upon
228
+ # @param [Hash{Symbol=>String}] opts Options to alter execution.
229
+ # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
230
+ def proxy_config( host, opts )
231
+ # repo_proxy
232
+ # supports ubuntu, debian and solaris platforms
233
+ logger = opts[:logger]
234
+ if host.is_a? Array
235
+ host.map { |h| proxy_config(h, opts) }
236
+ else
237
+ case
238
+ when host['platform'] =~ /ubuntu/
239
+ host.exec(Command.new("if test -f /etc/apt/apt.conf; then mv /etc/apt/apt.conf /etc/apt/apt.conf.bk; fi"))
240
+ copy_file_to_remote(host, '/etc/apt/apt.conf', APT_CFG)
241
+ apt_get_update(host)
242
+ when host['platform'] =~ /debian/
243
+ host.exec(Command.new("if test -f /etc/apt/apt.conf; then mv /etc/apt/apt.conf /etc/apt/apt.conf.bk; fi"))
244
+ copy_file_to_remote(host, '/etc/apt/apt.conf', APT_CFG)
245
+ apt_get_update(host)
246
+ when host['platform'] =~ /solaris-11/
247
+ host.exec(Command.new("/usr/bin/pkg unset-publisher solaris || :"))
248
+ host.exec(Command.new("/usr/bin/pkg set-publisher -g %s solaris" % IPS_PKG_REPO))
249
+ else
250
+ logger.debug "#{host}: repo proxy configuration not modified"
251
+ end
252
+ end
253
+ rescue => e
254
+ report_and_raise(logger, e, "proxy_config")
255
+ end
256
+
257
+ #Install EPEL on host or hosts with platform = /el-(5|6)/. Do nothing on host or hosts of other platforms.
258
+ # @param [Host, Array<Host>, String, Symbol] host One or more hosts to act upon
259
+ # @param [Hash{Symbol=>String}] opts Options to alter execution.
260
+ # @option opts [Boolean] :debug If true, print verbose rpm information when installing EPEL
261
+ # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
262
+ def add_el_extras( host, opts )
263
+ #add_el_extras
264
+ #only supports el-* platforms
265
+ logger = opts[:logger]
266
+ debug_opt = opts[:debug] ? 'vh' : ''
267
+ if host.is_a? Array
268
+ host.map { |h| add_el_extras(h, opts) }
269
+ else
270
+ case
271
+ when host['platform'] =~ /el-(5|6)/
272
+ result = host.exec(Command.new('rpm -qa | grep epel-release'), :acceptable_exit_codes => [0,1])
273
+ if result.exit_code == 1
274
+ url = epel_info_for! host
275
+ host.exec(Command.new("rpm -i#{debug_opt} #{url}"))
276
+ host.exec(Command.new('yum clean all && yum makecache'))
277
+ end
278
+ else
279
+ logger.debug "#{host}: package repo configuration not modified"
280
+ end
281
+ end
282
+ rescue => e
283
+ report_and_raise(logger, e, "add_repos")
284
+ end
285
+
286
+ #Determine the domain name of the provided host from its /etc/resolv.conf
287
+ # @param [Host] host the host to act upon
288
+ def get_domain_name(host)
289
+ domain = nil
290
+ search = nil
291
+ resolv_conf = host.exec(Command.new("cat /etc/resolv.conf")).stdout
292
+ resolv_conf.each_line { |line|
293
+ if line =~ /^\s*domain\s+(\S+)/
294
+ domain = $1
295
+ elsif line =~ /^\s*search\s+(\S+)/
296
+ search = $1
297
+ end
298
+ }
299
+ return domain if domain
300
+ return search if search
301
+ end
302
+
303
+ #Determine the ip address of the provided host
304
+ # @param [Host] host the host to act upon
305
+ def get_ip(host)
306
+ host.exec(Command.new("ip a|awk '/global/{print$2}' | cut -d/ -f1 | head -1")).stdout.chomp
307
+ end
308
+
309
+ #Append the provided string to the /etc/hosts file of the provided host
310
+ # @param [Host] host the host to act upon
311
+ # @param [String] etc_hosts The string to append to the /etc/hosts file
312
+ def set_etc_hosts(host, etc_hosts)
313
+ host.exec(Command.new("echo '#{etc_hosts}' > /etc/hosts"))
314
+ end
315
+
316
+ #Make it possible to log in as root by copying the current users ssh keys to the root account
317
+ # @param [Host, Array<Host>, String, Symbol] host One or more hosts to act upon
318
+ # @param [Hash{Symbol=>String}] opts Options to alter execution.
319
+ # @option opts [Beaker::Logger] :logger A {Beaker::Logger} object
320
+ def copy_ssh_to_root host, opts
321
+ logger = opts[:logger]
322
+ if host.is_a? Array
323
+ host.map { |h| copy_ssh_to_root(h, opts) }
324
+ else
325
+ logger.debug "Give root a copy of current user's keys, on #{host.name}"
326
+ if host['platform'] =~ /windows/
327
+ host.exec(Command.new('sudo su -c "cp -r .ssh /home/Administrator/."'))
328
+ else
329
+ host.exec(Command.new('sudo su -c "cp -r .ssh /root/."'))
330
+ end
331
+ end
332
+ end
333
+
334
+ end
335
+ end