From fde98bd0d721b4bd579ea06be1c19641a516cbec Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 14 Dec 2016 17:43:15 -0800 Subject: [PATCH] Uninstall the previous lvm gems This is quite noisy in the chef logs. I'll see if we can come up with a better way to handle this soon. Signed-off-by: Tim Smith --- attributes/default.rb | 1 + libraries/lvm.rb | 12 ++++++++++++ libraries/provider_lvm_volume_group.rb | 15 +++++++-------- test/fixtures/cookbooks/test/recipes/create.rb | 6 +++++- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 8998f4cf..4081902f 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -19,3 +19,4 @@ default['lvm']['chef-ruby-lvm']['version'] = '0.2.2' default['lvm']['chef-ruby-lvm-attrib']['version'] = '0.0.28' +default['lvm']['cleanup_old_gems'] = true diff --git a/libraries/lvm.rb b/libraries/lvm.rb index 8d63065c..289ef544 100644 --- a/libraries/lvm.rb +++ b/libraries/lvm.rb @@ -19,6 +19,18 @@ module LVMCookbook def require_lvm_gems raise 'The previous di-ruby-lvm and di-ruby-lvm-attrib gems have been replaced with chef maintained forks. You have set the legacy attributes for pinning installed gem versions. You will need to remove these attributes and instead set the new chef varients. See the attributes file for the latest attributes.' if node['lvm']['di-ruby-lvm'] || node['lvm']['di-ruby-lvm-attrib'] + if node['lvm']['cleanup_old_gems'] + chef_gem 'di-ruby-lvm-attrib' do + action :remove + compile_time true + end + + chef_gem 'di-ruby-lvm' do + action :remove + compile_time true + end + end + # require attribute specified gems gem 'chef-ruby-lvm-attrib', node['lvm']['chef-ruby-lvm-attrib']['version'] gem 'chef-ruby-lvm', node['lvm']['chef-ruby-lvm']['version'] diff --git a/libraries/provider_lvm_volume_group.rb b/libraries/provider_lvm_volume_group.rb index 5766ba07..01e2b730 100644 --- a/libraries/provider_lvm_volume_group.rb +++ b/libraries/provider_lvm_volume_group.rb @@ -93,14 +93,13 @@ def action_extend end end - unless pvs_to_add.empty? - command = "vgextend #{name} #{pvs_to_add.join(' ')}" - Chef::Log.debug "Executing lvm command: '#{command}'" - output = lvm.raw command - Chef::Log.debug "Command output: '#{output}'" - new_resource.updated_by_last_action(true) - resize_logical_volumes - end + return if pvs_to_add.empty? + command = "vgextend #{name} #{pvs_to_add.join(' ')}" + Chef::Log.debug "Executing lvm command: '#{command}'" + output = lvm.raw command + Chef::Log.debug "Command output: '#{output}'" + new_resource.updated_by_last_action(true) + resize_logical_volumes end private diff --git a/test/fixtures/cookbooks/test/recipes/create.rb b/test/fixtures/cookbooks/test/recipes/create.rb index 274e4446..240347b5 100644 --- a/test/fixtures/cookbooks/test/recipes/create.rb +++ b/test/fixtures/cookbooks/test/recipes/create.rb @@ -20,7 +20,11 @@ apt_update 'update' if platform_family?('debian') # install the old gems to make sure the uninstall works -chef_gem ['di-chef-ruby-lvm-attrib', 'di-chef-ruby-lvm'] do +chef_gem 'di-ruby-lvm' do + compile_time true +end + +chef_gem 'di-ruby-lvm-attrib' do compile_time true end