ruby Atlassian Bamboo的示例serverspec测试
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Atlassian Bamboo的示例serverspec测试相关的知识,希望对你有一定的参考价值。
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
以上是关于ruby Atlassian Bamboo的示例serverspec测试的主要内容,如果未能解决你的问题,请参考以下文章
RoboCopy + Atlassian Bamboo 持续集成
Jenkins 和 Atlassian Bamboo 的集成
使用 Atlassian Bamboo 的 Android CI