From 606507409d281233c34276de37ca4f6eca445d79 Mon Sep 17 00:00:00 2001 From: Samuel Cassiba Date: Mon, 6 Jun 2016 18:56:20 -0700 Subject: [PATCH] Convert provisioning recipes to cookbook Allows for newer ChefDK releases. Change-Id: I6619a4852dfeb4ad0dda610b14fe097ad84db9e0 Closes-Bug: #1589764 --- .chef/knife.rb | 3 +- README.md | 4 + Rakefile | 4 +- site-cookbooks/provisioning/.gitignore | 16 +++ site-cookbooks/provisioning/.kitchen.yml | 21 ++++ site-cookbooks/provisioning/Berksfile | 3 + site-cookbooks/provisioning/README.md | 16 +++ site-cookbooks/provisioning/chefignore | 102 ++++++++++++++++++ site-cookbooks/provisioning/metadata.rb | 7 ++ .../provisioning/recipes/allinone.rb | 2 +- .../provisioning/recipes/default.rb | 17 +++ .../provisioning/recipes/multi-node.rb | 4 +- .../provisioning/recipes/vagrant_linux.rb | 0 .../provisioning/spec/spec_helper.rb | 2 + .../spec/unit/recipes/default_spec.rb | 32 ++++++ .../default/serverspec/default_spec.rb | 9 ++ .../helpers/serverspec/spec_helper.rb | 8 ++ 17 files changed, 244 insertions(+), 6 deletions(-) create mode 100644 site-cookbooks/provisioning/.gitignore create mode 100644 site-cookbooks/provisioning/.kitchen.yml create mode 100644 site-cookbooks/provisioning/Berksfile create mode 100644 site-cookbooks/provisioning/README.md create mode 100644 site-cookbooks/provisioning/chefignore create mode 100644 site-cookbooks/provisioning/metadata.rb rename allinone.rb => site-cookbooks/provisioning/recipes/allinone.rb (95%) create mode 100644 site-cookbooks/provisioning/recipes/default.rb rename multi-node.rb => site-cookbooks/provisioning/recipes/multi-node.rb (92%) rename vagrant_linux.rb => site-cookbooks/provisioning/recipes/vagrant_linux.rb (100%) create mode 100644 site-cookbooks/provisioning/spec/spec_helper.rb create mode 100644 site-cookbooks/provisioning/spec/unit/recipes/default_spec.rb create mode 100644 site-cookbooks/provisioning/test/integration/default/serverspec/default_spec.rb create mode 100644 site-cookbooks/provisioning/test/integration/helpers/serverspec/spec_helper.rb diff --git a/.chef/knife.rb b/.chef/knife.rb index d62869f..2763f76 100644 --- a/.chef/knife.rb +++ b/.chef/knife.rb @@ -11,5 +11,6 @@ validation_key "#{current_dir}/validator.pem" chef_server_url 'https://api.opscode.com/organizations/my_awesome_org' cache_type 'BasicFile' cache_options(path: "#{ENV['HOME']}/.chef/checksums") -cookbook_path ["#{current_dir}/../cookbooks"] +cookbook_path ["#{current_dir}/../cookbooks", + "#{current_dir}/../site-cookbooks"] knife[:secret_file] = "#{current_dir}/encrypted_data_bag_secret" diff --git a/README.md b/README.md index b01676b..fbdb0d9 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,10 @@ $ chef exec rake clean See the doc/tools.md for more information. +## The provisioning cookbook + +See site-cookbooks/provisioning/README.md for more information + ## Databags Some basic information about the use of databags within this repo. diff --git a/Rakefile b/Rakefile index 3f392bf..22ad406 100644 --- a/Rakefile +++ b/Rakefile @@ -39,12 +39,12 @@ end desc "All-in-One build" task :allinone => :create_key do - run_command("chef-client #{client_opts} vagrant_linux.rb allinone.rb") + run_command("chef-client #{client_opts} -o 'provisioning::vagrant_linux,provisioning::allinone'") end desc "Multi-Node build" task :multi_node => :create_key do - run_command("chef-client #{client_opts} vagrant_linux.rb multi-node.rb") + run_command("chef-client #{client_opts} -o 'provisioning::vagrant_linux,provisioning::multi-node'") end desc "Blow everything away" diff --git a/site-cookbooks/provisioning/.gitignore b/site-cookbooks/provisioning/.gitignore new file mode 100644 index 0000000..ec2a890 --- /dev/null +++ b/site-cookbooks/provisioning/.gitignore @@ -0,0 +1,16 @@ +.vagrant +Berksfile.lock +*~ +*# +.#* +\#*# +.*.sw[a-z] +*.un~ + +# Bundler +Gemfile.lock +bin/* +.bundle/* + +.kitchen/ +.kitchen.local.yml diff --git a/site-cookbooks/provisioning/.kitchen.yml b/site-cookbooks/provisioning/.kitchen.yml new file mode 100644 index 0000000..5ef99ce --- /dev/null +++ b/site-cookbooks/provisioning/.kitchen.yml @@ -0,0 +1,21 @@ +--- +driver: + name: vagrant + +provisioner: + name: chef_zero + +# Uncomment the following verifier to leverage Inspec instead of Busser (the +# default verifier) +# verifier: +# name: inspec + +platforms: + - name: ubuntu-14.04 + - name: centos-7.1 + +suites: + - name: default + run_list: + - recipe[provisioning::default] + attributes: diff --git a/site-cookbooks/provisioning/Berksfile b/site-cookbooks/provisioning/Berksfile new file mode 100644 index 0000000..34fea21 --- /dev/null +++ b/site-cookbooks/provisioning/Berksfile @@ -0,0 +1,3 @@ +source 'https://supermarket.chef.io' + +metadata diff --git a/site-cookbooks/provisioning/README.md b/site-cookbooks/provisioning/README.md new file mode 100644 index 0000000..97b2873 --- /dev/null +++ b/site-cookbooks/provisioning/README.md @@ -0,0 +1,16 @@ +# provisioning + +This cookbook is used for serving chef-provisioning recipes for provisioning +OpenStack with Chef. It is intended to be referenced by chef-client in +local-mode a la ChefDK. + +# recipes + +## provisioning::vagrant_linux +* installs/uses a Vagrant box based on Linux distribution + +## provisioning::allinone +* provisions an all-in-one OpenStack Compute Controller + +## provisioning::multi-node +* provisions an OpenStack Controller with Compute nodes diff --git a/site-cookbooks/provisioning/chefignore b/site-cookbooks/provisioning/chefignore new file mode 100644 index 0000000..a976917 --- /dev/null +++ b/site-cookbooks/provisioning/chefignore @@ -0,0 +1,102 @@ +# Put files/directories that should be ignored in this file when uploading +# to a chef-server or supermarket. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +examples/* +Guardfile +Procfile +.kitchen* +.rubocop.yml +spec/* +Rakefile +.travis.yml +.foodcritic +.codeclimate.yml + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Cookbooks # +############# +CONTRIBUTING* +CHANGELOG* +TESTING* +MAINTAINERS.toml + +# Strainer # +############ +Colanderfile +Strainerfile +.colander +.strainer + +# Vagrant # +########### +.vagrant +Vagrantfile diff --git a/site-cookbooks/provisioning/metadata.rb b/site-cookbooks/provisioning/metadata.rb new file mode 100644 index 0000000..ba5786a --- /dev/null +++ b/site-cookbooks/provisioning/metadata.rb @@ -0,0 +1,7 @@ +name 'provisioning' +maintainer 'openstack-chef' +maintainer_email 'openstack-dev@lists.openstack.org' +license 'Apache 2.0' +description 'Helper cookbook for chef-provisioning' +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +version '0.1.0' diff --git a/allinone.rb b/site-cookbooks/provisioning/recipes/allinone.rb similarity index 95% rename from allinone.rb rename to site-cookbooks/provisioning/recipes/allinone.rb index c2ed450..f5af75b 100644 --- a/allinone.rb +++ b/site-cookbooks/provisioning/recipes/allinone.rb @@ -39,6 +39,6 @@ machine 'controller' do role 'allinone' chef_environment env file('/etc/chef/openstack_data_bag_secret', - "#{File.dirname(__FILE__)}/.chef/encrypted_data_bag_secret") + "#{File.dirname(__FILE__)}/../../../../../encrypted_data_bag_secret") converge true end diff --git a/site-cookbooks/provisioning/recipes/default.rb b/site-cookbooks/provisioning/recipes/default.rb new file mode 100644 index 0000000..2fedf7f --- /dev/null +++ b/site-cookbooks/provisioning/recipes/default.rb @@ -0,0 +1,17 @@ +# +# Cookbook Name:: provisioning +# Recipe:: default +# +# Copyright 2016 openstack-chef +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/multi-node.rb b/site-cookbooks/provisioning/recipes/multi-node.rb similarity index 92% rename from multi-node.rb rename to site-cookbooks/provisioning/recipes/multi-node.rb index 1e37ea1..89353a5 100644 --- a/multi-node.rb +++ b/site-cookbooks/provisioning/recipes/multi-node.rb @@ -27,7 +27,7 @@ machine 'controller' do role 'multi-node-controller' chef_environment env file('/etc/chef/openstack_data_bag_secret', - "#{File.dirname(__FILE__)}/.chef/encrypted_data_bag_secret") + "#{File.dirname(__FILE__)}/../../../../../encrypted_data_bag_secret") converge true end @@ -51,7 +51,7 @@ end role 'multi-node-compute' chef_environment env file('/etc/chef/openstack_data_bag_secret', - "#{File.dirname(__FILE__)}/.chef/encrypted_data_bag_secret") + "#{File.dirname(__FILE__)}/../../../../../encrypted_data_bag_secret") converge true end end diff --git a/vagrant_linux.rb b/site-cookbooks/provisioning/recipes/vagrant_linux.rb similarity index 100% rename from vagrant_linux.rb rename to site-cookbooks/provisioning/recipes/vagrant_linux.rb diff --git a/site-cookbooks/provisioning/spec/spec_helper.rb b/site-cookbooks/provisioning/spec/spec_helper.rb new file mode 100644 index 0000000..1dd5126 --- /dev/null +++ b/site-cookbooks/provisioning/spec/spec_helper.rb @@ -0,0 +1,2 @@ +require 'chefspec' +require 'chefspec/berkshelf' diff --git a/site-cookbooks/provisioning/spec/unit/recipes/default_spec.rb b/site-cookbooks/provisioning/spec/unit/recipes/default_spec.rb new file mode 100644 index 0000000..a5ee450 --- /dev/null +++ b/site-cookbooks/provisioning/spec/unit/recipes/default_spec.rb @@ -0,0 +1,32 @@ +# +# Cookbook Name:: provisioning +# Spec:: default +# +# Copyright 2016 openstack-chef +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'spec_helper' + +describe 'provisioning::default' do + context 'When all attributes are default, on an unspecified platform' do + let(:chef_run) do + runner = ChefSpec::ServerRunner.new + runner.converge(described_recipe) + end + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + end +end diff --git a/site-cookbooks/provisioning/test/integration/default/serverspec/default_spec.rb b/site-cookbooks/provisioning/test/integration/default/serverspec/default_spec.rb new file mode 100644 index 0000000..0f2e85a --- /dev/null +++ b/site-cookbooks/provisioning/test/integration/default/serverspec/default_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe 'provisioning::default' do + # Serverspec examples can be found at + # http://serverspec.org/resource_types.html + it 'does something' do + skip 'Replace this with meaningful tests' + end +end diff --git a/site-cookbooks/provisioning/test/integration/helpers/serverspec/spec_helper.rb b/site-cookbooks/provisioning/test/integration/helpers/serverspec/spec_helper.rb new file mode 100644 index 0000000..c1fddf0 --- /dev/null +++ b/site-cookbooks/provisioning/test/integration/helpers/serverspec/spec_helper.rb @@ -0,0 +1,8 @@ +require 'serverspec' + +if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil? + set :backend, :exec +else + set :backend, :cmd + set :os, family: 'windows' +end