class Beaker::Options::Presets

into the Beaker options Object.
A class representing the environment variables and preset argument values to be incorporated

def calculate_env_vars

Returns:
  • (OptionsHash) - The supported environment variables in an OptionsHash,
def calculate_env_vars
  found = Beaker::Options::OptionsHash.new
  found = found.merge(format_found_env_vars(collect_env_vars(ENVIRONMENT_SPEC)))
  found[:answers] = select_env_by_regex('\\Aq_')
  found.delete_if { |_key, value| value.nil? or value.empty? }
  found
end

def collect_env_vars(env_var_spec)

Returns:
  • (Hash) - Found environment values

Parameters:
  • env_var_spec (Hash{Symbol=>Array,String}) -- the spec of what env vars to search for
def collect_env_vars(env_var_spec)
  env_var_spec.each_with_object({}) do |key_value, memo|
    key, value = key_value[0], key_value[1]
    set_env_var = Array(value).detect { |possible_variable| ENV.fetch(possible_variable, nil) }
    memo[key] = ENV.fetch(set_env_var, nil) if set_env_var
  end
end

def env_vars

Returns:
  • (OptionsHash) - The supported environment variables in an OptionsHash,
def env_vars
  @env ||= calculate_env_vars
end

def format_found_env_vars(found_env_vars)

Returns:
  • (Hash) - Environment config values formatted appropriately

Parameters:
  • found_env_vars (Hash{Symbol=>String}) -- Environment variables to munge
def format_found_env_vars(found_env_vars)
  found_env_vars[:consoleport] &&= found_env_vars[:consoleport].to_i
  if found_env_vars[:is_pe]
    is_pe_val = found_env_vars[:is_pe]
    type = case is_pe_val
           when /yes|true/ then 'pe'
           when /no|false/ then 'foss'
           else
             raise "Invalid value for one of #{ENVIRONMENT_SPEC[:is_pe].join(' ,')}: #{is_pe_val}"
           end
    found_env_vars[:type] = type
  end
  found_env_vars[:run_in_parallel] = found_env_vars[:run_in_parallel].split(',') if found_env_vars[:run_in_parallel]
  found_env_vars[:pe_version_file_win] = found_env_vars[:pe_version_file]
  found_env_vars
end

def presets

Returns:
  • (OptionsHash) - The supported arguments in an OptionsHash
def presets
  h = Beaker::Options::OptionsHash.new
  h.merge({
            :project => 'Beaker',
            :department => 'unknown',
            :created_by => ENV['USER'] || ENV['USERNAME'] || 'unknown',
            :host_tags => {},
            :openstack_api_key => ENV.fetch('OS_PASSWORD', nil),
            :openstack_username => ENV.fetch('OS_USERNAME', nil),
            :openstack_auth_url => "#{ENV.fetch('OS_AUTH_URL', nil)}/tokens",
            :openstack_tenant => ENV.fetch('OS_TENANT_NAME', nil),
            :openstack_keyname => ENV.fetch('OS_KEYNAME', nil),
            :openstack_network => ENV.fetch('OS_NETWORK', nil),
            :openstack_region => ENV.fetch('OS_REGION', nil),
            :openstack_volume_support => ENV['OS_VOLUME_SUPPORT'] || true,
            :jenkins_build_url => nil,
            :validate => true,
            :configure => true,
            :log_level => 'info',
            :trace_limit => 10,
            :"master-start-curl-retries" => 120,
            :masterless => false,
            :options_file => nil,
            :type => 'pe',
            :provision => true,
            :preserve_hosts => 'never',
            :root_keys => false,
            :quiet => false,
            :project_root => File.expand_path(File.join(__dir__, "../")),
            :xml_dir => 'junit',
            :xml_file => 'beaker_junit.xml',
            :xml_time => 'beaker_times.xml',
            :xml_time_enabled => false,
            :xml_stylesheet => 'junit.xsl',
            :default_log_prefix => 'beaker_logs',
            :log_dir => 'log',
            :log_sut_event => 'sut.log',
            :color => true,
            :dry_run => false,
            :test_tag_and => '',
            :test_tag_or => '',
            :test_tag_exclude => '',
            :timeout => 900, # 15 minutes
            :fail_mode => 'slow',
            :test_results_file => '',
            :accept_all_exit_codes => false,
            :timesync => false,
            :set_env => true,
            :disable_updates => true,
            :repo_proxy => false,
            :package_proxy => false,
            :add_el_extras => false,
            :consoleport => 443,
            :pe_dir => '/opt/enterprise/dists',
            :pe_version_file => 'LATEST',
            :pe_version_file_win => 'LATEST-win',
            :host_env => {},
            :host_name_prefix => nil,
            :ssh_env_file => '~/.ssh/environment',
            :profile_d_env_file => '/etc/profile.d/beaker_env.sh',
            :dot_fog => File.join(ENV.fetch('HOME', nil), '.fog'),
            :ec2_yaml => 'config/image_templates/ec2.yaml',
            :help => false,
            :collect_perf_data => 'none',
            :puppetdb_port_ssl => 8081,
            :puppetdb_port_nonssl => 8080,
            :puppetserver_port => 8140,
            :nodeclassifier_port => 4433,
            :cache_files_locally => false,
            :aws_keyname_modifier => rand(10**10).to_s.rjust(10, '0'), # 10 digit random number string
            :run_in_parallel => [],
            :use_fog_credentials => true,
            :ssh => {
              :config => false,
              :verify_host_key => false,
              :auth_methods => ["publickey"],
              :port => 22,
              :forward_agent => true,
              :keys => ["#{ENV.fetch('HOME', nil)}/.ssh/id_rsa"],
              :user_known_hosts_file => "#{ENV.fetch('HOME', nil)}/.ssh/known_hosts",
              :keepalive => true,
            },
          })
end

def select_env_by_regex regex

Returns:
  • (Hash) - Hash of environment variables
def select_env_by_regex regex
  envs = Beaker::Options::OptionsHash.new
  ENV.each_pair do |k, v|
    envs[k] = v if /#{regex}/.match?(k.to_s)
  end
  envs
end