summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Dibowitz <phil@ipom.com>2014-08-05 13:05:02 -0700
committerPhil Dibowitz <phil@ipom.com>2014-08-05 13:05:02 -0700
commit128c2be3ac24e99504890d5e20a5392ad0931f01 (patch)
treeb050110f3a23d9beb8dec25e211946df34ef6460
parente1f6c2814a6a975b67fb8d8ace8348171d186654 (diff)
parentce8d117d7325909cc0262dac9dd657970bd8075c (diff)
downloadchef-128c2be3ac24e99504890d5e20a5392ad0931f01.tar.gz
Merge pull request #1746 from jaymzh/macosx_groups_10
Fix OSX Group provider to be properly idempotent
-rw-r--r--CHANGELOG.md3
-rw-r--r--RELEASE_NOTES.md1
-rw-r--r--chef/lib/chef/provider/group/dscl.rb36
-rw-r--r--chef/spec/unit/provider/group/dscl_spec.rb35
4 files changed, 65 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3d4dc7f2a6..4425d3330c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,7 +8,8 @@
* Set Net::HTTP open_timeout. (backport Chef-1585)
* Fix RPM package version detection (backport Issue 1554)
* Support for single letter environments.
-*
+* [**Phil Dibowitz**](https://github.com/jaymzh):
+ 'group' provider on OSX properly uses 'dscl' to determine existing groups
## 10.32.2
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index a2f9df5a09..c813e2d2fa 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -9,5 +9,6 @@ Details about the thing that changed that needs to get included in the Release N
# Chef Client 10.x Release Notes:
* Backport CHEF-5223 Fix to 10-stable
+* 'group' provider on OSX properly uses 'dscl' to determine existing groups
# Chef Client 10.x Breaking Changes:
diff --git a/chef/lib/chef/provider/group/dscl.rb b/chef/lib/chef/provider/group/dscl.rb
index 5af754fe87..1293a685e2 100644
--- a/chef/lib/chef/provider/group/dscl.rb
+++ b/chef/lib/chef/provider/group/dscl.rb
@@ -39,11 +39,33 @@ class Chef
return result[2]
end
- # This is handled in providers/group.rb by Etc.getgrnam()
- # def group_exists?(group)
- # groups = safe_dscl("list /Groups")
- # !! ( groups =~ Regexp.new("\n#{group}\n") )
- # end
+ def load_current_resource
+ @current_resource = Chef::Resource::Group.new(@new_resource.name)
+ @current_resource.group_name(@new_resource.name)
+ group_info = nil
+ begin
+ group_info = safe_dscl("read /Groups/#{@new_resource.name}")
+ rescue Chef::Exceptions::Group
+ @group_exists = false
+ Chef::Log.debug("#{@new_resource} group does not exist")
+ end
+
+ if group_info
+ group_info.each_line do |line|
+ key, val = line.split(': ')
+ val.strip! if val
+ case key.downcase
+ when 'primarygroupid'
+ @new_resource.gid(val) unless @new_resource.gid
+ @current_resource.gid(val)
+ when 'groupmembership'
+ @current_resource.members(val.split(' '))
+ end
+ end
+ end
+
+ @current_resource
+ end
# get a free GID greater than 200
def get_free_gid(search_limit=1000)
@@ -115,10 +137,6 @@ class Chef
end
end
- def load_current_resource
- super
- end
-
def create_group
dscl_create_group
set_gid
diff --git a/chef/spec/unit/provider/group/dscl_spec.rb b/chef/spec/unit/provider/group/dscl_spec.rb
index a3e3679eda..2a1864fc8e 100644
--- a/chef/spec/unit/provider/group/dscl_spec.rb
+++ b/chef/spec/unit/provider/group/dscl_spec.rb
@@ -293,3 +293,38 @@ describe Chef::Provider::Group::Dscl do
end
end
end
+
+describe 'Test DSCL loading' do
+ before do
+ @node = Chef::Node.new
+ @events = Chef::EventDispatch::Dispatcher.new
+ @run_context = Chef::RunContext.new(@node, {}, @events)
+ @new_resource = Chef::Resource::Group.new("aj")
+ @provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context)
+ @output = <<-EOF
+AppleMetaNodeLocation: /Local/Default
+Comment:
+ Test Group
+GeneratedUID: AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA
+NestedGroups: AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAB
+Password: *
+PrimaryGroupID: 999
+RealName:
+ TestGroup
+RecordName: com.apple.aj
+RecordType: dsRecTypeStandard:Groups
+GroupMembership: waka bar
+EOF
+ @provider.stub(:safe_dscl).with("read /Groups/aj").and_return(@output)
+ @current_resource = @provider.load_current_resource
+ end
+
+ it 'should parse gid properly' do
+ File.stub(:exists?).and_return(true)
+ @current_resource.gid.should eq("999")
+ end
+ it 'should parse members properly' do
+ File.stub(:exists?).and_return(true)
+ @current_resource.members.should eq(['waka', 'bar'])
+ end
+end