diff --git a/.kitchen.yml b/.kitchen.yml index 33cf28e..ac546d2 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -11,8 +11,25 @@ provisioner: platforms: - name: ubuntu-12.04 + run_list: + - recipe[apt] + attributes: + apt: + compile_time_update: true + - name: ubuntu-14.04 + run_list: + - recipe[apt] + attributes: + apt: + compile_time_update: true - name: debian-7.8 + run_list: + - recipe[apt] + attributes: + apt: + compile_time_update: true - name: centos-6.6 + - name: centos-7.2 - name: oel-6.6 driver: box: rafacas/oel66-plain @@ -26,7 +43,6 @@ suites: driver: vm_hostname: mongo3 run_list: - - recipe[apt] - recipe[mongodb3::default] attributes: chef_client: @@ -35,8 +51,6 @@ suites: log_level: info build-essential: compile_time: false - apt: - compile_time_update: true provisioner: client_rb: environment: dev @@ -44,26 +58,23 @@ suites: - oel-6.6 - ami-2014.03 - - name: default-305 + - name: chef-client-11 driver: vm_hostname: mongo3 + driver_config: + require_chef_omnibus: 11.18.12 run_list: - - recipe[apt] - recipe[mongodb3::default] + excludes: + - debian-7.8 + - oel-6.6 + - ami-2014.03 + - ubuntu-14.04 + + - name: default-30x + run_list: + - recipe[mongodb3-test::default-30x] attributes: - mongodb3: - version: 3.0.5 - chef_client: - config: - force_logger: true - log_level: info - build-essential: - compile_time: false - apt: - compile_time_update: true - provisioner: - client_rb: - environment: dev excludes: - oel-6.6 - ami-2014.03 @@ -72,7 +83,6 @@ suites: driver: vm_hostname: replica run_list: - - recipe[apt] - role[replset] attributes: chef_client: @@ -81,8 +91,6 @@ suites: log_level: info build-essential: compile_time: false - apt: - compile_time_update: true provisioner: client_rb: environment: dev @@ -94,7 +102,6 @@ suites: driver: vm_hostname: configsvr run_list: - - recipe[apt] - role[configsvr] attributes: chef_client: @@ -103,8 +110,6 @@ suites: log_level: info build-essential: compile_time: false - apt: - compile_time_update: true provisioner: client_rb: environment: dev @@ -116,7 +121,6 @@ suites: driver: vm_hostname: mongos run_list: - - recipe[apt] - role[mongos] attributes: chef_client: @@ -125,30 +129,26 @@ suites: log_level: info build-essential: compile_time: false - apt: - compile_time_update: true provisioner: client_rb: environment: dev excludes: - - oel-6.6 - ami-2014.03 - name: wired-tiger driver: vm_hostname: wired-tiger run_list: - - recipe[apt] - role[wired_tiger] attributes: + mongodb3: + version: '3.0.9' chef_client: config: force_logger: true log_level: info build-essential: compile_time: false - apt: - compile_time_update: true provisioner: client_rb: environment: dev @@ -160,7 +160,6 @@ suites: driver: vm_hostname: mms-automation-agent run_list: - - recipe[apt] - role[mms_automation_agent] attributes: chef_client: @@ -169,8 +168,6 @@ suites: log_level: info build-essential: compile_time: false - apt: - compile_time_update: true provisioner: client_rb: environment: dev @@ -178,12 +175,24 @@ suites: - oel-6.6 - ami-2014.03 - debian-7.8 + - centos-7.2 + + - name: mms-automation-agent-with-databag + driver: + vm_hostname: mms-automation-agent + encrypted_data_bag_secret_key_path: "test/data_bags/encrypted_data_bag_secret" + run_list: + - recipe[mongodb3-test::mms_automation_agent_with_data_bag] + provisioner: + client_rb: + environment: dev + includes: + - ubuntu-12.04 - name: mms-monitoring-agent driver: vm_hostname: mms-monitoring-agent run_list: - - recipe[apt] - role[mms_monitoring_agent] attributes: chef_client: @@ -192,8 +201,6 @@ suites: log_level: info build-essential: compile_time: false - apt: - compile_time_update: true provisioner: client_rb: environment: dev @@ -201,6 +208,7 @@ suites: - oel-6.6 - ami-2014.03 - debian-7.8 + - centos-7.2 - name: ami-default driver: @@ -219,8 +227,5 @@ suites: provisioner: client_rb: environment: dev - excludes: - - ubuntu-12.04 - - centos-6.6 - - oel-6.6 - - debian-7.8 + includes: + - ami-2014.03 diff --git a/Berksfile b/Berksfile index 967b9a7..12752b4 100644 --- a/Berksfile +++ b/Berksfile @@ -1,3 +1,7 @@ source "https://supermarket.chef.io" metadata + +group :integration do + cookbook 'mongodb3-test', :path => './test/cookbooks/mongodb3-test' +end diff --git a/CHANGELOG.md b/CHANGELOG.md index c7e208e..1796b47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,21 @@ # mongodb3 Cookbook CHANGELOG -## Next +## 5.0.0 + * Fixed Chef::Mixin::Template::TemplateError: Node attributes are read-only when you do not specify which precedence level to set with Chef 11.10 - Daniel Doubrovkine([@dblock](https://github.com/dblock)) #21. +* Adding test for chef client 11.18.12 as 11.x : testing for #21 +* Adding kitchen test for ubuntu 14.04 : #13 +* Using `/var/run/mongodb/mongod.pid` for centos7 : #25 +* Moving attribute setter to recipe in order to support install 3.0.x in wrapper cookbook. : #23 +* Adding the mongodb 3.0.x version testing in test wrapper cookbook : #23 +* Adding key file directory creation +* Fixing for yum and apt repo name +* Update default version as 3.2.1 : #24 ## 4.0.0 + Thank you so much for your contribution! + * Allowed overrides of mongo repo name for debian/ubuntu packages - Dave Augustus([@daugustus](https://github.com/daugustus)) * Added support for MongoDB 3.2.0 - Constantin Guay([@Cog-g](https://github.com/Cog-g)) * Support for both MongoDB 3.0.x and 3.2.x - Julien Pervillé([@jperville](https://github.com/jperville)) @@ -18,6 +29,7 @@ Thank you so much for your contribution! * Removing kitchen test of mongos for oel-6.6 : There was no 3.0.7-1.el6 of mongos package for Oracle Linux 6.6 (Test failure). I'll keep testing and bring it back later. NOTICE : + * Current version 3.0.0 is not supporting mongos 3.0.7 for Oracle Linux 6.6. The package version 3.0.7-1.el6 of mongodb-org-shell package wasn't existing (Test failure). * Current version 3.0.0 is not supporting automation and monitoring mms agent installation for Debian 7.8 @@ -29,7 +41,6 @@ WARNING : `mms-agent` recipe has been deprecated at this version. * Removing `mms-agent` recipe and divide it as `mms-automation-agent` and `mms-monitoring-agent` recipe * PR #3 : Bump up the runit dependency version to 1.7.0. Thank you for your contribution @dherges - ## 1.0.0 mongodb3 Chef Cookbook 1.0.0 release. diff --git a/README.md b/README.md index e6e74de..3236300 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/sunggun-yu/chef-mongodb3.svg?branch=master)](https://travis-ci.org/sunggun-yu/chef-mongodb3) -Install and configure the MongoDB 3 +## Install and configure the MongoDB 3 * Install and configure the mongod (or configure the config server for shard cluster) * Install and configure the mongos @@ -10,24 +10,28 @@ Install and configure the MongoDB 3 * Install the MMS Automation Agent * Install the MMS Monitoring Agent -NOTICE : -* Current version 4.0.0 is not supporting mongos 3.0.7 for Oracle Linux 6.6. The package version 3.0.7-1.el6 of mongodb-org-shell package wasn't existing (Test failure). -* Current version 4.0.0 is not supporting automation and monitoring mms agent installation for Debian 7.8 -* MongoDB 3.2.0 is default version of mongodb3 cookbook - by [@Cog_g](https://github.com/Cog-g) +### NOTICE : + +* Current version 5.0.0 is not supporting automation and monitoring mms agent installation for Debian 7.8 +* MongoDB 3.2.1 is default version of mongodb3 cookbook + +### Contributors -Contributors * David Herges - [@dherges](https://github.com/dherges) * Joe Passavanti - [@gottaloveit](https://github.com/gottaloveit) * MEGA MOnolithic meTHod - [@megamoth](https://github.com/megamoth) * Dave Augustus - [@daugustus](https://github.com/daugustus) * Constantin Guay - [@Cog-g](https://github.com/Cog-g) * Julien Pervillé - [@jperville](https://github.com/jperville) +* Daniel Doubrov - [@dblock](https://github.com/dblock) ## Supported Platforms +The following platforms have been tested with Test Kitchen + * Ubuntu 12.04, 14.04 * Debian 7.8 -* CentOS 6.6 +* CentOS 6.6, 7.2 * Oralce 6.6 * Amazon Linux @@ -40,16 +44,17 @@ WARNING : Please do not set the user and group attribute on your side. This cook ``` # MongoDB version to install -default['mongodb3']['version'] = '3.2.0' +default['mongodb3']['version'] = '3.2.1' default['mongodb3']['package']['version'] = Actual package version to install. It builds from version attribute. # Package repository url default['mongodb3']['package']['repo']['url'] = Package repository url # Attribute for apt_repository -default['mongodb3']['package']['repo']['apt']['keyserver'] = key server url for ubuntu or debian -default['mongodb3']['package']['repo']['apt']['key'] = 'EA312927' -default['mongodb3']['package']['repo']['apt']['components'] = `multiverse` for ubuntu. `main` for debian +default['mongodb3']['package']['repo']['apt']['name'] = nil # eg. 3.0, 3.2 +default['mongodb3']['package']['repo']['apt']['keyserver'] = nil # eg. hkp://keyserver.ubuntu.com:80 +default['mongodb3']['package']['repo']['apt']['key'] = nil # eg. 3.2 : 'EA312927', 3.0 : '7F0CEB10' +default['mongodb3']['package']['repo']['apt']['components'] = nil # `multiverse` for ubuntu. `main` for debian # MongoDB user:group : PLEASE DO NOT SET THE USER AND GROUP ATTRIBUTE default['mongodb3']['user'] = 'mongod' | 'mongodb' diff --git a/attributes/default.rb b/attributes/default.rb index 0804f1e..630e80e 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -18,40 +18,24 @@ # # MongoDB version to install -default['mongodb3']['version'] = '3.2.0' +default['mongodb3']['version'] = '3.2.1' -# Setup default package version attribute to install -pkg_version = node['mongodb3']['version'] -case node['platform_family'] - when 'rhel', 'fedora' - pkg_version = "#{node['mongodb3']['version']}-1.el#{node.platform_version.to_i}" # ~FC019 - if node['platform'] == 'amazon' - pkg_version = "#{node['mongodb3']['version']}-1.amzn1" # ~FC019 - end -end -pkg_major_version = pkg_version.to_f # eg. 3.0, 3.2 - -# Setup default package repo url attribute for each platform family or platform -case node['platform'] - when 'redhat', 'oracle','centos', 'fedora' - pkg_repo = "https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/#{pkg_major_version}/#{node['kernel']['machine'] =~ /x86_64/ ? 'x86_64' : 'i686'}" - when 'amazon' - pkg_repo = "https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/#{pkg_major_version}/x86_64/" - when 'ubuntu' - pkg_repo = 'http://repo.mongodb.org/apt/ubuntu' - when 'debian' - pkg_repo = 'http://repo.mongodb.org/apt/debian' -end +# Please note : The default values for ['mongodb3']['package'] attributes will be set in `package_repo` recipe. +# but, You can set custom values for yum/apt repo url, yum package version or apt related in your wrapper -# Setup apt variables -case node['platform'] - when 'ubuntu' - apt_repo_keyserver = 'hkp://keyserver.ubuntu.com:80' - apt_repo_component = ['multiverse'] - when 'debian' - apt_repo_keyserver = 'keyserver.ubuntu.com' - apt_repo_component = ['main'] -end +# MongoDB package version to install : eg. 3.0.8, 3.2.1, 3.2.1-1.el6 or 3.2.1-1.amzn1 +default['mongodb3']['package']['version'] = nil + +# MongoDB package repo url +# eg. ubuntu : 'http://repo.mongodb.org/apt/ubuntu' +# eg. centos : 'https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/' +default['mongodb3']['package']['repo']['url'] = nil + +# MongoDB repository info for apt +default['mongodb3']['package']['repo']['apt']['name'] = nil # eg. 3.0, 3.2 +default['mongodb3']['package']['repo']['apt']['keyserver'] = nil # eg. hkp://keyserver.ubuntu.com:80 +default['mongodb3']['package']['repo']['apt']['key'] = nil # eg. 3.2 : 'EA312927', 3.0 : '7F0CEB10' +default['mongodb3']['package']['repo']['apt']['components'] = nil # eg. ['multiverse'] # Default attribute for MongoDB installation case node['platform_family'] @@ -59,7 +43,12 @@ mongo_user = 'mongod' mongo_group = 'mongod' mongo_dbpath = '/var/lib/mongo' - mongo_pid_file = '/var/run/mongodb/mongodb.pid' + # To guarantee the compatibility for centos 6 in previous version of mongodb3 cookbook + if node['platform_version'].to_i >= 7 + mongo_pid_file = '/var/run/mongodb/mongod.pid' + else + mongo_pid_file = '/var/run/mongodb/mongodb.pid' + end config_processManagement_fork = true when 'debian' mongo_user = 'mongodb' @@ -69,24 +58,6 @@ config_processManagement_fork = nil end -# MongoDB package repo url -default['mongodb3']['package']['repo']['url'] = pkg_repo - -# MongoDB repository name -default['mongodb3']['package']['repo']['apt']['name'] = pkg_major_version.to_s - -# MongoDB apt keyserver and key -default['mongodb3']['package']['repo']['apt']['keyserver'] = apt_repo_keyserver -if pkg_major_version >= 3.2 - default['mongodb3']['package']['repo']['apt']['key'] = 'EA312927' -else - default['mongodb3']['package']['repo']['apt']['key'] = '7F0CEB10' -end -default['mongodb3']['package']['repo']['apt']['components'] = apt_repo_component - -# MongoDB package version to install -default['mongodb3']['package']['version'] = pkg_version - # MongoDB user:group default['mongodb3']['user'] = mongo_user default['mongodb3']['group'] = mongo_group @@ -187,11 +158,7 @@ default['mongodb3']['config']['mongod']['storage']['journal']['enabled'] = true default['mongodb3']['config']['mongod']['storage']['directoryPerDB'] = nil # default : false default['mongodb3']['config']['mongod']['storage']['syncPeriodSecs'] = nil # default : 60 -if pkg_major_version >= 3.2 - default['mongodb3']['config']['mongod']['storage']['engine'] = 'wiredTiger' # default since 3.2 : wiredTiger -else - default['mongodb3']['config']['mongod']['storage']['engine'] = 'mmapv1' # default until 3.2 : mmapv1 -end +default['mongodb3']['config']['mongod']['storage']['engine'] = nil # default - since 3.2 : wiredTiger, until 3.2 : mmapv1 # storage.mmapv1 Options : http://docs.mongodb.org/manual/reference/configuration-options/#storage-mmapv1-options default['mongodb3']['config']['mongod']['storage']['mmapv1']['preallocDataFiles'] = nil # default : true diff --git a/recipes/default.rb b/recipes/default.rb index cfeac40..a4890d2 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -41,6 +41,15 @@ unless node['mongodb3']['config']['key_file_content'].to_s.empty? # Create the key file if it is not exist key_file = node['mongodb3']['config']['mongod']['security']['keyFile'] + + # Create the directory for key file + directory File.dirname(key_file).to_s do + action :create + owner node['mongodb3']['user'] + group node['mongodb3']['group'] + recursive true + end + file key_file do content node['mongodb3']['config']['key_file_content'] mode '0600' diff --git a/recipes/package_repo.rb b/recipes/package_repo.rb index c7a46d3..ed6705c 100644 --- a/recipes/package_repo.rb +++ b/recipes/package_repo.rb @@ -17,10 +17,76 @@ # limitations under the License. # -# Add the MongoDB 3.0 Package repository +pkg_major_version = node['mongodb3']['version'].to_f # eg. 3.0, 3.2 + +# Setup default package version attribute to install +pkg_version = node['mongodb3']['version'] +case node['platform_family'] + when 'rhel', 'fedora' + pkg_version = "#{node['mongodb3']['version']}-1.el#{node.platform_version.to_i}" # ~FC019 + if node['platform'] == 'amazon' + pkg_version = "#{node['mongodb3']['version']}-1.amzn1" # ~FC019 + end +end + +# Setup default package repo url attribute for each platform family or platform +case node['platform'] + when 'redhat', 'oracle','centos', 'fedora' # ~FC024 + pkg_repo = "https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/#{pkg_major_version}/#{node['kernel']['machine'] =~ /x86_64/ ? 'x86_64' : 'i686'}" + when 'amazon' + pkg_repo = "https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/#{pkg_major_version}/x86_64/" + when 'ubuntu' + pkg_repo = 'http://repo.mongodb.org/apt/ubuntu' + when 'debian' + pkg_repo = 'http://repo.mongodb.org/apt/debian' +end + +# Setup apt variables +case node['platform'] + when 'ubuntu' + apt_repo_keyserver = 'hkp://keyserver.ubuntu.com:80' + apt_repo_component = ['multiverse'] + when 'debian' + apt_repo_keyserver = 'keyserver.ubuntu.com' + apt_repo_component = ['main'] +end + +# MongoDB package version to install +if node['mongodb3']['package']['version'].nil? + node.set['mongodb3']['package']['version'] = pkg_version +end + +# MongoDB package repo url +if node['mongodb3']['package']['repo']['url'].nil? + node.set['mongodb3']['package']['repo']['url'] = pkg_repo +end + +# MongoDB repository name +if node['mongodb3']['package']['repo']['apt']['name'].nil? + node.set['mongodb3']['package']['repo']['apt']['name'] = pkg_major_version.to_s +end + +# MongoDB apt keyserver and key +if node['mongodb3']['package']['repo']['apt']['keyserver'].nil? + node.set['mongodb3']['package']['repo']['apt']['keyserver'] = apt_repo_keyserver +end + +if node['mongodb3']['package']['repo']['apt']['key'].nil? + if pkg_major_version >= 3.2 + node.set['mongodb3']['package']['repo']['apt']['key'] = 'EA312927' + else + node.set['mongodb3']['package']['repo']['apt']['key'] = '7F0CEB10' + end +end + +if node['mongodb3']['package']['repo']['apt']['components'].nil? + node.set['mongodb3']['package']['repo']['apt']['components'] = apt_repo_component +end + +# Add the MongoDB Package repository case node['platform_family'] when 'rhel', 'fedora' - yum_repository 'mongodb-org-3.0' do + yum_repository "mongodb-org-#{pkg_major_version}" do description 'MongoDB Repository' baseurl node['mongodb3']['package']['repo']['url'] action :create @@ -29,7 +95,7 @@ sslverify false end when 'debian' - apt_repository 'mongodb' do + apt_repository "mongodb-org-#{pkg_major_version}" do uri node['mongodb3']['package']['repo']['url'] distribution "#{node['lsb']['codename']}/mongodb-org/#{node['mongodb3']['package']['repo']['apt']['name']}" components node['mongodb3']['package']['repo']['apt']['components'] diff --git a/test/.foodcritic b/test/.foodcritic new file mode 100644 index 0000000..b381b38 --- /dev/null +++ b/test/.foodcritic @@ -0,0 +1,3 @@ +~FC011 +~FC031 +~FC045 \ No newline at end of file diff --git a/test/cookbooks/mongodb3-test/CHANGELOG.md b/test/cookbooks/mongodb3-test/CHANGELOG.md new file mode 100644 index 0000000..47c1af6 --- /dev/null +++ b/test/cookbooks/mongodb3-test/CHANGELOG.md @@ -0,0 +1,13 @@ +mongodb3-test CHANGELOG +======================= + +This file is used to list changes made in each version of the mongodb3-test cookbook. + +0.1.0 +----- +- [your_name] - Initial release of mongodb3-test + +- - - +Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. + +The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. diff --git a/test/cookbooks/mongodb3-test/README.md b/test/cookbooks/mongodb3-test/README.md new file mode 100644 index 0000000..80cafb6 --- /dev/null +++ b/test/cookbooks/mongodb3-test/README.md @@ -0,0 +1,68 @@ +mongodb3-test Cookbook +====================== +TODO: Enter the cookbook description here. + +e.g. +This cookbook makes your favorite breakfast sandwich. + +Requirements +------------ +TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. + +e.g. +#### packages +- `toaster` - mongodb3-test needs toaster to brown your bagel. + +Attributes +---------- +TODO: List your cookbook attributes here. + +e.g. +#### mongodb3-test::default + + + + + + + + + + + + + +
KeyTypeDescriptionDefault
['mongodb3-test']['bacon']Booleanwhether to include bacontrue
+ +Usage +----- +#### mongodb3-test::default +TODO: Write usage instructions for each cookbook. + +e.g. +Just include `mongodb3-test` in your node's `run_list`: + +```json +{ + "name":"my_node", + "run_list": [ + "recipe[mongodb3-test]" + ] +} +``` + +Contributing +------------ +TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. + +e.g. +1. Fork the repository on Github +2. Create a named feature branch (like `add_component_x`) +3. Write your change +4. Write tests for your change (if applicable) +5. Run the tests, ensuring they all pass +6. Submit a Pull Request using Github + +License and Authors +------------------- +Authors: TODO: List authors diff --git a/test/cookbooks/mongodb3-test/attributes/default-30x.rb b/test/cookbooks/mongodb3-test/attributes/default-30x.rb new file mode 100644 index 0000000..9e98f44 --- /dev/null +++ b/test/cookbooks/mongodb3-test/attributes/default-30x.rb @@ -0,0 +1,20 @@ +# +# Cookbook Name:: mongodb3-test +# Attribute:: default-30x +# +# Copyright 2016, Sunggun Yu +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +default['mongodb3']['version'] = '3.0.9' diff --git a/test/cookbooks/mongodb3-test/attributes/default.rb b/test/cookbooks/mongodb3-test/attributes/default.rb new file mode 100644 index 0000000..794e468 --- /dev/null +++ b/test/cookbooks/mongodb3-test/attributes/default.rb @@ -0,0 +1,18 @@ +# +# Cookbook Name:: mongodb3-test +# Attribute:: default +# +# Copyright 2016, Sunggun Yu +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/test/cookbooks/mongodb3-test/metadata.rb b/test/cookbooks/mongodb3-test/metadata.rb new file mode 100644 index 0000000..6f001c7 --- /dev/null +++ b/test/cookbooks/mongodb3-test/metadata.rb @@ -0,0 +1,9 @@ +name 'mongodb3-test' +maintainer 'Sunggun Yu' +maintainer_email 'sunggun.dev@gmail.com' +license 'Apache 2.0' +description 'Installs/Configures mongodb3-test' +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +version '0.1.0' + +depends 'mongodb3' diff --git a/test/cookbooks/mongodb3-test/recipes/default-30x.rb b/test/cookbooks/mongodb3-test/recipes/default-30x.rb new file mode 100644 index 0000000..86471f8 --- /dev/null +++ b/test/cookbooks/mongodb3-test/recipes/default-30x.rb @@ -0,0 +1,20 @@ +# +# Cookbook Name:: mongodb3-test +# Recipe:: default-30x +# +# Copyright 2016, Sunggun Yu +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +include_recipe 'mongodb3::default' diff --git a/test/cookbooks/mongodb3-test/recipes/default.rb b/test/cookbooks/mongodb3-test/recipes/default.rb new file mode 100644 index 0000000..da032dc --- /dev/null +++ b/test/cookbooks/mongodb3-test/recipes/default.rb @@ -0,0 +1,20 @@ +# +# Cookbook Name:: mongodb3-test +# Recipe:: default +# +# Copyright 2016, Sunggun Yu +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +include_recipe 'mongodb3::default' diff --git a/test/cookbooks/mongodb3-test/recipes/mms_automation_agent_with_data_bag.rb b/test/cookbooks/mongodb3-test/recipes/mms_automation_agent_with_data_bag.rb new file mode 100644 index 0000000..8d2c80b --- /dev/null +++ b/test/cookbooks/mongodb3-test/recipes/mms_automation_agent_with_data_bag.rb @@ -0,0 +1,40 @@ +# +# Cookbook Name:: mongodb3-test +# Recipe:: mms_automation_agent_with_data_bag +# +# Copyright 2016, Sunggun Yu +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# The data bag content that is encrypted +# +# { +# "id" : "mms-agent", +# "environments": { +# "dev": { +# "mms_group_id" : "mms_group_id_from_data_bag", +# "mms_api_key" : "mms_api_key_from_data_bag" +# } +# } +# } + +# mms agent data bag +mms_data_bag_item = Chef::EncryptedDataBagItem.load('mongodb', 'mms-agent') +mms_data_bag = mms_data_bag_item['environments'][node.chef_environment] + +node.set['mongodb3']['config']['mms']['mmsGroupId'] = mms_data_bag['mms_group_id'] +node.set['mongodb3']['config']['mms']['mmsApiKey'] = mms_data_bag['mms_api_key'] + +include_recipe 'mongodb3::mms_automation_agent' diff --git a/test/data_bags/encrypted_data_bag_secret b/test/data_bags/encrypted_data_bag_secret new file mode 100644 index 0000000..2be58ee --- /dev/null +++ b/test/data_bags/encrypted_data_bag_secret @@ -0,0 +1,11 @@ +YC1xx2lq0MsaDW1lFihswcOP6XUzgMmSaWzI8ptspcnB6dCFBq1dFlGzpfsXXeys +X+fpkzLTo2aHMWDZiyzRuDl4ix1OO10TJRxNkLVvGiN4yHw+wk3+WOTcjm1qp0Vy +zsbN5BkjYPlzz9SfYyXZP2jTeo5aE/+oBiGDjzB8kiQ/7wJUt8aJdpW+ez6mwE+s +qLe8WvF73s0InPnxDIwcPfa2j8BCBY7fXgHsPf4xSMYG3DRG4dMNB2875NXVNLrW +d67eoNQedlQFsZlgeUDDVBCvsEWAhJImDvlzlGBLAn9UYKWwAnHFlFaEJ6zeN724 +RvQ5g1SatnJijF8mNztdE8Mz5zhFpYI107D10wLBnHn7bISY+nHZHBvhjtPfmvSv +fOi/XICH8gu28Rp2etsOa9virojvGx81aWNOAPBLDuqQgLqCs8P3HEIhnD1iaU4X +9yQlDGb79viGCWKQMMaJNa3pgLH4dzEqgsb9ySPM4jnItE3X2X5KPqr8X9NKiYHX +yCksc4ZE6IbtJ8f0uC/qUbC1YleGdiC/drWAlURqZXOutBFrNv3ysOmx8q08EPJV +l4JJnwh6bsESfIiZu0fymKN6PgO85hSTRli0/nRjcUj07e27SF59/eRIIiD5VAQo +MQw1wJGpV36XvmT/u69eUz/ZraNTACJ19pyhWNtBJ+w= diff --git a/test/data_bags/mongodb/mms-agent.json b/test/data_bags/mongodb/mms-agent.json new file mode 100644 index 0000000..e7872b4 --- /dev/null +++ b/test/data_bags/mongodb/mms-agent.json @@ -0,0 +1,9 @@ +{ + "id": "mms-agent", + "environments": { + "encrypted_data": "B2rMHbbtkhNcl+BgF+nA/9ZGhgfa1O+J27NjvD6bDuz46Y9nSjiABK6K/CDq\n3FWignVJfJ9GegwrWyscX2Uk2publKopj8ZTKTew6+RTvy6rTXB9FA5+zy+L\nERRe2K8C2MFlBvZG5FT1kn6T6rTi80Z5mywlscz4w5QnCQAWwvs=\n", + "iv": "9HwyIJXUCFqBBS1yiLPN5A==\n", + "version": 1, + "cipher": "aes-256-cbc" + } +} \ No newline at end of file diff --git a/test/integration/chef-client-11/serverspec/default_spec.rb b/test/integration/chef-client-11/serverspec/default_spec.rb new file mode 100644 index 0000000..667ec9e --- /dev/null +++ b/test/integration/chef-client-11/serverspec/default_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' + +# RHEL and Debian family has different value for some of mongodb settings. +if os[:family] == 'redhat' + mongo_user = 'mongod' + mongo_data_dir = '/var/lib/mongo' +elsif ['debian', 'ubuntu'] + mongo_user = 'mongodb' + mongo_data_dir = '/var/lib/mongodb' +end + +# Test `mongodb-org-server` package is installed. +describe package('mongodb-org-server') do + it { should be_installed } +end + +# Test `mongod` service is running. +describe service('mongod') do + it { should be_enabled } + it { should be_running } +end + +# Test mongodb port `27017` is listening. +describe port(27017) do + it { should be_listening } +end + +# Test mongod process starts with expected mongodb config file +describe command('ps -ef | grep mongod') do + its(:stdout) { should contain('/etc/mongod.conf') } +end + +# Test mongodb config file is created with right permission. +describe file('/etc/mongod.conf') do + it { should be_file } + it { should be_owned_by 'root' } + it { should be_grouped_into 'root' } +end + +# Test mongodb data directory is created with right permission. +describe file(mongo_data_dir) do + it { should be_directory } + it { should be_mode 755 } + it { should be_owned_by mongo_user } + it { should be_grouped_into mongo_user } +end + +# Test mongodb log file is created with right permission. +describe file('/var/log/mongodb/mongod.log') do + it { should be_file } + it { should be_owned_by mongo_user } +end + +# Test mongod process starts with expected mongodb config file +describe command('mongo --eval "db.version()"') do + its(:stdout) { should contain('3.2.1') } +end + +# Test chef client version +describe command('chef-client --version') do + its(:stdout) { should contain('11.18.12') } +end diff --git a/test/integration/default-305/serverspec/default_spec.rb b/test/integration/default-30x/serverspec/default_spec.rb similarity index 97% rename from test/integration/default-305/serverspec/default_spec.rb rename to test/integration/default-30x/serverspec/default_spec.rb index fe6473b..7b2700e 100644 --- a/test/integration/default-305/serverspec/default_spec.rb +++ b/test/integration/default-30x/serverspec/default_spec.rb @@ -53,5 +53,5 @@ # Test mongod process starts with expected mongodb config file describe command('mongo --eval "db.version()"') do - its(:stdout) { should contain('3.0.5') } + its(:stdout) { should contain('3.0.9') } end diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb index 108d6bf..cebb886 100644 --- a/test/integration/default/serverspec/default_spec.rb +++ b/test/integration/default/serverspec/default_spec.rb @@ -53,5 +53,5 @@ # Test mongod process starts with expected mongodb config file describe command('mongo --eval "db.version()"') do - its(:stdout) { should contain('3.2.0') } + its(:stdout) { should contain('3.2.1') } end diff --git a/test/integration/mms-automation-agent-with-databag/serverspec/default_spec.rb b/test/integration/mms-automation-agent-with-databag/serverspec/default_spec.rb new file mode 100644 index 0000000..1338389 --- /dev/null +++ b/test/integration/mms-automation-agent-with-databag/serverspec/default_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +# RHEL and Debian family has different value for some of mongodb settings. +if os[:family] == 'redhat' + mongo_user = 'mongod' +elsif ['debian', 'ubuntu'] + mongo_user = 'mongodb' +end + +# MMS Automation Agent is installed +describe package('mongodb-mms-automation-agent-manager') do + it { should be_installed } +end + +# MMS Automation Agent is running +describe service('mongodb-mms-automation-agent') do + it { should be_enabled } + it { should be_running } +end + +# MMS Automation Agent config file is in place +describe file('/etc/mongodb-mms/automation-agent.config') do + it { should be_file } + it { should be_mode 600 } + it { should be_owned_by mongo_user } +end + +# MMS Automation Agent config file is contains group_id and api_key value +describe file('/etc/mongodb-mms/automation-agent.config') do + it { should contain 'mmsGroupId=mms_group_id_from_data_bag' } + it { should contain 'mmsApiKey=mms_api_key_from_data_bag' } +end diff --git a/test/integration/mms-agent/serverspec/default_spec.rb b/test/integration/mms-automation-agent/serverspec/default_spec.rb similarity index 100% rename from test/integration/mms-agent/serverspec/default_spec.rb rename to test/integration/mms-automation-agent/serverspec/default_spec.rb diff --git a/test/integration/replica/serverspec/default_spec.rb b/test/integration/replica/serverspec/default_spec.rb index a943cd9..60b46dd 100644 --- a/test/integration/replica/serverspec/default_spec.rb +++ b/test/integration/replica/serverspec/default_spec.rb @@ -54,4 +54,17 @@ # Test mongodb config file contains expected replica set name describe file('/etc/mongod.conf') do it { should contain 'replSetName: replset-1' } -end \ No newline at end of file +end + +# Test mongodb replicaset key file is created with right permission. +describe file('/srv/mongodb/mongodb-keyfile') do + it { should be_file } + it { should be_mode 600 } + it { should be_owned_by mongo_user } + it { should be_grouped_into mongo_user } +end + +# Test mongodb replicaset key file is matching +describe file('/srv/mongodb/mongodb-keyfile') do + it { should contain "Mb5KNEpIVq1PRIZaA4lcV2KCi1BdSGuzhFUCH61tbhmgHk3Shcc8dbvYW1Lv7jC6\nAtrBWKG4Mn8G5fCTW0cEV0RexNhBRCmSUNszduVi00bMYipyisCD3UUu2ukdUqs9\nNRWlEqeAUEJp8nBZ0AnKpFdtYMsL3zKW7KepW9xWccC0DWQnfSmrZ19ppV0DNVRr\nS5zBbLw0pd7OImkovWAQurLdEVYlgXgkL2Sp7aOWIymrKmWe7leZ4+TITR6xXQ3H\nEcLuICxq+nyDOZ/eKblC5GTfcHyMfGRWiqdfuQeTJbWuo9xPCsbVgfz3c4saHphW\nMflwM1wKTFL/h2+dNSQfSDaOD9HZSprjqx0b4bFS5TsHfiJlaEfbZ0Mv9YPWd9Wi\nNnUDz6l6WW9UVIPCsTrCxRphzYjrn1MF2vIINypDbthpR4s97b89UtCxFsk/Rdzi\nN0RCQtf6a4UeeAf6SFZrWS2/PBzSCaaP/ic3fOaF7VAGQOand9fURkijWxiuBORB\nSP4ftXUoqROgjl1h4vz4C5BDERcN/TQtBmVcuhpqlwPFPhWBoCX09jUZRlodb181\nE9fDsISAZxsrmYNsqHtWwe/PioQFcRe55hk8FPC1TB+aHxtThof493Dd1nDzVXbp\nSOfttBB6qnG/XmgPXVNOov1kkmpaHjn8rvGN+SeMfq7XLnkJD24DgmW3037IYv2k\n/T2hNZaBBd875R+pVyzAmBR50yoJgiJjU/natq7VCcqJ4pMl/YjDvB1EFDQ/4sYy\nOnKtRrKmSEzsqarrKY6u1ttmmlF5i9q5vJmDUNVryxJOCZOS4V+Ma4ZPG3kkZ1sb\nPRS6ZUEBCdZW2Bscuxj3TJZDUuMS/dDq7FiGOC/hRm54YLgpwKaNK3Pc0Uw3FI3e\nObDVLKllDS6cKPDSetf3IJ3CBrCwpUtxDtLA5hIESzpBqbs9Kdm2GPO7UmapJ/ZQ\nKLkCs351W7MCmgXPqv0E7qFXcVnQ" } +end diff --git a/test/roles/replset.json b/test/roles/replset.json index cf7fe9b..4c0a993 100644 --- a/test/roles/replset.json +++ b/test/roles/replset.json @@ -8,8 +8,12 @@ "mongod" : { "replication" : { "replSetName" : "replset-1" + }, + "security" : { + "keyFile" : "/srv/mongodb/mongodb-keyfile" } - } + }, + "key_file_content" : "Mb5KNEpIVq1PRIZaA4lcV2KCi1BdSGuzhFUCH61tbhmgHk3Shcc8dbvYW1Lv7jC6\nAtrBWKG4Mn8G5fCTW0cEV0RexNhBRCmSUNszduVi00bMYipyisCD3UUu2ukdUqs9\nNRWlEqeAUEJp8nBZ0AnKpFdtYMsL3zKW7KepW9xWccC0DWQnfSmrZ19ppV0DNVRr\nS5zBbLw0pd7OImkovWAQurLdEVYlgXgkL2Sp7aOWIymrKmWe7leZ4+TITR6xXQ3H\nEcLuICxq+nyDOZ/eKblC5GTfcHyMfGRWiqdfuQeTJbWuo9xPCsbVgfz3c4saHphW\nMflwM1wKTFL/h2+dNSQfSDaOD9HZSprjqx0b4bFS5TsHfiJlaEfbZ0Mv9YPWd9Wi\nNnUDz6l6WW9UVIPCsTrCxRphzYjrn1MF2vIINypDbthpR4s97b89UtCxFsk/Rdzi\nN0RCQtf6a4UeeAf6SFZrWS2/PBzSCaaP/ic3fOaF7VAGQOand9fURkijWxiuBORB\nSP4ftXUoqROgjl1h4vz4C5BDERcN/TQtBmVcuhpqlwPFPhWBoCX09jUZRlodb181\nE9fDsISAZxsrmYNsqHtWwe/PioQFcRe55hk8FPC1TB+aHxtThof493Dd1nDzVXbp\nSOfttBB6qnG/XmgPXVNOov1kkmpaHjn8rvGN+SeMfq7XLnkJD24DgmW3037IYv2k\n/T2hNZaBBd875R+pVyzAmBR50yoJgiJjU/natq7VCcqJ4pMl/YjDvB1EFDQ/4sYy\nOnKtRrKmSEzsqarrKY6u1ttmmlF5i9q5vJmDUNVryxJOCZOS4V+Ma4ZPG3kkZ1sb\nPRS6ZUEBCdZW2Bscuxj3TJZDUuMS/dDq7FiGOC/hRm54YLgpwKaNK3Pc0Uw3FI3e\nObDVLKllDS6cKPDSetf3IJ3CBrCwpUtxDtLA5hIESzpBqbs9Kdm2GPO7UmapJ/ZQ\nKLkCs351W7MCmgXPqv0E7qFXcVnQ" } } },