Skip to content

Commit 1b8ba45

Browse files
committed
lvm_support: update fact to use no headings
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
1 parent cada6d4 commit 1b8ba45

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/facter/lvm_support.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@
3333
Facter.add("lvm_vg_#{i}") { setcode { vg } }
3434
Facter.add("lvm_vg_#{vg}_pvs") do
3535
setcode do
36-
pvs = Facter::Core::Execution.execute("vgs -o pv_name #{vg} 2>/dev/null", timeout: 30)
36+
pvs = Facter::Core::Execution.execute(
37+
"vgs -o pv_name --noheadings #{vg} 2>/dev/null",
38+
timeout: 30,
39+
)
3740
res = nil
3841
unless pvs.nil?
39-
res = pvs.split("\n").select { |l| l =~ %r{^\s+/} }.map(&:strip).sort.join(',')
42+
res = pvs.split("\n").map(&:strip).sort.join(',')
4043
end
4144
res
4245
end

spec/unit/facter/lvm_support_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
it 'lists vgs' do
6464
Facter::Core::Execution.stubs(:execute) # All other calls
6565
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o name --noheadings 2>/dev/null', timeout: 30).returns("vg0\nvg1")
66-
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")
67-
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o pv_name vg1 2>/dev/null', timeout: 30).returns(" PV\n /dev/pv0")
66+
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")
67+
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o pv_name --noheadings vg1 2>/dev/null', timeout: 30).returns(' /dev/pv0')
6868
Facter.fact(:lvm_support).expects(:value).at_least(1).returns(true)
6969
Facter.value(:lvm_vgs).should == 2
7070
Facter.value(:lvm_vg_0).should == 'vg0'

0 commit comments

Comments
 (0)