Skip to content
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

lvm_support: update fact to use --no-headings #259

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions lib/facter/lvm_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
Facter.add("lvm_vg_#{i}") { setcode { vg } }
Facter.add("lvm_vg_#{vg}_pvs") do
setcode do
pvs = Facter::Core::Execution.execute("vgs -o pv_name #{vg} 2>/dev/null", timeout: 30)
pvs = Facter::Core::Execution.execute(
"vgs -o pv_name --noheadings #{vg} 2>/dev/null",
timeout: 30,
)
res = nil
unless pvs.nil?
res = pvs.split("\n").select { |l| l =~ %r{^\s+/} }.map(&:strip).sort.join(',')
res = pvs.split("\n").map(&:strip).sort.join(',')
end
res
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/facter/lvm_support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
it 'lists vgs' do
Facter::Core::Execution.stubs(:execute) # All other calls
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o name --noheadings 2>/dev/null', timeout: 30).returns("vg0\nvg1")
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o pv_name vg0 2>/dev/null', timeout: 30).returns(" PV\n /dev/pv3\n /dev/pv2")
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o pv_name vg1 2>/dev/null', timeout: 30).returns(" PV\n /dev/pv0")
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o pv_name --noheadings vg0 2>/dev/null', timeout: 30).returns(" /dev/pv3\n /dev/pv2")
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o pv_name --noheadings vg1 2>/dev/null', timeout: 30).returns(' /dev/pv0')
Facter.fact(:lvm_support).expects(:value).at_least(1).returns(true)
Facter.value(:lvm_vgs).should == 2
Facter.value(:lvm_vg_0).should == 'vg0'
Expand Down