Class: Beaker::TestConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/beaker/test_config.rb

Overview

Config was taken by Ruby.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file, options) ⇒ TestConfig

Returns a new instance of TestConfig.



9
10
11
12
13
# File 'lib/beaker/test_config.rb', line 9

def initialize(config_file, options)
  @options = options
  @logger = options[:logger]
  @config = load_file(config_file)
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/beaker/test_config.rb', line 8

def logger
  @logger
end

Instance Method Details

#[](key) ⇒ Object



15
16
17
# File 'lib/beaker/test_config.rb', line 15

def [](key)
  @config[key]
end

#dumpObject

Print out test configuration



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/beaker/test_config.rb', line 124

def dump
  # Access "platform" for each host
  @config["HOSTS"].each_key do|host|
    @logger.notify "Platform for #{host} #{@config["HOSTS"][host]['platform']}"
  end

  # Access "roles" for each host
  @config["HOSTS"].each_key do|host|
    @config["HOSTS"][host]['roles'].each do |role|
      @logger.notify "Role for #{host} #{role}"
    end
  end

  # Print out Ruby versions
  @config["HOSTS"].each_key do|host|
      @logger.notify "Ruby version for #{host} #{@config["HOSTS"][host][:ruby_ver]}"
  end

  # Access @config keys/values
  @config["CONFIG"].each_key do|cfg|
      @logger.notify "Config Key|Val: #{cfg} #{@config["CONFIG"][cfg].inspect}"
  end
end

#is_pe?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
# File 'lib/beaker/test_config.rb', line 65

def is_pe?
  @is_pe ||= @options[:type] =~ /pe/ ? true : false
  unless ENV['IS_PE'].nil?
    @is_pe ||= ENV['IS_PE'] == 'true'
  end
  @is_pe
end

#load_file(config_file) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/beaker/test_config.rb', line 32

def load_file(config_file)
  if config_file.is_a? Hash
    config = config_file
  else
    config = YAML.load_file(config_file)

    # Make sure the roles array is present for all hosts
    config['HOSTS'].each_key do |host|
      config['HOSTS'][host]['roles'] ||= []
    end
  end

  # Merge some useful date into the config hash
  config['CONFIG'] ||= {}
  consoleport = ENV['consoleport'] || config['CONFIG']['consoleport'] || 443
  config['CONFIG']['consoleport']        = consoleport.to_i
  config['CONFIG']['ssh']                = ssh_defaults.merge(config['CONFIG']['ssh'] || {})
  config['CONFIG']['modules']            = @options[:modules] || []

  if is_pe?
    config['CONFIG']['pe_dir']           = puppet_enterprise_dir
    config['CONFIG']['pe_ver']           = puppet_enterprise_version
    config['CONFIG']['pe_ver_win']       = puppet_enterprise_version_win
  else
    config['CONFIG']['puppet_ver']       = @options[:puppet]
    config['CONFIG']['facter_ver']       = @options[:facter]
    config['CONFIG']['hiera_ver']        = @options[:hiera]
    config['CONFIG']['hiera_puppet_ver'] = @options[:hiera_puppet]
  end
  # need to load expect versions of PE binaries
  config
end

#load_pe_versionObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/beaker/test_config.rb', line 77

def load_pe_version
  dist_dir = puppet_enterprise_dir
  version_file = ENV['pe_version_file'] || 'LATEST'
  version = ""
  begin
    open("#{dist_dir}/#{version_file}") do |file|
      while line = file.gets
        if /(\w.*)/ =~ line then
          version = $1.strip
          @logger.debug "Found LATEST: Puppet Enterprise Version #{version}"
        end
      end
    end
  rescue
    version = 'unknown'
  end
  return version
end

#load_pe_version_winObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/beaker/test_config.rb', line 100

def load_pe_version_win
  dist_dir = puppet_enterprise_dir
  version_file = ENV['pe_version_file'] || 'LATEST-win'
  version = ""
  begin
    open("#{dist_dir}/#{version_file}") do |file|
      while line = file.gets
        if /(\w.*)/ =~ line then
          version=$1.strip
          @logger.debug "Found LATEST: Puppet Enterprise Windows Version #{version}"
        end
      end
    end
  rescue
    version = 'unknown'
  end
  return version
end

#puppet_enterprise_dirObject



73
74
75
# File 'lib/beaker/test_config.rb', line 73

def puppet_enterprise_dir
  @pe_dir ||= ENV['pe_dist_dir'] || '/opt/enterprise/dists'
end

#puppet_enterprise_versionObject



96
97
98
# File 'lib/beaker/test_config.rb', line 96

def puppet_enterprise_version
  @pe_ver ||= load_pe_version if is_pe?
end

#puppet_enterprise_version_winObject



119
120
121
# File 'lib/beaker/test_config.rb', line 119

def puppet_enterprise_version_win
  @pe_ver_win ||= load_pe_version_win if is_pe?
end

#ssh_defaultsObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/beaker/test_config.rb', line 19

def ssh_defaults
  {
    :config                => false,
    :paranoid              => false,
    :timeout               => 300,
    :auth_methods          => ["publickey"],
    :keys                  => [@options[:keyfile]],
    :port                  => 22,
    :user_known_hosts_file => "#{ENV['HOME']}/.ssh/known_hosts",
    :forward_agent         => true
  }
end