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

Fix having wildcards (%) in hostnames of grants #366

Merged
merged 2 commits into from
Nov 19, 2013

Conversation

liwo
Copy link

@liwo liwo commented Nov 8, 2013

This changes the mysql_grant grant regex to more closely
resemble the one in current master. This version is now
able to handle wildcards in grants ('user'@'192.168.%').

This changes the mysql_grant grant regex to more closely
resemble the one in current master. This version is now
able to handle wildcards in grants ('user'@'192.168.%').
@igalic
Copy link
Contributor

igalic commented Nov 10, 2013

Can you please add an rspec:system test so we won't break this kind of thing in the future?

@liwo
Copy link
Author

liwo commented Nov 10, 2013

Sorry, I neither know how to write ruby code (I can read it and patch a regexp, but that's about it) nor do I have any idea how to write such a test. I had a look at cc51d7a but I don't understand how that test works. It apparently tests only if the privileges are granted but not whether the regex does recognize them again (which was the problem here), as far as I can see. So copying and adjusting this doesn't seem like the way to go.

How should I proceed with that?

@apenney
Copy link
Contributor

apenney commented Nov 10, 2013

What we'd be looking for is basically a modification to https://github.com/puppetlabs/puppetlabs-mysql/blob/master/spec/system/types/mysql_grant_spec.rb to copy an existing test and tweak it. You'd copy a describe block completely, change the pp = puppet stuff to use 'user'@'192.168.%' and then modify one of the:

it 'should find the user' do
shell("mysql -NBe "SHOW GRANTS FOR test2@tester"") do |r|
r.stdout.should =~ /GRANT SELECT, UPDATE.*TO 'test2'@'tester'/

Blocks to be SHOW GRANTS FOR user@192.168.% and tweak what the stdout return is. I hope that makes sense, it's basically cut and pasting and tweaking a few bits. If you have vagrant and virtualbox installed you can run:

rake spec:system

And it'll run all those tests against a centos VM.

@igalic
Copy link
Contributor

igalic commented Nov 11, 2013

To install all the dependency ruby gems, you'll also need to install the gem bundler, e.g.:

sudo gem install bundler

and then, in your puppetlabs-mysql clone:

igalic@levix ~/src/puppet/puppetlabs-mysql (git)-[master] % bundle install
igalic@levix ~/src/puppet/puppetlabs-mysql (git)-[master] % bundle install
Fetching gem metadata from https://rubygems.org/............
Resolving dependencies...
Enter your password to install the bundled RubyGems to your system: 
Using rake (10.1.0) 
Installing CFPropertyList (2.2.4) 
Using builder (3.2.2) 
Installing excon (0.28.0) 
Installing formatador (0.2.4) 
Using mime-types (1.25) 
Installing multi_json (1.8.2) 
Using net-ssh (2.7.0) 
Using net-scp (1.1.2) 
Using nokogiri (1.5.10) 
Installing ruby-hmac (0.4.0) 
Installing fog (1.18.0) 
Installing minitar (0.5.4) 
Using thor (0.18.1) 
Installing blimpy (0.6.7) 
Installing fission (0.5.0) 
Installing inifile (2.0.2) 
Installing json (1.8.1) 
Using trollop (2.0) 
Using rbvmomi (1.6.0) 
Installing beaker (0.0.0) 
Installing coderay (1.1.0) 
Installing diff-lcs (1.2.5) 
Installing docile (1.1.0) 
Using facter (1.7.3) 
Installing json_pure (1.8.1) 
Using hiera (1.2.1) 
Installing highline (1.6.20) 
Using kwalify (0.7.2) 
Installing lockfile (2.1.0) 
Using metaclass (0.0.1) 
Using method_source (0.8.2) 
Using mocha (0.14.0) 
Using slop (3.4.6) 
Installing pry (0.9.12.3) 
Using rgen (0.6.6) 
Using puppet (3.3.1) 
Using puppet-lint (0.3.2) 
Installing rspec-core (2.14.7) 
Installing rspec-expectations (2.14.4) 
Installing rspec-mocks (2.14.4) 
Using rspec (2.14.1) 
Using rspec-puppet (0.1.6) 
Using puppetlabs_spec_helper (0.4.1.13) 
Using systemu (2.5.2) 
Installing rspec-system (2.7.1) 
Installing rspec-system-puppet (2.2.1) 
Installing serverspec (0.10.13) 
Installing rspec-system-serverspec (1.0.1) 
Installing simplecov-html (0.8.0) 
Installing simplecov (0.8.1) 
Using bundler (1.3.5) 
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
bundle install  13,02s user 2,46s system 4% cpu 6:00,70 total
igalic@levix ~/src/puppet/puppetlabs-mysql (git)-[master] %

@liwo
Copy link
Author

liwo commented Nov 11, 2013

Thanks for the pointers. I got bundler to run and install all those packages. My Laptops CPU is not able to run 64bit VMs with virtualbox, so I still have to find a way to actually run the tests. Tonight it's getting late, so that has to wait till tomorrow.

@igalic
Copy link
Contributor

igalic commented Nov 12, 2013

I was going to suggest to run spec:system with an option to select a different prefab, but we don't have a 32bit prefab

@liwo
Copy link
Author

liwo commented Nov 12, 2013

Status update: I got the tests to run on a machine at work, so tomorrow I can start writing the test.

I have one failing test which should be unrelated to this, but I'm wondering whether my setup is ok or not.

Failures:

  1) mysql::bindings class enabling bindings Package "ruby-mysql"
     Failure/Error: it { should be_installed }
       rpm -q ruby-mysql
       package ruby-mysql is not installed
       expected Package "ruby-mysql" to be installed
     # ./spec/system/mysql_bindings_spec.rb:85:in `block (4 levels) in <top (required)>'

@apenney
Copy link
Contributor

apenney commented Nov 12, 2013

I've seen this fail before and it bugs me, just ignore it, I don't know what's up with it :(

@apenney
Copy link
Contributor

apenney commented Nov 12, 2013

(I'll spend some time trying to figure out what's going on tho)

@igalic
Copy link
Contributor

igalic commented Nov 12, 2013

seeing how this issue is developing into that general direction, we should copy&paste its gist to the README or to CONTRIBUTING to tell people how to get started with writing tests.

I think the only thing missing is, how do I run one specific test or test file.

@liwo
Copy link
Author

liwo commented Nov 13, 2013

I did as suggested and added a test applying a puppet definition and then verifying that mysql indeed had the grant. However, this proved to be insufficient as this test also succeeded without my change (as expected, it did work, but reapplied the change on every puppet run without my change). Therefore I added another test applying the puppet definition a second time and checking whether puppet would change the grant again. This test only succeeds with my change applied.

As my ruby knowledge is near to zero I hope the code I copied and adjusted makes sense.

apenney pushed a commit that referenced this pull request Nov 19, 2013
Fix having wildcards (%) in hostnames of grants
@apenney apenney merged commit 0ca5bbf into puppetlabs:1.x Nov 19, 2013
@apenney
Copy link
Contributor

apenney commented Nov 19, 2013

Testing looked good to me, thanks!

@liwo liwo deleted the bugfix/wildcards-in-grants branch November 22, 2013 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants