Skip to content

Commit

Permalink
Make all cookbook tests pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
Udo Juettner committed Apr 4, 2014
1 parent 0b611a0 commit 1389372
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 74 deletions.
18 changes: 12 additions & 6 deletions deploy/specs/php-undeploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
include MiniTest::Chef::Assertions

it 'deletes the apache site-enabled link' do
if deploy[:application_type] = 'php'
file("#{node[:apache][:dir]}/sites-enabled/#{application}.conf").wont_exist
node[:deploy].each do |application, deploy|
if deploy[:application_type] == 'php'
file("#{node[:apache][:dir]}/sites-enabled/#{application}.conf").wont_exist
end
end
end

it 'deletes the apache site-available link' do
if deploy[:application_type] = 'php'
file("#{node[:apache][:dir]}/sites-available/#{application}.conf").wont_exist
node[:deploy].each do |application, deploy|
if deploy[:application_type] == 'php'
file("#{node[:apache][:dir]}/sites-available/#{application}.conf").wont_exist
end
end
end

it 'deletes the application directory' do
if deploy[:application_type] = 'php'
directory("#{deploy[:deploy_to]}").wont_exist
node[:deploy].each do |application, deploy|
if deploy[:application_type] == 'php'
directory("#{deploy[:deploy_to]}").wont_exist
end
end
end
end
51 changes: 32 additions & 19 deletions deploy/specs/php_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,44 @@
include MiniTest::Chef::Resources
include MiniTest::Chef::Assertions

it 'installs php apps' do
it 'creates a deployment directory' do
node[:deploy].each do |application, deploy|
if deploy[:application_type] = 'php'

it 'creates a deployment directory' do
directory(node[:deploy][application][:deploy_to]).must_exist(:mode, '0775').with(:owner, deploy[:user]).and(:group, deploy[:group])
end
if deploy[:application_type] == 'php'
directory(deploy[:deploy_to]).must_exist.with(:mode, '0775').and(:owner, deploy[:user]).and(:group, deploy[:group])
end
end
end

['log','config','system','pids','scripts','sockets'].each do |dir_name|
it "creates a directory #{dir_name} in the deployment directory" do
directory(node[:deploy][application][:deploy_to] + '/' + dir_name).must_exist(:mode, '0770').with(:owner, deploy[:user]).and(:group, deploy[:group])
end
['log','config','system','pids','scripts','sockets'].each do |dir_name|
it "creates a directory #{dir_name} in the deployment directory" do
node[:deploy].each do |application, deploy|
if deploy[:application_type] == 'php'
directory(::File.join(deploy[:deploy_to], 'shared', dir_name)).must_exist.with(:mode, '0770').and(:owner, deploy[:user]).and(:group, deploy[:group])
end
end
end
end

it 'creates the apache site-available link' do
file("#{node[:apache][:dir]}/sites-available/#{application}.conf").must_exist
end
it 'creates the apache site-available link' do
node[:deploy].each do |application, deploy|
if deploy[:application_type] == 'php'
file("#{node[:apache][:dir]}/sites-available/#{application}.conf").must_exist
end
end
end

it 'creates the apache site-enabled link' do
file("#{node[:apache][:dir]}/sites-enabled/#{application}.conf").must_exist
end
it 'creates the apache site-enabled link' do
node[:deploy].each do |application, deploy|
if deploy[:application_type] == 'php'
file("#{node[:apache][:dir]}/sites-enabled/#{application}.conf").must_exist
end
end
end

it 'creates a logrotate configuration' do
file("/etc/logrotate.d/opsworks_app_#{application}").must_exist(:mode, '0644').with(:owner, 'root').and(:group, 'root')
end
it 'creates a logrotate configuration' do
node[:deploy].each do |application, deploy|
if deploy[:application_type] == 'php'
file("/etc/logrotate.d/opsworks_app_#{application}").must_exist.with(:mode, '0644').and(:owner, 'root').and(:group, 'root')
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion deploy/specs/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

it 'should write a valid database configuration' do
node[:deploy].each do |app, deploy|
next if deploy[:application_type] == 'rails'
next unless deploy[:application_type] == 'rails'
skip unless deploy[:database][:host].present?
cfg = YAML.load_file("#{deploy[:deploy_to]}/shared/config/database.yml")
["development", "production", deploy[:rails_env]].uniq.each do |env|
cfg[env]['adapter'].must_equal deploy[:database][:adapter].to_s
Expand Down
8 changes: 0 additions & 8 deletions deploy/specs/web_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@
end
end
end

it 'should delete cached copy for static apps if toggled on' do
node[:deploy].each do |app, deploy|
if deploy[:delete_cached_copy] && deploy[:application_type].eql?('static')
directory("#{deploy[:deploy_to]}/shared/cached-copy").wont_exist
end
end
end
end

describe 'files' do
Expand Down
27 changes: 17 additions & 10 deletions mod_php5_apache2/specs/php_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,35 @@
include MiniTest::Chef::Resources
include MiniTest::Chef::Assertions

it "creates the application's cretificate" do
if deploy[:application_type] = 'php'
file("#{node[:apache][:dir]}/ssl/#{deploy[:domains].first}.crt").must_exist.with(:mode, '0600')
it "creates the application's certificate" do
node[:deploy].each do |application, deploy|
if deploy[:application_type] == 'php' && deploy[:ssl_support]
file("#{node[:apache][:dir]}/ssl/#{deploy[:domains].first}.crt").must_exist.with(:mode, '0600')
end
end
end

it "creates the application's certificate key" do
if deploy[:application_type] = 'php'
file("#{node[:apache][:dir]}/ssl/#{deploy[:domains].first}.key").must_exist.with(:mode, '0600')
node[:deploy].each do |application, deploy|
if deploy[:application_type] == 'php' && deploy[:ssl_support]
file("#{node[:apache][:dir]}/ssl/#{deploy[:domains].first}.key").must_exist.with(:mode, '0600')
end
end
end

it "creates the application's certificate chain file" do
if deploy[:application_type] = 'php'
file("#{node[:apache][:dir]}/ssl/#{deploy[:domains].first}.ca").must_exist.with(:mode, '0600')
node[:deploy].each do |application, deploy|
if deploy[:application_type] == 'php' && deploy[:ssl_support]
file("#{node[:apache][:dir]}/ssl/#{deploy[:domains].first}.ca").must_exist.with(:mode, '0600')
end
end
end

it "rename the systems default apache configuration if present" do
if deploy[:application_type] = 'php'
file("#{node[:apache][:dir]}/sites-enabled/000-default").must_not_exists
file("{node[:apache][:dir]}/sites-enabled/zzz-default").must_exist
node[:deploy].each do |application, deploy|
if deploy[:application_type] == 'php'
file("#{node[:apache][:dir]}/sites-enabled/000-default").wont_exist
end
end
end
end
2 changes: 1 addition & 1 deletion mysql/specs/client_install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
include MiniTest::Chef::Assertions

it 'installs packages for client' do
if node[:opsworks][:layers].has_key('db-master')
if node[:opsworks][:layers].has_key?('db-master')
case node[:platform]
when 'centos','redhat','fedora','amazon'
package('mysql-devel').must_be_installed
Expand Down
49 changes: 35 additions & 14 deletions opsworks_ganglia/specs/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,53 @@
include MiniTest::Chef::Resources
include MiniTest::Chef::Assertions

before :all do
@monitoring_master = node[:opsworks][:layers].has_key?('monitoring-master')
end

it 'installs ganglia monitor deamon' do
case node[:platform_family]
package_name = case node[:platform_family]
when 'debian'
package('ganglia-monitor').must_be_installed
'ganglia-monitor'
when "rhel"
package('ganglia-gmond').must_be_installed
'ganglia-gmond'
end

if @monitoring_master
package(package_name).must_be_installed
else
package(package_name).wont_be_installed
end
end

it 'creates /etc/ganglia/scripts directory' do
directory('/etc/ganglia/scripts').must_exist.with(:owner, 'root').and(:group, 'root').and(:mode, '755')
it 'creates /etc/ganglia/scripts directory' do
if @monitoring_master
directory('/etc/ganglia/scripts').must_exist.with(:owner, 'root').and(:group, 'root').and(:mode, '755')
else
directory('/etc/ganglia/scripts').wont_exist
end
end

it 'creates /etc/ganglia/conf.d' do
directory('/etc/ganglia/conf.d').must_exist.with(:owner, 'root').and(:group, 'root').and(:mode, '755')
if @monitoring_master
directory('/etc/ganglia/conf.d').must_exist.with(:owner, 'root').and(:group, 'root').and(:mode, '755')
else
directory('/etc/ganglia/conf.d').wont_exist
end
end

