Skip to content

Commit 9746bd7

Browse files
committed
Fix parsing size from lvs output
lvs prints 2.5G as 2.50g. This makes puppet try to extend the lv if you ensure a volume with size of 2.5g. lvextend complains because of the same size and fails, breaking the puppet apply. This commit strips zeros from floating point values from lvs ouptut.
1 parent b2cf3e9 commit 9746bd7

File tree

2 files changed

+10
-1
lines changed
  • lib/puppet/provider/logical_volume
  • spec/unit/puppet/provider/logical_volume

2 files changed

+10
-1
lines changed

lib/puppet/provider/logical_volume/lvm.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def size
148148
if $2.to_i == 00
149149
return $1 + unit.capitalize
150150
else
151-
return $1 + '.' + $2 + unit.capitalize
151+
return $1 + '.' + $2.sub(/0+$/, '') + unit.capitalize
152152
end
153153
end
154154
end

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
end
2828
end
2929

30+
describe 'when inspecting' do
31+
it "strips zeros from lvs output" do
32+
@resource.expects(:[]).with(:name).returns('mylv').at_least_once
33+
@resource.expects(:[]).with(:volume_group).returns('myvg').at_least_once
34+
@resource.expects(:[]).with(:size).returns('2.5g').at_least_once
35+
@provider.expects(:lvs).with('--noheading', '--unit', 'g', '/dev/myvg/mylv').returns(' 2.50g').at_least_once
36+
expect(@provider.size).to eq('2.5G')
37+
end
38+
end
3039
describe 'when creating' do
3140
context 'with size' do
3241
it "should execute 'lvcreate' with a '--size' option" do

0 commit comments

Comments
 (0)