Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error handling around obtaining the user's Group ID #89

Merged
merged 3 commits into from
Aug 26, 2015

Conversation

theckman
Copy link
Collaborator

During why_run mode, the user has not been created yet. As such, calls to Etc.getpwnam() result in an ArgumentError being thrown.

Add a user_gid method that either returns the gid or nil, and use it where the gid is required.

During `why_run` mode, the user has not been created yet. As such, calls to `Etc.getpwnam()` result in an `ArgumentError` being thrown.

Add a `user_gid` method that either returns the gid or nil, and use it where the gid is required.
@CpuID
Copy link
Contributor

CpuID commented Apr 14, 2015

I wonder if taking into account the converged_by logic in http://dougireton.com/blog/2013/01/07/creating-an-lwrp-part-2/ is relevant here...?

Also, getting the below when running a converge with this:

           NoMethodError
           -------------
           undefined method `user_gid' for Chef::Resource::Directory

           Cookbook Trace:
       ---------------
           /tmp/kitchen/cache/cookbooks/user/providers/account.rb:142:in `block in home_dir_resource'
       /tmp/kitchen/cache/cookbooks/user/providers/account.rb:139:in `home_dir_resource'
       /tmp/kitchen/cache/cookbooks/user/providers/account.rb:41:in `block in class_from_file'

Chef 12.2.1

@CpuID
Copy link
Contributor

CpuID commented Apr 14, 2015

I have a fix for the above error, will PR it to @theckman to merge together :)

@CpuID
Copy link
Contributor

CpuID commented Apr 14, 2015

Fix for Chef 12.x / Ruby 2.x for this PR in theckman#1, so it can be merged together with this PR

Fix whyrun on Chef 12.x / Ruby 2.x
@ranjib
Copy link
Collaborator

ranjib commented Apr 20, 2015

chef provides some built-in classes to deal with such scenarios, im thinking whether to convert the provider to leverage them. aka, define_resource_requirements
API: https://github.com/chef/chef/blob/master/lib/chef/provider.rb#L90
Usage: https://github.com/chef/chef/blob/master/lib/chef/provider/git.rb#L42

@ranjib
Copy link
Collaborator

ranjib commented Apr 20, 2015

also, cant we just use new_resource.username as the value of group attribute, instead of computing the gid?

@@ -94,6 +94,14 @@ def normalize_bool(val)
end
end

def user_gid
# this check is needed as the new user won't exit yet

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spell 'exist' correctly.

ranjib added a commit that referenced this pull request Aug 26, 2015
improve error handling around obtaining the user's Group ID
@ranjib ranjib merged commit fd2094c into fnichol:master Aug 26, 2015
theckman added a commit that referenced this pull request Nov 4, 2016
This project has been dormant for awhile, and I wanted to have a nice
recap of things introduced since `0.4.2` was released:

* fix an error in the LWRP when a `--why-run` invocation is invoked
  before the user has been created (PR #89 by Tim Heckman).
* add a `groups` resource to the LWRP to allow the user to be added to
  additional groups upon creation (PR #96 by acqant)
theckman added a commit that referenced this pull request Nov 4, 2016
This project has been dormant for awhile, and I wanted to have a nice
recap of things introduced since `0.4.2` was released:

* fix an error in the LWRP when a `--why-run` invocation is invoked
  before the user has been created (PR #89 by Tim Heckman).
* add a `groups` resource to the LWRP to allow the user to be added to
  additional groups upon creation (PR #96 by acqant)
theckman added a commit that referenced this pull request Nov 4, 2016
This project has been dormant for awhile, and I wanted to have a nice
recap of things introduced since `0.4.2` was released:

* fix an error in the LWRP when a `--why-run` invocation is invoked
  before the user has been created (PR #89 by Tim Heckman).
* add a `groups` resource to the LWRP to allow the user to be added to
  additional groups upon creation (PR #96 by acqant)
* fix tests and dependencies to work with Ruby 2.1.4 (version shipped
  with Chef 12.1.0)
theckman added a commit that referenced this pull request Nov 4, 2016
This project has been dormant for awhile, and I wanted to have a nice
recap of things introduced since `0.4.2` was released:

* fix an error in the LWRP when a `--why-run` invocation is invoked
  before the user has been created (PR #89 by Tim Heckman).
* add a `groups` resource to the LWRP to allow the user to be added to
  additional groups upon creation (PR #96 by acqant)
* add `issues_url` and `source_url` to the metadata file
* fix tests and dependencies to work with Ruby 2.1.4 (version shipped
  with Chef 12.1.0)
theckman added a commit that referenced this pull request Nov 20, 2016
Nico Kadel-Garcia reported this typo in #89 (7d445ed) and it was merged-in
before it could be fixed.

This finally gets around to fixing the issue only 537 days later. :( Sorry it
took so long Nico, and thank you for the earlier review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants