Skip to content

Commit 2383d59

Browse files
authored
Merge pull request #173 from ruriky/fix/lvs_pattern
Cannot add a new volume if the volume group has the same name. Fix: Better regexp for parsing the output of lvs
2 parents 5ce7aca + f51a270 commit 2383d59

File tree

2 files changed

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

2 files changed

+19
-1
lines changed

lib/puppet/provider/logical_volume/lvm.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ def mirrorlog=( new_mirror_log_location )
293293
private
294294

295295
def lvs_pattern
296-
/\s+#{Regexp.quote @resource[:name]}\s+/
296+
# lvs output format:
297+
# LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
298+
/\s+#{Regexp.quote @resource[:name]}\s+#{Regexp.quote @resource[:volume_group]}\s+/
297299
end
298300

299301
def path

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
1414
lv_root VolGroup -wi-ao---- 18.54g
1515
lv_swap VolGroup -wi-ao---- 992.00m
16+
data data -wi-ao---- 992.00m
1617
EOS
1718

1819
describe 'self.instances' do
@@ -27,6 +28,21 @@
2728
end
2829
end
2930

31+
describe 'when checking existence' do
32+
it "should return 'true', lv 'data' in vg 'data' exists" do
33+
@resource.expects(:[]).with(:name).returns('data')
34+
@resource.expects(:[]).with(:volume_group).returns('data').at_least_once
35+
@provider.class.stubs(:lvs).with('data').returns(lvs_output)
36+
expect(@provider.exists?).to be > 10
37+
end
38+
it "should return 'nil', lv 'data' in vg 'myvg' does not exist" do
39+
@resource.expects(:[]).with(:name).returns('data')
40+
@resource.expects(:[]).with(:volume_group).returns('myvg').at_least_once
41+
@provider.class.stubs(:lvs).with('myvg').returns(lvs_output)
42+
expect(@provider.exists?).to be_nil
43+
end
44+
end
45+
3046
describe 'when inspecting' do
3147
it "strips zeros from lvs output" do
3248
@resource.expects(:[]).with(:name).returns('mylv').at_least_once

0 commit comments

Comments
 (0)