Class: Sambot::Chef::Kitchen

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

Constant Summary collapse

LOCAL =
'.kitchen.yml'
GCP =
'.kitchen.gcp.yml'
RACKSPACE =
'.kitchen.rackspace.yml'

Class Method Summary collapse

Class Method Details

.generate_yml(cookbook_name, platforms, suites = nil) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sambot/chef/kitchen.rb', line 21

def generate_yml(cookbook_name, platforms, suites = nil)
  raise ApplicationError, 'Missing platforms when trying to generate Test-Kitchen YAML.' unless platforms
  raise ApplicationError, 'Missing cookbook name when trying to generate Test-Kitchen YAML.' unless cookbook_name
  test_kitchen_configs = {
    "#{LOCAL}": read_template(LOCAL, cookbook_name, platforms),
    "#{GCP}": read_template(GCP, cookbook_name, platforms),
    "#{RACKSPACE}": read_template(RACKSPACE, cookbook_name, platforms)
  }
  test_kitchen_configs.each do |key, value|
    if suites
      value['suites'] = Marshal.load(Marshal.dump(suites))
      case key.to_s
      when LOCAL
        add_platform_identifier(value, 'LOCAL')
      when GCP
        add_platform_identifier(value, 'GCP')
      when RACKSPACE
        add_platform_identifier(value, 'RACKSPACE')
      end
    end
    test_kitchen_configs[key] = value.to_yaml
  end
  test_kitchen_configs
end

.setup(config) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/sambot/chef/kitchen.rb', line 13

def setup(config)
  files = generate_yml(config['name'], config['platforms'], config['suites'])
  files.each do |filename, contents|
    File.write(filename.to_s, contents)
    UI.debug("#{filename.to_s} has been added to the cookbook.")
  end
end