Skip to content

Commit 5623ce7

Browse files
authored
Merge pull request #308 from rtib/GH-307
fix issues on nodes without lvm
2 parents 22ba15e + 8879717 commit 5623ce7

File tree

3 files changed

+27
-45
lines changed

3 files changed

+27
-45
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ Logical volume size can be extended, but not reduced -- this is for
347347
safety, as manual intervention is probably required for data
348348
migration, etc.
349349

350+
## Deprecation Notice
351+
352+
Some facts reported by this module are being deprecated in favor of upcomming structured facts. The following facts are being deprecated:
353+
354+
* `lvm_vg_*`
355+
* `lvm_vg_*_pvs`
356+
* `lvm_pv_*`
350357

351358
# Contributors
352359

lib/facter/lvm_support.rb

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@
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

3028
# lvm_vg_[0-9]+
3129
# 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
@@ -47,17 +47,18 @@
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

5958
# lvm_pv_[0-9]+
6059
# 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

spec/unit/facter/lvm_support_spec.rb

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,10 @@
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
58-
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o name --noheadings 2>/dev/null', timeout: 30).returns(nil)
5957
Facter.fact(:lvm_support).expects(:value).at_least(1).returns(true)
60-
Facter.value(:lvm_vgs).should == 0
61-
end
62-
end
63-
64-
context 'when there are vgs' do
65-
it 'lists vgs' do
6658
Facter::Core::Execution.stubs(:execute) # All other calls
67-
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o name --noheadings 2>/dev/null', timeout: 30).returns(" vg0\n vg1")
68-
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")
69-
Facter::Core::Execution.expects(:execute).at_least(1).with('vgs -o pv_name vg1 2>/dev/null', timeout: 30).returns(" PV\n /dev/pv0")
70-
Facter.fact(:lvm_support).expects(:value).at_least(1).returns(true)
71-
Facter.value(:lvm_vgs).should == 2
72-
Facter.value(:lvm_vg_0).should == 'vg0'
73-
Facter.value(:lvm_vg_1).should == 'vg1'
74-
Facter.value(:lvm_vg_vg0_pvs).should == '/dev/pv2,/dev/pv3'
75-
Facter.value(:lvm_vg_vg1_pvs).should == '/dev/pv0'
59+
Facter::Core::Execution.expects(:execute).at_least(0).with('vgs -o name --noheadings 2>/dev/null', timeout: 30).returns(nil)
60+
Facter.value(:lvm_vgs).should == 0
7661
end
7762
end
7863
end
@@ -95,21 +80,10 @@
9580
context 'when there are no pvs' do
9681
it 'is set to 0' do
9782
Facter::Core::Execution.stubs('execute') # All other calls
98-
Facter::Core::Execution.expects('execute').at_least(1).with('pvs -o name --noheadings 2>/dev/null', timeout: 30).returns(nil)
9983
Facter.fact(:lvm_support).expects(:value).at_least(1).returns(true)
84+
Facter::Core::Execution.expects('execute').at_least(0).with('pvs -o name --noheadings 2>/dev/null', timeout: 30).returns(nil)
10085
Facter.value(:lvm_pvs).should == 0
10186
end
10287
end
103-
104-
context 'when there are pvs' do
105-
it 'lists pvs' do
106-
Facter::Core::Execution.stubs('execute') # All other calls
107-
Facter::Core::Execution.expects('execute').at_least(1).with('pvs -o name --noheadings 2>/dev/null', timeout: 30).returns(" pv0\n pv1")
108-
Facter.fact(:lvm_support).expects(:value).at_least(1).returns(true)
109-
Facter.value(:lvm_pvs).should == 2
110-
Facter.value(:lvm_pv_0).should == 'pv0'
111-
Facter.value(:lvm_pv_1).should == 'pv1'
112-
end
113-
end
11488
end
11589
end

0 commit comments

Comments
 (0)