Class: Beaker::Utils::SetupHelper
- Inherits:
-
Object
- Object
- Beaker::Utils::SetupHelper
- Defined in:
- lib/beaker/utils/setup_helper.rb
Instance Method Summary collapse
- #add_master_entry ⇒ Object
- #find_masters(hosts) ⇒ Object
- #find_only_master(hosts) ⇒ Object
-
#initialize(options, hosts) ⇒ SetupHelper
constructor
A new instance of SetupHelper.
- #sync_root_keys ⇒ Object
Constructor Details
#initialize(options, hosts) ⇒ SetupHelper
Returns a new instance of SetupHelper.
5 6 7 8 9 |
# File 'lib/beaker/utils/setup_helper.rb', line 5 def initialize(, hosts) @options = .dup @hosts = hosts @logger = [:logger] end |
Instance Method Details
#add_master_entry ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/beaker/utils/setup_helper.rb', line 23 def add_master_entry @logger.notify "Add Master entry to /etc/hosts" master = find_only_master(@hosts) if master["hypervisor"] and master["hypervisor"] =~ /vagrant/ @logger.debug "Don't update master entry on vagrant masters" return end @logger.debug "Get ip address of Master #{master}" if master['platform'].include? 'solaris' stdout = master.exec(Command.new("ifconfig -a inet| awk '/broadcast/ {print $2}' | cut -d/ -f1 | head -1")).stdout else stdout = master.exec(Command.new("ip a|awk '/g/{print$2}' | cut -d/ -f1 | head -1")).stdout end ip=stdout.chomp path = "/etc/hosts" if master['platform'].include? 'solaris' path = "/etc/inet/hosts" end @logger.debug "Update %s on #{master}" % path # Preserve the mode the easy way... master.exec(Command.new("cp %s %s.old" % [path, path])) master.exec(Command.new("cp %s %s.new" % [path, path])) master.exec(Command.new("grep -v '#{ip} #{master}' %s > %s.new" % [path, path])) master.exec(Command.new("echo '#{ip} #{master}' >> %s.new" % path)) master.exec(Command.new("mv %s.new %s" % [path, path])) rescue => e report_and_raise(@logger, e, "add_master_entry") end |
#find_masters(hosts) ⇒ Object
11 12 13 14 15 |
# File 'lib/beaker/utils/setup_helper.rb', line 11 def find_masters(hosts) hosts.select do |host| host['roles'].include?("master") end end |
#find_only_master(hosts) ⇒ Object
17 18 19 20 21 |
# File 'lib/beaker/utils/setup_helper.rb', line 17 def find_only_master(hosts) m = find_masters(hosts) raise "too many masters, expected one but found #{m.map {|h| h.to_s }}" unless m.length == 1 m.first end |
#sync_root_keys ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/beaker/utils/setup_helper.rb', line 54 def sync_root_keys # JJM This step runs on every system under test right now. We're anticipating # issues on Windows and maybe Solaris. We will likely need to filter this step # but we're deliberately taking the approach of "assume it will work, fix it # when reality dictates otherwise" @logger.notify "Sync root authorized_keys from github" script = "https://raw.github.com/puppetlabs/puppetlabs-sshkeys/master/templates/scripts/manage_root_authorized_keys" = "curl -k -o - #{script} | %s" @logger.notify "Sync root authorized_keys from github" @hosts.each do |host| # Allow all exit code, as this operation is unlikely to cause problems if it fails. if host['platform'].include? 'solaris' host.exec(Command.new( % "bash"), :acceptable_exit_codes => (0..255)) else host.exec(Command.new( % "env PATH=/usr/gnu/bin:$PATH bash"), :acceptable_exit_codes => (0..255)) end end rescue => e report_and_raise(@logger, e, "sync_root_keys") end |