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

Allow to use different name for db resource other than db name #489

Merged
merged 2 commits into from Mar 17, 2014

Conversation

xcompass
Copy link
Contributor

@xcompass xcompass commented Mar 7, 2014

When defining the mysql::db as exported resources, there are chances that the
same resource names are defined across the site, which will cause puppet agent
fail. By adding an optional dbname parameter, default to the $name, it allows the
resource name to be defined differently, e.g. ${dbname}_${domain}.

@igalic
Copy link
Contributor

igalic commented Mar 7, 2014

Can you please add documentation for this new parameter as well as regression tests in spec/acceptance to test the new feature?

@xcompass
Copy link
Contributor Author

How's it now? I did some cleanup and rebase :)

@unthingable
Copy link

In general, puppet's way of handling resources makes using the resource name as a parameter a terrible idea. Thank you for the fix, xcompass.

mysql_user and mysql_grant need this also (and probably others).

@xcompass
Copy link
Contributor Author

Agreed! Using resource name/title can be troublesome as they have to be unique.

@igalic
Copy link
Contributor

igalic commented Mar 14, 2014

  1) mysql::db define creating a database with dbname parameter should have the database
     Failure/Error: shell("mysql -e 'show databases;'|grep realdb") do |s|
     Beaker::Host::CommandFailure:
       Host 'centos-64-x64' exited with 1 running:
         mysql -e 'show databases;'|grep realdb  
       Last 10 lines of output were:
     # ./spec/acceptance/mysql_db_spec.rb:71:in `block (3 levels) in <top (required)>'

It appears not to have been created:

[root@centos-64-x64 ~]# mysql -e "show databases;"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| foo                |
| mysql              |
| spec_db            |
| spec_latin1        |
| spec_utf8          |
| test               |
| zergdb             |
+--------------------+
[root@centos-64-x64 ~]#

@xcompass
Copy link
Contributor Author

@igalic I'm not a ruby guy. Which command did you use for the testing? I tried rake spec:system, but got the following error (one of them, basic all tests failed):

55) mysql class my.cnf should contain multiple instances of the same option File "/etc/my.cnf"
 Failure/Error: Unable to find matching line from backtrace
 NoMethodError: undefined method `success?' for #<Hash:0x007f926498dac0>
   undefined method `success?' for #<Hash:0x007f926498dac0>
 # /Users/compass/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/specinfra-0.7.1/lib/specinfra/backend/exec.rb:184:in `check_os'
 # /Users/compass/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/specinfra-0.7.1/lib/specinfra/helper/detect_os.rb:12:in `commands'
 # /Users/compass/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/rspec-system-serverspec-2.0.1/lib/rspec-system-serverspec/helper/rspec_system.rb:9:in `backend'

Tried ruby 1.9.3, 2.0.0, 2.1.0. All the same. I'm on a mac.

@xcompass
Copy link
Contributor Author

Found possible issue. Updated the tests. @igalic could you try again as I can't run acceptance tests on my machine? Thanks.

@xcompass
Copy link
Contributor Author

Hmm... Travis had some issue connecting to github....https://travis-ci.org/puppetlabs/puppetlabs-mysql/jobs/20842834#L99

fatal: unable to access 'https://github.com/puppetlabs/puppetlabs-stdlib/': Failed connect to github.com:443; Connection timed out
rake aborted!

Will try to trigger the CI build again...

When defining the mysql::db as exported resources, there are chances that the
same resource names are defined across the site, which will cause puppet agent
fail. By adding an optional dbname parameter, default to the $name, it allows the
resouce name to be defined differently, e.g. ${dbname}_${domain}.
Also updated test and docs for dbname parameter and add acceptance test for
dbname parameter feature
This will allow exported resource mysql::db to define same database but different
hostname and enables the cluster web nodes to declear the mysql::db and
to be collected on db node.
@xcompass
Copy link
Contributor Author

This time is better~

@igalic
Copy link
Contributor

igalic commented Mar 17, 2014

I'm running acceptance tests like so:

igalic@levix ~/src/puppet/puppetlabs-mysql (git)-[dbname] % RS_DEBUG=on RS_DESTROY=onpass ~/.gem/ruby/1.9.1/bin/bundle exec rspec spec/acceptance/ 
Hypervisor for centos-64-x64 is vagrant
Beaker::Hypervisor, found some vagrant boxes to create
[centos-64-x64] VM not created. Moving on...
created Vagrantfile for VagrantHost centos-64-x64
Bringing machine 'centos-64-x64' up with 'virtualbox' provider...
[centos-64-x64] Importing base box 'centos-64-x64-vbox4210-nocm'...

@igalic
Copy link
Contributor

igalic commented Mar 17, 2014

wheeee works now! (on the default set).…

I'm testing

% RS_SET=ubuntu-server-12042-x64 RS_DEBUG=on RS_DESTROY=onpass ~/.gem/ruby/1.9.1/bin/bundle exec rspec spec/acceptance/ 

now too

}
ensure_resource('mysql_database', $dbname, $db_resource)
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, I didn't notice this change before, but: Why are you doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is in the second commit message:

This will allow exported resource mysql::db to define same database but different hostname and enables the cluster web nodes to declare the mysql::db and to be collected on db node.

People can define different users on the same database. Before it will trigger and duplicated resources error because the mysql_database[$dbname] is already defined.

igalic added a commit that referenced this pull request Mar 17, 2014
Allow to use different name for db resource other than db name
@igalic igalic merged commit 97c4d4e into puppetlabs:master Mar 17, 2014
@xcompass xcompass deleted the exported-resource-mysql-db branch March 17, 2014 18:20
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.

None yet

4 participants