From cad6e3f9473a73359475a724c44df326def80cae Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Wed, 25 Jan 2017 08:56:28 -0600 Subject: [PATCH] updating and locking lvm to 3.0 (#55) * Update default.rb * Update metadata.rb * Update metadata.rb * Added attribute for wipe_attributes to pass along to the lvm_volump_group resource * Allow gem deps to vary within major version This fixes this error, which was solved in newer versions of Ridley: An error occurred while reading the Berksfile: uninitialized constant Ridley::Mixin::ParamsValidate::ValidationFailed https://travis-ci.org/rightscale-cookbooks/ephemeral_lvm/builds/125138768 * according to chai gce changed metadata ephemeral drives have type "LOCAL-SSD" now "gce": { "attached_disks": { "disks": [ { "deviceName": "persistent-disk-0", "index": 0, "mode": "READ_WRITE", "type": "PERSISTENT" }, { "deviceName": "local-ssd-0", "index": 1, "mode": "READ_WRITE", "type": "LOCAL-SSD" } ] }, * updated metadata and changeling * updating to lvm-3.0 * additional try for wipefs as new version supports -f flag * fix deprecation warning, using allow instead of should_receive * chef 12 migration * updating travis * updating net-persistent-http * fixing versions * updating from skeleton for tests * adding gitignore * 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 * using pipmychangelog * fixes #57 * updating lvm to 4.0.5 * updating changelog * reverting to 3.1.0, since 4.0.x has breaking changes --- .rubocop.yml | 12 ++---- Berksfile | 1 + Berksfile.lock | 6 ++- CHANGELOG.md | 20 ++++++++++ Gemfile | 1 + Vagrantfile | 1 + attributes/default.rb | 4 ++ libraries/helper.rb | 46 ++++++++++++++--------- metadata.rb | 13 ++++++- recipes/default.rb | 6 ++- spec/ephemeral_lvm_helper_spec.rb | 1 + spec/spec_helper.rb | 1 + test/cookbooks/fake/attributes/default.rb | 1 + test/cookbooks/fake/libraries/helper.rb | 1 + test/cookbooks/fake/metadata.rb | 1 + test/cookbooks/fake/recipes/default.rb | 1 + test/cookbooks/fake/recipes/gce.rb | 8 ++-- 17 files changed, 87 insertions(+), 37 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c6f3c49..62bd7ce 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,12 +2,6 @@ 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' +#Metrics/BlockNesting: +# Exclude: +# - 'libraries/helper.rb' diff --git a/Berksfile b/Berksfile index 38d3321..6e0debc 100644 --- a/Berksfile +++ b/Berksfile @@ -1,3 +1,4 @@ +# frozen_string_literal: true source 'https://supermarket.chef.io' metadata diff --git a/Berksfile.lock b/Berksfile.lock index 55f4f7c..e8a35b6 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -6,7 +6,9 @@ DEPENDENCIES path: test/cookbooks/fake GRAPH - ephemeral_lvm (2.0.0) - lvm (~> 3.1) + ephemeral_lvm (2.1.0) + lvm (~> 3.1.0) + now (>= 0.0.0) fake (0.1.0) lvm (3.1.0) + now (1.0.0) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ce7b27..b92ca16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,18 @@ ephemeral_lvm Cookbook CHANGELOG This file is used to list changes made in each version of the ephemeral_lvm cookbook. +v2.1.0 +------ +- [lvm-3.1.0](https://github.com/chef-cookbooks/lvm/releases/tag/v3.1.0) +- Pull Request [#50][]: fixed detection for gce ephemeral device type "LOCAL-SSD" ([@areznikov-kabam][]) +- Pull Request [#48][]: Wipe Signatures ([@kingpong][]) +- Pull Request [#46][]: Added attribute for wipe_attributes to pass along to the lvm_volump_group ([@freimer][]) +- Pull Request [#33][]: Using include_recipe_now technic to allow compile time lvm2 package run ([@felka][]) + +v2.0.1 +------- +- addressed GCE "LOCAL-SSD" type for ephemeral drives + v2.0.0 ------- @@ -113,7 +125,15 @@ v1.0.0 [#11]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/11 [#13]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/13 [#19]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/19 +[#33]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/33 +[#46]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/46 +[#48]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/48 +[#50]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/50 [#54]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/54 +[@areznikov-kabam]: https://github.com/areznikov-kabam [@autrejacoupa]: https://github.com/autrejacoupa [@drywheat]: https://github.com/drywheat +[@felka]: https://github.com/felka +[@freimer]: https://github.com/freimer [@juliandunn]: https://github.com/juliandunn +[@kingpong]: https://github.com/kingpong diff --git a/Gemfile b/Gemfile index 9ed36e1..0fac271 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,4 @@ +# frozen_string_literal: true source 'https://rubygems.org' gem 'rake' diff --git a/Vagrantfile b/Vagrantfile index 814837b..bc4fb26 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,3 +1,4 @@ +# frozen_string_literal: true # -*- mode: ruby -*- # vi: set ft=ruby : diff --git a/attributes/default.rb b/attributes/default.rb index 8a1fbfe..5a09a1b 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # # Cookbook Name:: ephemeral_lvm # Attributes:: default @@ -42,3 +43,6 @@ # The stripe size in kilobytes to be used if more than one ephemeral disk is found default['ephemeral_lvm']['stripe_size'] = 512 + +# Whether to wipe signatures on any existing drives +default['ephemeral_lvm']['wipe_signatures'] = false diff --git a/libraries/helper.rb b/libraries/helper.rb index e0251ee..7134317 100644 --- a/libraries/helper.rb +++ b/libraries/helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # # Cookbook Name:: ephemeral_lvm # Library:: helper @@ -24,7 +25,33 @@ module Helper # # @param cloud [String] the name of cloud # @param node [Chef::Node] the Chef node + def self.gce_ephemeral_devices?(cloud, node) + # According to the GCE documentation, the instances have links for ephemeral disks as + # /dev/disk/by-id/google-ephemeral-disk-*. Refer to + # 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['type'] == 'LOCAL-SSD')) && 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']}" + end + end unless node[cloud]['instance'].nil? + + # Removes nil elements from the ephemeral_devices array if any. + ephemeral_devices.compact! + ephemeral_devices + end + + # Identifies the ephemeral devices available on a cloud server based on cloud-specific Ohai data and returns + # them as an array. This method also does the mapping required for Xen hypervisors (/dev/sdX -> /dev/xvdX). # + # @param cloud [String] the name of cloud + # @param node [Chef::Node] the Chef node # @return [Array] list of ephemeral available ephemeral devices. # def self.get_ephemeral_devices(cloud, node) @@ -58,24 +85,7 @@ def self.get_ephemeral_devices(cloud, node) # case cloud when 'gce' - # According to the GCE documentation, the instances have links for ephemeral disks as - # /dev/disk/by-id/google-ephemeral-disk-*. Refer to - # 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']}" - 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']}" - end - end unless node[cloud]['instance'].nil? - - # Removes nil elements from the ephemeral_devices array if any. - ephemeral_devices.compact! + ephemeral_devices = gce_ephemeral_devices?(cloud, node) else Chef::Log.info 'No ephemeral disks found.' end diff --git a/metadata.rb b/metadata.rb index a0b4c52..aef0c43 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,10 +1,11 @@ +# frozen_string_literal: true name 'ephemeral_lvm' maintainer 'RightScale, Inc.' maintainer_email 'cookbooks@rightscale.com' 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 '2.0.0' +version '2.1.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) @@ -13,7 +14,8 @@ supports 'centos' supports 'debian' -depends 'lvm', '~> 3.1' +depends 'now' +depends 'lvm', '~> 3.1.0' recipe 'ephemeral_lvm::default', 'Sets up ephemeral devices on a cloud server' @@ -66,3 +68,10 @@ default: '512', recipes: ['ephemeral_lvm::default'], required: 'optional' + +attribute 'ephemeral_lvm/wipe_signatures', + display_name: 'Ephemeral LVM Wire Signatures', + description: 'Whether to wipe any existing filesystem signatures', + default: false, + recipes: ['ephemeral_lvm::default'], + required: 'optional' diff --git a/recipes/default.rb b/recipes/default.rb index 18612a6..9440646 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # # Cookbook Name:: ephemeral_lvm # Recipe:: default @@ -19,7 +20,7 @@ # Include the lvm::default recipe which sets up the resources/providers for lvm # -include_recipe 'lvm' +include_recipe_now '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' @@ -46,6 +47,7 @@ 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 -f #{ephemeral_device}").run_command end else Chef::Log.info 'No need to remove ephemeral disk filesystem signatures.' @@ -57,6 +59,8 @@ # they are created with LVM stripes with the stripe size set in the attributes. # lvm_volume_group node['ephemeral_lvm']['volume_group_name'] do + wipe_signatures node['ephemeral_lvm']['wipe_signatures'] + physical_volumes ephemeral_devices logical_volume node['ephemeral_lvm']['logical_volume_name'] do diff --git a/spec/ephemeral_lvm_helper_spec.rb b/spec/ephemeral_lvm_helper_spec.rb index 23c87d8..cb5919f 100644 --- a/spec/ephemeral_lvm_helper_spec.rb +++ b/spec/ephemeral_lvm_helper_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative 'spec_helper' require_relative '../libraries/helper' require 'logger' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dc70be5..962e1d9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # # Cookbook Name:: ephemeral_lvm # Spec:: spec_helper diff --git a/test/cookbooks/fake/attributes/default.rb b/test/cookbooks/fake/attributes/default.rb index d8b1c46..b046cab 100644 --- a/test/cookbooks/fake/attributes/default.rb +++ b/test/cookbooks/fake/attributes/default.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # # Cookbook Name:: fake # Attributes:: default diff --git a/test/cookbooks/fake/libraries/helper.rb b/test/cookbooks/fake/libraries/helper.rb index c6cc7cf..e27ac90 100644 --- a/test/cookbooks/fake/libraries/helper.rb +++ b/test/cookbooks/fake/libraries/helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # # Cookbook Name:: fake # Library:: helper diff --git a/test/cookbooks/fake/metadata.rb b/test/cookbooks/fake/metadata.rb index ea3b2d6..4807072 100644 --- a/test/cookbooks/fake/metadata.rb +++ b/test/cookbooks/fake/metadata.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true name 'fake' maintainer 'RightScale, Inc.' maintainer_email 'cookbooks@rightscale.com' diff --git a/test/cookbooks/fake/recipes/default.rb b/test/cookbooks/fake/recipes/default.rb index 6b48437..bcb107e 100644 --- a/test/cookbooks/fake/recipes/default.rb +++ b/test/cookbooks/fake/recipes/default.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # # Cookbook Name:: fake # Recipe:: default diff --git a/test/cookbooks/fake/recipes/gce.rb b/test/cookbooks/fake/recipes/gce.rb index a2139ea..cceb92f 100644 --- a/test/cookbooks/fake/recipes/gce.rb +++ b/test/cookbooks/fake/recipes/gce.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # # Cookbook Name:: fake # Recipe:: gce @@ -26,11 +27,8 @@ # node['fake']['devices'].each do |device| match = device.match(%{\/dev\/loop(\d+)}) - if match.nil? - next - else - device_index = match[1] - end + next if match.nil? + device_index = match[1] link "/dev/disk/by-id/google-ephemeral-disk-#{device_index}" do to device end