[COOK-1792] - add minitest-chef tests

* Create minitest-chef tests
* Also use better style (don't specify action if its the default, use
  5 digit modes, update notification syntax)
This commit is contained in:
jtimberman 2012-10-20 20:41:00 -06:00
parent 99a240edf2
commit d2f29085a3
13 changed files with 342 additions and 27 deletions

115
Gemfile.lock Normal file
View File

@ -0,0 +1,115 @@
GEM
remote: http://rubygems.org/
specs:
archive-tar-minitar (0.5.2)
bunny (0.7.9)
chef (10.14.4)
bunny (>= 0.6.0, < 0.8.0)
erubis
highline (>= 1.6.9)
json (>= 1.4.4, <= 1.6.1)
mixlib-authentication (>= 1.3.0)
mixlib-cli (>= 1.1.0)
mixlib-config (>= 1.1.2)
mixlib-log (>= 1.3.0)
mixlib-shellout
moneta
net-ssh (~> 2.2.2)
net-ssh-multi (~> 1.1.0)
ohai (>= 0.6.0)
rest-client (>= 1.0.4, < 1.7.0)
treetop (~> 1.4.9)
uuidtools
yajl-ruby (~> 1.1)
childprocess (0.3.6)
ffi (~> 1.0, >= 1.0.6)
coderay (1.0.8)
erubis (2.7.0)
ffi (1.1.5)
foodcritic (1.6.1)
erubis
gherkin (~> 2.11.1)
gist (~> 3.1.0)
nokogiri (= 1.5.0)
pry (~> 0.9.8.4)
rak (~> 1.4)
treetop (~> 1.4.10)
yajl-ruby (~> 1.1.0)
gherkin (2.11.5)
json (>= 1.4.6)
gist (3.1.0)
hashr (0.0.22)
highline (1.6.15)
i18n (0.6.1)
ipaddress (0.8.0)
json (1.5.4)
librarian (0.0.25)
archive-tar-minitar (>= 0.5.2)
chef (>= 0.10)
highline
thor (~> 0.15)
log4r (1.1.10)
method_source (0.7.1)
mime-types (1.19)
mixlib-authentication (1.3.0)
mixlib-log
mixlib-cli (1.2.2)
mixlib-config (1.1.2)
mixlib-log (1.4.1)
mixlib-shellout (1.1.0)
moneta (0.6.0)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-ssh (2.2.2)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
net-ssh-multi (1.1)
net-ssh (>= 2.1.4)
net-ssh-gateway (>= 0.99.0)
nokogiri (1.5.0)
ohai (6.14.1)
ipaddress
mixlib-cli
mixlib-config
mixlib-log
systemu
yajl-ruby
polyglot (0.3.3)
pry (0.9.8.4)
coderay (~> 1.0.5)
method_source (~> 0.7.1)
slop (>= 2.4.4, < 3)
rak (1.4)
rest-client (1.6.7)
mime-types (>= 1.16)
slop (2.4.4)
systemu (2.5.2)
test-kitchen (0.6.0)
foodcritic (~> 1.4)
hashr (~> 0.0.20)
highline (>= 1.6.9)
librarian (~> 0.0.20)
mixlib-cli (~> 1.2.2)
vagrant (~> 1.0.2)
yajl-ruby (~> 1.1.0)
thor (0.16.0)
treetop (1.4.11)
polyglot
polyglot (>= 0.3.1)
uuidtools (2.1.3)
vagrant (1.0.5)
archive-tar-minitar (= 0.5.2)
childprocess (~> 0.3.1)
erubis (~> 2.7.0)
i18n (~> 0.6.0)
json (~> 1.5.1)
log4r (~> 1.1.9)
net-scp (~> 1.0.4)
net-ssh (~> 2.2.2)
yajl-ruby (1.1.0)
PLATFORMS
ruby
DEPENDENCIES
test-kitchen

View File

