diff options
author | Brian Samek <brian.samek@mongodb.com> | 2016-11-03 14:51:00 -0400 |
---|---|---|
committer | Brian Samek <brian.samek@mongodb.com> | 2016-11-21 10:56:44 -0500 |
commit | 337df9553665d0a4a87ac66f6bd53159b87f67c0 (patch) | |
tree | b9f10009dd73f4458fce321e5a32cc2f88faeda6 /buildscripts/package_test | |
parent | 8edf38be766da31a778b3a8c24d90d45433957e4 (diff) | |
download | mongo-337df9553665d0a4a87ac66f6bd53159b87f67c0.tar.gz |
SERVER-27140 Linux package smoke testing
Diffstat (limited to 'buildscripts/package_test')
-rw-r--r-- | buildscripts/package_test/.kitchen.yml | 81 | ||||
-rw-r--r-- | buildscripts/package_test/metadata.rb | 2 | ||||
-rw-r--r-- | buildscripts/package_test/recipes/install_mongodb.rb | 96 | ||||
-rw-r--r-- | buildscripts/package_test/test/recipes/service/install_mongodb_spec.rb | 182 |
4 files changed, 361 insertions, 0 deletions
diff --git a/buildscripts/package_test/.kitchen.yml b/buildscripts/package_test/.kitchen.yml new file mode 100644 index 00000000000..e9b6989d221 --- /dev/null +++ b/buildscripts/package_test/.kitchen.yml @@ -0,0 +1,81 @@ +--- +driver: + name: ec2 + region: us-east-1 + subnet_id: <%= ENV['KITCHEN_SUBNET'] %> + security_group_ids: + - <%= ENV['KITCHEN_SECURITY_GROUP'] %> + aws_ssh_key_id: <%= ENV['KITCHEN_SSH_KEY_ID'] %> + interface: dns + associate_public_ip: true + +verifier: + name: inspec + sudo: true + +provisioner: + name: chef_solo + require_chef_omnibus: 12.6.0 + +platforms: + - name: amazon + driver: + image_id: ami-c481fad3 + transport: + username: ec2-user + - name: debian71 + driver: + image_id: ami-4b124a22 + transport: + username: admin + - name: debian81 + driver: + image_id: ami-896d85e2 + transport: + username: admin + - name: rhel62 + driver: + # Use rhel 6.3 because chef-solo fails on rhel 6.2 + image_id: ami-a35a33ca + transport: + username: root + - name: rhel70 + driver: + image_id: ami-60a1e808 + transport: + username: root + - name: suse11 + driver: + image_id: ami-7f2e6015 + transport: + username: ec2-user + - name: suse12 + driver: + image_id: ami-aeb532c6 + transport: + username: ec2-user + - name: ubuntu1204 + driver: + image_id: ami-3fec7956 + transport: + username: ubuntu + - name: ubuntu1404 + driver: + image_id: ami-1d8c9574 + transport: + username: ubuntu + - name: ubuntu1604 + driver: + image_id: ami-64140d0e + transport: + username: ubuntu + +transport: + ssh_key: ~/.ssh/kitchen.pem + +suites: + - name: service + run_list: + - recipe[package_test::install_mongodb] + attributes: + artifacts_url: <%= ENV['KITCHEN_ARTIFACTS_URL'] %> diff --git a/buildscripts/package_test/metadata.rb b/buildscripts/package_test/metadata.rb new file mode 100644 index 00000000000..3bbfb147acc --- /dev/null +++ b/buildscripts/package_test/metadata.rb @@ -0,0 +1,2 @@ +name 'package_test' +version '0.1.0' diff --git a/buildscripts/package_test/recipes/install_mongodb.rb b/buildscripts/package_test/recipes/install_mongodb.rb new file mode 100644 index 00000000000..28a2462afc7 --- /dev/null +++ b/buildscripts/package_test/recipes/install_mongodb.rb @@ -0,0 +1,96 @@ +artifacts_tarball = 'artifacts.tgz' +user = node['current_user'] +homedir = node['etc']['passwd'][user]['dir'] + +ruby_block 'allow sudo over tty' do + block do + file = Chef::Util::FileEdit.new('/etc/sudoers') + file.search_file_replace_line(/Defaults\s+requiretty/, '#Defaults requiretty') + file.search_file_replace_line(/Defaults\s+requiretty/, '#Defaults !visiblepw') + file.write_file + end +end + +# This file limits processes to 1024. It therefore interfereres with `ulimit -u` when present. +if platform_family? 'rhel' + file '/etc/security/limits.d/90-nproc.conf' do + action :delete + end +end + +remote_file "#{homedir}/#{artifacts_tarball}" do + source node['artifacts_url'] +end + +execute 'extract artifacts' do + command "tar xzvf #{artifacts_tarball}" + cwd homedir +end + +if platform_family? 'debian' + execute 'apt-get update' do + command 'apt-get update' + end + + package 'openssl' + + # dpkg returns 1 if dependencies are not satisfied, which they will not be + # for enterprise builds. We install dependencies in the next block. + execute 'install mongod' do + command 'dpkg -i `find . -name "*server*.deb"`' + cwd homedir + returns [0, 1] + end + + # yum and zypper fetch dependencies automatically, but dpkg does not. + # Installing the dependencies explicitly is fragile, so we reply on apt-get + # to install dependencies after the fact. + execute 'install dependencies' do + command 'apt-get update && apt-get -y -f install' + end + + execute 'install mongo shell' do + command 'dpkg -i `find . -name "*shell*.deb"`' + cwd homedir + end +end + +if platform_family? 'rhel' + execute 'install mongod' do + command 'yum install -y `find . -name "*server*.rpm"`' + cwd homedir + end + + execute 'install mongo shell' do + command 'yum install -y `find . -name "*shell*.rpm"`' + cwd homedir + end +end + +if platform_family? 'suse' + bash 'wait for zypper lock to be released' do + code <<-EOD + retry_counter=0 + # We also need to make sure another instance of zypper isn't running while + # we do our install, so just run zypper refresh until it doesn't fail. + # Waiting for 2 minutes is copied from an internal project where we do this. + until [ "$retry_counter" -ge "12" ]; do + zypper refresh && exit 0 + retry_counter=$(($retry_counter + 1)) + [ "$retry_counter" = "12" ] && break + sleep 10 + done + exit 1 + EOD + end + + execute 'install mongod' do + command 'zypper -n install `find . -name "*server*.rpm"`' + cwd homedir + end + + execute 'install mongo' do + command 'zypper -n install `find . -name "*shell*.rpm"`' + cwd homedir + end +end diff --git a/buildscripts/package_test/test/recipes/service/install_mongodb_spec.rb b/buildscripts/package_test/test/recipes/service/install_mongodb_spec.rb new file mode 100644 index 00000000000..bb5cd0d7585 --- /dev/null +++ b/buildscripts/package_test/test/recipes/service/install_mongodb_spec.rb @@ -0,0 +1,182 @@ +############################################################ +# This section verifies start, stop, and restart. +# - stop mongod so that we begin testing from a stopped state +# - verify start, stop, and restart +############################################################ + +# service is not in path for commands with sudo on suse +service = os[:name] == 'suse' ? '/sbin/service' : 'service' + +describe command("#{service} mongod stop") do + its('exit_status') { should eq 0 } +end + +describe command("#{service} mongod start") do + its('exit_status') { should eq 0 } +end + +describe service('mongod') do + it { should be_running } +end + +describe command("#{service} mongod stop") do + its('exit_status') { should eq 0 } +end + +describe service('mongod') do + it { should_not be_running } +end + +describe command("#{service} mongod restart") do + its('exit_status') { should eq 0 } +end + +describe service('mongod') do + it { should be_running } +end + +# wait for a few seconds so that we are sure mongod has +# written to its log and is ready to accept writes and reads +describe command("sleep 5") do + its('exit_status') { should eq 0 } +end + +############################################################ +# This section verifies files, directories, and users +# - files and directories exist and have correct attributes +# - mongod user exists and has correct attributes +############################################################ + +# convenience variables for init system and package type +upstart = (os[:name] == 'ubuntu' && os[:release][0..1] == '14') || + (os[:name] == 'amazon') +sysvinit = if (os[:name] == 'debian' && os[:release][0] == '7') || + (os[:name] == 'redhat' && os[:release][0] == '6') || + (os[:name] == 'suse' && os[:release][0..1] == '11') || + (os[:name] == 'ubuntu' && os[:release][0..1] == '12') + true + else + false + end +systemd = !(upstart || sysvinit) +rpm = if os[:name] == 'amazon' || os[:name] == 'redhat' || os[:name] == 'suse' + true + else + false + end +deb = !rpm + +# these files should exist on all systems +%w( + /etc/mongod.conf + /usr/bin/mongod + /var/log/mongodb/mongod.log +).each do |filename| + describe file(filename) do + it { should be_file } + end +end + +if sysvinit + describe file('/etc/init.d/mongod') do + it { should be_file } + it { should be_executable } + end +end + +if systemd + describe file('/lib/systemd/system/mongod.service') do + it { should be_file } + end +end + +if rpm + %w( + /var/lib/mongo + /var/run/mongodb + ).each do |filename| + describe file(filename) do + it { should be_directory } + end + end + + describe user('mongod') do + it { should exist } + its('groups') { should include 'mongod' } + its('home') { should eq '/var/lib/mongo' } + its('shell') { should eq '/bin/false' } + end +end + +if deb + describe file('/var/lib/mongodb') do + it { should be_directory } + end + + describe user('mongodb') do + it { should exist } + its('groups') { should include 'mongodb' } + its('shell') { should eq '/bin/false' } + end +end + +############################################################ +# This section verifies ulimits. +############################################################ + +ulimits = { + 'Max file size' => 'unlimited', + 'Max cpu time' => 'unlimited', + 'Max address space' => 'unlimited', + 'Max open files' => '64000', + 'Max resident set' => 'unlimited', + 'Max processes' => '64000' +} +ulimits_cmd = 'cat /proc/$(pgrep mongod)/limits' + +ulimits.each do |limit, value| + describe command("#{ulimits_cmd} | grep \"#{limit}\"") do + its('stdout') { should match(/#{limit}\s+#{value}/) } + end +end + +############################################################ +# This section verifies reads and writes. +# - insert a document into the database +# - verify that findOne() returns a matching document +############################################################ + +describe command('mongo --eval "db.smoke.insert({answer: 42})"') do + its('exit_status') { should eq 0 } + its('stdout') { should match(/.+WriteResult\({ "nInserted" : 1 }\).+/m) } +end + +# read a document from the db +describe command('mongo --eval "db.smoke.findOne()"') do + its('exit_status') { should eq 0 } + its('stdout') { should match(/.+"answer" : 42.+/m) } +end + +############################################################ +# This section verifies uninstall. +############################################################ + +if rpm + describe command('rpm -e $(rpm -qa | grep "mongodb.*server" | awk \'{print $1}\')') do + its('exit_status') { should eq 0 } + end +elsif deb + describe command('dpkg -r $(dpkg -l | grep "mongodb.*server" | awk \'{print $2}\')') do + its('exit_status') { should eq 0 } + end +end + +# make sure we cleaned up +%w( + /lib/systemd/system/mongod.service + /usr/bin/mongod +).each do |filename| + describe file(filename) do + it { should_not exist } + end +end |