(PUP-1459) Add support for root_home on OS X 10.9
getent does not exist on 10.9 so this commit uses dscacheutil to query the homedir for the root user.
This commit is contained in:
parent
e49d356fbf
commit
fe676f0ac4
3 changed files with 41 additions and 9 deletions
|
@ -17,3 +17,16 @@ end
|
||||||
Facter.add(:root_home) do
|
Facter.add(:root_home) do
|
||||||
setcode { Facter::Util::RootHome.get_root_home }
|
setcode { Facter::Util::RootHome.get_root_home }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Facter.add(:root_home) do
|
||||||
|
confine :kernel => :darwin
|
||||||
|
setcode do
|
||||||
|
str = Facter::Util::Resolution.exec("dscacheutil -q user -a name root")
|
||||||
|
hash = {}
|
||||||
|
str.split("\n").each do |pair|
|
||||||
|
key,value = pair.split(/:/)
|
||||||
|
hash[key] = value
|
||||||
|
end
|
||||||
|
hash['dir'].strip
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
8
spec/fixtures/dscacheutil/root
vendored
Normal file
8
spec/fixtures/dscacheutil/root
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
name: root
|
||||||
|
password: *
|
||||||
|
uid: 0
|
||||||
|
gid: 0
|
||||||
|
dir: /var/root
|
||||||
|
shell: /bin/bash
|
||||||
|
gecos: rawr Root
|
||||||
|
|
|
@ -20,15 +20,6 @@ describe Facter::Util::RootHome do
|
||||||
Facter::Util::RootHome.get_root_home.should == expected_root_home
|
Facter::Util::RootHome.get_root_home.should == expected_root_home
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "macosx" do
|
|
||||||
let(:root_ent) { "root:*:0:0:System Administrator:/var/root:/bin/sh" }
|
|
||||||
let(:expected_root_home) { "/var/root" }
|
|
||||||
|
|
||||||
it "should return /var/root" do
|
|
||||||
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
|
|
||||||
Facter::Util::RootHome.get_root_home.should == expected_root_home
|
|
||||||
end
|
|
||||||
end
|
|
||||||
context "windows" do
|
context "windows" do
|
||||||
before :each do
|
before :each do
|
||||||
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
|
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
|
||||||
|
@ -38,3 +29,23 @@ describe Facter::Util::RootHome do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'root_home', :type => :fact do
|
||||||
|
before { Facter.clear }
|
||||||
|
after { Facter.clear }
|
||||||
|
|
||||||
|
context "macosx" do
|
||||||
|
before do
|
||||||
|
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
||||||
|
Facter.fact(:osfamily).stubs(:value).returns("Darwin")
|
||||||
|
end
|
||||||
|
let(:expected_root_home) { "/var/root" }
|
||||||
|
sample_dscacheutil = File.read(fixtures('dscacheutil','root'))
|
||||||
|
|
||||||
|
it "should return /var/root" do
|
||||||
|
Facter::Util::Resolution.stubs(:exec).with("dscacheutil -q user -a name root").returns(sample_dscacheutil)
|
||||||
|
Facter.fact(:root_home).value.should == expected_root_home
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue