Skip to content

Commit 69ab182

Browse files
authored
Merge pull request #244 from genebean/fix_substing_false_positive
Make lv that is a substring of a vg work
2 parents d6c3514 + d8c31dd commit 69ab182

File tree

2 files changed

+12
-5
lines changed
  • lib/puppet/provider/logical_volume
  • spec/unit/puppet/provider/logical_volume

2 files changed

+12
-5
lines changed

lib/puppet/provider/logical_volume/lvm.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def destroy
157157
end
158158

159159
def exists?
160-
lvs(@resource[:volume_group]) =~ %r{#{@resource[:name]}}
160+
lvs(@resource[:volume_group]) =~ lvs_pattern
161161
rescue Puppet::ExecutionFailure
162162
# lvs fails if we give it an empty volume group name, as would
163163
# happen if we were running `puppet resource`. This should be

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
end
1010

1111
lvs_output = <<-EOS
12-
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
13-
lv_root VolGroup -wi-ao---- 18.54g
14-
lv_swap VolGroup -wi-ao---- 992.00m
15-
data data -wi-ao---- 992.00m
12+
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
13+
lv_root VolGroup -wi-ao---- 18.54g
14+
lv_swap VolGroup -wi-ao---- 992.00m
15+
data data -wi-ao---- 992.00m
16+
j1 vg_jenkins -wi-a----- 1.00g
1617
EOS
1718

1819
describe 'self.instances' do
@@ -34,6 +35,12 @@
3435
@provider.class.stubs(:lvs).with('data').returns(lvs_output)
3536
expect(@provider.exists?).to be > 10
3637
end
38+
it "returns 'nil', lv 'jenkins' in vg 'vg_jenkins' exists" do
39+
@resource.expects(:[]).with(:name).returns('jenkins')
40+
@resource.expects(:[]).with(:volume_group).returns('vg_jenkins').at_least_once
41+
@provider.class.stubs(:lvs).with('vg_jenkins').returns(lvs_output)
42+
expect(@provider.exists?).to be_nil
43+
end
3744
it "returns 'nil', lv 'data' in vg 'myvg' does not exist" do
3845
@resource.expects(:[]).with(:volume_group).returns('myvg').at_least_once
3946
@provider.class.stubs(:lvs).with('myvg').raises(Puppet::ExecutionFailure, 'Execution of \'/sbin/lvs myvg\' returned 5')

0 commit comments

Comments
 (0)