From f26cb3a7d2fd9918bf6ea1e6e41839c02dfe3160 Mon Sep 17 00:00:00 2001 From: David Goodlad Date: Sat, 1 Feb 2014 17:36:34 -0500 Subject: [PATCH 1/4] Start killing mysql::params in favor of hiera --- data/Darwin.yaml | 14 +++++++++++++ data/common.yaml | 4 ++++ data/hiera.yaml | 6 ++++++ manifests/config.pp | 22 ++++++++++---------- manifests/init.pp | 32 +++++++++++++++--------------- manifests/params.pp | 28 -------------------------- spec/classes/mysql__config_spec.rb | 14 +++++++++++++ spec/fixtures/Puppetfile | 3 ++- spec/fixtures/Puppetfile.lock | 10 ++++++++-- spec/fixtures/hiera/hiera.yaml | 6 ++++++ spec/fixtures/hiera/test.yaml | 6 ++++++ spec/spec_helper.rb | 5 ++++- 12 files changed, 91 insertions(+), 59 deletions(-) create mode 100644 data/Darwin.yaml create mode 100644 data/common.yaml create mode 100644 data/hiera.yaml create mode 100644 spec/fixtures/hiera/hiera.yaml create mode 100644 spec/fixtures/hiera/test.yaml diff --git a/data/Darwin.yaml b/data/Darwin.yaml new file mode 100644 index 0000000..90e4d09 --- /dev/null +++ b/data/Darwin.yaml @@ -0,0 +1,14 @@ +--- +mysql::configdir: "%{::boxen::config::configdir}/mysql" +mysql::globalconfigprefix: "%{::boxen::config::homebrewdir}" +mysql::datadir: "%{::boxen::config::datadir}/mysql" +mysql::executable: "%{::boxen::config::homebrewdir}/bin/mysqld_safe" +mysql::logdir: "%{::boxen::config::logdir}/mysql" + +mysql::user: "%{::boxen_user}" +mysql::host: 127.0.0.1 +mysql::port: 13306 +mysql::socket: "%{mysql::datadir}/socket" + +mysql::package: boxen/brews/mysql +mysql::version: 5.5.20-boxen2 diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 0000000..7611791 --- /dev/null +++ b/data/common.yaml @@ -0,0 +1,4 @@ +--- +mysql::ensure: present +mysql::enable: true + diff --git a/data/hiera.yaml b/data/hiera.yaml new file mode 100644 index 0000000..53f8f22 --- /dev/null +++ b/data/hiera.yaml @@ -0,0 +1,6 @@ +--- +:hierarchy: + - "%{::osfamily}" + - common + +:merge_behavior: deeper \ No newline at end of file diff --git a/manifests/config.pp b/manifests/config.pp index 0b4cc2b..0801e06 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -5,20 +5,20 @@ # include mysql::config class mysql::config( - $ensure = $mysql::params::ensure, + $ensure, - $configdir = $mysql::params::configdir, - $globalconfigprefix = $mysql::params::globalconfigprefix, - $datadir = $mysql::params::datadir, - $executable = $mysql::params::executable, + $configdir, + $globalconfigprefix, + $datadir, + $executable, - $logdir = $mysql::params::logdir, + $logdir, - $host = $mysql::params::host, - $port = $mysql::params::port, - $socket = $mysql::params::socket, - $user = $mysql::params::user, -) inherits mysql::params { + $host, + $port, + $socket, + $user, +) { File { ensure => $ensure, diff --git a/manifests/init.pp b/manifests/init.pp index 8e97091..594272b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -3,26 +3,26 @@ # Examples # # include mysql -class mysql( - $ensure = $mysql::params::ensure, - - $configdir = $mysql::params::configdir, - $globalconfigprefix = $mysql::params::globalconfigprefix, - $datadir = $mysql::params::datadir, - $executable = $mysql::params::executable, - $logdir = $mysql::params::logdir, +include boxen::config - $user = $mysql::params::user, - $host = $mysql::params::host, - $port = $mysql::params::port, - $socket = $mysql::params::socket, +class mysql( + $ensure = undef, + $enable = undef, - $package = $mysql::params::package, - $version = $mysql::params::version, + $configdir = undef, + $globalconfigprefix = undef, + $datadir = undef, + $executable = undef, + $logdir = undef, - $enable = $mysql::params::enable, + $user = undef, + $host = undef, + $port = undef, + $socket = undef, -) inherits mysql::params { + $package = undef, + $version = undef, +) { class { 'mysql::package': ensure => $ensure, diff --git a/manifests/params.pp b/manifests/params.pp index 0510e0c..b6de5f6 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,30 +1,2 @@ class mysql::params { - case $::operatingsystem { - Darwin: { - include boxen::config - - $ensure = present - - $configdir = "${boxen::config::configdir}/mysql" - $globalconfigprefix = $boxen::config::homebrewdir - $datadir = "${boxen::config::datadir}/mysql" - $executable = "${boxen::config::homebrewdir}/bin/mysqld_safe" - $logdir = "${boxen::config::logdir}/mysql" - - $user = $::boxen_user - $host = '127.0.0.1' - $port = 13306 - $socket = "${datadir}/socket" - - $package = 'boxen/brews/mysql' - $version = '5.5.20-boxen2' - - $enable = true - } - - default: { - fail("Unsupported operating system") - } - } - } diff --git a/spec/classes/mysql__config_spec.rb b/spec/classes/mysql__config_spec.rb index c7f36cf..061a645 100644 --- a/spec/classes/mysql__config_spec.rb +++ b/spec/classes/mysql__config_spec.rb @@ -2,6 +2,20 @@ describe "mysql::config" do let(:facts) { default_facts } + let(:params) { + { + "ensure" => "present", + "configdir" => "/test/boxen/config/mysql", + "globalconfigprefix" => "/test/boxen/homebrew", + "datadir" => "/test/boxen/data/mysql", + "executable" => "/test/boxen/homebrew/bin/mysql", + "logdir" => "/test/boxen/log/mysql", + "host" => "127.0.0.1", + "port" => "13306", + "socket" => "/test/boxen/sockets/mysql", + "user" => "boxenuser" + } + } it do %w(config data log).each do |d| diff --git a/spec/fixtures/Puppetfile b/spec/fixtures/Puppetfile index dcf3ac9..24a0ada 100644 --- a/spec/fixtures/Puppetfile +++ b/spec/fixtures/Puppetfile @@ -1,4 +1,5 @@ -mod 'boxen', '3.3.4', :github_tarball => 'boxen/puppet-boxen' +mod 'boxen', '3.4.0', :github_tarball => 'boxen/puppet-boxen' mod 'homebrew', '1.5.1', :github_tarball => 'boxen/puppet-homebrew' mod 'repository', '2.2.0', :github_tarball => 'boxen/puppet-repository' mod 'stdlib', '4.1.0', :github_tarball => 'puppetlabs/puppetlabs-stdlib' +mod "module-data", "0.0.1", :github_tarball => "ripienaar/puppet-module-data" \ No newline at end of file diff --git a/spec/fixtures/Puppetfile.lock b/spec/fixtures/Puppetfile.lock index 2ec4985..eda3c3e 100644 --- a/spec/fixtures/Puppetfile.lock +++ b/spec/fixtures/Puppetfile.lock @@ -1,7 +1,7 @@ GITHUBTARBALL remote: boxen/puppet-boxen specs: - boxen (3.3.4) + boxen (3.4.0) GITHUBTARBALL remote: boxen/puppet-homebrew @@ -18,9 +18,15 @@ GITHUBTARBALL specs: stdlib (4.1.0) +GITHUBTARBALL + remote: ripienaar/puppet-module-data + specs: + module-data (0.0.1) + DEPENDENCIES - boxen (= 3.3.4) + boxen (= 3.4.0) homebrew (= 1.5.1) + module-data (= 0.0.1) repository (= 2.2.0) stdlib (= 4.1.0) diff --git a/spec/fixtures/hiera/hiera.yaml b/spec/fixtures/hiera/hiera.yaml new file mode 100644 index 0000000..a6c6033 --- /dev/null +++ b/spec/fixtures/hiera/hiera.yaml @@ -0,0 +1,6 @@ +--- +:hierarchy: + - test + +:yaml: + :datadir: 'spec/fixtures/hiera' \ No newline at end of file diff --git a/spec/fixtures/hiera/test.yaml b/spec/fixtures/hiera/test.yaml new file mode 100644 index 0000000..5251caf --- /dev/null +++ b/spec/fixtures/hiera/test.yaml @@ -0,0 +1,6 @@ +--- +mysql::configdir: "/test/boxen/configmysql" +mysql::globalconfigprefix: "/test/boxen/homebrew" +mysql::datadir: "/test/boxen/data/mysql" +mysql::executable: "/test/boxen/homebrew/bin/mysqld_safe" +mysql::logdir: "/test/boxen/log/mysql" \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7ad2f65..89c590e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,15 +2,18 @@ fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) +$: << File.join(fixture_path, 'modules/module-data/lib') + RSpec.configure do |c| c.module_path = File.join(fixture_path, 'modules') c.manifest_dir = File.join(fixture_path, 'manifests') + c.hiera_config = File.join(fixture_path, 'hiera/hiera.yaml') end def default_facts { :boxen_home => "/test/boxen", :boxen_user => "testuser", - :operatingsystem => "Darwin", + :osfamily => "Darwin", } end From f377068aab0e335870ffa6a831c2069104895e60 Mon Sep 17 00:00:00 2001 From: David Goodlad Date: Sat, 1 Feb 2014 22:35:18 -0500 Subject: [PATCH 2/4] Validate mysql params --- manifests/init.pp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index 594272b..97deba5 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -23,6 +23,21 @@ $package = undef, $version = undef, ) { + validate_string( + $ensure, + $enable, + $configdir, + $globalconfigprefix, + $datadir, + $executable, + $logdir, + $user, + $host, + $port, + $socket, + $package, + $version + ) class { 'mysql::package': ensure => $ensure, From bf35ffb094087b2ace3ebcb06aa8a4a156fe6461 Mon Sep 17 00:00:00 2001 From: David Goodlad Date: Sat, 1 Feb 2014 22:53:30 -0500 Subject: [PATCH 3/4] More validations --- data/Darwin.yaml | 4 ++-- manifests/init.pp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/data/Darwin.yaml b/data/Darwin.yaml index 90e4d09..c9ff73b 100644 --- a/data/Darwin.yaml +++ b/data/Darwin.yaml @@ -6,8 +6,8 @@ mysql::executable: "%{::boxen::config::homebrewdir}/bin/mysqld_safe" mysql::logdir: "%{::boxen::config::logdir}/mysql" mysql::user: "%{::boxen_user}" -mysql::host: 127.0.0.1 -mysql::port: 13306 +mysql::host: "127.0.0.1" +mysql::port: "13306" mysql::socket: "%{mysql::datadir}/socket" mysql::package: boxen/brews/mysql diff --git a/manifests/init.pp b/manifests/init.pp index 97deba5..83e173d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -25,7 +25,6 @@ ) { validate_string( $ensure, - $enable, $configdir, $globalconfigprefix, $datadir, @@ -39,6 +38,8 @@ $version ) + validate_bool($enable) + class { 'mysql::package': ensure => $ensure, version => $version, From 89ecb9ee780bbbecbf69fc22da951e3c1af0eebb Mon Sep 17 00:00:00 2001 From: David Goodlad Date: Mon, 3 Feb 2014 16:50:31 -0500 Subject: [PATCH 4/4] Add config for linux machines --- data/Debian.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 data/Debian.yaml diff --git a/data/Debian.yaml b/data/Debian.yaml new file mode 100644 index 0000000..03294f2 --- /dev/null +++ b/data/Debian.yaml @@ -0,0 +1,13 @@ +--- +mysql::configdir: "/etc/mysql" +mysql::globalconfigprefix: "/etc/mysql" +mysql::datadir: "/data/mysql" +mysql::logdir: "/var/log/mysql" + +mysql::user: "root" +mysql::host: "%{::ipaddress}" +mysql::port: "3306" +mysql::socket: "/tmp/mysql.sock" + +mysql::package: mysql-server +mysql::version: installed