Class: Kitchen::DataMunger

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/data_munger.rb

Overview

Class to handle recursive merging of configuration between platforms, suites, and common data.

This object will mutate the data Hash passed into its constructor and so should not be reused or shared across threads.

If you are squeamish or faint of heart, then you might want to skip this class. Just remember, you were warned. And if you made it this far, be sure to tweet at @fnichol and let him know your fear factor level.

Author:

Instance Method Summary collapse

Constructor Details

#initialize(data, kitchen_config = {}) ⇒ DataMunger

Constructs a new DataMunger object.

Parameters:

  • data (Hash)

    the incoming user data hash

  • kitchen_config (Hash) (defaults to: {})

    the incoming Test Kitchen-provided configuration hash



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kitchen/data_munger.rb', line 39

def initialize(data, kitchen_config = {})
  @data = data
  @kitchen_config = kitchen_config
  convert_legacy_driver_format!
  convert_legacy_chef_paths_format!
  convert_legacy_require_chef_omnibus_format!
  convert_legacy_busser_format!
  convert_legacy_driver_http_proxy_format!
  move_chef_data_to_provisioner!
  convert_legacy_pre_create_command!
end

Instance Method Details

#driver_data_for(suite, platform) ⇒ Hash

Generate a new Hash of configuration data that can be used to construct a new Driver object.

Parameters:

  • suite (String)

    a suite name

  • platform (String)

    a platform name

Returns:

  • (Hash)

    a new configuration Hash that can be used to construct a new Driver



58
59
60
61
62
63
64
# File 'lib/kitchen/data_munger.rb', line 58

def driver_data_for(suite, platform)
  merged_data_for(:driver, suite, platform).tap do |ddata|
    set_kitchen_config_at!(ddata, :kitchen_root)
    set_kitchen_config_at!(ddata, :test_base_path)
    set_kitchen_config_at!(ddata, :log_level)
  end
end

#lifecycle_hooks_data_for(suite, platform) ⇒ Hash

Generate a new Hash of configuration data that can be used to construct a new LifecycleHooks object.

Parameters:

  • suite (String)

    a suite name

  • platform (String)

    a platform name

Returns:

  • (Hash)

    a new configuration Hash that can be used to construct a new LifecycleHooks



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/kitchen/data_munger.rb', line 73

def lifecycle_hooks_data_for(suite, platform)
  merged_data_for(:lifecycle, suite, platform).tap do |lhdata|
    lhdata.each_key do |k|
      combine_arrays!(lhdata, k, :common, :platform, :suite)
    end
    set_kitchen_config_at!(lhdata, :kitchen_root)
    set_kitchen_config_at!(lhdata, :test_base_path)
    set_kitchen_config_at!(lhdata, :log_level)
    set_kitchen_config_at!(lhdata, :debug)
  end
end

#platform_dataArray<Hash>

Returns an Array of platform Hashes.

Returns:

  • (Array<Hash>)

    an Array of Hashes



88
89
90
# File 'lib/kitchen/data_munger.rb', line 88

def platform_data
  data.fetch(:platforms, [])
end

#provisioner_data_for(suite, platform) ⇒ Hash

Generate a new Hash of configuration data that can be used to construct a new Provisioner object.

Parameters:

  • suite (String)

    a suite name

  • platform (String)

    a platform name

Returns:

  • (Hash)

    a new configuration Hash that can be used to construct a new Provisioner



99
100
101
102
103
104
105
106
# File 'lib/kitchen/data_munger.rb', line 99

def provisioner_data_for(suite, platform)
  merged_data_for(:provisioner, suite, platform).tap do |pdata|
    set_kitchen_config_at!(pdata, :kitchen_root)
    set_kitchen_config_at!(pdata, :test_base_path)
    set_kitchen_config_at!(pdata, :debug)
    combine_arrays!(pdata, :run_list, :platform, :suite)
  end
end

#suite_dataArray<Hash>

Returns an Array of suite Hashes.

Returns:

  • (Array<Hash>)

    an Array of Hashes



111
112
113
# File 'lib/kitchen/data_munger.rb', line 111

def suite_data
  data.fetch(:suites, [])
end

#transport_data_for(suite, platform) ⇒ Hash

Generate a new Hash of configuration data that can be used to construct a new Transport object.

Parameters:

  • suite (String)

    a suite name

  • platform (String)

    a platform name

Returns:

  • (Hash)

    a new configuration Hash that can be used to construct a new Transport



122
123
124
125
126
127
128
# File 'lib/kitchen/data_munger.rb', line 122

def transport_data_for(suite, platform)
  merged_data_for(:transport, suite, platform).tap do |tdata|
    set_kitchen_config_at!(tdata, :kitchen_root)
    set_kitchen_config_at!(tdata, :test_base_path)
    set_kitchen_config_at!(tdata, :log_level)
  end
end

#verifier_data_for(suite, platform) ⇒ Hash

Generate a new Hash of configuration data that can be used to construct a new Verifier object.

Parameters:

  • suite (String)

    a suite name

  • platform (String)

    a platform name

Returns:

  • (Hash)

    a new configuration Hash that can be used to construct a new Verifier



137
138
139
140
141
142
143
144
# File 'lib/kitchen/data_munger.rb', line 137

def verifier_data_for(suite, platform)
  merged_data_for(:verifier, suite, platform).tap do |vdata|
    set_kitchen_config_at!(vdata, :kitchen_root)
    set_kitchen_config_at!(vdata, :test_base_path)
    set_kitchen_config_at!(vdata, :log_level)
    set_kitchen_config_at!(vdata, :debug)
  end
end