Skip to content

Commit

Permalink
Merge pull request #83 from hogepodge/client
Browse files Browse the repository at this point in the history
Adds client installation support for RHEL systems
  • Loading branch information
Ashley Penney committed Jan 14, 2014
2 parents 3f39292 + bb2ad6a commit 5b0f6c5
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 41 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ For the 0.5 release, the MongoDB module now supports database and user types.
* MongoDB package.
* MongoDB configuration files.
* MongoDB service.
* MongoDB client.
* 10gen/mongodb apt/yum repository.

###Beginning with MongoDB
Expand All @@ -58,6 +59,15 @@ class {'::mongodb::server':
}
```

For Red Hat family systems, the client can be installed in a similar fashion:

```
puppet class {'::mongodb::client':}
```

Note that for Debian/Ubuntu family systems the client is installed with the
server. Using the client class will by default install the server.

Although most distros come with a prepacked MongoDB server we recommend to
use the 10gen/MongoDB software repository, because most of the current OS
packages are outdated and not appropriate for a production environment.
Expand All @@ -67,7 +77,8 @@ To install MongoDB from 10gen repository:
class {'::mongodb::globals':
manage_package_repo => true,
}->
class {'::mongodb::server': }
class {'::mongodb::server': }->
class {'::mondodb::client': }
```

## Usage
Expand Down Expand Up @@ -102,6 +113,7 @@ Unsafe plain text password could be used with 'password' parameter instead of 'p

####Public classes
* `mongodb::server`: Installs and configure MongoDB
* `mongodb::client`: Installs the MongoDB client shell (for Red Hat family systems)
* `mongodb::globals`: Configure main settings in a global way

####Private classes
Expand All @@ -111,6 +123,7 @@ Unsafe plain text password could be used with 'password' parameter instead of 'p
* `mongodb::server::config`: Configures MongoDB configuration files
* `mongodb::server::install`: Install MongoDB software packages
* `mongodb::server::service`: Manages service
* `mongodb::client::install`: Installs the MongoDB client software package

####Class: mongodb::globals
*Note:* most server specific defaults should be overridden in the `mongodb::server`
Expand Down
26 changes: 26 additions & 0 deletions manifests/client.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Class for installing a MongoDB client shell (CLI).
#
# == Parameters
#
# [ensure] Desired ensure state of the package. Optional.
# Defaults to 'true'
#
# [package_name] Name of the package to install the client from. Default
# is repository dependent.
#
class mongodb::client (
$ensure = $mongodb::params::ensure_client,
$package_name = $mongodb::params::client_package_name,
) inherits mongodb::params {
case $::osfamily {
'RedHat', 'Linux': {
class { 'mongodb::client::install': }
}
'Debian': {
warning ('Debian client is included by default with server. Please use ::mongodb::server to install the mongo client for Debian family systems.')
}
default: {
# no action taken, failure happens in params.pp
}
}
}
26 changes: 26 additions & 0 deletions manifests/client/install.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# PRIVATE CLASS: do not call directly
class mongodb::client::install {
$package_ensure = $mongodb::client::ensure
$package_name = $mongodb::client::package_name

case $package_ensure {
true: {
$my_package_ensure = 'present'
}
false: {
$my_package_ensure = 'purged'
}
'absent': {
$my_package_ensure = 'purged'
}
default: {
$my_package_ensure = $package_ensure
}
}

package { 'mongodb_client':
ensure => $my_package_ensure,
name => $package_name,
tag => 'mongodb',
}
}
2 changes: 1 addition & 1 deletion manifests/db.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
} elsif $password {
$hash = mongodb_password($user, $password)
} else {
fail("Parameter 'password_hash' or 'password' should be provided.")
fail("Parameter 'password_hash' or 'password' should be provided to mongodb::db.")
}

