]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
(MODULES-2478) Support root_home fact on AIX through "lsuser" command
authorJon Fautley <jon@dead.li>
Thu, 27 Aug 2015 13:53:02 +0000 (14:53 +0100)
committerJon Fautley <jon@dead.li>
Fri, 28 Aug 2015 14:21:13 +0000 (15:21 +0100)
Squashed, and amended test for comment lines.

lib/facter/root_home.rb
spec/fixtures/lsuser/root [new file with mode: 0644]
spec/unit/facter/root_home_spec.rb

index b4f87ff2ab2c7a49a421d2e5281d8d9f86211f97..ee3ffa8ced01dd61e10824f9bd50787fe72a249e 100644 (file)
@@ -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 (file)
index 0000000..afd59ca
--- /dev/null
@@ -0,0 +1,2 @@
+#name:home
+root:/root
index 98fe14196dbdf075140858040d41c800e42c2ec9..ac5160a7ff246a4a417fa657987ee94b623109b1 100755 (executable)
@@ -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