Skip to content

Commit 41a7129

Browse files
committed
Change Facter::Util::Resolution to Facter::Core::Execution and add timeout: 30 to options hash; add if around vgs and pvs commands to handle F::C::S new management of nil commands; attempt to update spec
1 parent e3e1df0 commit 41a7129

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

lib/facter/lvm_support.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
vg_list = []
1515
Facter.add('lvm_vgs') do
1616
confine :lvm_support => true
17-
vgs = Facter::Util::Resolution.exec('vgs -o name --noheadings 2>/dev/null')
17+
18+
lvm = Facter.value(:lvm_support)
19+
if lvm
20+
vgs = Facter::Core::Execution.execute('vgs -o name --noheadings 2>/dev/null', timeout: 30)
21+
end
1822
if vgs.nil?
1923
setcode { 0 }
2024
else
@@ -29,7 +33,7 @@
2933
Facter.add("lvm_vg_#{i}") { setcode { vg } }
3034
Facter.add("lvm_vg_#{vg}_pvs") do
3135
setcode do
32-
pvs = Facter::Util::Resolution.exec("vgs -o pv_name #{vg} 2>/dev/null")
36+
pvs = Facter::Core::Execution.execute("vgs -o pv_name #{vg} 2>/dev/null", timeout: 30)
3337
res = nil
3438
unless pvs.nil?
3539
res = pvs.split("\n").select{|l| l =~ /^\s+\// }.collect(&:strip).sort.join(',')
@@ -44,7 +48,11 @@
4448
pv_list = []
4549
Facter.add('lvm_pvs') do
4650
confine :lvm_support => true
47-
pvs = Facter::Util::Resolution.exec('pvs -o name --noheadings 2>/dev/null')
51+
52+
lvm = Facter.value(:lvm_support)
53+
if lvm
54+
pvs = Facter::Core::Execution.execute('pvs -o name --noheadings 2>/dev/null', timeout: 30)
55+
end
4856
if pvs.nil?
4957
setcode { 0 }
5058
else

spec/unit/facter/lvm_support_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@
5252
context 'when there is lvm support' do
5353
context 'when there are no vgs' do
5454
it 'should be set to 0' do
55-
Facter::Util::Resolution.stubs('exec') # All other calls
56-
Facter::Util::Resolution.expects('exec').at_least(1).with('vgs -o name --noheadings 2>/dev/null').returns(nil)
5755
Facter.fact(:lvm_support).expects(:value).at_least(1).returns(true)
56+
Facter::Core::Execution.stubs(:execute) # All other calls
57+
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o name --noheadings 2>/dev/null', timeout: 30).returns(nil)
5858
Facter.value(:lvm_vgs).should == 0
5959
end
6060
end
6161

6262
context 'when there are vgs' do
6363
it 'should list vgs' do
64-
Facter::Util::Resolution.stubs('exec') # All other calls
65-
Facter::Util::Resolution.expects('exec').at_least(1).with('vgs -o name --noheadings 2>/dev/null').returns("vg0\nvg1")
66-
Facter::Util::Resolution.expects('exec').at_least(1).with('vgs -o pv_name vg0 2>/dev/null').returns(" PV\n /dev/pv3\n /dev/pv2")
67-
Facter::Util::Resolution.expects('exec').at_least(1).with('vgs -o pv_name vg1 2>/dev/null').returns(" PV\n /dev/pv0")
64+
Facter::Core::Execution.stubs(:execute) # All other calls
65+
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")
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'
@@ -92,17 +92,17 @@
9292
context 'when there is lvm support' do
9393
context 'when there are no pvs' do
9494
it 'should be set to 0' do
95-
Facter::Util::Resolution.stubs('exec') # All other calls
96-
Facter::Util::Resolution.expects('exec').at_least(1).with('pvs -o name --noheadings 2>/dev/null').returns(nil)
95+
Facter::Core::Execution.stubs('execute') # All other calls
96+
Facter::Core::Execution.expects('execute').at_least(1).with('pvs -o name --noheadings 2>/dev/null', timeout: 30).returns(nil)
9797
Facter.fact(:lvm_support).expects(:value).at_least(1).returns(true)
9898
Facter.value(:lvm_pvs).should == 0
9999
end
100100
end
101101

102102
context 'when there are pvs' do
103103
it 'should list pvs' do
104-
Facter::Util::Resolution.stubs('exec') # All other calls
105-
Facter::Util::Resolution.expects('exec').at_least(1).with('pvs -o name --noheadings 2>/dev/null').returns("pv0\npv1")
104+
Facter::Core::Execution.stubs('execute') # All other calls
105+
Facter::Core::Execution.expects('execute').at_least(1).with('pvs -o name --noheadings 2>/dev/null', timeout: 30).returns("pv0\npv1")
106106
Facter.fact(:lvm_support).expects(:value).at_least(1).returns(true)
107107
Facter.value(:lvm_pvs).should == 2
108108
Facter.value(:lvm_pv_0).should == 'pv0'

0 commit comments

Comments
 (0)