mongodb_user { $user:
Expand Down
5 changes: 2 additions & 3 deletions manifests/globals.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class mongodb::globals (
$server_package_name = undef,
$client_package_name = undef,

$service_name = undef,
$service_provider = undef,
Expand All @@ -15,14 +16,12 @@
$version = undef,

$manage_package_repo = undef,

) {

# Setup of the repo only makes sense globally, so we are doing it here.
if($manage_package_repo) {
class { 'mongodb::repo':
class { '::mongodb::repo':
ensure => present,
}
}

}
6 changes: 3 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@
}
if $oplog {
fail("Parameter is no longer supported. On replica set Oplog is enabled by default.")
fail('Parameter is no longer supported. On replica set Oplog is enabled by default.')
}
notify { "An attempt has been made below to automatically apply your custom
notify { 'An attempt has been made below to automatically apply your custom
settings to mongodb::server. Please verify this works in a safe test
environment.": }
environment.': }
class { 'mongodb::server':
package_name => $packagename,
Expand Down
19 changes: 12 additions & 7 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
class mongodb::params inherits mongodb::globals {
$ensure = true
$service_status = $service_status
$ensure_client = true

# Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
case $::osfamily {
Expand All @@ -10,12 +11,14 @@
if $mongodb::globals::manage_package_repo {
$user = pick($user, 'mongod')
$group = pick($group, 'mongod')
if $version {
$server_package_name = "mongo-10gen-server-${version}"
if $::mongodb::globals::version {
$server_package_name = "mongo-10gen-server-${::mongodb::globals::version}"
$client_package_name = "mongo-10gen-${::mongodb::globals::version}"
} else {
$server_package_name = 'mongo-10gen-server'
$client_package_name = 'mongo-10gen'
}
$service_name = pick($service_name, "mongod")
$service_name = pick($service_name, 'mongod')
$config = '/etc/mongod.conf'
$dbpath = '/var/lib/mongo'
$logpath = '/var/log/mongo/mongod.log'
Expand All @@ -27,7 +30,8 @@
# so we assume that you are using EPEL repository.
$user = pick($user, 'mongodb')
$group = pick($group, 'mongodb')
$server_package_name = pick($server_package_name, "mongodb-server")
$server_package_name = pick($server_package_name, 'mongodb-server')
$client_package_name = pick($client_package_name, 'mongodb')

$service_name = pick($service_name, 'mongod')
$config = '/etc/mongodb.conf'
Expand All @@ -43,8 +47,8 @@
if $mongodb::globals::manage_package_repo {
$user = pick($user, 'mongodb')
$group = pick($group, 'mongodb')
if $version {
$server_package_name = "mongodb-10gen-${version}"
if $::mongodb::globals::version {
$server_package_name = "mongodb-10gen-${::mongodb::globals::version}"
} else {
$server_package_name = 'mongodb-10gen'
}
Expand All @@ -61,6 +65,7 @@
$user = pick($user, 'mongodb')
$group = pick($group, 'mongodb')
$server_package_name = pick($server_package_name, 'mongodb-server')
$client_package_name = pick($client_package_name, 'mongodb')
$service_name = pick($service_name, 'mongodb')
$config = '/etc/mongodb.conf'
$dbpath = '/var/lib/mongodb'
Expand All @@ -79,7 +84,7 @@
case $::operatingsystem {
'Ubuntu': {
$service_provider = pick($service_provider, 'upstart')
}
}
default: {
$service_provider = undef
}
Expand Down
6 changes: 3 additions & 3 deletions manifests/repo/apt.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# PRIVATE CLASS: do not use directly
class mongodb::repo::apt inherits mongodb::repo {
# we try to follow/reproduce the instruction
# from http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

include ::apt

if($ensure == 'present' or $ensure == true) {
if($::mongodb::repo::ensure == 'present' or $::mongodb::repo::ensure == true) {
apt::source { 'downloads-distro.mongodb.org':
location => $location,
location => $::mongodb::repo::location,
release => 'dist',
repos => '10gen',
key => '9ECBEC467F0CEB10',
Expand All @@ -21,5 +22,4 @@
ensure => absent,
}
}

}
4 changes: 2 additions & 2 deletions manifests/repo/yum.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# We try to follow/reproduce the instruction
# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/

if($ensure == 'present' or $ensure == true) {
if($::mongodb::repo::ensure == 'present' or $::mongodb::repo::ensure == true) {
yumrepo { 'mongodb':
descr => 'MongoDB/10gen Repository',
baseurl => $location,
baseurl => $::mongodb::repo::location,
gpgcheck => '0',
enabled => '1',
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/server/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
mode => '0755',
owner => $user,
group => $group,
require => File["${config}"]
require => File[$config]
}
} else {
file { $dbpath:
Expand Down
8 changes: 4 additions & 4 deletions manifests/server/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
}
}

package { 'mongodb':
ensure => $my_package_ensure,
name => $package_name,
tag => 'mongodb',
package { 'mongodb_server':
ensure => $my_package_ensure,
name => $package_name,
tag => 'mongodb',
}
}
13 changes: 13 additions & 0 deletions spec/classes/client_install_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'spec_helper'

describe 'mongodb::client::install', :type => :class do
describe 'it should create package' do
let(:pre_condition) { ["class mongodb::client { $ensure = true $package_name = 'mongodb' }", "include mongodb::client"]}
it {
should contain_package('mongodb_client').with({
:ensure => 'present',
:name => 'mongodb',
})
}
end
end
2 changes: 1 addition & 1 deletion spec/classes/server_install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:pre_condition) { ["class mongodb::server { $package_ensure = true $dbpath = '/var/lib/mongo' $user = 'mongodb' $package_name = 'mongodb-server' }", "include mongodb::server"]}

it {
should contain_package('mongodb').with({
should contain_package('mongodb_server').with({
:ensure => 'present',
:name => 'mongodb-server',
})
Expand Down
50 changes: 42 additions & 8 deletions spec/system/server_10gen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@
config_file = '/etc/mongodb.conf'
end

client_name = 'mongo --version'

context 'default parameters' do
it 'should work with no errors' do
pp = <<-EOS
class { 'mongodb::globals': manage_package_repo => true }->
class { 'mongodb::server': }
EOS
case node.facts['osfamily']
when 'RedHat'
pp = <<-EOS
class { 'mongodb::globals': manage_package_repo => true }->
class { 'mongodb::server': }->
class { 'mongodb::client': }
EOS
when 'Debian'
pp = <<-EOS
class { 'mongodb::globals': manage_package_repo => true }->
class { 'mongodb::server': }
EOS
end

puppet_apply(pp) do |r|
r.exit_code.should == 2
Expand All @@ -42,13 +53,19 @@ class { 'mongodb::server': }

describe port(27017) do
it do
sleep(20)
should be_listening
end
end

describe command(client_name) do
it do
should return_exit_status 0
end
end
end

context 'test using custom port' do

it 'change port to 27018' do
pp = <<-EOS
class { 'mongodb::globals': manage_package_repo => true }->
Expand All @@ -57,19 +74,36 @@ class { 'mongodb::server': port => 27018 }

puppet_apply(pp) do |r|
r.exit_code.should == 2
r.refresh
r.exit_code.should == 0
end
end

describe port(27018) do
sleep(20)
it { should be_listening }
end
end

context 'test shutdown of custom port' do
it 'shut down service on port 27018' do
pp = <<-EOS
class {'mongodb::globals': manage_package_repo => true}->
class {'mongodb::server': port => 27018, ensure => false}
EOS

puppet_apply(pp) do |r|
r.exit_code.should == 2
end
end

describe port(27018) do
it { should_not be_listening}
end

end

describe 'cleanup' do
it 'uninstalls mongodb' do
puppet_apply("class {'mongodb::globals': manage_package_repo => true }-> class { 'mongodb::server': ensure => false }") do |r|
puppet_apply("class {'mongodb::globals': manage_package_repo => true }-> class { 'mongodb::server': ensure => false }-> class { 'mongodb::client': ensure => false}") do |r|
r.exit_code.should_not == 1
end
end
Expand Down
Loading

0 comments on commit 5b0f6c5

Please sign in to comment.