class Beaker::Hypervisor

The Beaker class that interacts to all the supported hypervisors

Constants

CHARMAP

Generates an array with all letters a thru z and numbers 0 thru 9

DEFAULT_CONNECTION_PREFERENCE

Public Class Methods

create(type, hosts_to_provision, options) click to toggle source

Hypervisor creator method. Creates the appropriate hypervisor class object based upon the provided hypervisor type selected, then provisions hosts with hypervisor. @param [String] type The type of hypervisor to create - one of aix, solaris, vsphere, fusion,

blimpy, vcloud or vagrant

@param [Array<Host>] hosts_to_provision The hosts to be provisioned with the selected hypervisor @param [Hash] options options Options to alter execution @option options [String] :host_name_prefix (nil) Prefix host name if set

# File lib/beaker/hypervisor.rb, line 20
def self.create(type, hosts_to_provision, options)
  @logger = options[:logger]
  @logger.notify("Beaker::Hypervisor, found some #{type} boxes to create")

  hyper_class = case type
                when /^noop$/
                  Beaker::Noop
                when /^(default)|(none)$/
                  Beaker::Hypervisor
                else
                  # Custom hypervisor
                  require "beaker/hypervisor/#{type}"
                  Beaker.const_get(type.split('_').collect(&:capitalize).join)
                end

  hypervisor = hyper_class.new(hosts_to_provision, options)
  self.set_ssh_connection_preference(hosts_to_provision, hypervisor)
  hypervisor.provision if options[:provision]

  hypervisor
end
new(hosts, options) click to toggle source
# File lib/beaker/hypervisor.rb, line 42
def initialize(hosts, options)
  @hosts = hosts
  @options = options
end
set_ssh_connection_preference(hosts_to_provision, hypervisor) click to toggle source
# File lib/beaker/hypervisor.rb, line 63
def self.set_ssh_connection_preference(hosts_to_provision, hypervisor)
  hosts_to_provision.each do |host|
    ssh_methods = hypervisor.connection_preference(host) + DEFAULT_CONNECTION_PREFERENCE
    if host[:ssh_preference]
      # If user has provided ssh_connection_preference in hosts file then concat the preference provided by hypervisor
      # Followed by concatenating the default preference and keeping the unique once
      ssh_methods = host[:ssh_preference] + ssh_methods
    end
    host[:ssh_connection_preference] = ssh_methods.uniq
  end
end

Public Instance Methods

cleanup() click to toggle source

Cleanup steps to be run for a given hypervisor. Default is nil.

# File lib/beaker/hypervisor.rb, line 53
def cleanup
  nil
end
configure(opts = {}) click to toggle source

Default configuration steps to be run for a given hypervisor. Any additional configuration to be done to the provided SUT for test execution to be successful.

# File lib/beaker/hypervisor.rb, line 84
def configure(opts = {})
  begin
    return unless @options[:configure]

    run_in_parallel = run_in_parallel? opts, @options, 'configure'
    block_on @hosts, { :run_in_parallel => run_in_parallel } do |host|
      timesync(host, @options) if host[:timesync]
    end
    sync_root_keys(@hosts, @options) if @options[:root_keys]
    set_env(@hosts, @options) if @options[:set_env]
    disable_updates(@hosts, @options) if @options[:disable_updates]
  rescue SignalException => e
    report_and_raise(@logger, e, "configure") if e.signo == 15 # SIGTERM
    raise
  end
end
connection_preference(_host) click to toggle source

SSH connection method preference. Can be overwritten by hypervisor to change the order

# File lib/beaker/hypervisor.rb, line 59
def connection_preference(_host)
  DEFAULT_CONNECTION_PREFERENCE
end
generate_host_name() click to toggle source

Generate a random string composted of letter and numbers prefixed with value of {Beaker::Hypervisor::create} option :host_name_prefix

# File lib/beaker/hypervisor.rb, line 111
def generate_host_name
  n = CHARMAP[rand(25)] + (0...14).map { CHARMAP[rand(CHARMAP.length)] }.join
  return @options[:host_name_prefix] + n if @options[:host_name_prefix]

  n
end
provision() click to toggle source

Provisioning steps for be run for a given hypervisor. Default is nil.

# File lib/beaker/hypervisor.rb, line 48
def provision
  nil
end
proxy_package_manager() click to toggle source

Proxy package managers on tests hosts created by this hypervisor, runs before validation and configuration.

# File lib/beaker/hypervisor.rb, line 76
def proxy_package_manager
  return unless @options[:package_proxy]

  package_proxy(@hosts, @options)
end
validate() click to toggle source

Default validation steps to be run for a given hypervisor. Ensures that SUTs meet requirements to be beaker test nodes.

# File lib/beaker/hypervisor.rb, line 103
def validate
  return unless @options[:validate]

  validate_host(@hosts, @options)
end