From 741f4fd6da319d47b55a26554fc92d165bcff115 Mon Sep 17 00:00:00 2001 From: Glauco Oliveira Date: Wed, 26 Aug 2015 11:17:09 -0300 Subject: [PATCH] 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 Co-Authored-By: Danilo Ramalho Change-Id: I2bd7dbc29c05f9e29127d48a284913bd34fae438 --- .gitignore | 5 +- Gemfile | 6 + spec/acceptance/basic_spec.rb | 181 +++++++++++++++++++++ spec/acceptance/fixtures/default.pp | 14 ++ spec/acceptance/fixtures/postconditions.pp | 7 + spec/acceptance/fixtures/preconditions.pp | 34 ++++ 6 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 spec/acceptance/basic_spec.rb create mode 100644 spec/acceptance/fixtures/default.pp create mode 100644 spec/acceptance/fixtures/postconditions.pp create mode 100644 spec/acceptance/fixtures/preconditions.pp diff --git a/.gitignore b/.gitignore index 03c312d..ea90996 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ Gemfile.lock -.bundled_gems +.bundled_gems/ +log/ +junit/ +.vagrant/ diff --git a/Gemfile b/Gemfile index 7accde3..f61c3b3 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/spec/acceptance/basic_spec.rb b/spec/acceptance/basic_spec.rb new file mode 100644 index 0000000..5691422 --- /dev/null +++ b/spec/acceptance/basic_spec.rb @@ -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 diff --git a/spec/acceptance/fixtures/default.pp b/spec/acceptance/fixtures/default.pp new file mode 100644 index 0000000..dab22f7 --- /dev/null +++ b/spec/acceptance/fixtures/default.pp @@ -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', +} diff --git a/spec/acceptance/fixtures/postconditions.pp b/spec/acceptance/fixtures/postconditions.pp new file mode 100644 index 0000000..9551273 --- /dev/null +++ b/spec/acceptance/fixtures/postconditions.pp @@ -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' +} diff --git a/spec/acceptance/fixtures/preconditions.pp b/spec/acceptance/fixtures/preconditions.pp new file mode 100644 index 0000000..4ee171f --- /dev/null +++ b/spec/acceptance/fixtures/preconditions.pp @@ -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], +}