Permalink
Browse files

Merge pull request #93 from Savar/master

new config define and a small bugfix
  • Loading branch information...
2 parents e01b1fc + e27cff0 commit 0e4de09934be505ede1acc6232c1519a8715c6f1 @hunner hunner committed Aug 29, 2012
Showing with 178 additions and 1 deletion.
  1. +1 −1 manifests/config.pp
  2. +112 −0 manifests/server/config.pp
  3. +37 −0 spec/defines/mysql_server_config_spec.rb
  4. +17 −0 templates/my.conf.cnf.erb
  5. +11 −0 tests/server/config.pp
View
@@ -6,7 +6,7 @@
# [*old_root_password*] - previous root user password,
# [*bind_address*] - address to bind service.
# [*port*] - port to bind service.
-# [*etc_root_password*] - whether to save /etc/.my.cnf.
+# [*etc_root_password*] - whether to save /etc/my.cnf.
# [*service_name*] - mysql service name.
# [*config_file*] - my.cnf configuration file path.
# [*socket*] - mysql socket.
View
@@ -0,0 +1,112 @@
+# Creates a my.cnf like config file in the conf.d/ directory.
+#
+# IMPORTANT: this should be used AFTER the inclusion of
+# mysql::server because it needs some variables
+# out of the mysql::config class which will be
+# included!
+#
+# == Parameters:
+#
+# - name: is the name of the file
+# - notify_service: whether to notify the mysql daemon or not (default: true)
+# - settings: either a string which should be the content of the file
+# or a hash with the following structure
+#
+# section => {
+# <key> => <value>,
+# ...
+# },
+# ...
+#
+# +section+ means all these sections you can set in
+# an configuration file like +mysqld+, +client+,
+# +mysqldump+ and so on
+# +key+ has to be a valid property which you can set like
+# +datadir+, +socket+ or even flags like +read-only+
+#
+# +value+ can be
+# a) a string as the value
+# b) +true+ or +false+ to set a flag like 'read-only' or leave
+# it out (+false+ means, nothing will be done)
+# c) an array of values which can be of type a) and/or b)
+#
+#
+# == Examples:
+#
+# Easy one:
+#
+# mysql::server::config { 'basic_config':
+# settings => "[mysqld]\nskip-external-locking\n"
+# }
+#
+# This will create the file /etc/mysql/conf.d/10_basic_config.cnf with
+# the following content:
+#
+# [mysqld]
+# skip-external-locking
+#
+#
+# More complex example:
+#
+# mysql::server::config { 'basic_config':
+# settings => {
+# 'mysqld' => {
+# 'query_cache_limit' => '5M',
+# 'query_cache_size' => '128M',
+# 'port' => 3300,
+# 'skip-external-locking' => true,
+# 'replicate-ignore-db' => [
+# 'tmp_table',
+# 'whateveryouwant'
+# ]
+# },
+#
+# 'client' => {
+# 'port' => 3300
+# }
+# }
+# }
+#
+# This will create the file /etc/mysql/conf.d/14_basic_config.cnf with
+# the following content:
+#
+# [mysqld]
+# query_cache_limit = 5M
+# query_cache_size = 128M
+# port = 3300
+# skip-external-locking
+# replicate-ignore-db = tmp_table
+# replicate-ignore-db = whateveryouwant
+#
+# [client]
+# port = 3300
+#
+define mysql::server::config (
+ $settings,
+ $notify_service = true
+) {
+ include mysql::config
+
+ # XXX would be nicer to use the is_hash function from stdlib
+ if inline_template('<%= settings.is_a?(Hash) ? "true" : "false" %>') == 'true' {
+ $content = template('mysql/my.conf.cnf.erb')
+ } else {
+ $content = $settings
+ }
+
+ file { "/etc/mysql/conf.d/${name}.cnf":
+ ensure => file,
+ content => $content,
+ owner => 'root',
+ group => $mysql::config::root_group,
+ mode => '0644',
+ require => Package['mysql-server'],
+ }
+
+ if $notify_service {
+ File["/etc/mysql/conf.d/${name}.cnf"] {
+ # XXX notifing the Service gives us a dependency circle but I don't understand why
+ notify => Exec['mysqld-restart']
+ }
+ }
+}
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe 'mysql::server::config', :type => :define do
+ filename = '/etc/mysql/conf.d/test_config.cnf'
+
+ let :facts do
+ { :osfamily => 'Debian'}
+ end
+
+ let(:title) { File.basename(filename, '.cnf') }
+
+ let(:params) {
+ { 'settings' => {
+ 'mysqld' => {
+ 'bind-address' => '0.0.0.0'
+ }
+ }
+ }
+ }
+
+ it 'should notify the mysql daemon' do
+ should contain_file(filename).with_notify('Exec[mysqld-restart]')
+ end
+
+ it 'should contain config parameter in content' do
+ should contain_file(filename).with_content("### MANAGED BY PUPPET ###\n[mysqld]\nbind-address = 0.0.0.0\n\n")
+ end
+
+ it 'should not notify the mysql daemon' do
+ params.merge!({ 'notify_service' => false })
+ should contain_file(filename).without_notify
+ end
+
+ it 'should require on the mysql-server package' do
+ should contain_file(filename).with_require('Package[mysql-server]')
+ end
+end
View
@@ -0,0 +1,17 @@
+### MANAGED BY PUPPET ###
+<% settings.sort.each do |section, content| -%>
+[<%= section %>]
+<% content.sort.each do |key, values| -%>
+<% [values].flatten.sort.each do |value| -%>
+<%= value == false ? '#' : '' %><%= key -%><%=
+ case value
+ when true, false
+ ''
+ else
+ " = #{value}"
+ end
+%>
+<% end -%>
+<% end -%>
+
+<% end -%>
View
@@ -0,0 +1,11 @@
+mysql::server::config { 'testfile':
+ settings => {
+ 'mysqld' => {
+ 'bind-address' => '0.0.0.0',
+ 'read-only' => true,
+ },
+ 'client' => {
+ 'port' => '3306'
+ }
+ }
+}

0 comments on commit 0e4de09

Please sign in to comment.