Skip to content

Commit 536229e

Browse files
David HollingerDavid Hollinger
authored andcommitted
MODULES-4753 Allow removal of swap LVMs
Added logic to the destroy method that will check blkid for the LVM's type and run swapoff against it if it is of TYPE swap. This allows swap LVMs to be removed rather than simply erroring out.
1 parent cda5e84 commit 536229e

File tree

2 files changed

+18
-4
lines changed
  • lib/puppet/provider/logical_volume
  • spec/unit/puppet/provider/logical_volume

2 files changed

+18
-4
lines changed

lib/puppet/provider/logical_volume/lvm.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ def create
129129

130130
def destroy
131131
name_escaped = "#{@resource[:volume_group].gsub('-','--')}-#{@resource[:name].gsub('-','--')}"
132+
if blkid(path) =~ /\bTYPE=\"(swap)\"/
133+
swapoff(path)
134+
end
132135
dmsetup('remove', name_escaped)
133136
lvremove('-f', path)
134137
end

spec/unit/puppet/provider/logical_volume/lvm_spec.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,29 @@
228228

229229
describe 'when destroying' do
230230
it "should execute 'dmsetup' and 'lvremove'" do
231-
@resource.expects(:[]).with(:volume_group).returns('myvg').twice
232-
@resource.expects(:[]).with(:name).returns('mylv').twice
231+
@resource.expects(:[]).with(:volume_group).returns('myvg').times(3)
232+
@resource.expects(:[]).with(:name).returns('mylv').times(3)
233+
@provider.expects(:blkid).with('/dev/myvg/mylv')
233234
@provider.expects(:dmsetup).with('remove', 'myvg-mylv')
234235
@provider.expects(:lvremove).with('-f', '/dev/myvg/mylv')
235236
@provider.destroy
236237
end
237238
it "should execute 'dmsetup' and 'lvremove' and properly escape names with dashes" do
238-
@resource.expects(:[]).with(:volume_group).returns('my-vg').twice
239-
@resource.expects(:[]).with(:name).returns('my-lv').twice
239+
@resource.expects(:[]).with(:volume_group).returns('my-vg').times(3)
240+
@resource.expects(:[]).with(:name).returns('my-lv').times(3)
241+
@provider.expects(:blkid).with('/dev/my-vg/my-lv')
240242
@provider.expects(:dmsetup).with('remove', 'my--vg-my--lv')
241243
@provider.expects(:lvremove).with('-f', '/dev/my-vg/my-lv')
242244
@provider.destroy
243245
end
246+
it "should execute 'swapoff', 'dmsetup', and 'lvremove' when lvm is of type swap" do
247+
@resource.expects(:[]).with(:volume_group).returns('myvg').times(4)
248+
@resource.expects(:[]).with(:name).returns('mylv').times(4)
249+
@provider.expects(:blkid).with('/dev/myvg/mylv').returns('TYPE="swap"')
250+
@provider.expects(:swapoff).with('/dev/myvg/mylv')
251+
@provider.expects(:dmsetup).with('remove', 'myvg-mylv')
252+
@provider.expects(:lvremove).with('-f', '/dev/myvg/mylv')
253+
@provider.destroy
254+
end
244255
end
245256
end

0 commit comments

Comments
 (0)