From 959b9a103620ce8a63988368d12912850df47b56 Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Fri, 6 Jan 2017 16:55:27 -0600 Subject: [PATCH] Chef 12 migration (#59) * fix deprecation warning, using allow instead of should_receive * chef 12 migration * updating from skeleton for tests * updating for cookstyle * removing berksfile.lock * adding .travis_install.sh * removing centos7.0 * removing apt * updating ruby-version * updating rakefile and travis * pinning Berksfile.lock * updating readme to chef12 --- .gitignore | 9 +- .kitchen.yml | 50 ++-- .rspec | 2 + .rubocop.yml | 13 ++ .ruby-version | 1 + .travis.yml | 14 +- .travis_install.sh | 8 + Berksfile | 4 +- Berksfile.lock | 12 + CHANGELOG.md | 8 +- Gemfile | 17 +- Gemfile.lock | 264 ++++++++++++++++++++++ README.md | 2 +- Rakefile | 113 +++++++++ Strainerfile | 4 - Thorfile | 14 -- Vagrantfile | 20 +- attributes/default.rb | 10 +- libraries/helper.rb | 22 +- metadata.rb | 96 ++++---- recipes/default.rb | 15 +- spec/ephemeral_lvm_helper_spec.rb | 33 +-- spec/spec_helper.rb | 33 +++ test/cookbooks/fake/attributes/default.rb | 2 +- test/cookbooks/fake/libraries/helper.rb | 2 +- test/cookbooks/fake/metadata.rb | 1 - test/cookbooks/fake/recipes/default.rb | 2 +- test/cookbooks/fake/recipes/gce.rb | 4 +- 28 files changed, 597 insertions(+), 178 deletions(-) create mode 100644 .rspec create mode 100644 .rubocop.yml create mode 100644 .ruby-version create mode 100755 .travis_install.sh create mode 100644 Berksfile.lock create mode 100644 Gemfile.lock create mode 100644 Rakefile delete mode 100644 Strainerfile delete mode 100644 Thorfile create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore index cfc7252..6ea4fbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .vagrant -Berksfile.lock *~ *# .#* @@ -7,6 +6,7 @@ Berksfile.lock .*.sw[a-z] *.un~ /cookbooks +cache_dir # Bundler Gemfile.lock @@ -16,3 +16,10 @@ bin/* VERSION .kitchen/ .kitchen.local.yml + +doc/ +.yardoc/ +berks-cookbooks/ +knife.rb +syntaxcache/ +coverage/ diff --git a/.kitchen.yml b/.kitchen.yml index 5c35e8e..54885ab 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,50 +1,36 @@ --- driver_plugin: vagrant driver_config: - require_chef_omnibus: 11.6.0 + customize: + cpus: 1 + memory: 512 + ssh: + insert_key: false + +provisioner: + name: chef_zero + always_update_cookbooks: true + require_chef_omnibus: 12.16.42 platforms: -- name: centos-5.9 - driver_config: - box: opscode-centos-5.9 -- name: centos-6.5 - driver_config: - box: opscode-centos-6.5 -- name: centos-7.0 - driver_config: - box: opscode-centos-7.0 - attributes: - ephemeral_lvm: - filesystem: xfs -- name: centos-7.1 - driver_config: - box: opscode-centos-7.1 - attributes: - ephemeral_lvm: - filesystem: xfs -- name: debian-7.2.0 - driver_config: - box: opscode-debian-7.2.0 -- name: rhel-6.5 +- name: centos-6.8 driver_config: - box: local-rhel-6.5 - box_url: file://<%= File.expand_path('~') %>/opscode_rhel-6.5_chef-provisionerless.box -- name: rhel-7.1 + box: bento/centos-6.8 +- name: centos-7.2 driver_config: - box: opscode-rhel-7.1 - box_url: https://s3.amazonaws.com/st-vagrant-boxes/opscode_rhel-7.1_chef-provisionerless.box + box: bento/centos-7.2 attributes: ephemeral_lvm: filesystem: xfs -- name: ubuntu-10.04 +- name: debian-7.11 driver_config: - box: opscode-ubuntu-10.04 + box: bento/debian-7.11 - name: ubuntu-12.04 driver_config: - box: opscode-ubuntu-12.04 + box: bento/ubuntu-12.04 - name: ubuntu-14.04 driver_config: - box: opscode-ubuntu-14.04 + box: bento/ubuntu-14.04 suites: # This test suite mimics the behavior of being in a cloud which supports block device mapping diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..16f9cdb --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..c6f3c49 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,13 @@ +AllCops: + Exclude: + - 'berks-cookbooks/**/*' + - 'knife.rb' +Style/AccessorMethodName: + Exclude: + - 'Rakefile' +Metrics/BlockNesting: + Exclude: + - 'libraries/helper.rb' +Style/GuardClause: + Exclude: + - 'test/cookbooks/fake/recipes/gce.rb' diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..2bf1c1c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.3.1 diff --git a/.travis.yml b/.travis.yml index 859f325..9a8ed6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,13 @@ language: ruby rvm: -- 2.0.0 -- 1.9.3 -before_script: bundle exec berks install -script: bundle exec strainer test --except kitchen +- 2.3.1 +before_install: +- curl -L https://www.getchef.com/chef/install.sh | sudo bash -s -- -P chefdk -v 1.0.3 +- gem install bundler -v 1.11.2 +install: +- chef exec bundle install --jobs=3 --retry=3 +before_script: chef exec rake setup_test_environment +script: "./.travis_install.sh" notifications: slack: - secure: SqcVb40KzZcnESU9VKcUWpEmrPUamdrgqfmBAfndtHkGP4Pg3sESgPbZdY3CFsHtzjXV6I9LU+1b9YU3IXcKTos/+Eky5QixBxGwS2lq7yMB+FWHbi4FLvf9KaYx3lMwMuBzEmnJxMhbE7VX6rQk/FayR+0Og7g/InQKRVMJlMc= + secure: Nhz+yIbiEFxLUQqHe0EisN/r7gGSFfqm16eRRsCI9mMUiN6J9ao6/N6kE/YGcShDUO/rG1wvf0j9HEDE10kefQpVV1bp9AdDQfgYZJtYiV41xg3eJYquQcVRL96Fl7Td3gtazvGG6xwxjrZMFHz9tX1LTAD1/YWFUHn/NvdRB/Y= diff --git a/.travis_install.sh b/.travis_install.sh new file mode 100755 index 0000000..4564cce --- /dev/null +++ b/.travis_install.sh @@ -0,0 +1,8 @@ +set -ev +if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then + git clone https://github.com/$TRAVIS_REPO_SLUG.git $TRAVIS_REPO_SLUG + cd $TRAVIS_REPO_SLUG + git checkout master + git checkout -qf $TRAVIS_COMMIT +fi +chef exec rake except_kitchen diff --git a/Berksfile b/Berksfile index 5820c8c..38d3321 100644 --- a/Berksfile +++ b/Berksfile @@ -1,5 +1,5 @@ -site :opscode +source 'https://supermarket.chef.io' metadata -cookbook "fake", path: "./test/cookbooks/fake", group: :integration +cookbook 'fake', path: './test/cookbooks/fake', group: :integration diff --git a/Berksfile.lock b/Berksfile.lock new file mode 100644 index 0000000..55f4f7c --- /dev/null +++ b/Berksfile.lock @@ -0,0 +1,12 @@ +DEPENDENCIES + ephemeral_lvm + path: . + metadata: true + fake + path: test/cookbooks/fake + +GRAPH + ephemeral_lvm (2.0.0) + lvm (~> 3.1) + fake (0.1.0) + lvm (3.1.0) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c4d9ce..7ce7b27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ ephemeral_lvm Cookbook CHANGELOG This file is used to list changes made in each version of the ephemeral_lvm cookbook. +v2.0.0 +------- + +- Add support for chef 12 +- Remove support for chef 11 + v1.0.17 ------- @@ -110,4 +116,4 @@ v1.0.0 [#54]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/54 [@autrejacoupa]: https://github.com/autrejacoupa [@drywheat]: https://github.com/drywheat -[@juliandunn]: https://github.com/juliandunn \ No newline at end of file +[@juliandunn]: https://github.com/juliandunn diff --git a/Gemfile b/Gemfile index 40a2bcc..9ed36e1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,20 +1,7 @@ source 'https://rubygems.org' -gem 'berkshelf' -gem 'thor-foodcritic' -gem 'thor-scmversion' -gem 'rack', '= 1.6.4' -gem 'json', '~> 1.8', '>= 1.8.3' -gem 'buff-ignore', '~> 1.1.1' -gem 'net-http-persistent', '= 2.9.4' - +gem 'rake' +gem 'chef', '~> 12.16' group :integration do - gem 'test-kitchen', '~> 1.2.1' - gem 'kitchen-vagrant' -end - -group :test do - gem 'chefspec', '~> 3.4.0' - gem 'strainer', '~> 3.3.0' end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..98180eb --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,264 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.5.0) + public_suffix (~> 2.0, >= 2.0.2) + artifactory (2.5.1) + berkshelf (5.2.0) + addressable (~> 2.3, >= 2.3.4) + berkshelf-api-client (>= 2.0.2, < 4.0) + buff-config (~> 2.0) + buff-extensions (~> 2.0) + buff-shell_out (~> 1.0) + cleanroom (~> 1.0) + faraday (~> 0.9) + httpclient (~> 2.7) + minitar (~> 0.5, >= 0.5.4) + mixlib-archive (~> 0.1) + octokit (~> 4.0) + retryable (~> 2.0) + ridley (~> 5.0) + solve (> 2.0, < 4.0) + thor (~> 0.19) + berkshelf-api-client (3.0.0) + faraday (~> 0.9) + httpclient (~> 2.7) + ridley (>= 4.5, < 6.0) + buff-config (2.0.0) + buff-extensions (~> 2.0) + varia_model (~> 0.6) + buff-extensions (2.0.0) + buff-ignore (1.2.0) + buff-ruby_engine (1.0.0) + buff-shell_out (1.1.0) + buff-ruby_engine (~> 1.0) + builder (3.2.2) + celluloid (0.16.0) + timers (~> 4.0.0) + celluloid-io (0.16.2) + celluloid (>= 0.16.0) + nio4r (>= 1.1.0) + chef (12.16.42) + addressable + bundler (>= 1.10) + chef-config (= 12.16.42) + chef-zero (>= 4.8) + diff-lcs (~> 1.2, >= 1.2.4) + erubis (~> 2.7) + ffi-yajl (~> 2.2) + highline (~> 1.6, >= 1.6.9) + iniparse (~> 1.4) + mixlib-archive (>= 0.2.0) + mixlib-authentication (~> 1.4) + mixlib-cli (~> 1.7) + mixlib-log (~> 1.3) + mixlib-shellout (~> 2.0) + net-sftp (~> 2.1, >= 2.1.2) + net-ssh (>= 2.9, < 4.0) + net-ssh-multi (~> 1.1) + ohai (>= 8.6.0.alpha.1, < 9) + plist (~> 3.2) + proxifier (~> 1.0) + rspec-core (~> 3.5) + rspec-expectations (~> 3.5) + rspec-mocks (~> 3.5) + rspec_junit_formatter (~> 0.2.0) + serverspec (~> 2.7) + specinfra (~> 2.10) + syslog-logger (~> 1.6) + uuidtools (~> 2.1.5) + chef-config (12.16.42) + addressable + fuzzyurl + mixlib-config (~> 2.0) + mixlib-shellout (~> 2.0) + chef-zero (5.1.0) + ffi-yajl (~> 2.2) + hashie (>= 2.0, < 4.0) + mixlib-log (~> 1.3) + rack (~> 2.0) + uuidtools (~> 2.1) + chefspec (5.3.0) + chef (>= 12.0) + fauxhai (~> 3.6) + rspec (~> 3.0) + cleanroom (1.0.0) + diff-lcs (1.2.5) + erubis (2.7.0) + faraday (0.9.2) + multipart-post (>= 1.2, < 3) + fauxhai (3.10.0) + net-ssh + ffi (1.9.14) + ffi-yajl (2.3.0) + libyajl2 (~> 1.2) + foodcritic (3.0.3) + erubis + gherkin (~> 2.11.7) + nokogiri (~> 1.5.4) + rake + treetop (~> 1.4.10) + yajl-ruby (~> 1.1.0) + fuzzyurl (0.9.0) + gherkin (2.11.8) + multi_json (~> 1.3) + hashie (3.4.6) + highline (1.7.8) + hitimes (1.2.4) + httpclient (2.8.2.4) + iniparse (1.4.2) + ipaddress (0.8.3) + json (2.0.2) + kitchen-vagrant (0.21.1) + test-kitchen (~> 1.4) + libyajl2 (1.2.0) + minitar (0.5.4) + mixlib-archive (0.2.0) + mixlib-log + mixlib-authentication (1.4.1) + mixlib-log + mixlib-cli (1.7.0) + mixlib-config (2.2.4) + mixlib-install (2.1.8) + artifactory + mixlib-shellout + mixlib-versioning + thor + mixlib-log (1.7.1) + mixlib-shellout (2.2.7) + mixlib-versioning (1.1.0) + molinillo (0.5.4) + multi_json (1.12.1) + multipart-post (2.0.0) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-sftp (2.1.2) + net-ssh (>= 2.6.5) + net-ssh (3.2.0) + net-ssh-gateway (1.2.0) + net-ssh (>= 2.6.5) + net-ssh-multi (1.2.1) + net-ssh (>= 2.6.5) + net-ssh-gateway (>= 1.2.0) + net-telnet (0.1.1) + nio4r (1.2.1) + nokogiri (1.5.11) + octokit (4.6.2) + sawyer (~> 0.8.0, >= 0.5.3) + ohai (8.22.0) + chef-config (>= 12.5.0.alpha.1, < 13) + ffi (~> 1.9) + ffi-yajl (~> 2.2) + ipaddress + mixlib-cli + mixlib-config (~> 2.0) + mixlib-log (>= 1.7.1, < 2.0) + mixlib-shellout (~> 2.0) + plist (~> 3.1) + systemu (~> 2.6.4) + wmi-lite (~> 1.0) + plist (3.2.0) + polyglot (0.3.5) + proxifier (1.0.3) + public_suffix (2.0.4) + rack (2.0.1) + rake (12.0.0) + retryable (2.0.4) + ridley (5.1.0) + addressable + buff-config (~> 2.0) + buff-extensions (~> 2.0) + buff-ignore (~> 1.2) + buff-shell_out (~> 1.0) + celluloid (~> 0.16.0) + celluloid-io (~> 0.16.1) + chef-config (>= 12.5.0) + erubis + faraday (~> 0.9.0) + hashie (>= 2.0.2, < 4.0.0) + httpclient (~> 2.7) + json (>= 1.7.7) + mixlib-authentication (>= 1.3.0) + retryable (~> 2.0) + semverse (~> 2.0) + varia_model (~> 0.6) + rspec (3.5.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) + rspec-core (3.5.4) + rspec-support (~> 3.5.0) + rspec-expectations (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-its (1.2.0) + rspec-core (>= 3.0.0) + rspec-expectations (>= 3.0.0) + rspec-mocks (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-support (3.5.0) + rspec_junit_formatter (0.2.3) + builder (< 4) + rspec-core (>= 2, < 4, != 2.12.0) + safe_yaml (1.0.4) + sawyer (0.8.1) + addressable (>= 2.3.5, < 2.6) + faraday (~> 0.8, < 1.0) + semverse (2.0.0) + serverspec (2.37.2) + multi_json + rspec (~> 3.0) + rspec-its + specinfra (~> 2.53) + sfl (2.3) + solve (3.1.0) + molinillo (>= 0.5) + semverse (>= 1.1, < 3.0) + specinfra (2.66.2) + net-scp + net-ssh (>= 2.7, < 4.0) + net-telnet + sfl + syslog-logger (1.6.8) + systemu (2.6.5) + test-kitchen (1.14.0) + mixlib-install (>= 1.2, < 3.0) + mixlib-shellout (>= 1.2, < 3.0) + net-scp (~> 1.1) + net-ssh (>= 2.9, < 4.0) + net-ssh-gateway (~> 1.2.0) + safe_yaml (~> 1.0) + thor (~> 0.18) + thor (0.19.4) + thor-foodcritic (1.1.0) + foodcritic (~> 3.0) + thor + thor-scmversion (1.7.0) + mixlib-shellout + thor + timers (4.0.4) + hitimes + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + uuidtools (2.1.5) + varia_model (0.6.0) + buff-extensions (~> 2.0) + hashie (>= 2.0.2, < 4.0.0) + wmi-lite (1.0.0) + yajl-ruby (1.1.0) + +PLATFORMS + ruby + +DEPENDENCIES + berkshelf + chefspec (~> 5.0) + kitchen-vagrant + test-kitchen + thor-foodcritic + thor-scmversion + +BUNDLED WITH + 1.12.5 diff --git a/README.md b/README.md index 10364b8..daac670 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Github Repository: [https://github.com/rightscale-cookbooks/ephemeral_lvm](https # Requirements -* Chef 11 or higher +* Chef 12 or higher * A cloud that supports ephemeral devices. Currently supported clouds: EC2, Openstack, and Google. * Cookbook requirements * [lvm](http://community.opscode.com/cookbooks/lvm) diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..e0fbcd0 --- /dev/null +++ b/Rakefile @@ -0,0 +1,113 @@ +require 'rspec/core/rake_task' +require 'foodcritic' +require 'kitchen' + +directory = File.expand_path(File.dirname(__FILE__)) + +desc 'Sets up knife, and vendors cookbooks' +task :setup_test_environment do + File.open('knife.rb', 'w+') do |file| + file.write <<-EOF + log_level :debug + log_location STDOUT + cookbook_path ['.', 'berks-cookbooks/' ] + EOF + end + sh('berks vendor') +end + +desc 'verifies version and changelog' +task :verify_version do + def old_version? + f = `git show master:metadata.rb` + f.each_line do |line| + if line =~ /^version/ + _k, v = line.strip.split + @old_version = v + end + end + @old_version + end + + def new_version? + f = File.read('metadata.rb') + f.each_line do |line| + if line =~ /^version/ + _k, v = line.strip.split + @new_version = v + end + end + @new_version + end + + if `git rev-parse --abbrev-ref HEAD`.strip != ('master' && 'HEAD') + old_version = old_version?.tr('\'', '') + new_version = new_version?.tr('\'', '') + puts "Verifying Metdata Version - Old:#{old_version}, New:#{new_version}" + if old_version == new_version + raise 'You need to increment version before test will pass' + end + + puts "Verifying Changelog Contains Version #{new_version}" + counter = 0 + f = File.read('CHANGELOG.md') + f.each_line do |line| + counter += 1 if line.match new_version + end + raise 'CHANGELOG update needed' if counter == 0 + end +end + +desc 'runs cookstyle' +task cookstyle: [:setup_test_environment] do + cmd = 'chef exec cookstyle -D --format offenses --display-cop-names' + puts cmd + sh(cmd) +end + +desc 'runs foodcritic' +task :foodcritic do + cmd = "chef exec foodcritic --epic-fail any #{directory}" + puts cmd + sh(cmd) +end + +desc 'runs foodcritic linttask' +task :fc_new do + FoodCritic::Rake::LintTask.new(:chef) do |t| + t.options = { + fail_tags: ['any'] + } + end +end + +desc 'runs rspec' +task :rspec do + cmd = 'chef exec rspec --color --format documentation' + puts cmd + sh(cmd) +end + +desc 'runs testkitchen' +task :kitchen do + cmd = 'chef exec kitchen test --concurrency=2' + puts cmd + sh(cmd) +end + +desc 'clean up test files' +task :clean do + cmd = 'rm -fr berks-cookbooks knife.rb' + puts cmd + sh(cmd) +end + +desc 'runs all tests except kitchen' +task except_kitchen: [:verify_version, :cookstyle, :foodcritic, :rspec] do + puts 'running all tests except kitchen' +end + +desc 'runs all tests' +task all: [:except_kitchen, :kitchen] do + puts 'running all tests' +end diff --git a/Strainerfile b/Strainerfile deleted file mode 100644 index dd7d528..0000000 --- a/Strainerfile +++ /dev/null @@ -1,4 +0,0 @@ -knife: bundle exec knife cookbook test $COOKBOOK -foodcritic: bundle exec foodcritic --epic-fail any $SANDBOX/$COOKBOOK -rspec: bundle exec rspec --color --format documentation -kitchen: bundle exec kitchen test --concurrency=4 diff --git a/Thorfile b/Thorfile deleted file mode 100644 index 46b5ae4..0000000 --- a/Thorfile +++ /dev/null @@ -1,14 +0,0 @@ -# encoding: utf-8 - -require 'bundler' -require 'bundler/setup' -require 'thor/foodcritic' -require 'thor/scmversion' -require 'berkshelf/thor' - -begin - require 'kitchen/thor_tasks' - Kitchen::ThorTasks.new -rescue LoadError - puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI'] -end diff --git a/Vagrantfile b/Vagrantfile index 6c2d8fa..814837b 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,25 +1,25 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -Vagrant.configure("2") do |config| +Vagrant.configure('2') do |config| # All Vagrant configuration is done here. The most common configuration # options are documented and commented below. For a complete reference, # please see the online documentation at vagrantup.com. - config.vm.hostname = "ephemeral-lvm-berkshelf" + config.vm.hostname = 'ephemeral-lvm-berkshelf' # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = "opscode-ubuntu-12.04" + config.vm.box = 'opscode-ubuntu-12.04' # The url from where the 'config.vm.box' box will be fetched if it # doesn't already exist on the user's system. - config.vm.box_url = "https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box" + config.vm.box_url = 'https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box' # Assign this VM to a host-only network IP, allowing you to access it # via the IP. Host-only networks can talk to the host machine as well as # any other machines on the same network, but cannot be accessed (through this # network interface) by any external networks. - config.vm.network :private_network, ip: "33.33.33.10" + config.vm.network :private_network, ip: '33.33.33.10' # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on @@ -74,15 +74,15 @@ Vagrant.configure("2") do |config| config.vm.provision :chef_solo do |chef| chef.json = { - :mysql => { - :server_root_password => 'rootpass', - :server_debian_password => 'debpass', - :server_repl_password => 'replpass' + mysql: { + server_root_password: 'rootpass', + server_debian_password: 'debpass', + server_repl_password: 'replpass' } } chef.run_list = [ - "recipe[ephemeral_lvm::default]" + 'recipe[ephemeral_lvm::default]' ] end end diff --git a/attributes/default.rb b/attributes/default.rb index fdd4eae..8a1fbfe 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -23,22 +23,22 @@ node['platform_family'] == 'rhel' && node['platform_version'] =~ /^7\./ ? 'xfs' : 'ext4' # The ephemeral mount point -default['ephemeral_lvm']['mount_point'] = "/mnt/ephemeral" +default['ephemeral_lvm']['mount_point'] = '/mnt/ephemeral' # The ephemeral mount point options default['ephemeral_lvm']['mount_point_properties'] = { - options: ["defaults", "noauto"], + options: %w(defaults noauto), pass: 0 } # The ephemeral volume group name -default['ephemeral_lvm']['volume_group_name'] = "vg-data" +default['ephemeral_lvm']['volume_group_name'] = 'vg-data' # The logical volume size of the ephemeral disk -default['ephemeral_lvm']['logical_volume_size'] = "100%VG" +default['ephemeral_lvm']['logical_volume_size'] = '100%VG' # The ephemeral logical volume name -default['ephemeral_lvm']['logical_volume_name'] = "ephemeral0" +default['ephemeral_lvm']['logical_volume_name'] = 'ephemeral0' # The stripe size in kilobytes to be used if more than one ephemeral disk is found default['ephemeral_lvm']['stripe_size'] = 512 diff --git a/libraries/helper.rb b/libraries/helper.rb index a742551..e0251ee 100644 --- a/libraries/helper.rb +++ b/libraries/helper.rb @@ -36,8 +36,8 @@ def self.get_ephemeral_devices(cloud, node) # if node[cloud].keys.any? { |key| key.match(/^block_device_mapping_ephemeral\d+$/) } ephemeral_devices = node[cloud].map do |key, device| - if key.match(/^block_device_mapping_ephemeral\d+$/) - device.match(/\/dev\//) ? device : "/dev/#{device}" + if key =~ /^block_device_mapping_ephemeral\d+$/ + device =~ %r{\/dev\/} ? device : "/dev/#{device}" end end @@ -45,7 +45,7 @@ def self.get_ephemeral_devices(cloud, node) ephemeral_devices.compact! # Servers running on Xen hypervisor require the block device to be in /dev/xvdX instead of /dev/sdX - if node.attribute?('virtualization') && node['virtualization']['system'] == "xen" + if node.attribute?('virtualization') && node['virtualization']['system'] == 'xen' Chef::Log.info "Mapping for devices: #{ephemeral_devices.inspect}" ephemeral_devices = EphemeralLvm::Helper.fix_device_mapping( ephemeral_devices, @@ -63,21 +63,21 @@ def self.get_ephemeral_devices(cloud, node) # https://developers.google.com/compute/docs/disks#scratchdisks for more information. # ephemeral_devices = node[cloud]['attached_disks']['disks'].map do |disk| - if disk['type'] == "EPHEMERAL" && disk['deviceName'].match(/^local-ssd-\d+$/) - "/dev/disk/by-id/google-#{disk["deviceName"]}" + if disk['type'] == 'EPHEMERAL' && disk['deviceName'].match(/^local-ssd-\d+$/) + "/dev/disk/by-id/google-#{disk['deviceName']}" end end unless node[cloud]['attached_disks'].nil? ephemeral_devices = node[cloud]['instance']['disks'].map do |disk| - if disk['type'] == "LOCAL-SSD" && disk['deviceName'].match(/^local-ssd-\d+$/) - "/dev/disk/by-id/google-#{disk["deviceName"]}" + if disk['type'] == 'LOCAL-SSD' && disk['deviceName'].match(/^local-ssd-\d+$/) + "/dev/disk/by-id/google-#{disk['deviceName']}" end end unless node[cloud]['instance'].nil? # Removes nil elements from the ephemeral_devices array if any. ephemeral_devices.compact! else - Chef::Log.info "No ephemeral disks found." + Chef::Log.info 'No ephemeral disks found.' end end ephemeral_devices @@ -94,11 +94,11 @@ def self.get_ephemeral_devices(cloud, node) # def self.fix_device_mapping(devices, node_block_devices) devices.map! do |device| - if node_block_devices.include?(device.match(/\/dev\/(.+)$/)[1]) + if node_block_devices.include?(device.match(%{\/dev\/(.+)$})[1]) device else - fixed_device = device.sub("/sd", "/xvd") - if node_block_devices.include?(fixed_device.match(/\/dev\/(.+)$/)[1]) + fixed_device = device.sub('/sd', '/xvd') + if node_block_devices.include?(fixed_device.match(%{\/dev\/(.+)$})[1]) fixed_device else Chef::Log.warn "could not find ephemeral device: #{device}" diff --git a/metadata.rb b/metadata.rb index 846c11a..a0b4c52 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,63 +4,65 @@ license 'Apache 2.0' description 'Configures available ephemeral devices on a cloud server' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.0.17' +version '2.0.0' +issues_url 'https://github.com/rightscale-cookbooks/ephemeral_lvm/issues' if respond_to?(:issues_url) +source_url 'https://github.com/rightscale-cookbooks/ephemeral_lvm' if respond_to?(:source_url) +chef_version '>= 12.0' if respond_to?(:chef_version) supports 'ubuntu' supports 'centos' supports 'debian' -depends 'lvm', '>= 2.1.2' +depends 'lvm', '~> 3.1' -recipe "ephemeral_lvm::default", "Sets up ephemeral devices on a cloud server" +recipe 'ephemeral_lvm::default', 'Sets up ephemeral devices on a cloud server' -attribute "ephemeral_lvm/filesystem", - :display_name => "Ephemeral LVM Filesystem", - :description => - "The filesystem to be used on the ephemeral volume." + - " Defaults are based on OS and determined in attributes/defaults.rb.", - :recipes => ["ephemeral_lvm::default"], - :required => "recommended" +attribute 'ephemeral_lvm/filesystem', + display_name: 'Ephemeral LVM Filesystem', + description: 'The filesystem to be used on the ephemeral volume.' \ + ' Defaults are based on OS and determined in attributes/defaults.rb.', + recipes: ['ephemeral_lvm::default'], + required: 'recommended' -attribute "ephemeral_lvm/mount_point", - :display_name => "Ephemeral LVM Mount Point", - :description => "The mount point for the ephemeral volume", - :default => "/mnt/ephemeral", - :recipes => ["ephemeral_lvm::default"], - :required => "recommended" +attribute 'ephemeral_lvm/mount_point', + display_name: 'Ephemeral LVM Mount Point', + description: 'The mount point for the ephemeral volume', + default: '/mnt/ephemeral', + recipes: ['ephemeral_lvm::default'], + required: 'recommended' -attribute "ephemeral_lvm/mount_point_properties", - :display_name => "Ephemeral LVM Mount Properties", - :description => "The options used when mounting the ephemeral volume", - :type => "hash", - :default => {:options => ["defaults", "noauto"], :pass => 0}, - :recipes => ["ephemeral_lvm::default"], - :required => "optional" +attribute 'ephemeral_lvm/mount_point_properties', + display_name: 'Ephemeral LVM Mount Properties', + description: 'The options used when mounting the ephemeral volume', + type: 'hash', + default: { options: %w(defaults noauto), pass: 0 }, + recipes: ['ephemeral_lvm::default'], + required: 'optional' -attribute "ephemeral_lvm/volume_group_name", - :display_name => "Ephemeral LVM Volume Group Name", - :description => "The volume group name for the ephemeral LVM", - :default => "vg-data", - :recipes => ["ephemeral_lvm::default"], - :required => "optional" +attribute 'ephemeral_lvm/volume_group_name', + display_name: 'Ephemeral LVM Volume Group Name', + description: 'The volume group name for the ephemeral LVM', + default: 'vg-data', + recipes: ['ephemeral_lvm::default'], + required: 'optional' -attribute "ephemeral_lvm/logical_volume_size", - :display_name => "Ephemeral LVM Logical Volume Size", - :description => "The size to be used for the ephemeral LVM. Syntax for 'lvcreate --extents' flag is used", - :default => "100%VG", - :recipes => ["ephemeral_lvm::default"], - :required => "optional" +attribute 'ephemeral_lvm/logical_volume_size', + display_name: 'Ephemeral LVM Logical Volume Size', + description: "The size to be used for the ephemeral LVM. Syntax for 'lvcreate --extents' flag is used", + default: '100%VG', + recipes: ['ephemeral_lvm::default'], + required: 'optional' -attribute "ephemeral_lvm/logical_volume_name", - :display_name => "Ephemeral LVM Logical Volume Name", - :description => "The name of the logical volume for ephemeral LVM", - :default => "ephemeral0", - :recipes => ["ephemeral_lvm::default"], - :required => "optional" +attribute 'ephemeral_lvm/logical_volume_name', + display_name: 'Ephemeral LVM Logical Volume Name', + description: 'The name of the logical volume for ephemeral LVM', + default: 'ephemeral0', + recipes: ['ephemeral_lvm::default'], + required: 'optional' -attribute "ephemeral_lvm/stripe_size", - :display_name => "Ephemeral LVM Stripe Size", - :description => "The stripe size to be used for the ephemeral logical volume", - :default => "512", - :recipes => ["ephemeral_lvm::default"], - :required => "optional" +attribute 'ephemeral_lvm/stripe_size', + display_name: 'Ephemeral LVM Stripe Size', + description: 'The stripe size to be used for the ephemeral logical volume', + default: '512', + recipes: ['ephemeral_lvm::default'], + required: 'optional' diff --git a/recipes/default.rb b/recipes/default.rb index c83b0d3..18612a6 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -19,10 +19,10 @@ # Include the lvm::default recipe which sets up the resources/providers for lvm # -include_recipe "lvm" +include_recipe 'lvm' if !node.attribute?('cloud') || !node['cloud'].attribute?('provider') || !node.attribute?(node['cloud']['provider']) - log "Not running on a known cloud, not setting up ephemeral LVM" + log 'Not running on a known cloud, not setting up ephemeral LVM' else # Obtain the current cloud cloud = node['cloud']['provider'] @@ -33,27 +33,26 @@ ephemeral_devices = EphemeralLvm::Helper.get_ephemeral_devices(cloud, node) if ephemeral_devices.empty? - log "No ephemeral disks found. Skipping setup." + log 'No ephemeral disks found. Skipping setup.' else log "Ephemeral disks found for cloud '#{cloud}': #{ephemeral_devices.inspect}" # Ephemeral disks may have been previously formatted, which can hang some lvm calls. # Run 'wipefs' on each ephemeral disk to remove any filesystem signatures. - ruby_block "vgs command" do - block do + ruby_block 'vgs command' do + block do check_volume_group = Mixlib::ShellOut.new("vgs #{node['ephemeral_lvm']['volume_group_name']}").run_command if check_volume_group.exitstatus != 0 ephemeral_devices.each do |ephemeral_device| Chef::Log.info "Preparing #{ephemeral_device}" - Mixlib::ShellOut.new( "wipefs --all #{ephemeral_device}").run_command + Mixlib::ShellOut.new("wipefs --all #{ephemeral_device}").run_command end else - Chef::Log.info "No need to remove ephemeral disk filesystem signatures." + Chef::Log.info 'No need to remove ephemeral disk filesystem signatures.' end end end - # Create the volume group and logical volume. If more than one ephemeral disk is found, # they are created with LVM stripes with the stripe size set in the attributes. # diff --git a/spec/ephemeral_lvm_helper_spec.rb b/spec/ephemeral_lvm_helper_spec.rb index 58bfd60..23c87d8 100644 --- a/spec/ephemeral_lvm_helper_spec.rb +++ b/spec/ephemeral_lvm_helper_spec.rb @@ -1,33 +1,34 @@ +require_relative 'spec_helper' require_relative '../libraries/helper' require 'logger' describe EphemeralLvm::Helper do - describe "#fix_device_mapping" do - it "returns the devices as is when there is no need for mapping" do + describe '#fix_device_mapping' do + it 'returns the devices as is when there is no need for mapping' do expect( - EphemeralLvm::Helper.fix_device_mapping(["/dev/sda", "/dev/sdb"], ["sda", "sdb"]) - ).to eq(["/dev/sda", "/dev/sdb"]) + EphemeralLvm::Helper.fix_device_mapping(['/dev/sda', '/dev/sdb'], %w(sda sdb)) + ).to eq(['/dev/sda', '/dev/sdb']) end - it "maps the devices correctly" do + it 'maps the devices correctly' do expect( - EphemeralLvm::Helper.fix_device_mapping(["/dev/sda", "/dev/sdb"], ["xvda", "xvdb"]) - ).to eq(["/dev/xvda", "/dev/xvdb"]) + EphemeralLvm::Helper.fix_device_mapping(['/dev/sda', '/dev/sdb'], %w(xvda xvdb)) + ).to eq(['/dev/xvda', '/dev/xvdb']) end - it "returns the original device unmapped if the device is found" do + it 'returns the original device unmapped if the device is found' do expect( - EphemeralLvm::Helper.fix_device_mapping(["/dev/sda", "/dev/sdb"], ["xvda", "sdb"]) - ).to eq(["/dev/xvda", "/dev/sdb"]) + EphemeralLvm::Helper.fix_device_mapping(['/dev/sda', '/dev/sdb'], %w(xvda sdb)) + ).to eq(['/dev/xvda', '/dev/sdb']) end - it "skips the devices that cannot be mapped" do - stub_const("Chef::Log", Logger.new('/dev/null')) - Chef::Log.should_receive(:warn).with("could not find ephemeral device: /dev/sdb").and_return([]) - + it 'skips the devices that cannot be mapped' do + stub_const('Chef::Log', Logger.new('/dev/null')) + allow(Chef::Log).to receive(:warn).with('could not find ephemeral device: /dev/sdb').and_return([]) + expect( - EphemeralLvm::Helper.fix_device_mapping(["/dev/sda", "/dev/sdb"], ["xvda"]) - ).to eq(["/dev/xvda"]) + EphemeralLvm::Helper.fix_device_mapping(['/dev/sda', '/dev/sdb'], ['xvda']) + ).to eq(['/dev/xvda']) end it 'map devices with a numeric suffix' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..dc70be5 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,33 @@ +# +# Cookbook Name:: ephemeral_lvm +# Spec:: spec_helper +# +# Copyright (C) 2014 RightScale, Inc. +# +# 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. +# +libraries_path = File.expand_path('../../libraries', __FILE__) +$LOAD_PATH.unshift(libraries_path) unless $LOAD_PATH.include?(libraries_path) + +require 'chefspec' +require 'chefspec/berkshelf' +require 'chefspec/cacher' +require 'rspec/support' + +ChefSpec::Coverage.start! +RSpec.configure do |config| + config.extend(ChefSpec::Cacher) + config.platform = 'ubuntu' + config.version = '12.04' + config.log_level = :error +end diff --git a/test/cookbooks/fake/attributes/default.rb b/test/cookbooks/fake/attributes/default.rb index ffdbf4a..d8b1c46 100644 --- a/test/cookbooks/fake/attributes/default.rb +++ b/test/cookbooks/fake/attributes/default.rb @@ -18,4 +18,4 @@ # # Ephemeral devices used for testing ephemeral_lvm cookbook -default['fake']['devices'] = ["/dev/loop0", "/dev/loop1"] +default['fake']['devices'] = ['/dev/loop0', '/dev/loop1'] diff --git a/test/cookbooks/fake/libraries/helper.rb b/test/cookbooks/fake/libraries/helper.rb index 081122b..c6cc7cf 100644 --- a/test/cookbooks/fake/libraries/helper.rb +++ b/test/cookbooks/fake/libraries/helper.rb @@ -31,7 +31,7 @@ module Helper def self.create_loop_devices(devices) Array(devices).each do |device| num = device.slice(/\d+/) - if File.exists?("/vfile#{num}") + if File.exist?("/vfile#{num}") puts "/vfile#{num} previously created" else shell_out!("dd if=/dev/zero of=/vfile#{num} bs=1024 count=65536") diff --git a/test/cookbooks/fake/metadata.rb b/test/cookbooks/fake/metadata.rb index d5c4c0c..ea3b2d6 100644 --- a/test/cookbooks/fake/metadata.rb +++ b/test/cookbooks/fake/metadata.rb @@ -5,4 +5,3 @@ description 'A fake cookbook to prepare the test environment for ephemeral_lvm' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version '0.1.0' - diff --git a/test/cookbooks/fake/recipes/default.rb b/test/cookbooks/fake/recipes/default.rb index 37a28e0..6b48437 100644 --- a/test/cookbooks/fake/recipes/default.rb +++ b/test/cookbooks/fake/recipes/default.rb @@ -20,7 +20,7 @@ # Create the loopback devices used for testing ephemeral_lvm # if !node.attribute?('cloud') || !node['cloud'].attribute?('provider') - log "Not running on a known cloud, Skipping test setup." + log 'Not running on a known cloud, Skipping test setup.' else EphemeralLvmTest::Helper.create_loop_devices(node['fake']['devices']) end diff --git a/test/cookbooks/fake/recipes/gce.rb b/test/cookbooks/fake/recipes/gce.rb index c952b56..a2139ea 100644 --- a/test/cookbooks/fake/recipes/gce.rb +++ b/test/cookbooks/fake/recipes/gce.rb @@ -20,12 +20,12 @@ # Include the fake::default recipe which sets up the loopback # devices used in the test. # -include_recipe "fake" +include_recipe 'fake' # Setup the links for ephemeral devices for google by id # node['fake']['devices'].each do |device| - match = device.match(/\/dev\/loop(\d+)/) + match = device.match(%{\/dev\/loop(\d+)}) if match.nil? next else