Class: Beaker::Hypervisor
- Inherits:
-
Object
- Object
- Beaker::Hypervisor
- Includes:
- HostPrebuiltSteps
- Defined in:
- lib/beaker/hypervisor.rb
Overview
The Beaker class that interacts to all the supported hypervisors
Direct Known Subclasses
Constant Summary collapse
- CHARMAP =
Generates an array with all letters a thru z and numbers 0 thru 9
('a'..'z').to_a + ('0'..'9').to_a
- DEFAULT_CONNECTION_PREFERENCE =
%i[ip vmhostname hostname]
Constants included from HostPrebuiltSteps
Beaker::HostPrebuiltSteps::ETC_HOSTS_PATH, Beaker::HostPrebuiltSteps::ETC_HOSTS_PATH_SOLARIS, Beaker::HostPrebuiltSteps::NTPSERVER, Beaker::HostPrebuiltSteps::ROOT_KEYS_SCRIPT, Beaker::HostPrebuiltSteps::ROOT_KEYS_SYNC_CMD, Beaker::HostPrebuiltSteps::ROOT_KEYS_SYNC_CMD_AIX, Beaker::HostPrebuiltSteps::SLEEPWAIT, Beaker::HostPrebuiltSteps::TRIES
Class Method Summary collapse
-
.create(type, hosts_to_provision, options) ⇒ Object
Hypervisor creator method.
- .set_ssh_connection_preference(hosts_to_provision, hypervisor) ⇒ Object
Instance Method Summary collapse
-
#cleanup ⇒ Object
Cleanup steps to be run for a given hypervisor.
-
#configure(opts = {}) ⇒ Object
Default configuration steps to be run for a given hypervisor.
-
#connection_preference(_host) ⇒ Object
SSH connection method preference.
-
#generate_host_name ⇒ Object
Generate a random string composted of letter and numbers prefixed with value of create option :host_name_prefix.
-
#initialize(hosts, options) ⇒ Hypervisor
constructor
A new instance of Hypervisor.
-
#provision ⇒ Object
Provisioning steps for be run for a given hypervisor.
-
#proxy_package_manager ⇒ Object
Proxy package managers on tests hosts created by this hypervisor, runs before validation and configuration.
-
#validate ⇒ Object
Default validation steps to be run for a given hypervisor.
Methods included from HostPrebuiltSteps
#additive_hash_merge, #apt_get_update, #check_and_install_packages_if_needed, #construct_env, #copy_file_to_remote, #copy_ssh_to_root, #disable_se_linux, #disable_updates, #enable_root_login, #get_domain_name, #hack_etc_hosts, #host_packages, #install_one_of_packages, #package_proxy, #set_env, #set_etc_hosts, #sync_root_keys, #timesync, #validate_host
Methods included from DSL::Patterns
Constructor Details
#initialize(hosts, options) ⇒ Hypervisor
Returns a new instance of Hypervisor.
42 43 44 45 |
# File 'lib/beaker/hypervisor.rb', line 42 def initialize(hosts, ) @hosts = hosts @options = end |
Class Method Details
.create(type, hosts_to_provision, options) ⇒ Object
Hypervisor creator method. Creates the appropriate hypervisor class object based upon the provided hypervisor type selected, then provisions hosts with hypervisor.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/beaker/hypervisor.rb', line 20 def self.create(type, hosts_to_provision, ) @logger = [: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, ) self.set_ssh_connection_preference(hosts_to_provision, hypervisor) hypervisor.provision if [:provision] hypervisor end |
.set_ssh_connection_preference(hosts_to_provision, hypervisor) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# 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 |
Instance Method Details
#cleanup ⇒ Object
Cleanup steps to be run for a given hypervisor. Default is nil.
53 54 55 |
# File 'lib/beaker/hypervisor.rb', line 53 def cleanup nil end |
#configure(opts = {}) ⇒ Object
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.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# 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) ⇒ Object
SSH connection method preference. Can be overwritten by hypervisor to change the order
59 60 61 |
# File 'lib/beaker/hypervisor.rb', line 59 def connection_preference(_host) DEFAULT_CONNECTION_PREFERENCE end |
#generate_host_name ⇒ Object
Generate a random string composted of letter and numbers prefixed with value of create option :host_name_prefix
111 112 113 114 115 116 |
# 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 ⇒ Object
Provisioning steps for be run for a given hypervisor. Default is nil.
48 49 50 |
# File 'lib/beaker/hypervisor.rb', line 48 def provision nil end |
#proxy_package_manager ⇒ Object
Proxy package managers on tests hosts created by this hypervisor, runs before validation and configuration.
76 77 78 79 80 |
# File 'lib/beaker/hypervisor.rb', line 76 def proxy_package_manager return unless @options[:package_proxy] package_proxy(@hosts, @options) end |
#validate ⇒ Object
Default validation steps to be run for a given hypervisor. Ensures that SUTs meet requirements to be beaker test nodes.
103 104 105 106 107 |
# File 'lib/beaker/hypervisor.rb', line 103 def validate return unless @options[:validate] validate_host(@hosts, @options) end |