Skip to content

Make lv that is a substring of a vg work #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/provider/logical_volume/lvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def destroy
end

def exists?
lvs(@resource[:volume_group]) =~ %r{#{@resource[:name]}}
lvs(@resource[:volume_group]) =~ lvs_pattern
rescue Puppet::ExecutionFailure
# lvs fails if we give it an empty volume group name, as would
# happen if we were running `puppet resource`. This should be
Expand Down
15 changes: 11 additions & 4 deletions spec/unit/puppet/provider/logical_volume/lvm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
end

lvs_output = <<-EOS
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 18.54g
lv_swap VolGroup -wi-ao---- 992.00m
data data -wi-ao---- 992.00m
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 18.54g
lv_swap VolGroup -wi-ao---- 992.00m
data data -wi-ao---- 992.00m
j1 vg_jenkins -wi-a----- 1.00g
EOS

describe 'self.instances' do
Expand All @@ -34,6 +35,12 @@
@provider.class.stubs(:lvs).with('data').returns(lvs_output)
expect(@provider.exists?).to be > 10
end
it "returns 'nil', lv 'jenkins' in vg 'vg_jenkins' exists" do
@resource.expects(:[]).with(:name).returns('jenkins')
@resource.expects(:[]).with(:volume_group).returns('vg_jenkins').at_least_once
@provider.class.stubs(:lvs).with('vg_jenkins').returns(lvs_output)
expect(@provider.exists?).to be_nil
end
it "returns 'nil', lv 'data' in vg 'myvg' does not exist" do
@resource.expects(:[]).with(:volume_group).returns('myvg').at_least_once
@provider.class.stubs(:lvs).with('myvg').raises(Puppet::ExecutionFailure, 'Execution of \'/sbin/lvs myvg\' returned 5')
Expand Down