class Sambot::Chef::Kitchen
Constants
- GENERATED_FILE
Public Class Methods
clean()
click to toggle source
# File lib/sambot/chef/kitchen.rb, line 17 def clean FS.delete(GENERATED_FILE) end
generate_yml(cloud, cookbook_name, platforms, forwarded_ports = [], suites = nil, vault_setup = nil)
click to toggle source
# File lib/sambot/chef/kitchen.rb, line 21 def generate_yml(cloud, cookbook_name, platforms, forwarded_ports = [], suites = nil, vault_setup = 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 template = read_template(cloud, cookbook_name, platforms, vault_setup, forwarded_ports) if suites template['suites'] = Marshal.load(Marshal.dump(suites)) add_platform_identifier(template, cloud) end template.to_yaml end
setup(cloud, config, vault_setup)
click to toggle source
# File lib/sambot/chef/kitchen.rb, line 11 def setup(cloud, config, vault_setup) contents = generate_yml(cloud, config.name, config.available_platforms, config.forwarded_ports, config.suites, vault_setup) File.write(GENERATED_FILE, contents) UI.debug("#{GENERATED_FILE} has been added to the cookbook.") end
Private Class Methods
add_platform_identifier(value, platform)
click to toggle source
Adds attributes to each test suite that is only applicable to testing environments. These are things like controlling how Vault token renewal works and specifying the cloud platform.
# File lib/sambot/chef/kitchen.rb, line 37 def add_platform_identifier(value, platform) value['suites'].each do |suite| suite['run_list'] = handle_customized_runlists(suite, platform) # Changes to <platform> below to keep compatibility with existing cookbooks platform = 'LOCAL' if platform == 'local' platform = 'GCP' if platform == 'google' platform = 'RACKSPACE' if platform == 'rackspace' suite['attributes'] = suite['attributes'] || {} suite['attributes']['cloud_platform'] = platform suite['attributes']['vault'] = suite['attributes']['vault'] || {} suite['attributes']['vault']['exec_renew'] = suite['attributes']['vault']['exec_renew'] || false end end
handle_customized_runlists(config, platform)
click to toggle source
Provides the ability to have a different run-list for different clouds. This only works for the 'local' cloud and the 'dev' clouds i.e. Rackspace and Google.
# File lib/sambot/chef/kitchen.rb, line 54 def handle_customized_runlists(config, platform) runlist = config['run_list'] return runlist if runlist.is_a?(Array) platform == 'local' ? runlist['local'] : runlist['dev'] end
read_template(cloud, cookbook_name, platforms, vault_setup, forwarded_ports)
click to toggle source
# File lib/sambot/chef/kitchen.rb, line 60 def read_template(cloud, cookbook_name, platforms, vault_setup, forwarded_ports) ctx = { platforms: platforms, name: cookbook_name, vault_setup: vault_setup, forwarded_ports: forwarded_ports } result = Template.new("test_kitchen/#{cloud}.yml.erb").evaluate(ctx, pattern: '<!--% %-->') YAML.safe_load(result) end