Skip to content

Commit 9352db7

Browse files
committed
Merge pull request #515 from jfautley/ticket/MODULES-2478-support_root_home_fact_on_AIX
(MODULES-2478) Make root_home fact work on AIX using native lsuser command
2 parents b109787 + 6c2a003 commit 9352db7

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

lib/facter/root_home.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,16 @@ def get_root_home
3030
hash['dir'].strip
3131
end
3232
end
33+
34+
Facter.add(:root_home) do
35+
confine :kernel => :aix
36+
root_home = nil
37+
setcode do
38+
str = Facter::Util::Resolution.exec("lsuser -C -a home root")
39+
str && str.split("\n").each do |line|
40+
next if line =~ /^#/
41+
root_home = line.split(/:/)[1]
42+
end
43+
root_home
44+
end
45+
end

spec/fixtures/lsuser/root

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#name:home
2+
root:/root

spec/unit/facter/root_home_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,17 @@
4949
end
5050
end
5151

52+
context "aix" do
53+
before do
54+
Facter.fact(:kernel).stubs(:value).returns("AIX")
55+
Facter.fact(:osfamily).stubs(:value).returns("AIX")
56+
end
57+
let(:expected_root_home) { "/root" }
58+
sample_lsuser = File.read(fixtures('lsuser','root'))
59+
60+
it "should return /root" do
61+
Facter::Util::Resolution.stubs(:exec).with("lsuser -C -a home root").returns(sample_lsuser)
62+
expect(Facter.fact(:root_home).value).to eq(expected_root_home)
63+
end
64+
end
5265
end

0 commit comments

Comments
 (0)