Last active
October 2, 2017 00:55
-
-
Save haani-niyaz/3c746cc7694d79a5e417bb740419544c to your computer and use it in GitHub Desktop.
Sample serverspec tests for Atlassian Bamboo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
# Read configuration from puppet control repo hieradata file | |
# 'PRODUCT' is the name of the platform | |
hieradata_file_path = "../product-puppet-control-repo/hieradata/environments/PRODUCT_#{ENV['env']}.yaml" | |
begin | |
site_data = YAML.load(File.read(hieradata_file_path)) | |
rescue Errno::ENOENT | |
puts "Ensure #{hieradata_file_path} exists" | |
exit | |
end | |
want_deployment_or_rollback = ENV['dr'] | |
version = site_data['proteus_bamboo::package_version'][/\d+.\d+.\d+/] | |
bamboo_install_dir = "/opt/atlassian-bamboo-#{version}" | |
java_split_package_string = site_data['proteus_bamboo::java_package_install_name'].split('-') | |
jdk_install_dir = java_split_package_string[0] | |
# Tests | |
context "when the user is created" do | |
describe group('proteus') do | |
it { should have_gid 600 } | |
end | |
describe user('proteus') do | |
it { should exist } | |
it { should have_home_directory '/home/proteus' } | |
it { should belong_to_group 'proteus' } | |
it { should belong_to_group 'rbenv' } | |
it { should have_uid 600 } | |
end | |
end | |
context "when atlassian-bamboo package is installed" do | |
describe package("atlassian-bamboo-#{site_data['proteus_bamboo::package_version']}") do | |
it { should be_installed } | |
end | |
end | |
context 'when java package is installed' do | |
describe package("#{site_data['proteus_bamboo::java_package_install_name']}") do | |
it { should be_installed } | |
end | |
describe file('/usr/java/latest') do | |
it { should be_linked_to "/usr/java/#{jdk_install_dir}" } | |
end | |
end | |
context 'when bamboo installation directory is created' do | |
describe file(bamboo_install_dir) do | |
it { should be_directory} | |
it { should be_owned_by 'proteus' } | |
it { should be_grouped_into 'proteus' } | |
it { should be_mode 750 } | |
end | |
describe file('/opt/bamboo') do | |
it { should be_linked_to "#{bamboo_install_dir}/" } | |
end | |
end | |
context 'when setenv.sh file is deployed' do | |
describe file("#{bamboo_install_dir}/bin/setenv.sh") do | |
it { should be_file } | |
it { should be_owned_by 'proteus' } | |
it { should be_grouped_into 'proteus' } | |
it { should be_mode 755 } | |
it { should contain 'CATALINA_OUT="/var/log/bamboo/catalina.out"' } | |
it { should contain 'JVM_MINIMUM_MEMORY="512m"' } | |
it { should contain 'JVM_MAXIMUM_MEMORY="2048m"' } | |
end | |
end | |
context 'when catalina.sh file is deployed' do | |
describe file("#{bamboo_install_dir}/bin/catalina.sh") do | |
it { should be_file } | |
it { should be_owned_by 'proteus' } | |
it { should be_grouped_into 'proteus' } | |
it { should be_mode 755 } | |
it { should contain 'CATALINA_TMPDIR="$CATALINA_BASE"/temp' } | |
end | |
end | |
context 'when logging.properties file is deployed' do | |
describe file("#{bamboo_install_dir}/conf/logging.properties") do | |
it { should be_file } | |
it { should be_owned_by 'proteus' } | |
it { should be_grouped_into 'proteus' } | |
it { should be_mode 644 } | |
end | |
end | |
context 'when bamboo-init.properties file is deployed' do | |
describe file("#{bamboo_install_dir}/atlassian-bamboo/WEB-INF/classes/bamboo-init.properties") do | |
it { should be_file } | |
it { should be_owned_by 'proteus' } | |
it { should be_grouped_into 'proteus' } | |
it { should contain 'bamboo.home=/var/bamboo/bamboo-home' } | |
it { should be_mode 644 } | |
end | |
end | |
context 'when seraph-config.xml file is deployed' do | |
describe file("#{bamboo_install_dir}/atlassian-bamboo/WEB-INF/classes/seraph-config.xml") do | |
it { should be_file } | |
it { should be_owned_by 'proteus' } | |
it { should be_grouped_into 'proteus' } | |
it { should contain ' <authenticator class="com.atlassian.crowd.integration.seraph.v25.BambooAuthenticator"/>' } | |
it { should be_mode 644 } | |
end | |
end | |
context 'when context.xml file is deployed' do | |
describe file("#{bamboo_install_dir}/conf/context.xml") do | |
it { should be_file } | |
it { should be_owned_by 'proteus' } | |
it { should be_grouped_into 'proteus' } | |
it { should be_mode 640 } | |
end | |
end | |
context 'when server.xml file is deployed' do | |
describe file("#{bamboo_install_dir}/conf/server.xml") do | |
it { should be_file } | |
it { should be_owned_by 'proteus' } | |
it { should be_grouped_into 'proteus' } | |
it { should contain "#{site_data['proteus_bamboo::proxy_name']}" } | |
it { should be_mode 644 } | |
end | |
end | |
context 'when bamboo-home directory is managed' do | |
describe file('/var/bamboo/bamboo-home') do | |
it { should be_directory } | |
it { should be_owned_by 'proteus' } | |
it { should be_grouped_into 'proteus' } | |
end | |
end | |
context 'when service is checked' do | |
describe file('/etc/init.d/bamboo') do | |
it { should exist } | |
it { should be_mode 755 } | |
end | |
if want_deployment_or_rollback | |
describe service('bamboo') do | |
it { should_not be_running} | |
end | |
else | |
describe service('bamboo') do | |
it { should be_running} | |
end | |
end | |
end | |
context 'when the service is running' do | |
if site_data['env_type'] == 'model' | |
base_url = 'http://rlcol1autbldv01.mshm.bigpond.com' | |
elsif site_data['env_type'] == 'production' | |
base_url = 'http://rlhay9autbldv01.msh.bigpond.com' | |
end | |
if !want_deployment_or_rollback | |
describe command("curl -L #{base_url}:5020") do | |
its(:stdout) { should contain "#{version}" } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment