Skip to content

Commit 4d6da7f

Browse files
committed
fix issues on nodes without lvm
tested manually on nodes with and without lvm
1 parent c437d99 commit 4d6da7f

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

lib/facter/lvm_support.rb

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,48 @@
1717
Facter.add('lvm_vgs') do
1818
confine lvm_support: true
1919

20-
vgs = Facter::Core::Execution.execute('vgs -o name --noheadings 2>/dev/null', timeout: 30)
21-
22-
if vgs.nil?
23-
setcode { 0 }
24-
else
25-
vg_list = vgs.split
26-
setcode { vg_list.length }
20+
if Facter.value(:lvm_support)
21+
vgs = Facter::Core::Execution.execute('vgs -o name --noheadings 2>/dev/null', timeout: 30)
22+
vg_list = vgs.split unless vgs.nil?
2723
end
24+
25+
setcode { vg_list.length }
2826
end
2927

30-
# lvm_vg_[0-9]+
31-
# VG name by index
28+
# # lvm_vg_[0-9]+
29+
# # VG name by index
3230
vg_list.each_with_index do |vg, i|
33-
Facter.add("lvm_vg_#{i}") { setcode { vg } }
31+
Facter.add("lvm_vg_#{i}") do
32+
setcode { vg }
33+
end
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)
3736
res = nil
37+
pvs = Facter::Core::Execution.execute("vgs -o pv_name #{vg} 2>/dev/null", timeout: 30)
3838
res = pvs.split("\n").grep(%r{^\s+/}).map(&:strip).sort.join(',') unless pvs.nil?
3939
res
4040
end
4141
end
4242
end
4343

44-
# lvm_pvs: [0-9]+
45-
# Number of PVs
44+
# # lvm_pvs: [0-9]+
45+
# # Number of PVs
4646
pv_list = []
4747
Facter.add('lvm_pvs') do
4848
confine lvm_support: true
4949

50-
pvs = Facter::Core::Execution.execute('pvs -o name --noheadings 2>/dev/null', timeout: 30)
51-
if pvs.nil?
52-
setcode { 0 }
53-
else
54-
pv_list = pvs.split
55-
setcode { pv_list.length }
50+
if Facter.value(:lvm_support)
51+
pvs = Facter::Core::Execution.execute('pvs -o name --noheadings 2>/dev/null', timeout: 30)
52+
pv_list = pvs.split unless pvs.nil?
5653
end
54+
55+
setcode { pv_list.length }
5756
end
5857

59-
# lvm_pv_[0-9]+
60-
# PV name by index
58+
# # lvm_pv_[0-9]+
59+
# # PV name by index
6160
pv_list.each_with_index do |pv, i|
62-
Facter.add("lvm_pv_#{i}") { setcode { pv } }
61+
Facter.add("lvm_pv_#{i}") do
62+
setcode { pv }
63+
end
6364
end

0 commit comments

Comments
 (0)