diff --git a/.rubocop.yml b/.rubocop.yml index 083cca2..fc2b4bb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,28 +1,52 @@ AllCops: + DisplayCopNames: true Exclude: - - 'Berksfile' - - 'Thorfile' - 'Vagrantfile' - - 'Gemfile' - - 'metadata.rb' -AlignParameters: +Lint/LiteralInCondition: Enabled: false -Encoding: +Lint/ParenthesesAsGroupedExpression: Enabled: false -LineLength: - Max: 200 +Metrics/LineLength: + Enabled: false -HashSyntax: - EnforcedStyle: hash_rockets +Metrics/MethodLength: + Max: 18 -AsciiComments: +Style/AlignParameters: Enabled: false -MethodLength: - Max: 18 +Style/AsciiComments: + Enabled: false + +Style/ConditionalAssignment: + Enabled: false + +Style/Documentation: + Enabled: false + +Style/EachWithObject: + Enabled: false + +Style/Encoding: + Enabled: false Style/FileName: Enabled: false + +Style/HashSyntax: + EnforcedStyle: hash_rockets + +Style/NumericLiterals: + Enabled: false + +Style/SpaceInsideBrackets: + Enabled: false + +Style/RedundantParentheses: + Enabled: false + +Style/WordArray: + Enabled: false diff --git a/Berksfile b/Berksfile index 12752b4..da5fe21 100644 --- a/Berksfile +++ b/Berksfile @@ -1,4 +1,4 @@ -source "https://supermarket.chef.io" +source 'https://supermarket.chef.io' metadata diff --git a/Gemfile b/Gemfile index 1c59de0..db6ac4e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ source 'https://rubygems.org' gem 'berkshelf', '~> 4.0.1' -gem 'test-kitchen', '~> 1.4.0' gem 'foodcritic', '4.0.0' +gem 'test-kitchen', '~> 1.4.0' group :integration do gem 'kitchen-vagrant', '~> 0.18.0' diff --git a/Thorfile b/Thorfile index 7a0c0ff..19aaaf2 100644 --- a/Thorfile +++ b/Thorfile @@ -5,8 +5,8 @@ require 'bundler/setup' require 'berkshelf/thor' begin - require "kitchen/thor_tasks" + require 'kitchen/thor_tasks' Kitchen::ThorTasks.new rescue LoadError - puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV["CI"] + puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI'] end diff --git a/Vagrantfile b/Vagrantfile index 90c16ec..33d4fdd 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -2,7 +2,7 @@ # vi: set ft=ruby : # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! -VAGRANTFILE_API_VERSION = '2' +VAGRANTFILE_API_VERSION = '2'.freeze Vagrant.require_version '>= 1.5.0' @@ -18,7 +18,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # # $ vagrant plugin install vagrant-omnibus # - if Vagrant.has_plugin?("vagrant-omnibus") + if Vagrant.has_plugin?('vagrant-omnibus') config.omnibus.chef_version = 'latest' end @@ -27,7 +27,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # config.vm.box_url doesn't need to be specified. config.vm.box = 'chef/ubuntu-14.04' - # Assign this VM to a host-only network IP, allowing you to access it # via the IP. Host-only networks can talk to the host machine as well as # any other machines on the same network, but cannot be accessed (through this diff --git a/attributes/default.rb b/attributes/default.rb index fdfc912..0e9d6cf 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -32,30 +32,30 @@ 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']['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'] - when 'rhel', 'fedora' - mongo_user = 'mongod' - mongo_group = 'mongod' - mongo_dbpath = '/var/lib/mongo' - # 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' - mongo_group = 'mongodb' - mongo_dbpath = '/var/lib/mongodb' - mongo_pid_file = nil - config_processManagement_fork = nil +when 'rhel', 'fedora' + mongo_user = 'mongod' + mongo_group = 'mongod' + mongo_dbpath = '/var/lib/mongo' + # 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_process_management_fork = true +when 'debian' + mongo_user = 'mongodb' + mongo_group = 'mongodb' + mongo_dbpath = '/var/lib/mongodb' + mongo_pid_file = nil + config_process_management_fork = nil end # MongoDB user:group @@ -113,7 +113,7 @@ # processManagement Options : http://docs.mongodb.org/manual/reference/configuration-options/#processmanagement-options -default['mongodb3']['config']['mongod']['processManagement']['fork'] = config_processManagement_fork # default : false +default['mongodb3']['config']['mongod']['processManagement']['fork'] = config_process_management_fork # default : false default['mongodb3']['config']['mongod']['processManagement']['pidFilePath'] = mongo_pid_file # net Options : http://docs.mongodb.org/manual/reference/configuration-options/#net-options diff --git a/recipes/default.rb b/recipes/default.rb index 5e2147b..084aca2 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -26,9 +26,9 @@ package pkg do version node['mongodb3']['package']['version'] case node['platform_family'] - when 'debian' - # bypass dpkg errors about pre-existing init or conf file - options '-o Dpkg::Options::="--force-confold" --force-yes' + when 'debian' + # bypass dpkg errors about pre-existing init or conf file + options '-o Dpkg::Options::="--force-confold" --force-yes' end action :install end @@ -75,9 +75,9 @@ # Update the mongodb config file template node['mongodb3']['mongod']['config_file'] do source 'mongodb.conf.erb' - mode 0644 + mode '0644' variables( - :config => node['mongodb3']['config']['mongod'] + :config => node['mongodb3']['config']['mongod'] ) helpers Mongodb3Helper end @@ -90,59 +90,53 @@ group 'root' mode '0755' action :create - only_if { - node['mongodb3']['mongod']['disable-transparent-hugepages'] - } + only_if { node['mongodb3']['mongod']['disable-transparent-hugepages'] } end case node['platform'] - when 'ubuntu' - if node['platform_version'].to_f >= 15.04 - cookbook_file '/lib/systemd/system/disable-transparent-hugepages.service' do - source 'disable-transparent-hugepages.service' - owner 'root' - group 'root' - mode '0655' - action :create - only_if { - node['mongodb3']['mongod']['disable-transparent-hugepages'] - } - end +when 'ubuntu' + if node['platform_version'].to_f >= 15.04 + cookbook_file '/lib/systemd/system/disable-transparent-hugepages.service' do + source 'disable-transparent-hugepages.service' + owner 'root' + group 'root' + mode '0655' + action :create + only_if { node['mongodb3']['mongod']['disable-transparent-hugepages'] } end + end end service 'disable-transparent-hugepages' do case node['platform'] - when 'ubuntu' - if node['platform_version'].to_f >= 15.04 - provider Chef::Provider::Service::Systemd - end + when 'ubuntu' + if node['platform_version'].to_f >= 15.04 + provider Chef::Provider::Service::Systemd + end end action [ :enable, :start ] - only_if { - node['mongodb3']['mongod']['disable-transparent-hugepages'] - } + only_if { node['mongodb3']['mongod']['disable-transparent-hugepages'] } end # Create the mongod.service file case node['platform'] - when 'ubuntu' - template '/lib/systemd/system/mongod.service' do - source 'mongod.service.erb' - mode 0644 - only_if { node['platform_version'].to_f >= 15.04 } - end +when 'ubuntu' + template '/lib/systemd/system/mongod.service' do + source 'mongod.service.erb' + mode '0644' + only_if { node['platform_version'].to_f >= 15.04 } + end end # Start the mongod service service 'mongod' do case node['platform'] - when 'ubuntu' - if node['platform_version'].to_f >= 15.04 - provider Chef::Provider::Service::Systemd - elsif node['platform_version'].to_f >= 14.04 - provider Chef::Provider::Service::Upstart - end + when 'ubuntu' + if node['platform_version'].to_f >= 15.04 + provider Chef::Provider::Service::Systemd + elsif node['platform_version'].to_f >= 14.04 + provider Chef::Provider::Service::Upstart + end end supports :start => true, :stop => true, :restart => true, :status => true action :enable diff --git a/recipes/mms_automation_agent.rb b/recipes/mms_automation_agent.rb index 03ce479..d9f7649 100644 --- a/recipes/mms_automation_agent.rb +++ b/recipes/mms_automation_agent.rb @@ -24,17 +24,17 @@ # Set variables by platform case node['platform_family'] - when 'rhel', 'fedora' - mms_agent_source = 'https://cloud.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager-latest.x86_64.rpm' - mms_agent_file = '/root/mongodb-mms-automation-agent-manager-latest.x86_64.rpm' - when 'debian' - if node['platform'] == 'ubuntu' && node['platform_version'].to_f >= 15.04 - mms_agent_source = 'https://cloud.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager_latest_amd64.ubuntu1604.deb' - mms_agent_file = '/root/mongodb-mms-automation-agent-manager_latest_amd64.ubuntu1604.deb' - else - mms_agent_source = 'https://cloud.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager_latest_amd64.deb' - mms_agent_file = '/root/mongodb-mms-automation-agent-manager_latest_amd64.deb' - end +when 'rhel', 'fedora' + mms_agent_source = 'https://cloud.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager-latest.x86_64.rpm' + mms_agent_file = '/root/mongodb-mms-automation-agent-manager-latest.x86_64.rpm' +when 'debian' + if node['platform'] == 'ubuntu' && node['platform_version'].to_f >= 15.04 + mms_agent_source = 'https://cloud.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager_latest_amd64.ubuntu1604.deb' + mms_agent_file = '/root/mongodb-mms-automation-agent-manager_latest_amd64.ubuntu1604.deb' + else + mms_agent_source = 'https://cloud.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager_latest_amd64.deb' + mms_agent_file = '/root/mongodb-mms-automation-agent-manager_latest_amd64.deb' + end end # Download the mms automation agent manager latest @@ -48,26 +48,26 @@ # Install package case node['platform_family'] - when 'rhel', 'fedora' - rpm_package 'mongodb-mms-automation-agent-manager' do - source mms_agent_file - action :install - end - when 'debian' - dpkg_package 'mongodb-mms-automation-agent-manager' do - source mms_agent_file - action :install - end +when 'rhel', 'fedora' + rpm_package 'mongodb-mms-automation-agent-manager' do + source mms_agent_file + action :install + end +when 'debian' + dpkg_package 'mongodb-mms-automation-agent-manager' do + source mms_agent_file + action :install + end end # Create or modify the mms agent config file template '/etc/mongodb-mms/automation-agent.config' do source 'automation-agent.config.erb' - mode 0600 + mode '0600' owner node['mongodb3']['user'] group node['mongodb3']['group'] variables( - :config => node['mongodb3']['config']['mms'] + :config => node['mongodb3']['config']['mms'] ) end diff --git a/recipes/mms_monitoring_agent.rb b/recipes/mms_monitoring_agent.rb index 02f595b..0ee1a19 100644 --- a/recipes/mms_monitoring_agent.rb +++ b/recipes/mms_monitoring_agent.rb @@ -24,17 +24,17 @@ # Set variables by platform case node['platform_family'] - when 'rhel', 'fedora' - mms_agent_source = 'https://cloud.mongodb.com/download/agent/monitoring/mongodb-mms-monitoring-agent-latest.x86_64.rpm' - mms_agent_file = '/root/mongodb-mms-monitoring-agent-latest.x86_64.rpm' - when 'debian' - if node['platform'] == 'ubuntu' && node['platform_version'].to_f >= 15.04 - mms_agent_source = 'https://cloud.mongodb.com/download/agent/monitoring/mongodb-mms-monitoring-agent_latest_amd64.ubuntu1604.deb' - mms_agent_file = '/root/mongodb-mms-monitoring-agent_latest_amd64.ubuntu1604.deb' - else - mms_agent_source = 'https://cloud.mongodb.com/download/agent/monitoring/mongodb-mms-monitoring-agent_latest_amd64.deb' - mms_agent_file = '/root/mongodb-mms-monitoring-agent_latest_amd64.deb' - end +when 'rhel', 'fedora' + mms_agent_source = 'https://cloud.mongodb.com/download/agent/monitoring/mongodb-mms-monitoring-agent-latest.x86_64.rpm' + mms_agent_file = '/root/mongodb-mms-monitoring-agent-latest.x86_64.rpm' +when 'debian' + if node['platform'] == 'ubuntu' && node['platform_version'].to_f >= 15.04 + mms_agent_source = 'https://cloud.mongodb.com/download/agent/monitoring/mongodb-mms-monitoring-agent_latest_amd64.ubuntu1604.deb' + mms_agent_file = '/root/mongodb-mms-monitoring-agent_latest_amd64.ubuntu1604.deb' + else + mms_agent_source = 'https://cloud.mongodb.com/download/agent/monitoring/mongodb-mms-monitoring-agent_latest_amd64.deb' + mms_agent_file = '/root/mongodb-mms-monitoring-agent_latest_amd64.deb' + end end # Download the mms automation agent manager latest @@ -45,26 +45,26 @@ # Install package case node['platform_family'] - when 'rhel', 'fedora' - rpm_package 'mongodb-mms-monitoring-agent' do - source mms_agent_file - action :install - end - when 'debian' - dpkg_package 'mongodb-mms-monitoring-agent' do - source mms_agent_file - action :install - end +when 'rhel', 'fedora' + rpm_package 'mongodb-mms-monitoring-agent' do + source mms_agent_file + action :install + end +when 'debian' + dpkg_package 'mongodb-mms-monitoring-agent' do + source mms_agent_file + action :install + end end # Create or modify the mms agent config file template '/etc/mongodb-mms/monitoring-agent.config' do source 'monitoring-agent.config.erb' - mode 0600 + mode '0600' owner 'mongodb-mms-agent' group 'mongodb-mms-agent' variables( - :config => node['mongodb3']['config']['mms'] + :config => node['mongodb3']['config']['mms'] ) end diff --git a/recipes/mongos.rb b/recipes/mongos.rb index 175595e..fc110e1 100644 --- a/recipes/mongos.rb +++ b/recipes/mongos.rb @@ -39,9 +39,9 @@ template node['mongodb3']['mongos']['config_file'] do source 'mongodb.conf.erb' owner node['mongodb3']['user'] - mode 0644 + mode '0644' variables( - :config => node['mongodb3']['config']['mongos'] + :config => node['mongodb3']['config']['mongos'] ) helpers Mongodb3Helper notifies :restart, 'runit_service[mongos]' @@ -84,7 +84,7 @@ restart_on_update true cookbook node['mongodb3']['mongos']['runit_template_cookbook'] options ({ - :user => node['mongodb3']['user'], - :config_file => node['mongodb3']['mongos']['config_file'] - }) + :user => node['mongodb3']['user'], + :config_file => node['mongodb3']['mongos']['config_file'] + }) end diff --git a/recipes/package_repo.rb b/recipes/package_repo.rb index 6d774e0..b5145e2 100644 --- a/recipes/package_repo.rb +++ b/recipes/package_repo.rb @@ -22,33 +22,33 @@ # 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 +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' +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'] +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 @@ -85,28 +85,28 @@ # Add the MongoDB Package repository case node['platform_family'] - when 'rhel', 'fedora' - yum_repository "mongodb-org-#{pkg_major_version}" do - description 'MongoDB Repository' - baseurl node['mongodb3']['package']['repo']['url'] - action :create - gpgcheck false - enabled true - sslverify false - end - when 'debian' - apt_repository "mongodb-org-#{pkg_major_version}" do - uri node['mongodb3']['package']['repo']['url'] - if node['platform'] == 'ubuntu' and node['platform_version'].to_f == 15.04 - # seems that mongodb supports only LTS versions of Ubuntu - distribution "trusty/mongodb-org/#{node['mongodb3']['package']['repo']['apt']['name']}" - else - distribution "#{node['lsb']['codename']}/mongodb-org/#{node['mongodb3']['package']['repo']['apt']['name']}" - end - components node['mongodb3']['package']['repo']['apt']['components'] - keyserver node['mongodb3']['package']['repo']['apt']['keyserver'] - key node['mongodb3']['package']['repo']['apt']['key'] - action :add +when 'rhel', 'fedora' + yum_repository "mongodb-org-#{pkg_major_version}" do + description 'MongoDB Repository' + baseurl node['mongodb3']['package']['repo']['url'] + action :create + gpgcheck false + enabled true + sslverify false + end +when 'debian' + apt_repository "mongodb-org-#{pkg_major_version}" do + uri node['mongodb3']['package']['repo']['url'] + if node['platform'] == 'ubuntu' && node['platform_version'].to_f == 15.04 + # seems that mongodb supports only LTS versions of Ubuntu + distribution "trusty/mongodb-org/#{node['mongodb3']['package']['repo']['apt']['name']}" + else + distribution "#{node['lsb']['codename']}/mongodb-org/#{node['mongodb3']['package']['repo']['apt']['name']}" end - include_recipe 'apt' + components node['mongodb3']['package']['repo']['apt']['components'] + keyserver node['mongodb3']['package']['repo']['apt']['keyserver'] + key node['mongodb3']['package']['repo']['apt']['key'] + action :add + end + include_recipe 'apt' end diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb index 3e931cf..56dd70d 100644 --- a/test/integration/default/serverspec/default_spec.rb +++ b/test/integration/default/serverspec/default_spec.rb @@ -48,7 +48,7 @@ # Test disable-transparent-hugepages script is created describe file('/etc/init.d/disable-transparent-hugepages') do it { should be_file } - it { should be_mode 755} + it { should be_mode 755 } it { should be_owned_by 'root' } it { should be_grouped_into 'root' } end diff --git a/test/integration/helpers/serverspec/Gemfile b/test/integration/helpers/serverspec/Gemfile index 8c74ed4..8340188 100644 --- a/test/integration/helpers/serverspec/Gemfile +++ b/test/integration/helpers/serverspec/Gemfile @@ -1,2 +1,2 @@ source 'https://rubygems.org' -gem 'serverspec', '> 2.0' \ No newline at end of file +gem 'serverspec', '> 2.0'