Module: Beaker::DSL::Helpers::TKHelpers
- Included in:
- BeakerPuppet
- Defined in:
- lib/beaker-puppet/helpers/tk_helpers.rb
Overview
Convenience methods for modifying and reading TrapperKeeper configs
Instance Method Summary collapse
-
#modify_tk_config(host, config_file_path, options_hash, replace = false) ⇒ Object
Modify the given TrapperKeeper config file.
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.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/beaker-puppet/helpers/tk_helpers.rb', line 26 def modify_tk_config(host, config_file_path, , replace = false) return nil if .empty? new_hash = Beaker::Options::OptionsHash.new if replace new_hash.merge!() else raise "Error: #{config_file_path} does not exist on #{host}" unless host.file_exist?(config_file_path) 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!() end file_string = JSON.pretty_generate(new_hash) create_remote_file host, config_file_path, file_string end |