diff options
author | Salim Alam <salam@chef.io> | 2016-02-05 15:09:17 -0800 |
---|---|---|
committer | Salim Alam <salam@chef.io> | 2016-02-09 15:05:05 -0800 |
commit | b4a0661e75108b641621e687d083dad1793334a0 (patch) | |
tree | 4e514cff6debd103035069acc5b21f64c6ad52d7 /acceptance | |
parent | 7755b93c72ef33d5041b6a9c4b53bcf29814579d (diff) | |
download | chef-b4a0661e75108b641621e687d083dad1793334a0.tar.gz |
WIP: Make cookbooks infra more generic
Diffstat (limited to 'acceptance')
13 files changed, 90 insertions, 71 deletions
diff --git a/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb b/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb index 5380b7002c..e0f860851c 100644 --- a/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb +++ b/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb @@ -1,43 +1,45 @@ -class Kitchen < Chef::Resource - resource_name :kitchen +module KitchenAcceptance + class Kitchen < Chef::Resource + resource_name :kitchen - property :command, String, name_property: true - property :driver, %w(ec2 vagrant), coerce: proc { |v| v.to_s }, default: lazy { ENV["KITCHEN_DRIVER"] || :ec2 } - property :instances, String, default: lazy { ENV["KITCHEN_INSTANCES"] } - property :kitchen_dir, String, default: Chef.node['chef-acceptance']['suite-dir'] - property :chef_product, String, default: lazy { - ENV["KITCHEN_CHEF_PRODUCT"] || - # If we're running the chef or chefdk projects in jenkins, pick up the project name. - (%w(chef chefdk).include?(ENV["PROJECT_NAME"]) ? ENV["PROJECT_NAME"] : "chef") - } - property :chef_channel, String, default: lazy { - ENV["KITCHEN_CHEF_CHANNEL"] || - # Pick up current if we can't connect to artifactory - (ENV["ARTIFACTORY_USERNAME"] ? "unstable" : "current") - } - property :chef_version, String, default: lazy { - ENV["KITCHEN_CHEF_VERSION"] || - # If we're running the chef or chefdk projects in jenkins, pick up the project name. - (ENV["PROJECT_NAME"] == chef_product ? ENV["OMNIBUS_BUILD_VERSION"] : nil) || - "latest" - } - property :artifactory_username, String, default: lazy { ENV["ARTIFACTORY_USERNAME"] } - property :artifactory_password, String, default: lazy { ENV["ARTIFACTORY_PASSWORD"] } - property :env, Hash, default: {} + property :command, String, name_property: true + property :driver, %w(ec2 vagrant), coerce: proc { |v| v.to_s }, default: lazy { ENV["KITCHEN_DRIVER"] || :ec2 } + property :instances, String, default: lazy { ENV["KITCHEN_INSTANCES"] } + property :kitchen_dir, String, default: Chef.node['chef-acceptance']['suite-dir'] + property :chef_product, String, default: lazy { + ENV["KITCHEN_CHEF_PRODUCT"] || + # If we're running the chef or chefdk projects in jenkins, pick up the project name. + (%w(chef chefdk).include?(ENV["PROJECT_NAME"]) ? ENV["PROJECT_NAME"] : "chef") + } + property :chef_channel, String, default: lazy { + ENV["KITCHEN_CHEF_CHANNEL"] || + # Pick up current if we can't connect to artifactory + (ENV["ARTIFACTORY_USERNAME"] ? "unstable" : "current") + } + property :chef_version, String, default: lazy { + ENV["KITCHEN_CHEF_VERSION"] || + # If we're running the chef or chefdk projects in jenkins, pick up the project name. + (ENV["PROJECT_NAME"] == chef_product ? ENV["OMNIBUS_BUILD_VERSION"] : nil) || + "latest" + } + property :artifactory_username, String, default: lazy { ENV["ARTIFACTORY_USERNAME"] } + property :artifactory_password, String, default: lazy { ENV["ARTIFACTORY_PASSWORD"] } + property :env, Hash, default: {} - action :run do - execute "bundle exec kitchen #{command}#{instances ? " #{instances}" : ""}" do - cwd kitchen_dir - env({ - "KITCHEN_DRIVER" => driver, - "KITCHEN_INSTANCES" => instances, - "KITCHEN_LOCAL_YAML" => ::File.expand_path("../../.kitchen.#{driver}.yml", __FILE__), - "KITCHEN_CHEF_PRODUCT" => chef_product, - "KITCHEN_CHEF_CHANNEL" => chef_channel, - "KITCHEN_CHEF_VERSION" => chef_version, - "ARTIFACTORY_USERNAME" => artifactory_username, - "ARTIFACTORY_PASSWORD" => artifactory_password - }.merge(new_resource.env)) + action :run do + execute "bundle exec kitchen #{command}#{instances ? " #{instances}" : ""}" do + cwd kitchen_dir + env({ + "KITCHEN_DRIVER" => driver, + "KITCHEN_INSTANCES" => instances, + "KITCHEN_LOCAL_YAML" => ::File.expand_path("../../.kitchen.#{driver}.yml", __FILE__), + "KITCHEN_CHEF_PRODUCT" => chef_product, + "KITCHEN_CHEF_CHANNEL" => chef_channel, + "KITCHEN_CHEF_VERSION" => chef_version, + "ARTIFACTORY_USERNAME" => artifactory_username, + "ARTIFACTORY_PASSWORD" => artifactory_password + }.merge(new_resource.env)) + end end end end diff --git a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/recipes/destroy.rb b/acceptance/cookbook-git/.acceptance/acceptance-cookbook/recipes/destroy.rb deleted file mode 100644 index fce4a2f315..0000000000 --- a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/recipes/destroy.rb +++ /dev/null @@ -1,7 +0,0 @@ -# Run the test on the current platform -kitchen "destroy" do - kitchen_dir "#{CookbookGit.test_run_path}/#{CookbookGit.test_cookbook_name}" - env "BUNDLE_GEMFILE" => CookbookGit.acceptance_gemfile, - "KITCHEN_GLOBAL_YAML" => ::File.join(CookbookGit.test_run_path, CookbookGit.test_cookbook_name, ".kitchen.yml"), - "KITCHEN_YAML" => ::File.join(node["chef-acceptance"]["suite-dir"], ".kitchen.yml") -end diff --git a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/recipes/provision.rb b/acceptance/cookbook-git/.acceptance/acceptance-cookbook/recipes/provision.rb deleted file mode 100644 index 39cbafc7dd..0000000000 --- a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/recipes/provision.rb +++ /dev/null @@ -1,17 +0,0 @@ -# Grab the cookbook -directory CookbookGit.test_run_path - -# TODO Grab the source URL from supermarket -# TODO get git to include its kitchen tests in the cookbook. -git "#{CookbookGit.test_run_path}/#{CookbookGit.test_cookbook_name}" do - repository "https://github.com/jkeiser/#{CookbookGit.test_cookbook_name}.git" - branch "jk/windows-fix" -end - -# Run the test on the current platform -kitchen "converge" do - kitchen_dir "#{CookbookGit.test_run_path}/#{CookbookGit.test_cookbook_name}" - env "BUNDLE_GEMFILE" => CookbookGit.acceptance_gemfile, - "KITCHEN_GLOBAL_YAML" => ::File.join(CookbookGit.test_run_path, CookbookGit.test_cookbook_name, ".kitchen.yml"), - "KITCHEN_YAML" => ::File.join(node["chef-acceptance"]["suite-dir"], ".kitchen.yml") -end diff --git a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/recipes/verify.rb b/acceptance/cookbook-git/.acceptance/acceptance-cookbook/recipes/verify.rb deleted file mode 100644 index 84004bab3a..0000000000 --- a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/recipes/verify.rb +++ /dev/null @@ -1,6 +0,0 @@ -kitchen "verify" do - kitchen_dir "#{CookbookGit.test_run_path}/#{CookbookGit.test_cookbook_name}" - env "BUNDLE_GEMFILE" => CookbookGit.acceptance_gemfile, - "KITCHEN_GLOBAL_YAML" => ::File.join(CookbookGit.test_run_path, CookbookGit.test_cookbook_name, ".kitchen.yml"), - "KITCHEN_YAML" => ::File.join(node["chef-acceptance"]["suite-dir"], ".kitchen.yml") -end diff --git a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/.gitignore b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/.gitignore index 041413b040..041413b040 100644 --- a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/.gitignore +++ b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/.gitignore diff --git a/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/cookbook_kitchen.rb b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/cookbook_kitchen.rb new file mode 100644 index 0000000000..c2d65b4b0c --- /dev/null +++ b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/cookbook_kitchen.rb @@ -0,0 +1,41 @@ +class CookbookKitchen < KitchenAcceptance::Kitchen + resource_name :cookbook_kitchen + + property :command, default: lazy { name.split(" ")[0] } + property :test_cookbook, default: lazy { name.split(" ")[1] } + property :kitchen_dir, default: lazy { ::File.join(Chef.node["chef-acceptance"]["suite-dir"], "test_run", test_cookbook) } + property :repository, default: lazy { "chef-cookbooks/#{test_cookbook}" }, + coerce: proc { |v| + # chef-cookbooks/runit -> https://github.com/chef-cookbooks/runit.git + if !v.include?(':') + "https://github.com/#{v}.git" + else + v + end + } + property :branch, default: "master" + property :env, default: lazy { + { + "BUNDLE_GEMFILE" => ::File.expand_path("../Gemfile", Chef.node["chef-acceptance"]["suite-dir"]), + "KITCHEN_GLOBAL_YAML" => ::File.join(kitchen_dir, ".kitchen.yml"), + "KITCHEN_YAML" => ::File.join(node["chef-acceptance"]["suite-dir"], ".kitchen.yml") + } + } + + action :run do + if command == "converge" + # Ensure the parent directory exists + directory ::File.expand_path("..", kitchen_dir) + + # Grab the cookbook + # TODO Grab the source URL from supermarket + # TODO get git to include its kitchen tests in the cookbook. + git kitchen_dir do + repository new_resource.repository + branch new_resource.branch + end + end + + super() + end +end diff --git a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/libraries/init.rb b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/init.rb index 8561d6e798..8561d6e798 100644 --- a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/libraries/init.rb +++ b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/init.rb diff --git a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/metadata.rb b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/metadata.rb index 26cdab4e99..26cdab4e99 100644 --- a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/metadata.rb +++ b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/metadata.rb diff --git a/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/recipes/destroy.rb b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/recipes/destroy.rb new file mode 100644 index 0000000000..35af0e020c --- /dev/null +++ b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/recipes/destroy.rb @@ -0,0 +1 @@ +cookbook_kitchen "destroy git" diff --git a/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/recipes/provision.rb b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/recipes/provision.rb new file mode 100644 index 0000000000..8e87a548e3 --- /dev/null +++ b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/recipes/provision.rb @@ -0,0 +1,2 @@ +# Run the test on the current platform +cookbook_kitchen "converge git" diff --git a/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/recipes/verify.rb b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/recipes/verify.rb new file mode 100644 index 0000000000..ddc5d27514 --- /dev/null +++ b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/recipes/verify.rb @@ -0,0 +1 @@ +cookbook_kitchen "verify git" diff --git a/acceptance/cookbook-git/.gitignore b/acceptance/top-cookbooks/.gitignore index 306f0cce57..306f0cce57 100644 --- a/acceptance/cookbook-git/.gitignore +++ b/acceptance/top-cookbooks/.gitignore diff --git a/acceptance/cookbook-git/.kitchen.yml b/acceptance/top-cookbooks/.kitchen.yml index d087446a40..4f4e15807f 100644 --- a/acceptance/cookbook-git/.kitchen.yml +++ b/acceptance/top-cookbooks/.kitchen.yml @@ -1,10 +1,12 @@ suites: - - name: default + - name: git-default run_list: ["recipe[git]"] includes: [ubuntu-14.04] - - name: source + - name: git-source run_list: ["recipe[git::source]"] includes: [nonexistent] - - name: default-windows + - name: git-default-windows run_list: ["recipe[git]"] includes: [windows-2012r2] + # - name: learn-the-basics-windows + # includes: [windows-2012r2] |