Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #38 from boxen/hiera-the-business
Browse files Browse the repository at this point in the history
Start killing mysql::params in favor of hiera
  • Loading branch information
dgoodlad committed Feb 3, 2014
2 parents a07b4cd + 89ecb9e commit 15749e8
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 58 deletions.
14 changes: 14 additions & 0 deletions data/Darwin.yaml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions data/Debian.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
mysql::ensure: present
mysql::enable: true

6 changes: 6 additions & 0 deletions data/hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
:hierarchy:
- "%{::osfamily}"
- common

:merge_behavior: deeper
22 changes: 11 additions & 11 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
46 changes: 31 additions & 15 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,42 @@
# Examples
#
# include mysql
class mysql(
$ensure = $mysql::params::ensure,
include boxen::config

$configdir = $mysql::params::configdir,
$globalconfigprefix = $mysql::params::globalconfigprefix,
$datadir = $mysql::params::datadir,
$executable = $mysql::params::executable,
$logdir = $mysql::params::logdir,
class mysql(
$ensure = undef,
$enable = undef,

$user = $mysql::params::user,
$host = $mysql::params::host,
$port = $mysql::params::port,
$socket = $mysql::params::socket,
$configdir = undef,
$globalconfigprefix = undef,
$datadir = undef,
$executable = undef,
$logdir = undef,

$package = $mysql::params::package,
$version = $mysql::params::version,
$user = undef,
$host = undef,
$port = undef,
$socket = undef,

$enable = $mysql::params::enable,
$package = undef,
$version = undef,
) {
validate_string(
$ensure,
$configdir,
$globalconfigprefix,
$datadir,
$executable,
$logdir,
$user,
$host,
$port,
$socket,
$package,
$version
)

) inherits mysql::params {
validate_bool($enable)

class { 'mysql::package':
ensure => $ensure,
Expand Down
28 changes: 0 additions & 28 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -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")
}
}

}
14 changes: 14 additions & 0 deletions spec/classes/mysql__config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
3 changes: 2 additions & 1 deletion spec/fixtures/Puppetfile
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 8 additions & 2 deletions spec/fixtures/Puppetfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GITHUBTARBALL
remote: boxen/puppet-boxen
specs:
boxen (3.3.4)
boxen (3.4.0)

GITHUBTARBALL
remote: boxen/puppet-homebrew
Expand All @@ -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)

6 changes: 6 additions & 0 deletions spec/fixtures/hiera/hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
:hierarchy:
- test

:yaml:
:datadir: 'spec/fixtures/hiera'
6 changes: 6 additions & 0 deletions spec/fixtures/hiera/test.yaml
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 15749e8

Please sign in to comment.