Skip to content

Commit

Permalink
lvm_support: update fact to use no headings
Browse files Browse the repository at this point in the history
I noticed upgrading that the `lvm_vg_#{vg}_pv` facts dose not use
the `--no-headings` switch like the other facts.

This PR adds the `--no-headings` switch and simplifies the collection
  • Loading branch information
b4ldr committed Jan 4, 2021
1 parent cada6d4 commit 1b8ba45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
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

0 comments on commit 1b8ba45

Please sign in to comment.