From 99ff198588c6124aed1c25f3fb955b1e9869de0c Mon Sep 17 00:00:00 2001 From: Lukas Bezdicka Date: Fri, 27 Feb 2015 15:33:31 +0100 Subject: [PATCH] Update mongodb to 4f5ca99fcba4339a8093d2cb329f5498866a8c8c 4f5ca99fcba4339a8093d2cb329f5498866a8c8c Merge pull request #176 from enovance/pin_rspec_core 7df82cc8f330f4d8b129c09dc66267ee1a720d6e Gemfile: Pin to rspec-core 3.1.7 due to some bug with ruby 1.8.7 cb8db6aafa7c55729adb7b35db02315f784ff2ec Merge pull request #175 from enovance/various_26_fix 191a08831bf76d77fc1e0790892b4ff8a650d13a conn_validator: Run on 127.0.0.1 when bind_ip is set at 0.0.0.0 d6a9e4b00922b0bc35819a750bf7c3173520ec43 acceptance: use proper command exit status a70e7dd3d7d34d30e5f9fa50314319c2498db3d9 Allow mongo client to connect on conf spec port abfc625bdfb9587bb41b36d1125a4c91692f442a Uniformize the way mongos works in 2.4 and 2.6 eaff55ca631a832972ca9032984f62d7d1fddc66 Enable configsvr and shardsvr mode in 2.6 accf317263e8416391b7d51f9445fb863998a6d3 rs.conf() connects to the proper IP with 2.6 80650e0899c6d946e48a3281358ed4a05c01bbad Merge pull request #173 from Cloudlynx/replsetfix befb6954f5b0c276d53d1f7cfe9c19d0cfd9c4b9 More fixes to debug messages d37b97c60b923ebe3dfefc1d0180e0d45f8f9eb3 Fixed a few debug statements 76682cffe8ce16b255f329af33083ccde7845271 Added code so the case of multiple IP adresses on bind_ip is correctly handled. 8e9ceced8e53f42152e1be8e3b18ba2c2e1e20c1 Merge pull request #171 from Mylezeem/fix_lint 75baf2f221c8750f2e8227d957e6b42d6bc60d8e Fix some lint error to reach 5.0 on Code Quality def1a3dd04fa1e8170b2fd07a62acede14e66683 Merge pull request #170 from cmurphy/release 6ec0139ca4d6de3eb69fc84b57d6f2f64e1482b1 Merge pull request #168 from cmurphy/fix_port 2d38fff73c28c19137485d3c8a68b87e65c1df2d Prepare 0.10.0 Release 8644e55bcaf59bfd75800327a2aec6a9e85818d2 Merge pull request #169 from cmurphy/fix_150 14208c294108a161edd22c5b5e359932b3a56546 Add acceptance tests for mongodb user 10d8f22323a4bda128661ebe8216dea2594013dd Fix port in 2.6 mongo.conf template 16991924e1e90ca76a9123daae03e95d58951fc9 Fix unit tests for mongodb_user provider changes 572ae1b0a6128b0faf97ea1bf09a85dc32e0974d db.runCommand with manually-joint json command d3121775932be5ac8e286628ed601e8e99b2bdb7 Fix the bug that new user's password_hash will be rehashed 218238c24fe7c0bc1a5d895b307eb064acc4c2ea Merge pull request #164 from cmurphy/fix_137 e65d2dc41f565ef15f7cd7eab9eb7739eeef8033 Add validation to ssl parameters f24a1cc8b4004f170bb3069d787cf43cf5a83b11 Merge pull request #167 from cmurphy/fix_165 bd579b79c9945801e4447d6e24fba8cda5296a04 Adding documentation for ssl support. 3d4bd2d51654080f9f686a40430f24bf31865976 Adding rudimentary support for ssl configuration options. ab2540076abdd4b66689a972a42f205039785aed Fix non-default port support and add tests 7aea8c07eb70847ebe4b37dc0f86372e863c7b3f Merge pull request #151 from enovance/sharding dc5d6effbad7ca766ebf4dadd4b085cdf78aaa5c Implement Sharding Support a37d826b118fec9f939abb9887c34db8a058f3b7 Add support for mongos configuration 92632dc823f2468e8498bf6030c97d09005c4e32 Ensure rs.conf() is run on the proper mongod process 4a43ab4d07374f172aa41f55c99597889fdc0c99 Make port definition optional 1bb1995e8f4067a69a59fb335f1e27e601383af6 Add support for shardsvr 6cd09d1bbb304b2137f6819bdadd682da712882f Add support for configsvr 67bdd17956991e99d888cf282ce6bfcaecabba37 Fix the bug mongo js client fail to run under non-default port 51c6edb7b71ac67326c36e452a755178262f7a5d Merge pull request #140 from crawlik/add_enterprise_support a3991bfeccd1d7ea8796f2c055ecf3b6275e76b5 Merge pull request #159 from cmurphy/revert_rhel7 da347a00e0650d444df83947694b5da044c9962e Fix against mongodb 2.6.5 from epel 96c78e7b7c71ea88c00b76cd13f505e0298d000b Merge pull request #155 from cmurphy/fix_epel_tests c10880221a94170007cdc2297189f20696d52455 Add centos 7 nodesets and fix spec helper to setup iptables on all hosts 799d22b3ad1dd7999221d8950a7057e510ded7aa Merge pull request #154 from cmurphy/rhel7 bb6aff8fee032a2f71c4cd5cbb7d851af634dccb Merge pull request #153 from cmurphy/fix_tests a45104593779e8c7acf46a3585fe18f43b8c8715 Add support for RHEL 7 f50e9c03e1b948ea49f6059ab5eca8600d857d77 Fix server acceptance tests a2fb53c7b58ea0c8fce1537cb75eaece581c8a44 Merge pull request #152 from cmurphy/fix_beaker 37f237a66c3753f8bb077957cae7f0dc3f8ae4d2 Update Gemfile and .travis.yml 6805321418e7f4d6359e9b8e5f1233f20b5e1c65 Use boolean to check enterprise flag 640e18d20e40535c1ee6212a1efba839c7bd56ad Add enterprise repo support --- Puppetfile | 2 +- mongodb/.travis.yml | 42 +-- mongodb/CHANGELOG.md | 15 + mongodb/Gemfile | 28 +- mongodb/README.md | 110 +++++++- mongodb/lib/puppet/provider/mongodb.rb | 59 +++- .../puppet/provider/mongodb_replset/mongo.rb | 21 +- .../puppet/provider/mongodb_shard/mongo.rb | 236 ++++++++++++++++ .../puppet/provider/mongodb_user/mongodb.rb | 27 +- mongodb/lib/puppet/type/mongodb_shard.rb | 39 +++ mongodb/manifests/client/install.pp | 6 +- mongodb/manifests/db.pp | 6 +- mongodb/manifests/globals.pp | 4 + mongodb/manifests/init.pp | 6 +- mongodb/manifests/mongos.pp | 36 +++ mongodb/manifests/mongos/config.pp | 28 ++ mongodb/manifests/mongos/install.pp | 32 +++ mongodb/manifests/mongos/service.pp | 69 +++++ mongodb/manifests/params.pp | 75 +++-- mongodb/manifests/repo.pp | 17 +- mongodb/manifests/repo/yum.pp | 2 +- mongodb/manifests/server.pp | 12 +- mongodb/manifests/server/config.pp | 5 + mongodb/manifests/server/install.pp | 6 +- mongodb/manifests/server/service.pp | 28 +- mongodb/manifests/shardsvr.pp | 11 + mongodb/metadata.json | 14 +- mongodb/spec/acceptance/database_spec.rb | 83 ++++++ mongodb/spec/acceptance/mongos_spec.rb | 107 +++++++ .../acceptance/nodesets/centos-7-vcloud.yml | 15 + .../spec/acceptance/nodesets/centos-7-x64.yml | 9 + .../nodesets/multi-centos-7-vcloud.yml | 21 ++ .../nodesets/multi-centos-7-x64.yml | 15 + mongodb/spec/acceptance/server_spec.rb | 18 +- mongodb/spec/acceptance/sharding_spec.rb | 55 ++++ mongodb/spec/acceptance/user_spec.rb | 99 +++++++ mongodb/spec/classes/mongos_config_spec.rb | 23 ++ mongodb/spec/classes/mongos_install_spec.rb | 29 ++ mongodb/spec/classes/mongos_service_spec.rb | 56 ++++ mongodb/spec/classes/mongos_spec.rb | 30 ++ mongodb/spec/spec_helper_acceptance.rb | 3 + .../provider/mongodb_replset/mongodb_spec.rb | 16 ++ .../provider/mongodb_shard/mongodb_spec.rb | 79 ++++++ .../provider/mongodb_user/mongodb_spec.rb | 28 +- .../unit/puppet/type/mongodb_shard_spec.rb | 29 ++ mongodb/templates/mongodb-shard.conf.erb | 21 ++ mongodb/templates/mongodb.conf.2.6.erb | 10 + mongodb/templates/mongodb.conf.erb | 15 + mongodb/templates/mongos/Debian/mongos.erb | 266 ++++++++++++++++++ mongodb/templates/mongos/RedHat/mongos.erb | 106 +++++++ mongodb/tests/replicaset.pp | 3 - mongodb/tests/sharding.pp | 55 ++++ 52 files changed, 2001 insertions(+), 126 deletions(-) create mode 100644 mongodb/lib/puppet/provider/mongodb_shard/mongo.rb create mode 100644 mongodb/lib/puppet/type/mongodb_shard.rb create mode 100644 mongodb/manifests/mongos.pp create mode 100644 mongodb/manifests/mongos/config.pp create mode 100644 mongodb/manifests/mongos/install.pp create mode 100644 mongodb/manifests/mongos/service.pp create mode 100644 mongodb/manifests/shardsvr.pp create mode 100644 mongodb/spec/acceptance/database_spec.rb create mode 100644 mongodb/spec/acceptance/mongos_spec.rb create mode 100644 mongodb/spec/acceptance/nodesets/centos-7-vcloud.yml create mode 100644 mongodb/spec/acceptance/nodesets/centos-7-x64.yml create mode 100644 mongodb/spec/acceptance/nodesets/multi-centos-7-vcloud.yml create mode 100644 mongodb/spec/acceptance/nodesets/multi-centos-7-x64.yml create mode 100644 mongodb/spec/acceptance/sharding_spec.rb create mode 100644 mongodb/spec/acceptance/user_spec.rb create mode 100644 mongodb/spec/classes/mongos_config_spec.rb create mode 100644 mongodb/spec/classes/mongos_install_spec.rb create mode 100644 mongodb/spec/classes/mongos_service_spec.rb create mode 100644 mongodb/spec/classes/mongos_spec.rb create mode 100644 mongodb/spec/unit/puppet/provider/mongodb_shard/mongodb_spec.rb create mode 100644 mongodb/spec/unit/puppet/type/mongodb_shard_spec.rb create mode 100644 mongodb/templates/mongodb-shard.conf.erb create mode 100644 mongodb/templates/mongos/Debian/mongos.erb create mode 100644 mongodb/templates/mongos/RedHat/mongos.erb create mode 100644 mongodb/tests/sharding.pp diff --git a/Puppetfile b/Puppetfile index f1e384ffe..835f31fd6 100644 --- a/Puppetfile +++ b/Puppetfile @@ -91,7 +91,7 @@ mod 'module-data', :git => 'https://github.com/ripienaar/puppet-module-data.git' mod 'mongodb', - :commit => 'fe562b86f388a6d107bb1f3cb3b32a3978f59c2a', + :commit => '4f5ca99fcba4339a8093d2cb329f5498866a8c8c', :git => 'https://github.com/puppetlabs/puppetlabs-mongodb.git' mod 'mysql', diff --git a/mongodb/.travis.yml b/mongodb/.travis.yml index f6eff1ce9..6cf8b0044 100644 --- a/mongodb/.travis.yml +++ b/mongodb/.travis.yml @@ -1,33 +1,17 @@ -branches: - only: - - master +--- language: ruby -before_install: - - gem update bundler - - bundle --version - - gem update --system 2.1.11 - - gem --version -bundler_args: --without development -script: "bundle exec rake spec SPEC_OPTS='--format documentation'" -after_success: - - git clone -q git://github.com/puppetlabs/ghpublisher.git .forge-release - - .forge-release/publish -rvm: - - 1.8.7 - - 1.9.3 - - 2.0.0 -env: - matrix: - - PUPPET_GEM_VERSION="~> 2.7.0" - - PUPPET_GEM_VERSION="~> 3.3.0" - global: - - PUBLISHER_LOGIN=puppetlabs - - secure: "iUYpjvk33JffZB9lVRqjuwRWesvcvmTknh908xnf60rUOA0QbGEPXxQY+LsQJEIimVsMA22fV6vp9BcqMEjO7OfK2MvAWsEWU/lG+kisFqhWDRf96sADE7k/RvPWJeB2xe+lWXK7Eh26jgctNfk4NptX1X1MjGmdzEvH7Aq79/w=" +bundler_args: --without system_tests +script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'" matrix: - exclude: - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 2.7.0" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 2.7.0" + fast_finish: true + include: + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 3.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.0" notifications: email: false diff --git a/mongodb/CHANGELOG.md b/mongodb/CHANGELOG.md index b85bb68c3..0c50d2a85 100644 --- a/mongodb/CHANGELOG.md +++ b/mongodb/CHANGELOG.md @@ -1,3 +1,18 @@ +##2015-01-13 - Release 0.10.0 +###Summary + +This release adds a number of significant features and several bug fixes. + +####Features +- Adds support for sharding +- Adds support for RHEL 7 +- Adds rudimentary support for SSL configuration +- Adds support for the enterprise repository + +####Bugfixes +- Fixes support for running on non-default ports +- Fixes the idempotency of password setting (for mongo 2.6) + ##2014-11-25 - Release 0.9.0 ###Summary diff --git a/mongodb/Gemfile b/mongodb/Gemfile index 39abe867d..340dc984a 100644 --- a/mongodb/Gemfile +++ b/mongodb/Gemfile @@ -1,19 +1,31 @@ -source ENV['GEM_SOURCE'] || 'https://rubygems.org' +source ENV['GEM_SOURCE'] || "https://rubygems.org" -group :test, :development do - gem 'rspec-puppet', :require => false +group :development, :unit_tests do gem 'rake', :require => false + gem 'rspec-puppet', '~> 1.0', :require => false gem 'puppetlabs_spec_helper', :require => false - gem 'serverspec', :require => false gem 'puppet-lint', :require => false - gem 'pry', :require => false gem 'simplecov', :require => false - gem 'beaker', :require => false - gem 'beaker-rspec', :require => false + gem 'puppet_facts', :require => false + gem 'json', :require => false + gem 'rspec-core', '3.1.7' end -if puppetversion = ENV['PUPPET_VERSION'] +group :system_tests do + gem 'beaker-rspec', :require => false + gem 'serverspec', :require => false +end + +if facterversion = ENV['FACTER_GEM_VERSION'] + gem 'facter', facterversion, :require => false +else + gem 'facter', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] gem 'puppet', puppetversion, :require => false else gem 'puppet', :require => false end + +# vim:ft=ruby diff --git a/mongodb/README.md b/mongodb/README.md index 5483642a8..b5742ce0b 100644 --- a/mongodb/README.md +++ b/mongodb/README.md @@ -19,9 +19,9 @@ Installs MongoDB on RHEL/Ubuntu/Debian from OS repo, or alternatively from ### Deprecation Warning ### -This release is a major refactoring of the module which means that the API may -have changed in backwards incompatible ways. If your project depends on the old API, -please pin your dependencies to 0.3 version to ensure your environments don't break. +This module is still in beta which means the API is subject to change in +backwards incompatible ways. If your project depends on an old API, please pin +your dependencies to the necessary version to ensure your environments don't break. The current module design is undergoing review for potential 1.0 release. We welcome any feedback with regard to the APIs and patterns used in this release. @@ -45,6 +45,7 @@ For the 0.6 release, the MongoDB module now supports basic replicaset features * MongoDB configuration files. * MongoDB service. * MongoDB client. +* MongoDB sharding support (mongos) * 10gen/mongodb apt/yum repository. ###Beginning with MongoDB @@ -69,6 +70,15 @@ 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. +If one plans to configure sharding for a Mongo deployment, the module offer +the `mongos` installation. `mongos` can be installed the following way : + +```puppet +class {'::mongodb::mongos' : + configdb => ['configsvr1.example.com:27018'], +} +``` + 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. @@ -116,6 +126,7 @@ Unsafe plain text password could be used with 'password' parameter instead of 'p * `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 +* `mongodb::mongos`: Installs and configure Mongos server (for sharding support) ####Private classes * `mongodb::repo`: Manage 10gen/MongoDB software repository @@ -125,6 +136,9 @@ Unsafe plain text password could be used with 'password' parameter instead of 'p * `mongodb::server::install`: Install MongoDB software packages * `mongodb::server::service`: Manages service * `mongodb::client::install`: Installs the MongoDB client software package +* `mongodb::mongos::config`: Configures Mongos configuration files +* `mongodb::mongos::install`: Install Mongos software packages +* `mongodb::mongos::service`: Manages Mongos service ####Class: mongodb::globals *Note:* most server specific defaults should be overridden in the `mongodb::server` @@ -328,6 +342,12 @@ MMS identifier for mms monitoring. Default: None #####`mms_interval` MMS interval for mms monitoring. Default: None +#####`configsvr` +Use this setting to enable config server mode for mongod. + +#####`shardsvr` +Use this setting to enable shard server mode for mongod. + #####`replset` Use this setting to configure replication with replica sets. Specify a replica set name as an argument to this set. All hosts must have the same set name. @@ -379,6 +399,64 @@ Used with the slave setting to specify the master instance from which this slave instance will replicate. Default: <> *Note*: deprecated – use replica sets +#####`ssl` +Set to true to enable ssl. Default: <> +*Important*: You need to have ssl_key and ssl_ca set as well and files +need to pre-exist on node. + +#####`ssl_key` +Default: <> + +#####`ssl_ca` +Default: <> + +####Class: mongodb::mongos +class. This class should only be used if you want to implement sharding within +your mongodb deployment. + +This class allows you to configure the mongos daemon (responsible for routing) +on your platform. + +#####`ensure` +Used to ensure that the package is installed and the service is running, or that the package is absent/purged and the service is stopped. Valid values are true/false/present/absent/purged. + +#####`config` +Path of the config file. If not specified, the module will use the default +for your OS distro. + +#####`config_content` +Path to the config template if the default doesn't match one needs. + +#####`configdb` +Array of the config servers IP addresses the mongos should connect to. + +#####`service_name` +This setting can be used to override the default Mongos service name. If not +specified, the module will use whatever service name is the default for your OS distro. + +#####`service_provider` +This setting can be used to override the default Mongos service provider. If +not specified, the module will use whatever service provider is the default for +your OS distro. + +#####`service_status` +This setting can be used to override the default status check command for +your Mongos service. If not specified, the module will use whatever service +name is the default for your OS distro. + +#####`service_enable` +This setting can be used to specify if the service should be enable at boot + +#####`service_ensure` +This setting can be used to specify if the service should be running + +#####`package_ensure` +This setting can be used to specify if puppet should install the package or not + +#####`package_name` +This setting can be used to specify the name of the package that should be installed. +If not specified, the module will use whatever service name is the default for your OS distro. + ### Definitions #### Definition: mongodb:db @@ -464,6 +542,28 @@ Array of 'host:port' of the replicaset members. It currently only adds members without options. +#### Provider: mongodb_shard +'mongodb_shard' can be used to create and manage MongoDB shards. +*Note:* Removing a shard is not yet supported. Shard can only be added. + +```puppet +mongodb_shard { 'rsmain': + member => 'rsmain/host1:27017', + keys => [{'rsmain.foo' => {'name' => 1}}], +} +``` +#####`member` +Member of the shard in the form; + +* [hostname] +* [hostname]:[port] +* [replica-set-name]/[hostname] +* [replica-set-name]/[hostname]:port + +#####`keys` +Sharding keys for a specific database. This variable should be an array +of sharding keys. + ## Limitations This module has been tested on: @@ -472,8 +572,8 @@ This module has been tested on: * Debian 6.* (squeeze) * Ubuntu 12.04.2 (precise) * Ubuntu 10.04.4 LTS (lucid) -* RHEL 5/6 -* CentOS 5/6 +* RHEL 5/6/7 +* CentOS 5/6/7 For a full list of tested operating systems please have a look at the [.nodeset.xml](https://github.com/puppetlabs/puppetlabs-mongodb/blob/master/.nodeset.yml) definition. diff --git a/mongodb/lib/puppet/provider/mongodb.rb b/mongodb/lib/puppet/provider/mongodb.rb index 9a579bd52..101f3fd6a 100644 --- a/mongodb/lib/puppet/provider/mongodb.rb +++ b/mongodb/lib/puppet/provider/mongodb.rb @@ -1,3 +1,4 @@ +require 'yaml' class Puppet::Provider::Mongodb < Puppet::Provider # Without initvars commands won't work. @@ -17,13 +18,69 @@ def mongorc_file self.class.mongorc_file end + def self.get_mongod_conf_file + if File.exists? '/etc/mongod.conf' + file = '/etc/mongod.conf' + else + file = '/etc/mongodb.conf' + end + file + end + + def self.get_conn_string + file = get_mongod_conf_file + # The mongo conf is probably a key-value store, even though 2.6 is + # supposed to use YAML, because the config template is applied + # based on $::mongodb::globals::version which is the user will not + # necessarily set. This attempts to get the port from both types of + # config files. + config = YAML.load_file(file) + if config.kind_of?(Hash) # Using a valid YAML file for mongo 2.6 + bindip = config['net.bindIp'] + port = config['net.port'] + shardsvr = config['sharding.clusterRole'] + confsvr = config['sharding.clusterRole'] + else # It has to be a key-value config file + config = {} + File.readlines(file).collect do |line| + k,v = line.split('=') + config[k.rstrip] = v.lstrip.chomp if k and v + end + bindip = config['bind_ip'] + port = config['port'] + shardsvr = config['shardsvr'] + confsvr = config['confsvr'] + end + + if bindip + first_ip_in_list = bindip.split(',').first + if first_ip_in_list.eql? '0.0.0.0' + ip_real = '127.0.0.1' + else + ip_real = first_ip_in_list + end + end + + if port + port_real = port + elsif !port and (confsvr.eql? 'configsvr' or confsvr.eql? 'true') + port_real = 27019 + elsif !port and (shardsvr.eql? 'shardsvr' or shardsvr.eql? 'true') + port_real = 27018 + else + port_real = 27017 + end + + "#{ip_real}:#{port_real}" + end + # Mongo Command Wrapper def self.mongo_eval(cmd, db = 'admin') if mongorc_file cmd = mongorc_file + cmd end - out = mongo([db, '--quiet', '--eval', cmd]) + out = mongo([db, '--quiet', '--host', get_conn_string, '--eval', cmd]) out.gsub!(/ObjectId\(([^)]*)\)/, '\1') out diff --git a/mongodb/lib/puppet/provider/mongodb_replset/mongo.rb b/mongodb/lib/puppet/provider/mongodb_replset/mongo.rb index d77afe303..eb9f5aabd 100644 --- a/mongodb/lib/puppet/provider/mongodb_replset/mongo.rb +++ b/mongodb/lib/puppet/provider/mongodb_replset/mongo.rb @@ -2,7 +2,8 @@ # Author: François Charlier # -Puppet::Type.type(:mongodb_replset).provide(:mongo) do +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'mongodb')) +Puppet::Type.type(:mongodb_replset).provide(:mongo, :parent => Puppet::Provider::Mongodb) do desc "Manage hosts members for a replicaset." @@ -95,8 +96,19 @@ def master_host(hosts) false end + def self.get_mongod_conf_file + if File.exists? '/etc/mongod.conf' + file = '/etc/mongod.conf' + else + file = '/etc/mongodb.conf' + end + file + end + def self.get_replset_properties - output = mongo_command('rs.conf()') + + conn_string = get_conn_string + output = mongo_command('rs.conf()', conn_string) if output['members'] members = output['members'].collect do |val| val['host'] @@ -128,10 +140,10 @@ def alive_members(hosts) end # This node is alive and supposed to be a member of our set - Puppet.debug "Host #{self.name} is available for replset #{status['set']}" + Puppet.debug "Host #{host} is available for replset #{status['set']}" true elsif status.has_key?('info') - Puppet.debug "Host #{self.name} is alive but unconfigured: #{status['info']}" + Puppet.debug "Host #{host} is alive but unconfigured: #{status['info']}" true end rescue Puppet::ExecutionFailure @@ -181,6 +193,7 @@ def set_members # Add members to an existing replset if master = master_host(alive_hosts) current_hosts = db_ismaster(master)['hosts'] + Puppet.debug "Current Hosts are: #{current_hosts.inspect}" newhosts = alive_hosts - current_hosts newhosts.each do |host| output = rs_add(host, master) diff --git a/mongodb/lib/puppet/provider/mongodb_shard/mongo.rb b/mongodb/lib/puppet/provider/mongodb_shard/mongo.rb new file mode 100644 index 000000000..f745f0015 --- /dev/null +++ b/mongodb/lib/puppet/provider/mongodb_shard/mongo.rb @@ -0,0 +1,236 @@ +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'mongodb')) +Puppet::Type.type(:mongodb_shard).provide(:mongo, :parent => Puppet::Provider::Mongodb ) do + + desc "Manage mongodb sharding." + + confine :true => + begin + require 'json' + true + rescue LoadError + false + end + + mk_resource_methods + + commands :mongo => 'mongo' + + def initialize(value={}) + super(value) + @property_flush = {} + end + + def destroy + @property_flush[:ensure] = :absent + end + + def create + @property_flush[:ensure] = :present + @property_flush[:member] = resource.should(:member) + @property_flush[:keys] = resource.should(:keys) + end + + def sh_addshard member + return mongo_command("sh.addShard(\"#{member}\")", '127.0.0.1:27017') + end + + def sh_shardcollection shard_key + collection = shard_key.keys.first + keys = shard_key.values.first.collect do |key, value| + "\"#{key}\": #{value.to_s}" + end + + return mongo_command("sh.shardCollection(\"#{collection}\", {#{keys.join(',')}})", '127.0.0.1:27017') + end + + def sh_enablesharding member + return mongo_command("sh.enableSharding(\"#{member}\")", '127.0.0.1:27017') + end + + def self.prefetch(resources) + instances.each do |prov| + if resource = resources[prov.name] + resource.provider = prov + end + end + end + + def flush + set_member + @property_hash = self.class.get_shard_properties(resource[:name]) + end + + def set_member + if @property_flush[:ensure] == :absent + # a shard can't be removed easily at this time + return + end + + if @property_flush[:ensure] == :present and @property_hash[:ensure] != :present + Puppet.debug "Adding the shard #{self.name}" + output = sh_addshard(@property_flush[:member]) + if output['ok'] == 0 + raise Puppet::Error, "sh.addShard() failed for shard #{self.name}: #{output['errmsg']}" + end + output = sh_enablesharding(self.name) + if output['ok'] == 0 + raise Puppet::Error, "sh.enableSharding() failed for shard #{self.name}: #{output['errmsg']}" + end + if @property_flush[:keys] + @property_flush[:keys].each do |key| + output = sh_shardcollection(key) + if output['ok'] == 0 + raise Puppet::Error, "sh.shardCollection() failed for shard #{self.name}: #{output['errmsg']}" + end + end + end + end + end + + + def self.instances + instances = get_shards_properties.collect do |shard| + new (shard) + end + end + + def self.get_shard_collection_details obj, shard_name + collection_array = [] + obj.each do |database| + if database['_id'].eql? shard_name and ! database['shards'].nil? + collection_array = database['shards'].collect do |collection| + { collection.keys.first => collection.values.first['shardkey']} + end + end + end + collection_array + end + + def self.get_shard_properties shard + properties = {} + output = mongo_command('sh.status()') + output['shards'].each do |s| + if s['_id'] == shard + properties = { + :name => s['_id'], + :ensure => :present, + :member => s['host'], + :keys => get_shard_collection_details(output['databases'], s['_id']), + :provider => :mongo, + } + end + end + properties + end + + def self.get_shards_properties + output = mongo_command('sh.status()') + if output['shards'].size > 0 + properties = output['shards'].collect do |shard| + { + :name => shard['_id'], + :ensure => :present, + :member => shard['host'], + :keys => get_shard_collection_details(output['databases'], shard['_id']), + :provider => :mongo, + } + end + else + properties = [] + end + Puppet.debug("MongoDB shard properties: #{properties.inspect}") + properties + end + + def exists? + @property_hash[:ensure] == :present + end + + def mongo_command(command, host, retries=4) + self.class.mongo_command(command,host,retries) + end + + def self.mongo_command(command, host=nil, retries=4) + # Allow waiting for mongod to become ready + # Wait for 2 seconds initially and double the delay at each retry + wait = 2 + begin + args = Array.new + args << '--quiet' + args << ['--host',host] if host + args << ['--eval',"printjson(#{command})"] + output = mongo(args.flatten) + rescue Puppet::ExecutionFailure => e + if e =~ /Error: couldn't connect to server/ and wait <= 2**max_wait + info("Waiting #{wait} seconds for mongod to become available") + sleep wait + wait *= 2 + retry + else + raise + end + end + + # NOTE (spredzy) : sh.status() + # does not return a json stream + # we jsonify it so it is easier + # to parse and deal with it + if command == 'sh.status()' + myarr = output.split("\n") + myarr.shift + myarr.pop + myarr.pop + final_stream = [] + prev_line = nil + in_shard_list = 0 + in_chunk = 0 + myarr.each do |line| + line.gsub!(/sharding version:/, '{ "sharding version":') + line.gsub!(/shards:/, ',"shards":[') + line.gsub!(/databases:/, '], "databases":[') + line.gsub!(/"clusterId" : ObjectId\("(.*)"\)/, '"clusterId" : "ObjectId(\'\1\')"') + line.gsub!(/\{ "_id" :/, ",{ \"_id\" :") if /_id/ =~ prev_line + # Modification for shard + line = '' if line =~ /on :.*Timestamp/ + if line =~ /_id/ and in_shard_list == 1 + in_shard_list = 0 + last_line = final_stream.pop.strip + proper_line = "#{last_line}]}," + final_stream << proper_line + end + if line =~ /shard key/ and in_shard_list == 1 + shard_name = final_stream.pop.strip + proper_line = ",{\"#{shard_name}\":" + final_stream << proper_line + end + if line =~ /shard key/ and in_shard_list == 0 + in_shard_list = 1 + shard_name = final_stream.pop.strip + id_line = "#{final_stream.pop[0..-2]}, \"shards\": " + proper_line = "[{\"#{shard_name}\":" + final_stream << id_line + final_stream << proper_line + end + if in_chunk == 1 + in_chunk = 0 + line = "\"#{line.strip}\"}}" + end + if line =~ /chunks/ and in_chunk == 0 + in_chunk = 1 + end + line.gsub!(/shard key/, '{"shard key"') + line.gsub!(/chunks/, ',"chunks"') + final_stream << line if line.size > 0 + prev_line = line + end + final_stream << ' ] }' if in_shard_list == 1 + final_stream << ' ] }' + output = final_stream.join("\n") + end + + #Hack to avoid non-json empty sets + output = "{}" if output == "null\n" + output.gsub!(/\s*/, '') + JSON.parse(output) + end +end diff --git a/mongodb/lib/puppet/provider/mongodb_user/mongodb.rb b/mongodb/lib/puppet/provider/mongodb_user/mongodb.rb index 635d44a06..27502572c 100644 --- a/mongodb/lib/puppet/provider/mongodb_user/mongodb.rb +++ b/mongodb/lib/puppet/provider/mongodb_user/mongodb.rb @@ -64,14 +64,17 @@ def create mongo_eval("db.addUser(#{user.to_json})", @resource[:database]) else - user = { - :user => @resource[:username], - :pwd => @resource[:password_hash], - :customData => { :createdBy => "Puppet Mongodb_user['#{@resource[:name]}']" }, - :roles => @resource[:roles] + cmd_json=<<-EOS.gsub(/^\s*/, '').gsub(/$\n/, '') + { + "createUser": "#{@resource[:username]}", + "pwd": "#{@resource[:password_hash]}", + "customData": {"createdBy": "Puppet Mongodb_user['#{@resource[:name]}']"}, + "roles": #{@resource[:roles].to_json}, + "digestPassword": false } + EOS - mongo_eval("db.createUser(#{user.to_json})", @resource[:database]) + mongo_eval("db.runCommand(#{cmd_json})", @resource[:database]) end @property_hash[:ensure] = :present @@ -97,13 +100,15 @@ def exists? end def password_hash=(value) - cmd = { - :updateUser => @resource[:username], - :pwd => @resource[:password_hash], - :digestPassword => false + cmd_json=<<-EOS.gsub(/^\s*/, '').gsub(/$\n/, '') + { + "updateUser": "#{@resource[:username]}", + "pwd": "#{@resource[:password_hash]}", + "digestPassword": false } + EOS - mongo_eval("db.runCommand(#{cmd.to_json})", @resource[:database]) + mongo_eval("db.runCommand(#{cmd_json})", @resource[:database]) end def roles=(roles) diff --git a/mongodb/lib/puppet/type/mongodb_shard.rb b/mongodb/lib/puppet/type/mongodb_shard.rb new file mode 100644 index 000000000..b903a8496 --- /dev/null +++ b/mongodb/lib/puppet/type/mongodb_shard.rb @@ -0,0 +1,39 @@ +# +# Author: Emilien Macchi +# + +Puppet::Type.newtype(:mongodb_shard) do + @doc = "Manage a MongoDB Shard" + + ensurable do + defaultto :present + + newvalue(:present) do + provider.create + end + end + + newparam(:name) do + desc "The name of the shard" + end + + newproperty(:member) do + desc "The shard member" + end + + newproperty(:keys, :array_matching => :all) do + desc "The sharding keys" + + def insync?(is) + is.sort == should.sort + end + end + + autorequire(:package) do + 'mongodb_client' + end + + autorequire(:service) do + 'mongodb' + end +end diff --git a/mongodb/manifests/client/install.pp b/mongodb/manifests/client/install.pp index 51ed31474..f63efc1e6 100644 --- a/mongodb/manifests/client/install.pp +++ b/mongodb/manifests/client/install.pp @@ -20,9 +20,9 @@ if $package_name { package { 'mongodb_client': - ensure => $my_package_ensure, - name => $package_name, - tag => 'mongodb', + ensure => $my_package_ensure, + name => $package_name, + tag => 'mongodb', } } } diff --git a/mongodb/manifests/db.pp b/mongodb/manifests/db.pp index 708f5d75e..2b7f4a52f 100644 --- a/mongodb/manifests/db.pp +++ b/mongodb/manifests/db.pp @@ -19,9 +19,9 @@ ) { mongodb_database { $name: - ensure => present, - tries => $tries, - require => Class['mongodb::server'], + ensure => present, + tries => $tries, + require => Class['mongodb::server'], } if $password_hash { diff --git a/mongodb/manifests/globals.pp b/mongodb/manifests/globals.pp index 0eebcd59b..6a7f52981 100644 --- a/mongodb/manifests/globals.pp +++ b/mongodb/manifests/globals.pp @@ -4,10 +4,12 @@ class mongodb::globals ( $server_package_name = undef, $client_package_name = undef, + $mongos_package_name = undef, $service_enable = undef, $service_ensure = undef, $service_name = undef, + $mongos_service_name = undef, $service_provider = undef, $service_status = undef, @@ -18,6 +20,8 @@ $version = undef, $manage_package_repo = undef, + + $use_enterprise_repo = undef, ) { # Setup of the repo only makes sense globally, so we are doing it here. diff --git a/mongodb/manifests/init.pp b/mongodb/manifests/init.pp index ca4500c69..79a2800bf 100644 --- a/mongodb/manifests/init.pp +++ b/mongodb/manifests/init.pp @@ -46,7 +46,7 @@ $logpath = $mongodb::params::logpath, $logappend = true, $fork = $mongodb::params::fork, - $port = 27017, + $port = undef, $dbpath = $mongodb::params::dbpath, $journal = undef, $nojournal = undef, @@ -72,6 +72,8 @@ $only = undef, $master = undef, $source = undef, + $configsvr = undef, + $shardsvr = undef, $replset = undef, $rest = undef, $quiet = undef, @@ -126,6 +128,8 @@ only => $only, master => $master, source => $source, + configsvr => $configsvr, + shardsvr => $shardsvr, replset => $replset, rest => $rest, quiet => $quiet, diff --git a/mongodb/manifests/mongos.pp b/mongodb/manifests/mongos.pp new file mode 100644 index 000000000..75d03af95 --- /dev/null +++ b/mongodb/manifests/mongos.pp @@ -0,0 +1,36 @@ +# This installs a Mongo Shard daemon. See README.md for more details. +class mongodb::mongos ( + $ensure = $mongodb::params::mongos_ensure, + $config = $mongodb::params::mongos_config, + $config_content = undef, + $configdb = $mongodb::params::mongos_configdb, + $service_provider = $mongodb::params::mongos_service_provider, + $service_name = $mongodb::params::mongos_service_name, + $service_enable = $mongodb::params::mongos_service_enable, + $service_ensure = $mongodb::params::mongos_service_ensure, + $service_status = $mongodb::params::mongos_service_status, + $package_ensure = $mongodb::params::package_ensure_mongos, + $package_name = $mongodb::params::mongos_package_name, + $unixsocketprefix = undef, + $pidfilepath = undef, + $logpath = undef, + $bind_ip = undef, + $fork = undef, + $port = undef, +) inherits mongodb::params { + + if ($ensure == 'present' or $ensure == true) { + anchor { 'mongodb::mongos::start': }-> + class { 'mongodb::mongos::install': }-> + class { 'mongodb::mongos::config': }-> + class { 'mongodb::mongos::service': }-> + anchor { 'mongodb::mongos::end': } + } else { + anchor { 'mongodb::mongos::start': }-> + class { 'mongodb::mongos::service': }-> + class { 'mongodb::mongos::config': }-> + class { 'mongodb::mongos::install': }-> + anchor { 'mongodb::mongos::end': } + } + +} diff --git a/mongodb/manifests/mongos/config.pp b/mongodb/manifests/mongos/config.pp new file mode 100644 index 000000000..fc7154762 --- /dev/null +++ b/mongodb/manifests/mongos/config.pp @@ -0,0 +1,28 @@ +# PRIVATE CLASS: do not call directly +class mongodb::mongos::config ( + $ensure = $mongodb::mongos::ensure, + $config = $mongodb::mongos::config, + $config_content = $mongodb::mongos::config_content, + $configdb = $mongodb::mongos::configdb, +) { + + if ($ensure == 'present' or $ensure == true) { + + #Pick which config content to use + if $config_content { + $config_content_real = $config_content + } else { + $config_content_real = template('mongodb/mongodb-shard.conf.erb') + } + + file { $config: + content => $config_content_real, + owner => 'root', + group => 'root', + mode => '0644', + notify => Class['mongodb::mongos::service'] + } + + } + +} diff --git a/mongodb/manifests/mongos/install.pp b/mongodb/manifests/mongos/install.pp new file mode 100644 index 000000000..e9285af71 --- /dev/null +++ b/mongodb/manifests/mongos/install.pp @@ -0,0 +1,32 @@ +# PRIVATE CLASS: do not call directly +class mongodb::mongos::install ( + $package_ensure = $mongodb::mongos::package_ensure, + $package_name = $mongodb::mongos::package_name, +) { + + case $package_ensure { + true: { + $my_package_ensure = 'present' + } + false: { + $my_package_ensure = 'absent' + } + 'absent': { + $my_package_ensure = 'absent' + } + 'purged': { + $my_package_ensure = 'purged' + } + default: { + $my_package_ensure = $package_ensure + } + } + + if !defined(Package[$package_name]) { + package { 'mongodb_mongos': + ensure => $my_package_ensure, + name => $package_name, + } + } + +} diff --git a/mongodb/manifests/mongos/service.pp b/mongodb/manifests/mongos/service.pp new file mode 100644 index 000000000..7d1b7551a --- /dev/null +++ b/mongodb/manifests/mongos/service.pp @@ -0,0 +1,69 @@ +# PRIVATE CLASS: do not call directly +class mongodb::mongos::service ( + $service_name = $mongodb::mongos::service_name, + $service_enable = $mongodb::mongos::service_enable, + $service_ensure = $mongodb::mongos::service_ensure, + $service_status = $mongodb::mongos::service_status, + $service_provider = $mongodb::mongos::service_provider, + $bind_ip = $mongodb::mongos::bind_ip, + $port = $mongodb::mongos::port, +) { + + $service_ensure_real = $service_ensure ? { + absent => false, + purged => false, + stopped => false, + default => true + } + + if $port { + $port_real = $port + } else { + $port_real = '27017' + } + + if $bind_ip == '0.0.0.0' { + $bind_ip_real = '127.0.0.1' + } else { + $bind_ip_real = $bind_ip + } + + if $::osfamily == 'RedHat' { + file { '/etc/sysconfig/mongos' : + ensure => present, + owner => 'root', + group => 'root', + mode => '0755', + content => 'OPTIONS="--quiet -f /etc/mongodb-shard.conf"', + before => Service['mongos'], + } + } + + file { '/etc/init.d/mongos' : + ensure => present, + content => template("mongodb/mongos/${::osfamily}/mongos.erb"), + owner => 'root', + group => 'root', + mode => '0755', + before => Service['mongos'], + } + + service { 'mongos': + ensure => $service_ensure_real, + name => $service_name, + enable => $service_enable, + provider => $service_provider, + hasstatus => true, + status => $service_status, + } + + if $service_ensure_real { + mongodb_conn_validator { 'mongos': + server => $bind_ip_real, + port => $port_real, + timeout => '240', + require => Service['mongos'], + } + } + +} diff --git a/mongodb/manifests/params.pp b/mongodb/manifests/params.pp index 7789e27d3..1f94d8479 100644 --- a/mongodb/manifests/params.pp +++ b/mongodb/manifests/params.pp @@ -1,10 +1,16 @@ # PRIVATE CLASS: do not use directly class mongodb::params inherits mongodb::globals { $ensure = true + $mongos_ensure = true $service_enable = pick($mongodb::globals::service_enable, true) $service_ensure = pick($mongodb::globals::service_ensure, 'running') $service_status = $mongodb::globals::service_status + $mongos_service_enable = pick($mongodb::globals::mongos_service_enable, true) + $mongos_service_ensure = pick($mongodb::globals::mongos_service_ensure, 'running') + $mongos_service_status = $mongodb::globals::mongos_service_status + $mongos_configdb = '127.0.0.1:27019' + # Amazon Linux's OS Family is 'Linux', operating system 'Amazon'. case $::osfamily { 'RedHat', 'Linux': { @@ -13,51 +19,68 @@ $user = pick($::mongodb::globals::user, 'mongod') $group = pick($::mongodb::globals::group, 'mongod') if ($::mongodb::globals::version == undef) { - $server_package_name = pick($::mongodb::globals::server_package_name, 'mongodb-org-server') - $client_package_name = pick($::mongodb::globals::client_package_name, 'mongodb-org-shell') - $package_ensure = true + $server_package_name = pick($::mongodb::globals::server_package_name, 'mongodb-org-server') + $client_package_name = pick($::mongodb::globals::client_package_name, 'mongodb-org-shell') + $mongos_package_name = pick($::mongodb::globals::mongos_package_name, 'mongodb-org-mongos') + $package_ensure = true $package_ensure_client = true + $package_ensure_mongos = true } else { # check if the version is greater than 2.6 if(versioncmp($::mongodb::globals::version, '2.6.0') >= 0) { - $server_package_name = pick($::mongodb::globals::server_package_name, 'mongodb-org-server') - $client_package_name = pick($::mongodb::globals::client_package_name, 'mongodb-org-shell') - $package_ensure = $::mongodb::globals::version + $server_package_name = pick($::mongodb::globals::server_package_name, 'mongodb-org-server') + $client_package_name = pick($::mongodb::globals::client_package_name, 'mongodb-org-shell') + $mongos_package_name = pick($::mongodb::globals::mongos_package_name, 'mongodb-org-mongos') + $package_ensure = $::mongodb::globals::version $package_ensure_client = $::mongodb::globals::version + $package_ensure_mongos = $::mongodb::globals::version } else { - $server_package_name = pick($::mongodb::globals::server_package_name, 'mongodb-10gen') - $client_package_name = pick($::mongodb::globals::client_package_name, 'mongodb-10gen') - $package_ensure = $::mongodb::globals::version + $server_package_name = pick($::mongodb::globals::server_package_name, 'mongodb-10gen') + $client_package_name = pick($::mongodb::globals::client_package_name, 'mongodb-10gen') + $mongos_package_name = pick($::mongodb::globals::mongos_package_name, 'mongodb-10gen') + $package_ensure = $::mongodb::globals::version $package_ensure_client = $::mongodb::globals::version #this is still needed in case they are only installing the client + $package_ensure_mongos = $::mongodb::globals::version } } - $service_name = pick($::mongodb::globals::service_name, 'mongod') - $config = '/etc/mongod.conf' - $dbpath = '/var/lib/mongodb' - $logpath = '/var/log/mongodb/mongod.log' - $pidfilepath = '/var/run/mongodb/mongod.pid' - $bind_ip = pick($::mongodb::globals::bind_ip, ['127.0.0.1']) - $fork = true + $service_name = pick($::mongodb::globals::service_name, 'mongod') + $mongos_service_name = pick($::mongodb::globals::mongos_service_name, 'mongos') + $config = '/etc/mongod.conf' + $mongos_config = '/etc/mongodb-shard.conf' + $dbpath = '/var/lib/mongodb' + $logpath = '/var/log/mongodb/mongod.log' + $pidfilepath = '/var/run/mongodb/mongod.pid' + $bind_ip = pick($::mongodb::globals::bind_ip, ['127.0.0.1']) + $fork = true } else { # RedHat/CentOS doesn't come with a prepacked mongodb # so we assume that you are using EPEL repository. if ($::mongodb::globals::version == undef) { $package_ensure = true $package_ensure_client = true + $package_ensure_mongos = true } else { $package_ensure = $::mongodb::globals::version $package_ensure_client = $::mongodb::globals::version + $package_ensure_mongos = $::mongodb::globals::version } $user = pick($::mongodb::globals::user, 'mongodb') $group = pick($::mongodb::globals::group, 'mongodb') $server_package_name = pick($::mongodb::globals::server_package_name, 'mongodb-server') $client_package_name = pick($::mongodb::globals::client_package_name, 'mongodb') + $mongos_package_name = pick($::mongodb::globals::mongos_package_name, 'mongodb-server') $service_name = pick($::mongodb::globals::service_name, 'mongod') $config = '/etc/mongodb.conf' + $mongos_config = '/etc/mongodb-shard.conf' $dbpath = '/var/lib/mongodb' $logpath = '/var/log/mongodb/mongodb.log' $bind_ip = pick($::mongodb::globals::bind_ip, ['127.0.0.1']) - $pidfilepath = '/var/run/mongodb/mongodb.pid' + if ($::operatingsystem == 'fedora' and versioncmp($::operatingsystemrelease, '22') >= 0 or + $::operatingsystem != 'fedora' and versioncmp($::operatingsystemrelease, '7.0') >= 0) { + $pidfilepath = '/var/run/mongodb/mongod.pid' + } else { + $pidfilepath = '/var/run/mongodb/mongodb.pid' + } $fork = true $journal = true } @@ -69,8 +92,10 @@ if ($::mongodb::globals::version == undef) { $server_package_name = pick($::mongodb::globals::server_package_name, 'mongodb-org-server') $client_package_name = pick($::mongodb::globals::client_package_name, 'mongodb-org-shell') + $mongos_package_name = pick($::mongodb::globals::mongos_package_name, 'mongodb-org-mongos') $package_ensure = true $package_ensure_client = true + $package_ensure_mongos = true $service_name = pick($::mongodb::globals::service_name, 'mongod') $config = '/etc/mongod.conf' } else { @@ -78,22 +103,27 @@ if(versioncmp($::mongodb::globals::version, '2.6.0') >= 0) { $server_package_name = pick($::mongodb::globals::server_package_name, 'mongodb-org-server') $client_package_name = pick($::mongodb::globals::client_package_name, 'mongodb-org-shell') + $mongos_package_name = pick($::mongodb::globals::mongos_package_name, 'mongodb-org-mongos') $package_ensure = $::mongodb::globals::version $package_ensure_client = $::mongodb::globals::version + $package_ensure_mongos = $::mongodb::globals::version $service_name = pick($::mongodb::globals::service_name, 'mongod') $config = '/etc/mongod.conf' } else { $server_package_name = pick($::mongodb::globals::server_package_name, 'mongodb-10gen') $client_package_name = pick($::mongodb::globals::client_package_name, 'mongodb-10gen') + $mongos_package_name = pick($::mongodb::globals::mongos_package_name, 'mongodb-10gen') $package_ensure = $::mongodb::globals::version $package_ensure_client = $::mongodb::globals::version #this is still needed in case they are only installing the client $service_name = pick($::mongodb::globals::service_name, 'mongodb') $config = '/etc/mongodb.conf' } } - $dbpath = '/var/lib/mongodb' - $logpath = '/var/log/mongodb/mongodb.log' - $bind_ip = pick($::mongodb::globals::bind_ip, ['127.0.0.1']) + $mongos_service_name = pick($::mongodb::globals::mongos_service_name, 'mongos') + $mongos_config = '/etc/mongodb-shard.conf' + $dbpath = '/var/lib/mongodb' + $logpath = '/var/log/mongodb/mongodb.log' + $bind_ip = pick($::mongodb::globals::bind_ip, ['127.0.0.1']) } else { # although we are living in a free world, # I would not recommend to use the prepacked @@ -102,16 +132,21 @@ if ($::mongodb::globals::version == undef) { $package_ensure = true $package_ensure_client = true + $package_ensure_mongos = true } else { $package_ensure = $::mongodb::globals::version $package_ensure_client = $::mongodb::globals::version + $package_ensure_mongos = $::mongodb::globals::version } $user = pick($::mongodb::globals::user, 'mongodb') $group = pick($::mongodb::globals::group, 'mongodb') $server_package_name = pick($::mongodb::globals::server_package_name, 'mongodb-server') $client_package_name = $::mongodb::globals::client_package_name + $mongos_package_name = pick($::mongodb::globals::mongos_package_name, 'mongodb-server') $service_name = pick($::mongodb::globals::service_name, 'mongodb') + $mongos_service_name = pick($::mongodb::globals::mongos_service_name, 'mongos') $config = '/etc/mongodb.conf' + $mongos_config = '/etc/mongodb-shard.conf' $dbpath = '/var/lib/mongodb' $logpath = '/var/log/mongodb/mongodb.log' $bind_ip = pick($::mongodb::globals::bind_ip, ['127.0.0.1']) diff --git a/mongodb/manifests/repo.pp b/mongodb/manifests/repo.pp index ecd6de1b7..90f4dae53 100644 --- a/mongodb/manifests/repo.pp +++ b/mongodb/manifests/repo.pp @@ -4,11 +4,18 @@ ) inherits mongodb::params { case $::osfamily { 'RedHat', 'Linux': { - $location = $::architecture ? { - 'x86_64' => 'http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/', - 'i686' => 'http://downloads-distro.mongodb.org/repo/redhat/os/i686/', - 'i386' => 'http://downloads-distro.mongodb.org/repo/redhat/os/i686/', - default => undef + if $mongodb::globals::use_enterprise_repo == true { + $location = 'https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/stable/$basearch/' + $description = 'MongoDB Enterprise Repository' + } + else { + $location = $::architecture ? { + 'x86_64' => 'http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/', + 'i686' => 'http://downloads-distro.mongodb.org/repo/redhat/os/i686/', + 'i386' => 'http://downloads-distro.mongodb.org/repo/redhat/os/i686/', + default => undef + } + $description = 'MongoDB/10gen Repository' } class { 'mongodb::repo::yum': } } diff --git a/mongodb/manifests/repo/yum.pp b/mongodb/manifests/repo/yum.pp index 3a3f6b5d8..cc033327f 100644 --- a/mongodb/manifests/repo/yum.pp +++ b/mongodb/manifests/repo/yum.pp @@ -5,7 +5,7 @@ if($::mongodb::repo::ensure == 'present' or $::mongodb::repo::ensure == true) { yumrepo { 'mongodb': - descr => 'MongoDB/10gen Repository', + descr => $::mongodb::repo::description, baseurl => $::mongodb::repo::location, gpgcheck => '0', enabled => '1', diff --git a/mongodb/manifests/server.pp b/mongodb/manifests/server.pp index 32984a58c..239f26340 100644 --- a/mongodb/manifests/server.pp +++ b/mongodb/manifests/server.pp @@ -22,7 +22,7 @@ $bind_ip = $mongodb::params::bind_ip, $logappend = true, $fork = $mongodb::params::fork, - $port = 27017, + $port = undef, $journal = $mongodb::params::journal, $nojournal = undef, $smallfiles = undef, @@ -49,14 +49,18 @@ $mms_name = undef, $mms_interval = undef, $replset = undef, + $configsvr = undef, + $shardsvr = undef, $rest = undef, $quiet = undef, $slowms = undef, $keyfile = undef, $set_parameter = undef, $syslog = undef, - $config_content = undef, + $ssl = undef, + $ssl_key = undef, + $ssl_ca = undef, # Deprecated parameters $master = undef, @@ -66,6 +70,10 @@ ) inherits mongodb::params { + if $ssl { + validate_string($ssl_key, $ssl_ca) + } + if ($ensure == 'present' or $ensure == true) { anchor { 'mongodb::server::start': }-> class { 'mongodb::server::install': }-> diff --git a/mongodb/manifests/server/config.pp b/mongodb/manifests/server/config.pp index 587f76de5..f3bb6a5c6 100644 --- a/mongodb/manifests/server/config.pp +++ b/mongodb/manifests/server/config.pp @@ -38,6 +38,8 @@ $slave = $mongodb::server::slave $only = $mongodb::server::only $source = $mongodb::server::source + $configsvr = $mongodb::server::configsvr + $shardsvr = $mongodb::server::shardsvr $replset = $mongodb::server::replset $rest = $mongodb::server::rest $quiet = $mongodb::server::quiet @@ -48,6 +50,9 @@ $profile = $mongodb::server::profile $set_parameter = $mongodb::server::set_parameter $syslog = $mongodb::server::syslog + $ssl = $mongodb::server::ssl + $ssl_key = $mongodb::server::ssl_key + $ssl_ca = $mongodb::server::ssl_ca File { owner => $user, diff --git a/mongodb/manifests/server/install.pp b/mongodb/manifests/server/install.pp index 46b0e749b..8adc24de4 100644 --- a/mongodb/manifests/server/install.pp +++ b/mongodb/manifests/server/install.pp @@ -27,8 +27,8 @@ } package { 'mongodb_server': - ensure => $my_package_ensure, - name => $package_name, - tag => 'mongodb', + ensure => $my_package_ensure, + name => $package_name, + tag => 'mongodb', } } diff --git a/mongodb/manifests/server/service.pp b/mongodb/manifests/server/service.pp index 93a448743..3a7478bda 100644 --- a/mongodb/manifests/server/service.pp +++ b/mongodb/manifests/server/service.pp @@ -7,10 +7,31 @@ $service_status = $mongodb::server::service_status $bind_ip = $mongodb::server::bind_ip $port = $mongodb::server::port + $configsvr = $mongodb::server::configsvr + $shardsvr = $mongodb::server::shardsvr + + if !$port { + if $configsvr { + $port_real = 27019 + } elsif $shardsvr { + $port_real = 27018 + } else { + $port_real = 27017 + } + } else { + $port_real = $port + } + + if $bind_ip == '0.0.0.0' { + $bind_ip_real = '127.0.0.1' + } else { + $bind_ip_real = $bind_ip + } $service_ensure = $ensure ? { absent => false, purged => false, + stopped => false, default => true } @@ -22,10 +43,11 @@ hasstatus => true, status => $service_status, } + if $service_ensure { - mongodb_conn_validator { "mongodb": - server => $bind_ip, - port => $port, + mongodb_conn_validator { 'mongodb': + server => $bind_ip_real, + port => $port_real, timeout => '240', require => Service['mongodb'], } diff --git a/mongodb/manifests/shardsvr.pp b/mongodb/manifests/shardsvr.pp new file mode 100644 index 000000000..e8adbbffe --- /dev/null +++ b/mongodb/manifests/shardsvr.pp @@ -0,0 +1,11 @@ +# Wrapper class useful for hiera based deployments + +class mongodb::shardsvr( + $shards = undef +) { + + if $shards { + create_resources(mongodb_shard, $shards) + } + +} diff --git a/mongodb/metadata.json b/mongodb/metadata.json index ca4ddb6d2..873182cdd 100644 --- a/mongodb/metadata.json +++ b/mongodb/metadata.json @@ -1,9 +1,9 @@ { "name": "puppetlabs-mongodb", - "version": "0.9.0", + "version": "0.10.0", "author": "puppetlabs", "summary": "Installs MongoDB on RHEL/Ubuntu/Debian.", - "license": "Apache License Version 2.0", + "license": "Apache-2.0", "source": "https://github.com/puppetlabs/puppetlabs-mongodb", "project_page": "https://github.com/puppetlabs/puppetlabs-mongodb", "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", @@ -12,14 +12,16 @@ "operatingsystem": "RedHat", "operatingsystemrelease": [ "5", - "6" + "6", + "7" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "5", - "6" + "6", + "7" ] }, { @@ -38,7 +40,7 @@ } ], "dependencies": [ - {"name":"puppetlabs/apt","version_requirement":">= 1.0.0"}, - {"name":"puppetlabs/stdlib","version_requirement":">= 2.2.0"} + {"name":"puppetlabs/apt","version_requirement":">= 1.0.0 <2.0.0"}, + {"name":"puppetlabs/stdlib","version_requirement":">= 2.2.0 <5.0.0"} ] } diff --git a/mongodb/spec/acceptance/database_spec.rb b/mongodb/spec/acceptance/database_spec.rb new file mode 100644 index 000000000..1546bf773 --- /dev/null +++ b/mongodb/spec/acceptance/database_spec.rb @@ -0,0 +1,83 @@ +require 'spec_helper_acceptance' + +describe 'mongodb_database' do + case fact('osfamily') + when 'RedHat' + version = "'2.6.6-1'" + when 'Debian' + version = "'2.6.6'" + end + shared_examples 'normal tests' do |tengen, version| + context "when manage_package_repo is #{tengen} and version is #{version}" do + describe 'creating a database' do + context 'with default port' do + after :all do + puts "XXX uninstalls mongodb because changing the port with tengen doesn't work because they have a crappy init script" + pp = <<-EOS + class {'mongodb::globals': manage_package_repo => #{tengen}, } + -> class { 'mongodb::server': + ensure => absent, + package_ensure => absent, + service_ensure => stopped, + service_enable => false + } + -> class { 'mongodb::client': ensure => absent, } + EOS + apply_manifest(pp, :catch_failures => true) + end + it 'should compile with no errors' do + pp = <<-EOS + class { 'mongodb::globals': manage_package_repo => #{tengen}, version => #{version.nil? ? 'undef' : version} } + -> class { 'mongodb::server': } + -> class { 'mongodb::client': } + -> mongodb_database { 'testdb': ensure => present } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + it 'should create the database' do + shell("mongo testdb --eval 'printjson(db.getMongo().getDBs())'") + end + end + + # MODULES-878 + context 'with custom port' do + after :all do + puts "XXX uninstalls mongodb because changing the port with tengen doesn't work because they have a crappy init script" + pp = <<-EOS + class {'mongodb::globals': manage_package_repo => #{tengen}, } + -> class { 'mongodb::server': + ensure => absent, + package_ensure => absent, + service_ensure => stopped, + service_enable => false + } + -> class { 'mongodb::client': ensure => absent, } + EOS + apply_manifest(pp, :catch_failures => true) + end + it 'should work with no errors' do + pp = <<-EOS + class { 'mongodb::globals': manage_package_repo => #{tengen}, } + -> class { 'mongodb::server': port => 27018 } + -> class { 'mongodb::client': } + -> mongodb_database { 'testdb': ensure => present } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + it 'should create the database' do + shell("mongo testdb --port 27018 --eval 'printjson(db.getMongo().getDBs())'") + end + end + end + end + end + + it_behaves_like 'normal tests', false, nil + it_behaves_like 'normal tests', true, nil # This will give a key-value config file even though the version will be 2.6 + it_behaves_like 'normal tests', true, version # This will give the YAML config file for 2.6 +end diff --git a/mongodb/spec/acceptance/mongos_spec.rb b/mongodb/spec/acceptance/mongos_spec.rb new file mode 100644 index 000000000..663d698d7 --- /dev/null +++ b/mongodb/spec/acceptance/mongos_spec.rb @@ -0,0 +1,107 @@ +require 'spec_helper_acceptance' + +describe 'mongodb::mongos class' do + + shared_examples 'normal tests' do |tengen| + if tengen + package_name = 'mongodb-org-mongos' + else + package_name = 'mongodb-server' + end + service_name = 'mongos' + config_file = '/etc/mongodb-shard.conf' + + client_name = 'mongo --version' + + context "default parameters with 10gen => #{tengen}" do + after :all do + if tengen + puts "XXX uninstalls mongodb and mongos because changing the port with tengen doesn't work because they have a crappy init script" + pp = <<-EOS + class {'mongodb::globals': manage_package_repo => #{tengen}, } + -> class { 'mongodb::server': + ensure => absent, + package_ensure => absent, + service_ensure => stopped, + service_enable => false + } + -> class { 'mongodb::client': ensure => absent, } + -> class { 'mongodb::mongos': + ensure => absent, + package_ensure => absent, + service_ensure => stopped, + service_enable => false + } + EOS + apply_manifest(pp, :catch_failures => true) + end + end + + it 'should work with no errors' do + pp = <<-EOS + class { 'mongodb::globals': manage_package_repo => #{tengen}, + } -> class { 'mongodb::server': + configsvr => true, + } + -> class { 'mongodb::client': } + -> class { 'mongodb::mongos': + configdb => ['127.0.0.1:27019'], + } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + describe package(package_name) do + it { should be_installed } + end + + describe file(config_file) do + it { should be_file } + end + + describe service(service_name) do + it { should be_enabled } + it { should be_running } + end + + describe port(27017) do + it { should be_listening } + end + + describe port(27019) do + it { should be_listening } + end + + describe command(client_name) do + its(:exit_status) { should eq 0 } + end + end + + describe "uninstalling with 10gen => #{tengen}" do + it 'uninstalls mongodb' do + pp = <<-EOS + class {'mongodb::globals': manage_package_repo => #{tengen}, } + -> class { 'mongodb::server': + ensure => absent, + package_ensure => absent, + service_ensure => stopped, + service_enable => false + } + -> class { 'mongodb::client': ensure => absent, } + -> class { 'mongodb::mongos': + ensure => absent, + package_ensure => absent, + service_ensure => stopped, + service_enable => false + } + EOS + apply_manifest(pp, :catch_failures => true) + end + end + end + + it_behaves_like 'normal tests', false + it_behaves_like 'normal tests', true +end diff --git a/mongodb/spec/acceptance/nodesets/centos-7-vcloud.yml b/mongodb/spec/acceptance/nodesets/centos-7-vcloud.yml new file mode 100644 index 000000000..1cecb6b28 --- /dev/null +++ b/mongodb/spec/acceptance/nodesets/centos-7-vcloud.yml @@ -0,0 +1,15 @@ +HOSTS: + 'centos-7-vcloud': + roles: + - master + platform: el-7-x86_64 + hypervisor: vcloud + template: centos-7-x86_64 +CONFIG: + type: foss + ssh: + keys: "~/.ssh/id_rsa-acceptance" + datastore: instance0 + folder: Delivery/Quality Assurance/Enterprise/Dynamic + resourcepool: delivery/Quality Assurance/Enterprise/Dynamic + pooling_api: http://vcloud.delivery.puppetlabs.net/ diff --git a/mongodb/spec/acceptance/nodesets/centos-7-x64.yml b/mongodb/spec/acceptance/nodesets/centos-7-x64.yml new file mode 100644 index 000000000..983238cfc --- /dev/null +++ b/mongodb/spec/acceptance/nodesets/centos-7-x64.yml @@ -0,0 +1,9 @@ +HOSTS: + centos-7-x64: + roles: + - master + platform: el-7-x86_64 + box : puppetlabs/centos-7.0-64-nocm + hypervisor : vagrant +CONFIG: + type: foss diff --git a/mongodb/spec/acceptance/nodesets/multi-centos-7-vcloud.yml b/mongodb/spec/acceptance/nodesets/multi-centos-7-vcloud.yml new file mode 100644 index 000000000..a7adb1674 --- /dev/null +++ b/mongodb/spec/acceptance/nodesets/multi-centos-7-vcloud.yml @@ -0,0 +1,21 @@ +HOSTS: + 'master': + roles: + - master + platform: el-7-x86_64 + hypervisor: vcloud + template: centos-7-x86_64 + 'slave': + roles: + - slave + platform: el-7-x86_64 + hypervisor: vcloud + template: centos-7-x86_64 +CONFIG: + type: foss + ssh: + keys: "~/.ssh/id_rsa-acceptance" + datastore: instance0 + folder: Delivery/Quality Assurance/Enterprise/Dynamic + resourcepool: delivery/Quality Assurance/Enterprise/Dynamic + pooling_api: http://vcloud.delivery.puppetlabs.net/ diff --git a/mongodb/spec/acceptance/nodesets/multi-centos-7-x64.yml b/mongodb/spec/acceptance/nodesets/multi-centos-7-x64.yml new file mode 100644 index 000000000..877ccbbad --- /dev/null +++ b/mongodb/spec/acceptance/nodesets/multi-centos-7-x64.yml @@ -0,0 +1,15 @@ +HOSTS: + 'master': + roles: + - master + platform: el-7-x86_64 + hypervisor : vagrant + box : puppetlabs/centos-7.0-64-nocm + 'slave': + roles: + - slave + platform: el-7-x86_64 + hypervisor : vagrant + box : puppetlabs/centos-7.0-64-nocm +CONFIG: + type: foss diff --git a/mongodb/spec/acceptance/server_spec.rb b/mongodb/spec/acceptance/server_spec.rb index a313b9885..794cb70bd 100644 --- a/mongodb/spec/acceptance/server_spec.rb +++ b/mongodb/spec/acceptance/server_spec.rb @@ -35,7 +35,12 @@ puts "XXX uninstalls mongodb because changing the port with tengen doesn't work because they have a crappy init script" pp = <<-EOS class {'mongodb::globals': manage_package_repo => #{tengen}, } - -> class { 'mongodb::server': ensure => absent, } + -> class { 'mongodb::server': + ensure => absent, + package_ensure => absent, + service_ensure => stopped, + service_enable => false + } -> class { 'mongodb::client': ensure => absent, } EOS apply_manifest(pp, :catch_failures => true) @@ -71,9 +76,7 @@ class { 'mongodb::globals': manage_package_repo => #{tengen}, } end describe command(client_name) do - it do - should return_exit_status 0 - end + its(:exit_status) { should eq 0 } end end @@ -98,7 +101,12 @@ class { 'mongodb::globals': manage_package_repo => #{tengen}, } it 'uninstalls mongodb' do pp = <<-EOS class {'mongodb::globals': manage_package_repo => #{tengen}, } - -> class { 'mongodb::server': ensure => absent, } + -> class { 'mongodb::server': + ensure => absent, + package_ensure => absent, + service_ensure => stopped, + service_enable => false + } -> class { 'mongodb::client': ensure => absent, } EOS apply_manifest(pp, :catch_failures => true) diff --git a/mongodb/spec/acceptance/sharding_spec.rb b/mongodb/spec/acceptance/sharding_spec.rb new file mode 100644 index 000000000..c51f2f2a4 --- /dev/null +++ b/mongodb/spec/acceptance/sharding_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper_acceptance' + +if hosts.length > 1 + describe 'mongodb_shard resource' do + + it 'configures the shard server' do + pp = <<-EOS + class { 'mongodb::globals': } + -> class { 'mongodb::server': + bind_ip => '0.0.0.0', + replset => 'foo', + shardsvr => true, + }-> + mongodb_replset { 'foo' : + members => ["shard:27018"], + } + if $::osfamily == 'RedHat' { + class { 'mongodb::client': } + } + EOS + + apply_manifest_on(hosts_as('shard'), pp, :catch_failures => true) + apply_manifest_on(hosts_as('shard'), pp, :catch_changes => true) + end + + it 'configures the router server' do + pp = <<-EOS + class { 'mongodb::globals': } + -> class { 'mongodb::server': + bind_ip => '0.0.0.0', + configsvr => true, + } -> + class { 'mongodb::mongos' : + configdb => ["router:27019"], + } -> + exec { '/bin/sleep 20' : + } -> + mongodb_shard { 'foo': + member => 'foo/shard:27018', + keys => [{'foo.toto' => {'name' => 1}}] + } + if $::osfamily == 'RedHat' { + class { 'mongodb::client': } + } + EOS + + apply_manifest_on(hosts_as('router'), pp, :catch_failures => true) + on(hosts_as('router'), 'mongo --quiet --eval "printjson(sh.status())"') do |r| + expect(r.stdout).to match /foo\/shard:27018/ + expect(r.stdout).to match /foo\.toto/ + end + end + + end +end diff --git a/mongodb/spec/acceptance/user_spec.rb b/mongodb/spec/acceptance/user_spec.rb new file mode 100644 index 000000000..3e200939e --- /dev/null +++ b/mongodb/spec/acceptance/user_spec.rb @@ -0,0 +1,99 @@ +require 'spec_helper_acceptance' + +describe 'mongodb_database' do + case fact('osfamily') + when 'RedHat' + version = "'2.6.6-1'" + when 'Debian' + version = "'2.6.6'" + end + shared_examples 'normal tests' do |version| + context "when version is #{version.nil? ? 'nil' : version}" do + describe 'creating a database' do + context 'with default port' do + after :all do + puts "XXX uninstalls mongodb because changing the port with tengen doesn't work because they have a crappy init script" + pp = <<-EOS + class {'mongodb::globals': manage_package_repo => true, } + -> class { 'mongodb::server': + ensure => absent, + package_ensure => absent, + service_ensure => stopped, + service_enable => false + } + -> class { 'mongodb::client': ensure => absent, } + EOS + apply_manifest(pp, :catch_failures => true) + end + it 'should compile with no errors' do + pp = <<-EOS + class { 'mongodb::globals': manage_package_repo => true, version => #{version.nil? ? 'undef' : version} } + -> class { 'mongodb::server': } + -> class { 'mongodb::client': } + -> mongodb_database { 'testdb': ensure => present } + -> + mongodb_user {'testuser': + ensure => present, + password_hash => mongodb_password('testuser', 'passw0rd'), + database => 'testdb', + } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + it 'should create the user' do + shell("mongo testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r| + expect(r.stdout.chomp).to eq("1") + end + end + end + + # MODULES-878 + context 'with custom port' do + after :all do + puts "XXX uninstalls mongodb because changing the port with tengen doesn't work because they have a crappy init script" + pp = <<-EOS + class {'mongodb::globals': manage_package_repo => true, } + -> class { 'mongodb::server': + ensure => absent, + package_ensure => absent, + service_ensure => stopped, + service_enable => false + } + -> class { 'mongodb::client': ensure => absent, } + EOS + apply_manifest(pp, :catch_failures => true) + end + it 'should work with no errors' do + pp = <<-EOS + class { 'mongodb::globals': manage_package_repo => true, } + -> class { 'mongodb::server': port => 27018 } + -> class { 'mongodb::client': } + -> mongodb_database { 'testdb': ensure => present } + -> + mongodb_user {'testuser': + ensure => present, + password_hash => mongodb_password('testuser', 'passw0rd'), + database => 'testdb', + } + EOS + + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + it 'should create the user' do + shell("mongo testdb --quiet --port 27018 --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r| + expect(r.stdout.chomp).to eq("1") + end + end + end + end + end + end + + it_behaves_like 'normal tests', nil # This will give a key-value config file even though the version will be 2.6 + it_behaves_like 'normal tests', version # This will give the YAML config file for 2.6 +end diff --git a/mongodb/spec/classes/mongos_config_spec.rb b/mongodb/spec/classes/mongos_config_spec.rb new file mode 100644 index 000000000..e591ad4f3 --- /dev/null +++ b/mongodb/spec/classes/mongos_config_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe 'mongodb::mongos::config' do + + describe 'it should create mongos configuration file' do + + let :facts do + { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + } + end + + let :pre_condition do + "class { 'mongodb::mongos': }" + end + + it { + should contain_file('/etc/mongodb-shard.conf') + } + end + +end diff --git a/mongodb/spec/classes/mongos_install_spec.rb b/mongodb/spec/classes/mongos_install_spec.rb new file mode 100644 index 000000000..33f0a2e57 --- /dev/null +++ b/mongodb/spec/classes/mongos_install_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe 'mongodb::mongos::install', :type => :class do + + describe 'it should include package' do + + let :facts do + { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + } + end + + let :pre_condition do + "class { 'mongodb::mongos': + configdb => ['127.0.0.1:27019'], + package_name => 'mongo-foo', + }" + end + + it { + should contain_package('mongodb_mongos').with({ + :ensure => 'present', + :name => 'mongo-foo', + }) + } + end + +end diff --git a/mongodb/spec/classes/mongos_service_spec.rb b/mongodb/spec/classes/mongos_service_spec.rb new file mode 100644 index 000000000..2a51acacb --- /dev/null +++ b/mongodb/spec/classes/mongos_service_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe 'mongodb::mongos::service', :type => :class do + + context 'on Debian' do + let :facts do + { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + } + end + + let :pre_condition do + "class { 'mongodb::mongos': + configdb => ['127.0.0.1:27019'], + }" + end + + describe 'include init script' do + it { should contain_file('/etc/init.d/mongos') } + end + + describe 'configure the mongos service' do + it { should contain_service('mongos') } + end + end + + context 'on RedHat' do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystem => 'RedHat', + } + end + + let :pre_condition do + "class { 'mongodb::mongos': + configdb => ['127.0.0.1:27019'], + }" + end + + describe 'include mongos sysconfig file' do + it { should contain_file('/etc/sysconfig/mongos') } + end + + describe 'include init script' do + it { should contain_file('/etc/init.d/mongos') } + end + + describe 'configure the mongos service' do + it { should contain_service('mongos') } + end + end + + +end diff --git a/mongodb/spec/classes/mongos_spec.rb b/mongodb/spec/classes/mongos_spec.rb new file mode 100644 index 000000000..d50d7556c --- /dev/null +++ b/mongodb/spec/classes/mongos_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe 'mongodb::mongos' do + let :facts do + { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + } + end + + let :params do + { + :configdb => ['127.0.0.1:27019'] + } + end + + context 'with defaults' do + it { should contain_class('mongodb::mongos::install') } + it { should contain_class('mongodb::mongos::config') } + it { should contain_class('mongodb::mongos::service') } + end + + context 'when deploying on Solaris' do + let :facts do + { :osfamily => 'Solaris' } + end + it { expect { should raise_error(Puppet::Error) } } + end + +end diff --git a/mongodb/spec/spec_helper_acceptance.rb b/mongodb/spec/spec_helper_acceptance.rb index 5ea038b34..5e2af52b9 100755 --- a/mongodb/spec/spec_helper_acceptance.rb +++ b/mongodb/spec/spec_helper_acceptance.rb @@ -35,6 +35,9 @@ when 'RedHat' on hosts, 'puppet module install stahnma-epel' apply_manifest_on hosts, 'include epel' + if fact('operatingsystemrelease') =~ /^7/ + on hosts, 'yum install -y iptables-services' + end on hosts, 'service iptables stop' end end diff --git a/mongodb/spec/unit/puppet/provider/mongodb_replset/mongodb_spec.rb b/mongodb/spec/unit/puppet/provider/mongodb_replset/mongodb_spec.rb index d0c2d128e..c93376b1f 100644 --- a/mongodb/spec/unit/puppet/provider/mongodb_replset/mongodb_spec.rb +++ b/mongodb/spec/unit/puppet/provider/mongodb_replset/mongodb_spec.rb @@ -4,6 +4,7 @@ # require 'spec_helper' +require 'tempfile' describe Puppet::Type.type(:mongodb_replset).provider(:mongo) do @@ -33,6 +34,11 @@ end describe '#exists?' do + before :each do + tmp = Tempfile.new('test') + @mongodconffile = tmp.path + provider.class.stubs(:get_mongod_conf_file).returns(@mongodconffile) + end describe 'when the replicaset does not exist' do it 'returns false' do provider.class.stubs(:mongo).returns(< :present, + :name => 'rs_test', + :member => 'rs_test/mongo1:27018', + :keys => [], + :provider => :mongo + } + ) + end + + let(:provider) { resource.provider } + let(:instance) { provider.class.instances.first } + + let(:parsed_shards) { %w(rs_test) } + + let(:raw_shards) do + { + "sharding version" => { + "_id" => 1, + "version" => 4, + "minCompatibleVersion" => 4, + "currentVersion" => 5, + "clusterId" => "ObjectId(\'548e9110f3aca177c94c5e49\')" + }, + "shards" => [ + { "_id" => "rs_test", "host" => "rs_test/mongo1:27018" } + ], + "databases" => [ + { "_id" => "admin", "partitioned" => false, "primary" => "config" }, + { "_id" => "test", "partitioned" => false, "primary" => "rs_test" }, + { "_id" => "rs_test", "partitioned" => true, "primary" => "rs_test" } + ] + } + end + + before :each do + provider.class.stubs(:mongo_command).with('sh.status()').returns(raw_shards) + end + + describe 'self.instances' do + + it 'should create a shard' do + shards = provider.class.instances.collect { |x| x.name } + expect(parsed_shards).to match_array(shards) + end + + end + + describe '#create' do + it 'makes a shard' do + provider.expects('sh_addshard').with("rs_test/mongo1:27018").returns( + { "shardAdded" => "rs_test", + "ok" => 1 } + ) + provider.expects('sh_enablesharding').with("rs_test").returns( + { "ok" => 1 } + ) + provider.create + provider.flush + end + end + + describe 'destroy' do + it 'removes a shard' do + end + end + + describe 'exists?' do + it 'checks if shard exists' do + instance.exists? + end + end + +end diff --git a/mongodb/spec/unit/puppet/provider/mongodb_user/mongodb_spec.rb b/mongodb/spec/unit/puppet/provider/mongodb_user/mongodb_spec.rb index f2a90598b..c9f31d8dc 100644 --- a/mongodb/spec/unit/puppet/provider/mongodb_user/mongodb_spec.rb +++ b/mongodb/spec/unit/puppet/provider/mongodb_user/mongodb_spec.rb @@ -39,15 +39,17 @@ describe 'create' do it 'creates a user' do - user = { - :user => 'new_user', - :pwd => 'pass', - :customData => { :createdBy => "Puppet Mongodb_user['new_user']" }, - :roles => ['role1','role2'], + cmd_json=<<-EOS.gsub(/^\s*/, '').gsub(/$\n/, '') + { + "createUser": "new_user", + "pwd": "pass", + "customData": {"createdBy": "Puppet Mongodb_user['new_user']"}, + "roles": ["role1","role2"], + "digestPassword": false } + EOS - - provider.expects(:mongo_eval).with("db.createUser(#{user.to_json})", 'new_database') + provider.expects(:mongo_eval).with("db.runCommand(#{cmd_json})", 'new_database') provider.create end end @@ -73,13 +75,15 @@ describe 'password_hash=' do it 'changes a password_hash' do - cmd = { - :updateUser => 'new_user', - :pwd => 'pass', - :digestPassword => false + cmd_json=<<-EOS.gsub(/^\s*/, '').gsub(/$\n/, '') + { + "updateUser": "new_user", + "pwd": "pass", + "digestPassword": false } + EOS provider.expects(:mongo_eval). - with("db.runCommand(#{cmd.to_json})", 'new_database') + with("db.runCommand(#{cmd_json})", 'new_database') provider.password_hash=("newpass") end end diff --git a/mongodb/spec/unit/puppet/type/mongodb_shard_spec.rb b/mongodb/spec/unit/puppet/type/mongodb_shard_spec.rb new file mode 100644 index 000000000..eaaaf09e7 --- /dev/null +++ b/mongodb/spec/unit/puppet/type/mongodb_shard_spec.rb @@ -0,0 +1,29 @@ +require 'puppet' +require 'puppet/type/mongodb_shard' +describe Puppet::Type.type(:mongodb_shard) do + + before :each do + @shard = Puppet::Type.type(:mongodb_shard).new(:name => 'test') + end + + it 'should accept a shard name' do + @shard[:name].should == 'test' + end + + it 'should accept a member' do + @shard[:member] = 'rs_test/mongo1:27017' + @shard[:member].should == 'rs_test/mongo1:27017' + end + + it 'should accept a keys array' do + @shard[:keys] = [{'foo.bar' => {'name' => 1}}] + @shard[:keys].should == [{'foo.bar' => {'name' => 1}}] + end + + it 'should require a name' do + expect { + Puppet::Type.type(:mongodb_shard).new({}) + }.to raise_error(Puppet::Error, 'Title or name must be provided') + end + +end diff --git a/mongodb/templates/mongodb-shard.conf.erb b/mongodb/templates/mongodb-shard.conf.erb new file mode 100644 index 000000000..5825ddc44 --- /dev/null +++ b/mongodb/templates/mongodb-shard.conf.erb @@ -0,0 +1,21 @@ +<% if @configdb -%> +configdb = <%= Array(@configdb).join(',') %> +<% end -%> +<% if @bind_ip -%> +bind_ip = <%= @bind_ip %> +<% end -%> +<% if @port -%> +port = <%= @port %> +<% end -%> +<% if @fork -%> +fork = <%= @fork %> +<% end -%> +<% if @pidfilepath -%> +pidfilepath = <%= @pidfilepath %> +<% end -%> +<% if @logpath -%> +logpath = <%= @logpath %> +<% end -%> +<% if @unixsocketprefix -%> +unixSocketPrefix = <%= @unixsocketprefix %> +<% end -%> diff --git a/mongodb/templates/mongodb.conf.2.6.erb b/mongodb/templates/mongodb.conf.2.6.erb index fe6182210..e892779b3 100644 --- a/mongodb/templates/mongodb.conf.2.6.erb +++ b/mongodb/templates/mongodb.conf.2.6.erb @@ -81,7 +81,9 @@ security.javascriptEnabled: <%= @noscripting %> <% if @bind_ip -%> net.bindIp: <%= Array(@bind_ip).join(',') %> <% end -%> +<% if @port -%> net.port: <%= @port %> +<% end -%> <% if @objcheck -%> net.wireObjectCheck: <%= @objcheck %> <% end -%> @@ -103,6 +105,14 @@ replication.replSetName: <%= @replset %> replication.oplogSizeMB: <%= @oplog_size %> <% end -%> +# Sharding +<% if @configsvr -%> +sharding.clusterRole: configsvr +<% end -%> +<% if @shardsvr -%> +sharding.clusterRole: shardsvr +<% end -%> + #Operation Profiling <% if @profile == "0" -%> operationProfiling.mode: off diff --git a/mongodb/templates/mongodb.conf.erb b/mongodb/templates/mongodb.conf.erb index f6328b474..faaa67ceb 100644 --- a/mongodb/templates/mongodb.conf.erb +++ b/mongodb/templates/mongodb.conf.erb @@ -18,7 +18,9 @@ bind_ip = <%= Array(@bind_ip).join(',') %> # fork and run in background fork=<%= @fork %> <% end -%> +<% if @port -%> port = <%= @port %> +<% end -%> dbpath=<%= @dbpath %> <% if @pidfilepath -%> # location of pidfile @@ -133,6 +135,14 @@ master = <%= @master %> # files in a distinct folder. directoryperdb = <%= @directoryperdb %> <% end -%> +<% if @configsvr -%> +# Is the mongod instance a configuration server +configsvr = <%= @configsvr %> +<% end -%> +<% if @shardsvr -%> +# Is the mongod instance a shard server +shardsvr = <%= @shardsvr %> +<% end -%> <% if @replset -%> # Configure ReplicaSet membership replSet = <%= @replset %> @@ -170,3 +180,8 @@ syslog = <%= @syslog %> <% if @quiet -%> quiet = <%= @quiet %> <% end -%> +<% if @ssl -%> +sslOnNormalPorts = true +sslPEMKeyFile = <%= @ssl_key %> +sslCAFile = <%= @ssl_ca %> +<% end -%> diff --git a/mongodb/templates/mongos/Debian/mongos.erb b/mongodb/templates/mongos/Debian/mongos.erb new file mode 100644 index 000000000..98dada202 --- /dev/null +++ b/mongodb/templates/mongos/Debian/mongos.erb @@ -0,0 +1,266 @@ +#!/bin/sh +# +# init.d script with LSB support. +# +# Copyright (c) 2007 Javier Fernandez-Sanguino +# +# This is free software; you may redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2, +# or (at your option) any later version. +# +# This is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License with +# the Debian operating system, in /usr/share/common-licenses/GPL; if +# not, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA +# +### BEGIN INIT INFO +# Provides: mongos +# Required-Start: $network $local_fs $remote_fs +# Required-Stop: $network $local_fs $remote_fs +# Should-Start: $named +# Should-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: An object/document-oriented database +# Description: MongoDB is a high-performance, open source, schema-free +# document-oriented data store that's easy to deploy, manage +# and use. It's network accessible, written in C++ and offers +# the following features: +# +# * Collection oriented storage - easy storage of object- +# style data +# * Full index support, including on inner objects +# * Query profiling +# * Replication and fail-over support +# * Efficient storage of binary data including large +# objects (e.g. videos) +# * Automatic partitioning for cloud-level scalability +# +# High performance, scalability, and reasonable depth of +# functionality are the goals for the project. +### END INIT INFO + +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +DAEMON=/usr/bin/mongos +DESC=database + +NAME=mongos +# Defaults. Can be overridden by the /etc/default/$NAME +# Other configuration options are located in $CONF file. See here for more: +# http://dochub.mongodb.org/core/configurationoptions +CONF=/etc/mongodb-shard.conf +PIDFILE=/var/run/$NAME.pid +ENABLE_MONGOD=yes + +# Include mongodb defaults if available +if [ -f /etc/default/$NAME ] ; then + . /etc/default/$NAME +fi + +# Handle NUMA access to CPUs (SERVER-3574) +# This verifies the existence of numactl as well as testing that the command works +NUMACTL_ARGS="--interleave=all" +if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null +then + NUMACTL="`which numactl` -- $NUMACTL_ARGS" + DAEMON_OPTS=${DAEMON_OPTS:-"--config $CONF"} +else + NUMACTL="" + DAEMON_OPTS="-- "${DAEMON_OPTS:-"--config $CONF"} +fi + +if test ! -x $DAEMON; then + echo "Could not find $DAEMON" + exit 0 +fi + +if test "x$ENABLE_MONGOD" != "xyes"; then + exit 0 +fi + +. /lib/lsb/init-functions + +STARTTIME=1 +DIETIME=10 # Time to wait for the server to die, in seconds + # If this value is set too low you might not + # let some servers to die gracefully and + # 'restart' will not work + +DAEMONUSER=${DAEMONUSER:-mongodb} + +set -e + +running_pid() { +# Check if a given process pid's cmdline matches a given name + pid=$1 + name=$2 + [ -z "$pid" ] && return 1 + [ ! -d /proc/$pid ] && return 1 + cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1` + # Is this the expected server + [ "$cmd" != "$name" ] && return 1 + return 0 +} + +running() { +# Check if the process is running looking at /proc +# (works for all users) + + # No pidfile, probably no daemon present + [ ! -f "$PIDFILE" ] && return 1 + pid=`cat $PIDFILE` + running_pid $pid $DAEMON || return 1 + return 0 +} + +start_server() { + # Recommended ulimit values for mongod or mongos + # See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings + # + ulimit -f unlimited + ulimit -t unlimited + ulimit -v unlimited + ulimit -n 64000 + ulimit -m unlimited + + # In dash, ulimit takes -p for maximum user processes + # In bash, it's -u + if readlink /proc/$$/exe | grep -q dash + then + ulimit -p 32000 + else + ulimit -u 32000 + fi + + # Start the process using the wrapper + start-stop-daemon --background --start --quiet --pidfile $PIDFILE \ + --make-pidfile --chuid $DAEMONUSER \ + --exec $NUMACTL $DAEMON $DAEMON_OPTS + errcode=$? + return $errcode +} + +stop_server() { +# Stop the process using the wrapper + start-stop-daemon --stop --quiet --pidfile $PIDFILE \ + --retry 300 \ + --user $DAEMONUSER \ + --exec $DAEMON + errcode=$? + return $errcode +} + +force_stop() { +# Force the process to die killing it manually + [ ! -e "$PIDFILE" ] && return + if running ; then + kill -15 $pid + # Is it really dead? + sleep "$DIETIME"s + if running ; then + kill -9 $pid + sleep "$DIETIME"s + if running ; then + echo "Cannot kill $NAME (pid=$pid)!" + exit 1 + fi + fi + fi + rm -f $PIDFILE +} + + +case "$1" in + start) + log_daemon_msg "Starting $DESC" "$NAME" + # Check if it's running first + if running ; then + log_progress_msg "apparently already running" + log_end_msg 0 + exit 0 + fi + if start_server ; then + # NOTE: Some servers might die some time after they start, + # this code will detect this issue if STARTTIME is set + # to a reasonable value + [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time + if running ; then + # It's ok, the server started and is running + log_end_msg 0 + else + # It is not running after we did start + log_end_msg 1 + fi + else + # Either we could not start it + log_end_msg 1 + fi + ;; + stop) + log_daemon_msg "Stopping $DESC" "$NAME" + if running ; then + # Only stop the server if we see it running + errcode=0 + stop_server || errcode=$? + log_end_msg $errcode + else + # If it's not running don't do anything + log_progress_msg "apparently not running" + log_end_msg 0 + exit 0 + fi + ;; + force-stop) + # First try to stop gracefully the program + $0 stop + if running; then + # If it's still running try to kill it more forcefully + log_daemon_msg "Stopping (force) $DESC" "$NAME" + errcode=0 + force_stop || errcode=$? + log_end_msg $errcode + fi + ;; + restart|force-reload) + log_daemon_msg "Restarting $DESC" "$NAME" + errcode=0 + stop_server || errcode=$? + # Wait some sensible amount, some server need this + [ -n "$DIETIME" ] && sleep $DIETIME + start_server || errcode=$? + [ -n "$STARTTIME" ] && sleep $STARTTIME + running || errcode=$? + log_end_msg $errcode + ;; + status) + + log_daemon_msg "Checking status of $DESC" "$NAME" + if running ; then + log_progress_msg "running" + log_end_msg 0 + else + log_progress_msg "apparently not running" + log_end_msg 1 + exit 1 + fi + ;; + # MongoDB can't reload its configuration. + reload) + log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon" + log_warning_msg "cannot re-read the config file (use restart)." + ;; + + *) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/mongodb/templates/mongos/RedHat/mongos.erb b/mongodb/templates/mongos/RedHat/mongos.erb new file mode 100644 index 000000000..757175b5a --- /dev/null +++ b/mongodb/templates/mongos/RedHat/mongos.erb @@ -0,0 +1,106 @@ +#!/bin/bash + +# mongos - Startup script for mongos + +# chkconfig: 35 85 15 +# description: Mongo Router Process for sharding +# processname: mongos +# config: /etc/mongodb-shard.conf +# pidfile: /var/run/mongodb/mongos.pid + +. /etc/rc.d/init.d/functions + +# mongos will read mongodb-shard.conf for configuration settings + +# Add variable to support multiple instances of mongos +# The instance name is by default the name of this init script +# In this way another instance can be created by just copying this init script +# and creating a config file with the same name and a .conf extension +# For Example: +# /etc/init.d/mongos2 +# /etc/mongos2.conf +# Optionally also create a sysconfig file to override env variables below +# /etc/sysconfig/mongos2 +INSTANCE=`basename $0` + +# By default OPTIONS just points to the /etc/mongod.conf config file +# This can be overriden in /etc/sysconfig/mongod +OPTIONS=" -f /etc/mongodb-shard.conf" + +PID_PATH=/var/run/mongodb +PID_FILE=${PID_PATH}/${INSTANCE}.pid +MONGO_BIN=/usr/bin/mongos +MONGO_USER=<%=@user%> +MONGO_GROUP=<%=@group%> +MONGO_ULIMIT=12000 +MONGO_LOCK_FILE=/var/lock/subsys/${INSTANCE} + +# Source sysconfig options so that above values can be overriden +SYSCONFIG="/etc/sysconfig/${INSTANCE}" +if [ -f "$SYSCONFIG" ]; then + . "$SYSCONFIG" || true +fi + +# Create mongo pids path if it does not exist +if [ ! -d "${PID_PATH}" ]; then + mkdir -p "${PID_PATH}" + chown "${MONGO_USER}:${MONGO_GROUP}" "${PID_PATH}" +fi + +start() +{ + echo -n $"Starting ${INSTANCE}: " + ulimit -n $MONGO_ULIMIT + touch ${PID_FILE} + touch '/var/log/mongodb/mongodb-shard.log' + chown "${MONGO_USER}:${MONGO_GROUP}" "${PID_FILE}" + chown "${MONGO_USER}:${MONGO_GROUP}" '/var/log/mongodb/mongodb-shard.log' + daemon --user "$MONGO_USER" --pidfile $PID_FILE "$MONGO_BIN $OPTIONS --pidfilepath=$PID_FILE >>/var/log/mongodb/mongodb-shard.log 2>&1 &" + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch $MONGO_LOCK_FILE + return $RETVAL +} + +stop() +{ + echo -n $"Stopping ${INSTANCE}: " + killproc -p $PID_FILE -t30 -TERM $MONGO_BIN + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && rm -f $MONGO_LOCK_FILE + [ $RETVAL -eq 0 ] && rm -f $PID_FILE + return $RETVAL +} + +restart () { + stop + # TODO need to wait for process to stop before continuing + start +} + +RETVAL=0 + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart|reload|force-reload) + restart + ;; + condrestart) + [ -f $MONGO_LOCK_FILE ] && restart || : + ;; + status) + status -p $PID_FILE $MONGO_BIN + RETVAL=$? + ;; + *) + echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" + RETVAL=1 +esac + +exit $RETVAL diff --git a/mongodb/tests/replicaset.pp b/mongodb/tests/replicaset.pp index a758b8dd2..cf2857aea 100644 --- a/mongodb/tests/replicaset.pp +++ b/mongodb/tests/replicaset.pp @@ -7,9 +7,6 @@ bind_ip => ['0.0.0.0'], replset => 'rsmain' } -} - -node /mongo1/ inherits default { mongodb_replset{'rsmain': members => ['mongo1:27017', 'mongo2:27017', 'mongo3:27017'] } diff --git a/mongodb/tests/sharding.pp b/mongodb/tests/sharding.pp new file mode 100644 index 000000000..4dc1ebfaa --- /dev/null +++ b/mongodb/tests/sharding.pp @@ -0,0 +1,55 @@ +node 'mongos' { + + class {'::mongodb::globals': + manage_package_repo => true, + }-> + class {'::mongodb::server': + configsvr => true, + bind_ip => $::ipaddress, + }-> + class {'::mongodb::client': + }-> + class {'::mongodb::mongos': + configdb => ["${::ipaddress}:27019"], + }-> + mongodb_shard { 'rs1' : + member => 'rs1/mongod1:27018', + keys => [{'rs1.foo' => {'name' => 1}}], + } + +} + +node 'mongod1' { + + class {'::mongodb::globals': + manage_package_repo => true, + }-> + class {'::mongodb::server': + shardsvr => true, + replset => 'rs1', + bind_ip => $::ipaddress, + }-> + class {'::mongodb::client': + } + mongodb_replset{'rs1': + members => ['mongod1:27018', 'mongod2:27018'], + } +} + +node 'mongod2' { + + class {'::mongodb::globals': + manage_package_repo => true, + }-> + class {'::mongodb::server': + shardsvr => true, + replset => 'rs1', + bind_ip => $::ipaddress, + }-> + class {'::mongodb::client': + } + mongodb_replset{'rs1': + members => ['mongod1:27018', 'mongod2:27018'], + } + +}