diff options
author | Bryan McLellan <btm@loftninjas.org> | 2016-02-10 10:02:38 -0500 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2016-02-10 10:02:38 -0500 |
commit | 458d9f1e4ba44ce924347092a4bf5a6bfa84126c (patch) | |
tree | f616e324cc5245ffe8d4c95ad5592f9f06d88cb3 | |
parent | a057d4418bfb696be389419c028ad2e2e4827977 (diff) | |
parent | fc7dcb24b24be1f096f195e08a3433c39b285212 (diff) | |
download | chef-458d9f1e4ba44ce924347092a4bf5a6bfa84126c.tar.gz |
Merge pull request #4542 from chef/salam/learn-chef
Add learn-chef cookbook acceptance test
18 files changed, 171 insertions, 142 deletions
diff --git a/acceptance/.shared/kitchen_acceptance/.kitchen.ec2.yml b/acceptance/.shared/kitchen_acceptance/.kitchen.ec2.yml index fc82c907e6..e4b2211c8b 100644 --- a/acceptance/.shared/kitchen_acceptance/.kitchen.ec2.yml +++ b/acceptance/.shared/kitchen_acceptance/.kitchen.ec2.yml @@ -30,6 +30,8 @@ provisioner: product_name: <%= ENV["KITCHEN_CHEF_PRODUCT"] %> product_version: <%= ENV["KITCHEN_CHEF_VERSION"] %> channel: <%= ENV["KITCHEN_CHEF_CHANNEL"] %> + client_rb: + audit_mode: :enabled platforms: # @@ -44,7 +46,7 @@ platforms: driver: image_search: name: debian-jessie-* - owner-id: 379101102735 + owner-id: "379101102735" architecture: x86_64 virtualization-type: hvm block-device-mapping.volume-type: gp2 @@ -55,7 +57,7 @@ platforms: driver: image_search: name: debian-wheezy-* - owner-id: 379101102735 + owner-id: "379101102735" architecture: x86_64 virtualization-type: hvm block-device-mapping.volume-type: standard @@ -69,7 +71,7 @@ platforms: driver: image_search: name: ubuntu/images/*/ubuntu-*-15.10-amd64-server-* - owner-id: 099720109477 + owner-id: "099720109477" architecture: x86_64 virtualization-type: hvm block-device-mapping.volume-type: gp2 @@ -80,24 +82,24 @@ platforms: driver: image_search: name: ubuntu/images/*/ubuntu-*-14.04-*-server-* - owner-id: 099720109477 + owner-id: "099720109477" + architecture: x86_64 + virtualization-type: hvm + block-device-mapping.volume-type: gp2 + image-type: machine + transport: + username: ubuntu + - name: ubuntu-12.04 + driver: + image_search: + name: ubuntu/images/*/ubuntu-*-12.04-*-server-* + owner-id: "099720109477" architecture: x86_64 virtualization-type: hvm block-device-mapping.volume-type: gp2 image-type: machine transport: username: ubuntu - # - name: ubuntu-12.04 - # driver: - # image_search: - # name: ubuntu/images/*/ubuntu-*-12.04-*-server-* - # owner-id: 099720109477 - # architecture: x86_64 - # virtualization-type: hvm - # block-device-mapping.volume-type: gp2 - # image-type: machine - # transport: - # username: ubuntu # # Red Hat Enterprise Linux # @@ -105,7 +107,7 @@ platforms: driver: image_search: name: RHEL-7.* - owner-id: 309956199498 + owner-id: "309956199498" architecture: x86_64 virtualization-type: hvm block-device-mapping.volume-type: gp2 @@ -116,7 +118,7 @@ platforms: driver: image_search: name: RHEL-6.* - owner-id: 309956199498 + owner-id: "309956199498" architecture: x86_64 virtualization-type: hvm block-device-mapping.volume-type: gp2 @@ -127,7 +129,7 @@ platforms: driver: image_search: name: RHEL-5.* - owner-id: 309956199498 + owner-id: "309956199498" architecture: x86_64 virtualization-type: paravirtual block-device-mapping.volume-type: gp2 @@ -141,7 +143,7 @@ platforms: driver: image_search: name: FreeBSD/EC2 10.*-RELEASE* - owner-id: 118940168514 + owner-id: "118940168514" architecture: x86_64 virtualization-type: hvm block-device-mapping.volume-type: gp2 @@ -152,24 +154,24 @@ platforms: driver: image_search: name: FreeBSD/EC2 9.*-RELEASE* - owner-id: 118940168514 + owner-id: "118940168514" architecture: x86_64 virtualization-type: hvm block-device-mapping.volume-type: gp2 image-type: machine transport: username: ec2-user - # - name: freebsd-8 - # driver: - # image_search: - # name: FreeBSD/EC2 8.*-RELEASE* - # owner-id: 118940168514 - # architecture: x86_64 - # virtualization-type: hvm - # block-device-mapping.volume-type: standard - # image-type: machine - # transport: - # username: ec2-user + - name: freebsd-8 + driver: + image_search: + name: FreeBSD/EC2 8.*-RELEASE* + owner-id: "118940168514" + architecture: x86_64 + virtualization-type: hvm + block-device-mapping.volume-type: standard + image-type: machine + transport: + username: ec2-user # # OS/X # @@ -243,28 +245,28 @@ platforms: # # Centos # - # - name: centos-7 - # driver: - # image_search: - # name: CentOS Linux 7 * - # owner-alias: aws-marketplace - # architecture: x86_64 - # virtualization-type: hvm - # block-device-mapping.volume-type: standard - # image-type: machine - # transport: - # username: root - # - name: centos-6 - # driver: - # image_search: - # name: CentOS-6.5-GA-* - # owner-alias: aws-marketplace - # architecture: x86_64 - # virtualization-type: paravirtual - # block-device-mapping.volume-type: standard - # image-type: machine - # transport: - # username: root + - name: centos-7 + driver: + image_search: + name: CentOS Linux 7 * + owner-alias: aws-marketplace + architecture: x86_64 + virtualization-type: hvm + block-device-mapping.volume-type: standard + image-type: machine + transport: + username: root + - name: centos-6 + driver: + image_search: + name: CentOS-6.5-GA-* + owner-alias: aws-marketplace + architecture: x86_64 + virtualization-type: paravirtual + block-device-mapping.volume-type: standard + image-type: machine + transport: + username: root # # Fedora # @@ -272,7 +274,7 @@ platforms: driver: image_search: name: Fedora-Cloud-Base-21-* - owner-id: 125523088429 + owner-id: "125523088429" architecture: x86_64 virtualization-type: hvm block-device-mapping.volume-type: gp2 diff --git a/acceptance/.shared/kitchen_acceptance/.kitchen.vagrant.yml b/acceptance/.shared/kitchen_acceptance/.kitchen.vagrant.yml index f978658477..2cdb74a475 100644 --- a/acceptance/.shared/kitchen_acceptance/.kitchen.vagrant.yml +++ b/acceptance/.shared/kitchen_acceptance/.kitchen.vagrant.yml @@ -10,6 +10,8 @@ provisioner: product_name: <%= ENV["KITCHEN_CHEF_PRODUCT"] %> product_version: <%= ENV["KITCHEN_CHEF_VERSION"] %> channel: <%= ENV["KITCHEN_CHEF_CHANNEL"] %> + client_rb: + audit_mode: :enabled platforms: <% %w( diff --git a/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb b/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb index 5380b7002c..d3913ebb11 100644 --- a/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb +++ b/acceptance/.shared/kitchen_acceptance/libraries/kitchen.rb @@ -1,43 +1,46 @@ -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: {} + property :kitchen_options, String, default: lazy { ENV["PROJECT_NAME"] ? "-c -l debug" : "-c" } - 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}" : ""}#{kitchen_options ? " #{kitchen_options}" : ""}" 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/libraries/init.rb b/acceptance/cookbook-git/.acceptance/acceptance-cookbook/libraries/init.rb deleted file mode 100644 index 8561d6e798..0000000000 --- a/acceptance/cookbook-git/.acceptance/acceptance-cookbook/libraries/init.rb +++ /dev/null @@ -1,17 +0,0 @@ -module CookbookGit - def self.test_cookbook_name - "git" - end - - def self.test_run_path - File.join(Chef.node["chef-acceptance"]["suite-dir"], "test_run") - end - - def self.acceptance_path - File.expand_path("..", Chef.node["chef-acceptance"]["suite-dir"]) - end - - def self.acceptance_gemfile - File.join(acceptance_path, "Gemfile") - 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..5d851a6ac6 --- /dev/null +++ b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/cookbook_kitchen.rb @@ -0,0 +1,43 @@ +class CookbookKitchen < KitchenAcceptance::Kitchen + resource_name :cookbook_kitchen + + property :command, default: lazy { name.split(" ")[0] } + property :kitchen_dir, default: lazy { ::File.join(repository_root, cookbook_relative_dir) } + property :test_cookbook, String, default: lazy { name.split(" ")[1] } + property :repository, String, 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 :repository_root, String, default: lazy { ::File.join(Chef.node["chef-acceptance"]["suite-dir"], "test_run", test_cookbook) } + property :branch, String, default: "master" + property :cookbook_relative_dir, String, default: "" + 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.#{test_cookbook}.yml") + } + } + + action :run do + # Ensure the parent directory exists + directory ::File.expand_path("..", repository_root) do + recursive true + end + + # Grab the cookbook + # TODO Grab the source URL from supermarket + # TODO get git to include its kitchen tests in the cookbook. + git repository_root do + repository new_resource.repository + branch new_resource.branch + end + + super() + end +end diff --git a/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/top_cookbooks.rb b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/top_cookbooks.rb new file mode 100644 index 0000000000..d9086366da --- /dev/null +++ b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/libraries/top_cookbooks.rb @@ -0,0 +1,15 @@ +class TopCookbooks < Chef::Resource + resource_name :top_cookbooks + + property :command, String, name_property: true + + action :run do + cookbook_kitchen "#{command} git" do + end + + cookbook_kitchen "#{command} learn-the-basics-ubuntu" do + repository "learn-chef/learn-chef-acceptance" + cookbook_relative_dir "cookbooks/learn-the-basics-ubuntu" + end + end +end 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..63d10e86e4 --- /dev/null +++ b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/recipes/destroy.rb @@ -0,0 +1 @@ +top_cookbooks "destroy" 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..7b16f8e66f --- /dev/null +++ b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/recipes/provision.rb @@ -0,0 +1 @@ +top_cookbooks "converge" 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..8d00a2e301 --- /dev/null +++ b/acceptance/top-cookbooks/.acceptance/acceptance-cookbook/recipes/verify.rb @@ -0,0 +1 @@ +top_cookbooks "verify" 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.git.yml index d087446a40..8db1829d5f 100644 --- a/acceptance/cookbook-git/.kitchen.yml +++ b/acceptance/top-cookbooks/.kitchen.git.yml @@ -1,10 +1,10 @@ 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] diff --git a/acceptance/top-cookbooks/.kitchen.learn-the-basics-rhel.yml b/acceptance/top-cookbooks/.kitchen.learn-the-basics-rhel.yml new file mode 100644 index 0000000000..6b8848efae --- /dev/null +++ b/acceptance/top-cookbooks/.kitchen.learn-the-basics-rhel.yml @@ -0,0 +1,4 @@ +suites: + - name: learn-the-basics-rhel-default + run_list: ["recipe[learn-the-basics-rhel::default]"] + includes: [el-6] diff --git a/acceptance/top-cookbooks/.kitchen.learn-the-basics-ubuntu.yml b/acceptance/top-cookbooks/.kitchen.learn-the-basics-ubuntu.yml new file mode 100644 index 0000000000..b0a3e45aa3 --- /dev/null +++ b/acceptance/top-cookbooks/.kitchen.learn-the-basics-ubuntu.yml @@ -0,0 +1,4 @@ +suites: + - name: learn-the-basics-ubuntu-default + run_list: ["recipe[learn-the-basics-ubuntu::default]"] + includes: [ubuntu-14.04] |