Add acceptance tests for puppet-zuul

Add acceptance tests for puppet-zuul module so that once the module is
applied we check if files were created, packages were installed and
services were started.

Co-Authored-By: Bruno Tavares <btavare@thoughtworks.com>
Co-Authored-By: Danilo Ramalho <dramalho@thoughtworks.com>

Change-Id: I2bd7dbc29c05f9e29127d48a284913bd34fae438
This commit is contained in:
Glauco Oliveira 2015-08-26 11:17:09 -03:00 committed by Bruno Tavares
parent ff73305d77
commit 741f4fd6da
6 changed files with 246 additions and 1 deletions

5
.gitignore vendored
View File

@ -1,2 +1,5 @@
Gemfile.lock
.bundled_gems
.bundled_gems/
log/
junit/
.vagrant/

View File

@ -27,3 +27,9 @@ group :development, :test do
gem 'puppet', '~> 3.0', :require => false
end
end
group :system_tests do
gem 'beaker-rspec', :require => false
end
# vim:ft=ruby

View File

@ -0,0 +1,181 @@
require 'spec_helper_acceptance'
describe 'puppet-zuul module', :if => ['debian', 'ubuntu'].include?(os[:family]) do
def pp_path
base_path = File.dirname(__FILE__)
File.join(base_path, 'fixtures')
end
def preconditions_puppet_module
module_path = File.join(pp_path, 'preconditions.pp')
File.read(module_path)
end
def post_conditions_puppet_module
module_path = File.join(pp_path, 'postconditions.pp')
File.read(module_path)
end
def default_puppet_module
module_path = File.join(pp_path, 'default.pp')
File.read(module_path)
end
before(:all) do
apply_manifest(preconditions_puppet_module, catch_failures: true)
end
it 'should work with no errors' do
apply_manifest(default_puppet_module, catch_failures: true)
end
it 'should be idempotent' do
apply_manifest(default_puppet_module, catch_changes: true)
end
it 'should enable zuul server and zuul merger services' do
apply_manifest(post_conditions_puppet_module, catch_failures: true)
end
describe 'required users' do
describe user('zuul') do
it { should exist }
it { should belong_to_group 'zuul' }
it { should have_home_directory '/home/zuul' }
it { should have_login_shell '/bin/bash' }
end
end
describe 'required operating system packages' do
packages = [
package('git'),
package('gcc'),
package('python-lxml'),
package('python-yaml'),
package('python-paramiko'),
package('python-daemon'),
package('yui-compressor'),
package('python-paste'),
package('python-webob')
]
packages << package('apache2') if ['ubuntu', 'debian'].include?(os[:family])
packages << package('httpd') if ['centos', 'redhat'].include?(os[:family])
packages.each do |package|
describe package do
it { should be_installed }
end
end
end
describe 'required pip packages' do
packages = [
package('yappi'),
package('zuul')
]
packages.each do |package|
describe package do
it { should be_installed.by('pip') }
end
end
end
describe 'required files' do
describe file('/etc/zuul/zuul.conf') do
it { should be_file }
it { should contain('[gearman]') }
it { should contain('server=127.0.0.1') }
it { should contain('[gerrit]') }
it { should contain('server=') }
it { should contain('[zuul]') }
it { should contain('layout_config=/etc/zuul/layout/layout.yaml') }
end
describe file('/etc/default/zuul') do
it { should be_file }
end
describe file('/var/log/zuul') do
it { should be_directory }
it { should be_owned_by 'zuul'}
end
describe file('/var/lib/zuul/git') do
it { should be_directory }
it { should be_owned_by 'zuul'}
end
describe 'directories belonging to zuul user and group' do
directories = [
file('/var/lib/zuul'),
file('/var/run/zuul-merger'),
file('/var/lib/zuul/ssh'),
file('/var/run/zuul'),
]
directories.each do |dir|
describe dir do
it { should be_directory }
it { should be_owned_by 'zuul'}
it { should be_grouped_into 'zuul'}
end
end
end
describe 'public_html symlinks' do
symlinkies = {
file('/var/lib/zuul/www/images') => '/opt/zuul/etc/status/public_html/images',
file('/var/lib/zuul/www/index.html') => '/opt/zuul/etc/status/public_html/index.html',
file('/var/lib/zuul/www/jquery.zuul.js') => '/opt/zuul/etc/status/public_html/jquery.zuul.js',
file('/var/lib/zuul/www/styles') => '/opt/zuul/etc/status/public_html/styles',
file('/var/lib/zuul/www/zuul.app.js') => '/opt/zuul/etc/status/public_html/zuul.app.js',
file('/var/lib/zuul/www/lib/jquery.graphite.js') => '/opt/graphitejs/jquery.graphite.js',
file('/var/lib/zuul/www/lib/bootstrap') => '/opt/twitter-bootstrap/dist',
}
symlinkies.each do |link, destination|
describe link do
it { should be_symlink }
it { should be_linked_to destination }
end
end
end
describe file('/var/lib/zuul/ssh/id_rsa') do
it { should be_file }
it { should contain('-----BEGIN RSA PRIVATE KEY-----') }
end
describe file('/home/zuul/.ssh/known_hosts') do
it { should be_file }
it { should contain('known_hosts_content') }
end
end
describe cron do
it { should have_entry('7 4 * * * find /var/lib/zuul/git/ -maxdepth 3 -type d -name ".git" -exec git --git-dir="{}" pack-refs --all \\\;').with_user('zuul') }
end
describe 'required services' do
describe port(80) do
it { should be_listening }
end
describe command("curl http://localhost --location") do
its(:stdout) { should contain('Zuul Status') }
end
describe port(443) do
it { should be_listening }
end
describe command("curl https://localhost --insecure --location") do
its(:stdout) { should contain('Zuul Status') }
end
describe port(4730) do
it { should be_listening }
end
end
end

View File

@ -0,0 +1,14 @@
class { '::zuul':
proxy_ssl_cert_file_contents => file('/etc/ssl/certs/ssl-cert-snakeoil.pem'),
proxy_ssl_key_file_contents => file('/etc/ssl/private/ssl-cert-snakeoil.key'),
zuul_ssh_private_key => file('/tmp/zuul-ssh-keys/ssh_rsa_key'),
}
class { '::zuul::server':
layout_dir => '/etc/project-config/zuul'
}
class { '::zuul::merger': }
class { '::zuul::known_hosts':
known_hosts_content => 'known_hosts_content',
}

View File

@ -0,0 +1,7 @@
exec { 'starting zuul server':
command => '/etc/init.d/zuul start',
}
exec { 'starting zuul merger':
command => '/etc/init.d/zuul-merger start'
}

View File

@ -0,0 +1,34 @@
# Installing ssl-cert in order to get snakeoil certs
package { 'ssl-cert':
ensure => present,
}
vcsrepo { '/etc/project-config':
ensure => latest,
provider => git,
revision => 'master',
source => 'git://git.openstack.org/openstack-infra/project-config',
}
# Creating ssh rsa keys
define ssh_keygen (
$ssh_directory = undef
) {
Exec { path => '/bin:/usr/bin' }
$ssh_key_file = "${ssh_directory}/${name}"
exec { "ssh-keygen for ${name}":
command => "ssh-keygen -t rsa -f ${ssh_key_file} -N ''",
creates => $ssh_key_file,
}
}
$ssh_key_directory = '/tmp/zuul-ssh-keys'
file { $ssh_key_directory:
ensure => directory
}
ssh_keygen {'ssh_rsa_key':
ssh_directory => $ssh_key_directory,
require => File[$ssh_key_directory],
}