-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Fix sysctl -a line parsing for FreeBSD #18
Conversation
lib/puppet/provider/sysctl/augeas.rb
Outdated
@@ -78,11 +78,10 @@ def self.instances(reference_resource = nil) | |||
resources ||= [] | |||
|
|||
sysctl('-a').each_line do |line| | |||
value = line.split('=') | |||
value = line.split(/(=|:)/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather use the form /[=:]/
I see what you're doing, but it's not strictly equivalent. Iirc, there were cases when values contained Old code:irb(main):002:0> line="a.b.c = 3=4"
=> "a.b.c = 3=4"
irb(main):003:0> value = line.split('=')
=> ["a.b.c ", " 3", "4"]
irb(main):004:0> key = value.shift.strip
=> "a.b.c"
irb(main):005:0> value = value.join('=').strip
=> "3=4" Your codeirb(main):016:0> line="a.b.c = 3=4"
=> "a.b.c = 3=4"
irb(main):017:0> value = line.split(/(=|:)/)
=> ["a.b.c ", "=", " 3", "=", "4"]
irb(main):018:0> key = value.shift.strip
=> "a.b.c"
irb(main):019:0> value = value.shift.to_s.strip
=> "=" |
Thanks for the feedback. I updated the PR. |
1 similar comment
Is there any chance of some progress on this, I've just come across this because I got an error of |
That looks good to me (although a bit harder to understand). Do you think you could add tests for this? |
I'm new to Ruby and having trouble getting the tests to build. Do you have insight what I'm doing wrong? Thanks.
|
It looks like you also need I too am new to Ruby and try to interact with it as little as Puppet allows me to (which is far too much for my liking) but this is definitely an area that I need to learn. |
I've had a good look into how you are supposed to add the There is this comment: |
@rick-pri Check and make sure that the It appears to be in my copy, but may have been removed at some point. Also, you may need to remove |
Hi @trevor-vaughan it seems that I do have a
Actually, I can see that the module gets imported by watching the directory as the test run so the issue seems to be maybe one of pathing. |
The error starts with If I do a I had a look at using |
@rick-pri Try following these instructions for setting up a test environment. I generally prefer http://simp.readthedocs.io/en/master/getting_started_guide/ISO_Build/Environment_Preparation.html |
I followed that as far as I could. I have rvm installed, tried to activate rvm (how do you know if you're using the rvm? virtualenv changes the shell on sourcing the env so you know when you're in the virtualenv). I've done a bundle install and it installed a bunch of stuff. Now in python venv that would have been installed to the virtualenv, and I'd have been able to see the contents of the venv with a |
@rick-pri You should be good to go. You can see what Ruby you're using by running The shell doesn't change by default due to not wanting to disrupt the developer's environment. Think of |
@raphink Any reason not to merge this? |
Fixed in #30 |
Hello,
I ran in to a problem while using this nice module on FreeBSD.
Error: /Stage[main]/MyModule::Config/Sysctl[security.bsd.see_other_uids]: Could not evaluate: Error:
security.bsd.see_other_uids
is not a valid sysctl keyError: /Stage[main]/MyModule::Config/Sysctl[security.bsd.see_other_gids]: Could not evaluate: Error:
security.bsd.see_other_gids
is not a valid sysctl keyThese are valid keys for FreeBSD, so it shouldn't be giving the error. I tracked it down to https://github.com/hercules-team/augeasproviders_sysctl/blob/master/lib/puppet/provider/sysctl/augeas.rb#L81
value = line.split('=')
It's splitting each line of output from sysctl -a, looking for the equals sign, so it can extract the key and the value. The problem is that the output from Linux has an equals sign seperator, while the output from BSD has a colon ":" seperator. Since it can't match the key with the colon seperator it throws the error.
I fixed it by changing L81 to a RegExp
value = line.split(/(=|:)/)
that matches on either an equals sign, or a colon.Thanks