Add acceptance tests for puppet-gerrit

Add acceptance tests for puppet-gerrit module so that once the module is
applied we check if files were created, packages were installed and
services are available to users.
We left one pending test because this module is still not idempotent.

Co-Authored-By: Caio Carrara <ccarrara@thoughtworks.com>
Co-Authored-By: Dhiana Deva <ddeva@thoughtworks.com>
Change-Id: I88b5730d369578ae6763226c0424467286e753a2
This commit is contained in:
Glauco Oliveira 2015-08-19 14:36:16 -03:00
parent e6a0a48b8e
commit ff88a8f6fb
9 changed files with 237 additions and 0 deletions

3
.gitignore vendored
View File

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

View File

@ -26,7 +26,10 @@ group :development, :test do
else
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,34 @@
require 'spec_helper_acceptance'
describe 'basic gerrit' do
context 'module is working' do
def pp_path
base_path = File.dirname(__FILE__)
File.join(base_path, 'fixtures')
end
def ssh_keygen_puppet_module
module_path = File.join(pp_path, 'ssh_keygen.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(ssh_keygen_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
pending("this module is not idempotent, yet.")
apply_manifest(default_puppet_module, catch_failures: true)
apply_manifest(default_puppet_module, catch_changes: true)
end
end
end

View File

@ -0,0 +1,53 @@
require 'spec_helper_acceptance'
describe 'required files and directories' do
describe file('/home/gerrit2/review_site/etc/gerrit.config') do
it { should be_file }
it { should contain('javaHome = /usr/lib/jvm/java-7-openjdk-amd64/jre') }
end
describe file('/home/gerrit2/review_site/etc/secure.config') do
it { should be_file }
it { should contain('password = 12345') }
end
describe file('/etc/default/gerritcodereview') do
it { should be_file }
it { should contain('GERRIT_SITE=/home/gerrit2/review_site') }
end
describe file('/etc/mysql/conf.d/client.conf') do
it { should be_file }
it { should contain('port = 3306') }
end
describe file('/home/gerrit2/review_site/etc/ssh_host_rsa_key') do
it { should be_file }
it { should contain('-----BEGIN RSA PRIVATE KEY-----') }
end
describe file('/home/gerrit2/review_site/etc/ssh_host_rsa_key.pub') do
it { should be_file }
it { should contain('ssh-rsa') }
end
describe file('/home/gerrit2/review_site/etc/ssh_project_rsa_key') do
it { should be_file }
it { should contain('-----BEGIN RSA PRIVATE KEY-----') }
end
describe file('/home/gerrit2/review_site/etc/ssh_project_rsa_key.pub') do
it { should be_file }
it { should contain('ssh-rsa') }
end
describe file('/home/gerrit2/.ssh/id_rsa') do
it { should be_file }
it { should contain('-----BEGIN RSA PRIVATE KEY-----') }
end
describe file('/home/gerrit2/id_rsa.pub') do
it { should be_file }
it { should contain('ssh-rsa') }
end
end

View File

@ -0,0 +1,35 @@
# workaround since ssl-cert group is not being installed as part of
# this module
package { 'ssl-cert':
ensure => present,
}
exec { 'ensure ssl-cert exists':
command => '/usr/sbin/groupadd -f ssl-cert'
}
# workaround since pip is not being installed as part of this module
package { 'python-pip':
ensure => present,
}
class { '::gerrit::mysql':
mysql_root_password => 'UNSET',
database_name => 'reviewdb',
database_user => 'gerrit2',
database_password => '12345',
}
class { '::gerrit':
mysql_host => 'localhost',
mysql_password => '12345',
war => 'http://tarballs.openstack.org/ci/gerrit/gerrit-v2.8.4.19.4548330.war',
ssh_rsa_key_contents => file('/tmp/gerrit-ssh-keys/ssh_rsa_key'),
ssh_rsa_pubkey_contents => file('/tmp/gerrit-ssh-keys/ssh_rsa_key.pub'),
ssh_project_rsa_key_contents => file('/tmp/gerrit-ssh-keys/ssh_project_rsa_key'),
ssh_project_rsa_pubkey_contents => file('/tmp/gerrit-ssh-keys/ssh_project_rsa_key.pub'),
ssh_replication_rsa_key_contents => file('/tmp/gerrit-ssh-keys/ssh_replication_rsa_key'),
ssh_replication_rsa_pubkey_contents => file('/tmp/gerrit-ssh-keys/ssh_replication_rsa_key.pub'),
}
class { '::gerrit::cron': }

View File

@ -0,0 +1,25 @@
define create_ssh_key_directory() {
Exec { path => '/bin:/usr/bin' }
exec { "create temporary ${name} directory":
command => "mkdir -p ${name}",
}
}
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/gerrit-ssh-keys'
create_ssh_key_directory { $ssh_key_directory: }
ssh_keygen {'ssh_rsa_key': ssh_directory => $ssh_key_directory }
ssh_keygen {'ssh_project_rsa_key': ssh_directory => $ssh_key_directory }
ssh_keygen {'ssh_replication_rsa_key': ssh_directory => $ssh_key_directory }

View File

@ -0,0 +1,30 @@
require 'spec_helper_acceptance'
describe 'operating system packages' do
shared_examples "a required package is installed" do |packages|
packages.each do |package|
describe package(package) do
it { should be_installed }
end
end
end
@installed_packages = ['gitweb', 'unzip', 'openjdk-7-jre-headless',
'libmysql-java', 'mysql-client', 'mysql-server']
@installed_packages << 'apache2' if ['ubuntu', 'debian'].include?(os[:family])
@installed_packages << 'httpd' if ['centos', 'redhat'].include?(os[:family])
it_behaves_like "a required package is installed", @installed_packages
shared_examples "an unnecessary package is not installed" do |packages|
packages.each do |package|
describe package(package) do
it { should_not be_installed }
end
end
end
@unnecessary_packages = ['openjdk-6-jre-headless']
it_behaves_like "an unnecessary package is not installed", @unnecessary_packages
end

View File

@ -0,0 +1,44 @@
require 'spec_helper_acceptance'
describe 'operating system services' do
describe service('apache2'), :if => ['debian', 'ubuntu'].include?(os[:family]) do
it { should be_enabled }
it { should be_running }
end
describe service('httpd'), :if => ['centos', 'redhat'].include?(os[:family]) do
it { should be_enabled }
it { should be_running }
end
describe port(80) do
it { should be_listening }
end
describe command("curl http://localhost:80 --insecure --location") do
its(:stdout) { should contain('Gerrit Code Review') }
its(:stdout) { should contain('version":"2.8.4-19-g4548330') }
end
describe port(443) do
it { should be_listening }
end
describe command("curl https://localhost:443 --insecure --location") do
its(:stdout) { should contain('Gerrit Code Review') }
its(:stdout) { should contain('version":"2.8.4-19-g4548330') }
end
describe port(8081) do
it { should be_listening }
end
describe command("curl http://localhost:8081") do
its(:stdout) { should contain('Gerrit Code Review') }
its(:stdout) { should contain('version":"2.8.4-19-g4548330') }
end
describe port(29418) do
it { should be_listening }
end
end

View File

@ -0,0 +1,10 @@
require 'spec_helper_acceptance'
describe 'user' do
describe user('gerrit2') do
it { should exist }
it { should belong_to_group 'gerrit2' }
it { should have_home_directory '/home/gerrit2' }
it { should have_login_shell '/bin/bash' }
end
end