Class: Beaker::Utils::SetupHelper
- Inherits:
-
Object
- Object
- Beaker::Utils::SetupHelper
- Defined in:
- lib/beaker/utils/setup_helper.rb
Constant Summary collapse
- ETC_HOSTS_PATH =
"/etc/hosts"
- ETC_HOSTS_PATH_SOLARIS =
"/etc/inet/hosts"
- ROOT_KEYS_SCRIPT =
"https://raw.github.com/puppetlabs/puppetlabs-sshkeys/master/templates/scripts/manage_root_authorized_keys"
- ROOT_KEYS_SYNC_CMD =
"curl -k -o - #{ROOT_KEYS_SCRIPT} | %s"
Instance Method Summary collapse
- #add_master_entry ⇒ 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.
9 10 11 12 13 |
# File 'lib/beaker/utils/setup_helper.rb', line 9 def initialize(, hosts) @options = .dup @hosts = hosts @logger = [:logger] end |
Instance Method Details
#add_master_entry ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/beaker/utils/setup_helper.rb', line 15 def add_master_entry @logger.notify "Add Master entry to /etc/hosts" master = only_host_with_role(@hosts, :master) 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_PATH if master['platform'].include? 'solaris' path = ETC_HOSTS_PATH_SOLARIS 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 |
#sync_root_keys ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/beaker/utils/setup_helper.rb', line 46 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" @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(ROOT_KEYS_SYNC_CMD % "bash"), :acceptable_exit_codes => (0..255)) else host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "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 |