it 'creates /etc/ganglia/python_modules' do
link('/etc/ganglia/python_modules').must_exist.with(:link_type, :symbolic).and(
:to,
case node[:platform]
when 'debian','ubuntu'
"/usr/lib/ganglia/python_modules"
when 'centos','redhat','fedora','amazon'
"/usr/lib#{RUBY_PLATFORM[/64/]}/ganglia/python_modules"
end
if @monitoring_master
link('/etc/ganglia/python_modules').must_exist.with(:link_type, :symbolic).and(:to,
case node[:platform]
when 'debian','ubuntu'
"/usr/lib/ganglia/python_modules"
when 'centos','redhat','fedora','amazon'
"/usr/lib#{RUBY_PLATFORM[/64/]}/ganglia/python_modules"
end
)
else
link('/etc/ganglia/python_modules').wont_exist
end
end
end
18 changes: 12 additions & 6 deletions opsworks_ganglia/specs/configure-client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@
include MiniTest::Chef::Assertions

before :all do
@monitoring_master = node[:opsworks][:layers]['monitoring-master'][:instances].collect{|instance, names| names["private_ip"]}.first rescue nil
@monitoring_master = node[:opsworks][:layers].has_key?('monitoring-master')
@monitoring_master_ip = node[:opsworks][:layers]['monitoring-master'][:instances].collect{|instance, names| names["private_ip"]}.first rescue nil
end

it 'creates gmond.conf' do
file('/etc/ganglia/gmond.conf').must_exist
if @monitoring_master
file('/etc/ganglia/gmond.conf').must_exist
else
file('/etc/ganglia/gmond.conf').wont_exist
end
end

it 'makes sure monitoring master is defined in gmond.conf' do
skip unless @monitoring_master
file('/etc/ganglia/gmond.conf').must_include @monitoring_master
skip unless @monitoring_master_ip
file('/etc/ganglia/gmond.conf').must_include @monitoring_master_ip
end

it 'makes sure stack name is defined in gmond.conf' do
file('/etc/ganglia/gmond.conf').must_include node[:opsworks][:stack][:name]
skip unless @monitoring_master_ip
file('/etc/ganglia/gmond.conf').must_include node[:opsworks][:stack][:name].gsub(/\W/,'-')
end

it 'makes sure gmond is running if necessary' do
if @monitoring_master
if @monitoring_master_ip
service('gmond').must_be_running
else
service('gmond').wont_be_running
Expand Down
4 changes: 2 additions & 2 deletions opsworks_ganglia/specs/configure-server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
end

it 'makes sure stack name is set in gmetad.conf' do
file('/etc/ganglia/gmetad.conf').must_include node[:opsworks][:stack][:name]
file('/etc/ganglia/gmetad.conf').must_include node[:opsworks][:stack][:name].gsub(/\W/,'-')
end

it 'ensures gmetad is running' do
service('gmetad').must_be_running
end

it 'creates /etc/ganglia-webfrontend' do
file('/etc/ganglia-webfrontend').must_exist.with(:mode, '755')
directory('/etc/ganglia-webfrontend').must_exist.with(:mode, '755')
end

it 'updates htaccess' do
Expand Down
2 changes: 1 addition & 1 deletion opsworks_ganglia/specs/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end

it 'has stack name in gmetad.conf' do
file('/etc/ganglia/gmetad.conf').must_include node[:opsworks][:stack][:name]
file('/etc/ganglia/gmetad.conf').must_include node[:opsworks][:stack][:name].gsub(/\W/,'-')
end

it 'starts and enables gmetad' do
Expand Down
5 changes: 2 additions & 3 deletions opsworks_initial_setup/specs/bind_mounts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
include MiniTest::Chef::Assertions

it 'creates directories for bind mount' do
skip unless node[:platform] == 'amazon'
node[:opsworks_initial_setup][:bind_mounts][:mounts].each do |dir, source|
directory(dir).must_exist.with(:mode, '755')
directory(source).must_exist.with(:mode, '755')
directory(dir).must_exist
directory(source).must_exist
end
end

Expand Down
2 changes: 1 addition & 1 deletion opsworks_initial_setup/specs/tweak_chef_yum_dump_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

it 'sets lock timeout in Chef\'s yum-dump.py' do
skip unless node[:platform] == 'amazon' && node[:opsworks][:instance][:instance_type] == 't1.micro'
assert system("grep '^lock_timeout = #{node[:opsworks_initial_setup][:micro][:yum_dump_lock_timeout]}$' #{node[:opsworks_agent][:current_dir]}/vendor/bundle/ruby/1.8/gems/chef-0.9.15.5/lib/chef/provider/package/yum-dump.py")
assert system("grep -i '^lock_timeout = #{node[:opsworks_initial_setup][:yum_dump_lock_timeout]}$' #{node[:opsworks_initial_setup][:yum_dump_file]}")
end
end
6 changes: 4 additions & 2 deletions php/specs/configure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
include MiniTest::Chef::Assertions

it 'creates the php file for data exchange' do
if deploy[:application_type] = 'php'
file("#{deploy[:deploy_to]}/shared/config/opsworks.php").must_exist.with(:mode, '0660').and(:owner, deploy[:user]).and(:group, deploy[:group])
node[:deploy].each do |application, deploy|
if deploy[:application_type] == 'php'
file("#{deploy[:deploy_to]}/shared/config/opsworks.php").must_exist.with(:mode, '0660').and(:owner, deploy[:user]).and(:group, deploy[:group])
end
end
end
end

0 comments on commit 1389372

Please sign in to comment.