From 6c2a003f2139a482f92f245ce1d49830be13c5f1 Mon Sep 17 00:00:00 2001 From: Jon Fautley Date: Thu, 27 Aug 2015 14:53:02 +0100 Subject: [PATCH] (MODULES-2478) Support root_home fact on AIX through "lsuser" command Squashed, and amended test for comment lines. --- lib/facter/root_home.rb | 13 +++++++++++++ spec/fixtures/lsuser/root | 2 ++ spec/unit/facter/root_home_spec.rb | 13 +++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 spec/fixtures/lsuser/root diff --git a/lib/facter/root_home.rb b/lib/facter/root_home.rb index b4f87ff..ee3ffa8 100644 --- a/lib/facter/root_home.rb +++ b/lib/facter/root_home.rb @@ -30,3 +30,16 @@ Facter.add(:root_home) do hash['dir'].strip end end + +Facter.add(:root_home) do + confine :kernel => :aix + root_home = nil + setcode do + str = Facter::Util::Resolution.exec("lsuser -C -a home root") + str && str.split("\n").each do |line| + next if line =~ /^#/ + root_home = line.split(/:/)[1] + end + root_home + end +end diff --git a/spec/fixtures/lsuser/root b/spec/fixtures/lsuser/root new file mode 100644 index 0000000..afd59ca --- /dev/null +++ b/spec/fixtures/lsuser/root @@ -0,0 +1,2 @@ +#name:home +root:/root diff --git a/spec/unit/facter/root_home_spec.rb b/spec/unit/facter/root_home_spec.rb index 98fe141..ac5160a 100755 --- a/spec/unit/facter/root_home_spec.rb +++ b/spec/unit/facter/root_home_spec.rb @@ -49,4 +49,17 @@ describe 'root_home', :type => :fact do end end + context "aix" do + before do + Facter.fact(:kernel).stubs(:value).returns("AIX") + Facter.fact(:osfamily).stubs(:value).returns("AIX") + end + let(:expected_root_home) { "/root" } + sample_lsuser = File.read(fixtures('lsuser','root')) + + it "should return /root" do + Facter::Util::Resolution.stubs(:exec).with("lsuser -C -a home root").returns(sample_lsuser) + expect(Facter.fact(:root_home).value).to eq(expected_root_home) + end + end end