Skip to content

Commit d2454c9

Browse files
committed
Revert "(CONT-982) - Spec test fix"
This reverts commit 8e1e8eb.
1 parent 0f60b28 commit d2454c9

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

lib/facter/lvm_support.rb

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,34 @@
1313

1414
# lvm_vgs: [0-9]+
1515
# Number of VGs
16+
vg_list = []
1617
Facter.add('lvm_vgs') do
1718
confine lvm_support: true
1819

19-
setcode do
20+
if Facter.value(:lvm_support)
2021
vgs = Facter::Core::Execution.execute('vgs -o name --noheadings 2>/dev/null', timeout: 30)
22+
end
2123

22-
if vgs.nil?
23-
0
24-
else
25-
vg_list = vgs.split
24+
if vgs.nil?
25+
setcode { 0 }
26+
else
27+
vg_list = vgs.split
28+
setcode { vg_list.length }
29+
end
30+
end
2631

27-
# lvm_vg_[0-9]+
28-
# VG name by index
29-
vg_list.each_with_index do |vg, i|
30-
Facter.add("lvm_vg_#{i}") { setcode { vg } }
31-
Facter.add("lvm_vg_#{vg}_pvs") do
32-
setcode do
33-
pvs = Facter::Core::Execution.execute("vgs -o pv_name #{vg} 2>/dev/null", timeout: 30)
34-
res = nil
35-
res = pvs.split("\n").grep(%r{^\s+/}).collect(&:strip).sort.join(',') unless pvs.nil?
36-
res
37-
end
38-
end
32+
# lvm_vg_[0-9]+
33+
# VG name by index
34+
vg_list.each_with_index do |vg, i|
35+
Facter.add("lvm_vg_#{i}") { setcode { vg } }
36+
Facter.add("lvm_vg_#{vg}_pvs") do
37+
setcode do
38+
pvs = Facter::Core::Execution.execute("vgs -o pv_name #{vg} 2>/dev/null", timeout: 30)
39+
res = nil
40+
unless pvs.nil?
41+
res = pvs.split("\n").select { |l| l =~ %r{^\s+/} }.map(&:strip).sort.join(',')
3942
end
40-
vg_list.length
43+
res
4144
end
4245
end
4346
end
@@ -47,21 +50,20 @@
4750
pv_list = []
4851
Facter.add('lvm_pvs') do
4952
confine lvm_support: true
50-
51-
setcode do
53+
if Facter.value(:lvm_support)
5254
pvs = Facter::Core::Execution.execute('pvs -o name --noheadings 2>/dev/null', timeout: 30)
55+
end
5356

54-
if pvs.nil?
55-
0
56-
else
57-
pv_list = pvs.split
58-
59-
# lvm_pv_[0-9]+
60-
# PV name by index
61-
pv_list.each_with_index do |pv, i|
62-
Facter.add("lvm_pv_#{i}") { setcode { pv } }
63-
end
64-
pv_list.length
65-
end
57+
if pvs.nil?
58+
setcode { 0 }
59+
else
60+
pv_list = pvs.split
61+
setcode { pv_list.length }
6662
end
6763
end
64+
65+
# lvm_pv_[0-9]+
66+
# PV name by index
67+
pv_list.each_with_index do |pv, i|
68+
Facter.add("lvm_pv_#{i}") { setcode { pv } }
69+
end

spec/unit/facter/lvm_support_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
context 'when there is lvm support' do
5555
context 'when there are no vgs' do
5656
it 'is set to 0' do
57-
Facter::Core::Execution.stubs(:execute) # All other calls
57+
allow(Facter::Core::Execution).to receive(:execute) # All other calls
5858
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o name --noheadings 2>/dev/null', timeout: 30).returns(nil)
5959
Facter.fact(:lvm_support).expects(:value).at_least(1).returns(true)
6060
Facter.value(:lvm_vgs).should == 0

0 commit comments

Comments
 (0)