diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /buildscripts/package_test | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'buildscripts/package_test')
| -rw-r--r-- | buildscripts/package_test/files/sources.list.debian8 | 4 | ||||
| -rw-r--r-- | buildscripts/package_test/kitchen.legacy.yml | 122 | ||||
| -rw-r--r-- | buildscripts/package_test/kitchen.yml | 139 | ||||
| -rw-r--r-- | buildscripts/package_test/metadata.rb | 2 | ||||
| -rw-r--r-- | buildscripts/package_test/recipes/install_mongodb.rb | 146 | ||||
| -rw-r--r-- | buildscripts/package_test/test/recipes/service/install_mongodb_spec.rb | 219 |
6 files changed, 632 insertions, 0 deletions
diff --git a/buildscripts/package_test/files/sources.list.debian8 b/buildscripts/package_test/files/sources.list.debian8 new file mode 100644 index 00000000000..0ad1174270a --- /dev/null +++ b/buildscripts/package_test/files/sources.list.debian8 @@ -0,0 +1,4 @@ +deb http://archive.debian.org/debian jessie main +deb-src http://archive.debian.org/debian jessie main +deb http://security.debian.org/ jessie/updates main +deb-src http://security.debian.org/ jessie/updates main diff --git a/buildscripts/package_test/kitchen.legacy.yml b/buildscripts/package_test/kitchen.legacy.yml new file mode 100644 index 00000000000..c44c9a92d5e --- /dev/null +++ b/buildscripts/package_test/kitchen.legacy.yml @@ -0,0 +1,122 @@ +--- +driver: + name: ec2 + region: us-east-1 + vpc_mode: true + vpc_id: <%= ENV['KITCHEN_VPC'] %> + subnet_id: <%= ENV['KITCHEN_SUBNET'] %> + security_group_ids: + - <%= ENV['KITCHEN_SECURITY_GROUP'] %> + aws_ssh_key_id: <%= ENV['KITCHEN_SSH_KEY_ID'] %> + interface: private + associate_public_ip: true + tags: + name: "server package test" + owner: "build" + expire-on: "<%= ENV['KITCHEN_EXPIRE'] %>" + +verifier: + name: inspec + sudo: true + +provisioner: + name: chef_zero + log_level: info + require_chef_omnibus: 12 + +platforms: + - name: amazon-x86-64 + driver: + image_id: ami-0080e4c5bc078760e + transport: + username: ec2-user + - name: amazon2-x86-64 + driver: + image_id: ami-428aa838 + transport: + username: ec2-user + - name: amazon2-arm64 + driver: + image_id: ami-0c582118883b46f4f + instance_type: c6g.medium + transport: + username: ec2-user + - name: debian10-x86-64 + driver: + image_id: ami-0dedf6a6502877301 + transport: + username: admin + - name: rhel70-x86-64 + driver: + image_id: ami-2051294a + transport: + username: root + - name: rhel80-x86-64 + driver: + image_id: ami-0c322300a1dd5dc79 + transport: + username: ec2-user + - name: rhel82-arm64 + driver: + image_id: ami-029ba835ddd43c34f + instance_type: m6g.medium + transport: + username: ec2-user + - name: suse11-x86-64 + driver: + image_id: ami-7f2e6015 + transport: + username: ec2-user + - name: suse12-x86-64 + driver: + image_id: ami-043eebeabcc4e3d35 + transport: + username: ec2-user + - name: suse15-x86-64 + driver: + image_id: ami-06ea7729e394412c8 + transport: + username: ec2-user + - name: ubuntu1204-x86-64 + driver: + image_id: ami-3fec7956 + transport: + username: ubuntu + - name: ubuntu1404-x86-64 + driver: + image_id: ami-1d8c9574 + transport: + username: ubuntu + - name: ubuntu1604-x86-64 + driver: + image_id: ami-64140d0e + transport: + username: ubuntu + - name: ubuntu1804-x86-64 + driver: + image_id: ami-7ad76705 + transport: + username: ubuntu + - name: ubuntu1804-arm64 + driver: + image_id: ami-01ac7d9c1179d7b74 + instance_type: m6g.medium + - name: ubuntu2004-x86-64 + driver: + image_id: ami-068663a3c619dd892 + transport: + username: ubuntu + - name: ubuntu2004-arm64 + driver: + image_id: ami-00579fbb15b954340 + instance_type: m6g.medium + +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/kitchen.yml b/buildscripts/package_test/kitchen.yml new file mode 100644 index 00000000000..f27ab0bfd26 --- /dev/null +++ b/buildscripts/package_test/kitchen.yml @@ -0,0 +1,139 @@ +--- +driver: + name: ec2 + region: us-east-1 + vpc_mode: true + vpc_id: <%= ENV['KITCHEN_VPC'] %> + subnet_id: <%= ENV['KITCHEN_SUBNET'] %> + security_group_ids: + - <%= ENV['KITCHEN_SECURITY_GROUP'] %> + aws_ssh_key_id: <%= ENV['KITCHEN_SSH_KEY_ID'] %> + interface: private + associate_public_ip: true + tags: + name: "server package test" + owner: "build" + expire-on: "<%= ENV['KITCHEN_EXPIRE'] %>" + +verifier: + name: inspec + sudo: true + +provisioner: + name: chef_zero + log_level: info + product_name: cinc + product_version: 17.9.52 + download_url: https://omnitruck.cinc.sh/install.sh + +platforms: + - name: amazon-x86-64 + driver: + image_id: ami-0080e4c5bc078760e + transport: + username: ec2-user + - name: amazon2-x86-64 + driver: + image_id: ami-02013ed1a71752ea7 + transport: + username: ec2-user + - name: amazon2-arm64 + driver: + image_id: ami-0c582118883b46f4f + instance_type: c6g.medium + transport: + username: ec2-user + - name: debian71-x86-64 + driver: + image_id: ami-4b124a22 + transport: + username: admin + - name: debian81-x86-64 + driver: + image_id: ami-896d85e2 + transport: + username: admin + - name: debian10-x86-64 + driver: + image_id: ami-0dedf6a6502877301 + transport: + username: admin + - name: debian11-x86-64 + driver: + image_id: ami-06a80441f25333895 + transport: + username: admin + - name: rhel70-x86-64 + driver: + image_id: ami-0051b1b2c5a166c8c + transport: + username: root + - name: rhel80-x86-64 + driver: + image_id: ami-0c322300a1dd5dc79 + transport: + username: ec2-user + - name: rhel82-arm64 + driver: + image_id: ami-029ba835ddd43c34f + instance_type: m6g.medium + transport: + username: ec2-user + - name: suse11-x86-64 + driver: + image_id: ami-7f2e6015 + transport: + username: ec2-user + - name: suse12-x86-64 + driver: + image_id: ami-043eebeabcc4e3d35 + transport: + username: ec2-user + - name: suse15-x86-64 + driver: + image_id: ami-06ea7729e394412c8 + transport: + username: ec2-user + - name: ubuntu1204-x86-64 + driver: + image_id: ami-3fec7956 + transport: + username: ubuntu + - name: ubuntu1404-x86-64 + driver: + image_id: ami-1d8c9574 + transport: + username: ubuntu + - name: ubuntu1604-x86-64 + driver: + image_id: ami-64140d0e + transport: + username: ubuntu + - name: ubuntu1804-x86-64 + driver: + image_id: ami-7ad76705 + transport: + username: ubuntu + - name: ubuntu1804-arm64 + driver: + image_id: ami-01ac7d9c1179d7b74 + instance_type: m6g.medium + - name: ubuntu2004-x86-64 + driver: + image_id: ami-068663a3c619dd892 + transport: + username: ubuntu + - name: ubuntu2004-arm64 + driver: + image_id: ami-00579fbb15b954340 + instance_type: m6g.medium + +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..d57546ce6b9 --- /dev/null +++ b/buildscripts/package_test/recipes/install_mongodb.rb @@ -0,0 +1,146 @@ +# This Chef task installs MongoDB in a new EC2 instance spun up by Kitchen in +# preparation for running some basic server functionality tests. + +artifacts_tarball = 'artifacts.tgz' +homedir = "/tmp" + +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' or platform_family? 'amazon' + 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}" + live_stream true + cwd homedir +end + +if platform_family? 'debian' + + # SERVER-40491 Debian 8 sources.list need to point to archive url + if node['platform'] == 'debian' and node['platform_version'] == '8.1' + cookbook_file '/etc/apt/sources.list' do + source 'sources.list.debian8' + owner 'root' + group 'root' + mode '0644' + action :create + end + end + + execute 'apt update' do + command 'apt update' + live_stream true + end + + ENV['DEBIAN_FRONTEND'] = 'noninteractive' + package 'openssl' + + # the ubuntu image does not have some dependencies installed by default + # and it is required for the install_compass script + if node['platform'] == 'ubuntu' and node['platform_version'] == '20.04' + execute 'install dependencies ubuntu 20.04' do + command 'apt-get install -y python3 libsasl2-modules-gssapi-mit' + live_stream true + end + link '/usr/bin/python' do + to '/usr/bin/python3' + end + else + execute 'install dependencies' do + command 'apt-get install -y python libsasl2-modules-gssapi-mit' + live_stream true + end + end + + # 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"`' + live_stream true + cwd homedir + returns [0, 1] + end + + # install the tools so we can test install_compass + execute 'install mongo tools' do + command 'dpkg -i `find . -name "*tools-extra*.deb"`' + live_stream true + 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 'update and fix broken dependencies' do + command 'apt update && apt -y -f install' + live_stream true + end +end + +if platform_family? 'rhel' or platform_family? 'amazon' + bash 'wait for yum updates if they are running' do + code <<-EOH + sleep 120 + EOH + end + execute 'install mongod' do + command 'yum install -y `find . -name "*server*.rpm"`' + live_stream true + cwd homedir + end + + # install the tools so we can test install_compass + execute 'install mongo tools' do + command 'yum install -y `find . -name "*tools-extra*.rpm"`' + live_stream true + 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 + flags "-x" + end + + execute 'install mongod' do + command 'zypper --no-gpg-checks -n install `find . -name "*server*.rpm"`' + live_stream true + cwd homedir + end + + execute 'install mongo tools' do + command 'zypper --no-gpg-checks -n install `find . -name "*tools-extra*.rpm"`' + live_stream true + 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..821f55f1a57 --- /dev/null +++ b/buildscripts/package_test/test/recipes/service/install_mongodb_spec.rb @@ -0,0 +1,219 @@ +############################################################ +# This section verifies start, stop, and restart after +# installation within a new EC2 instance spun up by Kitchen. +# +# - 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 + +# Inspec treats all amazon linux as upstart, we explicitly make it use +# systemd_service https://github.com/chef/inspec/issues/2639 +if (os[:name] == 'amazon' and os[:release] == '2.0') + describe systemd_service('mongod') do + it { should be_running } + end +else + describe service('mongod') do + it { should be_running } + end +end + +describe command("#{service} mongod stop") do + its('exit_status') { should eq 0 } +end + +describe command("#{service} mongod restart") do + its('exit_status') { should eq 0 } +end + +if (os[:name] == 'amazon' and os[:release] == '2.0') + describe systemd_service('mongod') do + it { should be_running } + end +else + describe service('mongod') do + it { should be_running } + end +end + +if os[:arch] == 'x86_64' + # install_compass does not run Amazon Linux but *does* run on Amazon Linux 2, + # but the 'redhat' family includes both, apparently. We need to specifically + # exclude Amazon Linux from the set of allowed distributions here because the + # version strings would otherwise pass it. + if ((os[:family] == 'redhat' and os[:name] != "amazon" and os[:release].split('.')[0].to_i >= 7) or + (os[:name] == 'ubuntu' and os[:release].split('.')[0].to_i >= 16) or + (os[:name] == 'debian' and os[:release].split('.')[0].to_i >= 9) or + (os[:name] == 'amazon' and os[:release].split('.')[0].to_i == 2)) + describe command("install_compass") do + its('exit_status') { should eq 0 } + its('stderr') { should eq '' } + end + elsif os[:name] == 'suse' + describe command("install_compass") do + its('exit_status') { should eq 1 } + its('stderr') { should match /You are using an unsupported platform/ } + end + else + describe command("install_compass") do + its('exit_status') { should eq 1 } + its('stderr') { should match /You are using an unsupported Linux distribution/ } + end + end +else + describe command("install_compass") do + its('exit_status') { should eq 1 } + its('stderr') { should match /Sorry, MongoDB Compass is only supported on 64-bit Intel platforms/ } + end +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 + unit_file_prefix = '' + if os[:name] == 'suse' + # Putting systemd unit files in /usr, which may be a separate partition + # and therefore not available during isolated startups, is bad practice. + # But it's what SUSE has chosen to do, so we have to deal with it. + unit_file_prefix = '/usr' + end + describe file("#{unit_file_prefix}/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' } + # All versions of Debian 10 will use /usr/sbin/nologin for service + # account shells + its('shell') { + if ((os[:name] == 'debian' and os[:release].split('.')[0] >= '10') or + (os[:name] == 'ubuntu' and os[:release] == '18.04') or + (os[:name] == 'ubuntu' and os[:release] == '20.04')) + should eq '/usr/sbin/nologin' + else + should eq '/bin/false' + end + } + 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 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 |
