Module: Beaker::DSL::Helpers::TKHelpers

Included in:
Beaker::DSL::Helpers
Defined in:
lib/beaker/dsl/helpers/tk_helpers.rb

Overview

Convenience methods for modifying and reading TrapperKeeper configs

Instance Method Summary collapse

Instance Method Details

#modify_tk_config(host, config_file_path, options_hash, replace = false) ⇒ Object

Note:

TrapperKeeper config files can be HOCON, JSON, or Ini. We don’t

Modify the given TrapperKeeper config file.

particularly care which of these the file named by ‘config_file_path` on the SUT actually is, just that the contents can be parsed into a map.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/beaker/dsl/helpers/tk_helpers.rb', line 28

def modify_tk_config(host, config_file_path, options_hash, replace=false)
  if options_hash.empty?
    return nil
  end

  new_hash = Beaker::Options::OptionsHash.new

  if replace
    new_hash.merge!(options_hash)
  else
    if not host.file_exist?( config_file_path )
      raise "Error: #{config_file_path} does not exist on #{host}"
    end
    file_string = host.exec( Command.new( "cat #{config_file_path}" )).stdout

    begin
      tk_conf_hash = read_tk_config_string(file_string)
    rescue RuntimeError
      raise "Error reading trapperkeeper config: #{config_file_path} at host: #{host}"
    end

    new_hash.merge!(tk_conf_hash)
    new_hash.merge!(options_hash)
  end

  file_string = JSON.pretty_generate(new_hash)
  create_remote_file host, config_file_path, file_string
end