@ -0,0 +1,26 @@
#
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require File.expand_path('../support/helpers', __FILE__)
describe "postfix::aliases" do
include Helpers::Postfix
it 'manages /etc/aliases' do
file("/etc/aliases").must_match(/^# This file is generated by Chef for/)
end
end

View File

@ -0,0 +1,24 @@
#
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require File.expand_path('../support/helpers', __FILE__)
describe "postfix::client" do
include Helpers::Postfix
it 'doesnt configure postfix because solo is unsupported' do
skip "Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo"
end
end

View File

@ -0,0 +1,38 @@
#
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require File.expand_path('../support/helpers', __FILE__)
describe "postfix::default" do
include Helpers::Postfix
it 'installs the postfix package' do
package("postfix").must_be_installed
end
it 'enables the postfix service' do
service("postfix").must_be_enabled
end
it 'starts the postfix service' do
service("postfix").must_be_running
end
it 'configures postfix main.cf' do
file("/etc/postfix/main.cf").must_match(/^# Generated by Chef for /)
end
end

View File

@ -0,0 +1,25 @@
#
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require File.expand_path('../support/helpers', __FILE__)
describe "postfix::sasl_auth" do
include Helpers::Postfix
it 'manages /etc/postfix/sasl_passwd' do
file("/etc/postfix/sasl_passwd").must_match(/^# This file is generated by Chef for/)
end
end

View File

@ -0,0 +1,23 @@
#
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require File.expand_path('../support/helpers', __FILE__)
describe "postfix::server" do
include Helpers::Postfix
it 'doesnt configure postfix because solo is unsupported' do
skip "Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo"
end
end

View File

@ -0,0 +1,24 @@
#
# Copyright 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module Helpers
module Postfix
include MiniTest::Chef::Assertions
include MiniTest::Chef::Context
include MiniTest::Chef::Resources
end
end

View File

@ -1,3 +1,19 @@
#
# Copyright:: Copyright (c) 2012, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require_recipe "postfix" require_recipe "postfix"
execute "update-postfix-aliases" do execute "update-postfix-aliases" do
@ -7,7 +23,5 @@ end
template "/etc/aliases" do template "/etc/aliases" do
source "aliases.erb" source "aliases.erb"
notifies :run, resources("execute[update-postfix-aliases]") notifies :run, "execute[update-postfix-aliases]"
#notifies :reload, resources(:service => "postfix")
end end

View File

@ -18,14 +18,12 @@
# limitations under the License. # limitations under the License.
# #
package "postfix" do package "postfix"
action :install
end if node['postfix']['use_procmail']
package "procmail"
if node['postfix']['use_procmail'] then
package "procmail" do
action :install
end
end end
@ -34,26 +32,31 @@ service "postfix" do
action :enable action :enable
end end
case node[:platform] case node['platform_family']
when "redhat", "centos", "amazon", "scientific" when "rhel", "fedora"
service "sendmail" do service "sendmail" do
action :nothing action :nothing
end end
execute "switch_mailer_to_postfix" do execute "switch_mailer_to_postfix" do
command "/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix" command "/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix"
notifies :stop, resources(:service => "sendmail") notifies :stop, "service[sendmail]"
notifies :start, resources(:service => "postfix") notifies :start, "service[postfix]"
not_if "/usr/bin/test /etc/alternatives/mta -ef /usr/sbin/sendmail.postfix" not_if "/usr/bin/test /etc/alternatives/mta -ef /usr/sbin/sendmail.postfix"
end end
end end
%w{main master}.each do |cfg| %w{main master}.each do |cfg|
template "/etc/postfix/#{cfg}.cf" do template "/etc/postfix/#{cfg}.cf" do
source "#{cfg}.cf.erb" source "#{cfg}.cf.erb"
owner "root" owner "root"
group "root" group 0
mode 0644 mode 00644
notifies :restart, resources(:service => "postfix") notifies :restart, "service[postfix]"
end end
end end

View File

@ -18,10 +18,29 @@
# limitations under the License. # limitations under the License.
# #
%w{ libsasl2-2 ca-certificates}.each do |pkg| include_recipe "postfix"
package pkg do
action :install sasl_pkgs = []
# We use case instead of value_for_platform_family because we need
# version specifics for RHEL.
case node['platform_family']
when "debian"
sasl_pkgs = %w{libsasl2-2 ca-certificates}
when "rhel"
if node['platform_version'].to_i < 6
sasl_pkgs = %w{cyrus-sasl openssl}
else
sasl_pkgs = %w{cyrus-sasl ca-certificates}
end end
when "fedora"
sasl_pkgs = %w{cyrus-sasl ca-certificates}
end
sasl_pkgs.each do |pkg|
package pkg
end end
execute "postmap-sasl_passwd" do execute "postmap-sasl_passwd" do
@ -34,7 +53,6 @@ template "/etc/postfix/sasl_passwd" do
owner "root" owner "root"
group "root" group "root"
mode 0400 mode 0400
notifies :run, resources(:execute => "postmap-sasl_passwd"), :immediately notifies :run, "execute[postmap-sasl_passwd]", :immediately
notifies :restart, resources(:service => "postfix") notifies :restart, "service[postfix]"
end end

View File

@ -1 +1,2 @@
<%= node[:postfix][:relayhost] %> <%= node[:postfix][:smtp_sasl_user_name] %>:<%= node[:postfix][:smtp_sasl_passwd] %> # This file is generated by Chef for <%= node['fqdn'] %>
<%= node['postfix']['relayhost'] %> <%= node['postfix']['smtp_sasl_user_name'] %>:<%= node['postfix']['smtp_sasl_passwd'] %>

View File

@ -1,3 +1,7 @@
cookbook "postfix" do cookbook "postfix" do
runtimes [] configuration "default"
configuration "aliases"
configuration "client"
configuration "server"
configuration "sasl_auth"
end end