Fix acceptance tests

In 2940279 management of the apache vhost was split into a separate
class and the vhost_name parameter was removed from the
bandersnatch::mirror class. This wasn't done in a backwards compatible
way and the acceptance tests were never updated to use the new API.
Additionally, a88c399 split the bandersnatch cron job out of the mirror
class into its own class, so the test for the existence of the job was
failing. This patch updates the tests to use the new classes and to
stop using the now invalid parameter.

We also relax some of the internal system assertions and opt instead
for checking that the service is working correctly by curling the
endpoints and checking the contents. This exposed an issue on CentOS
where selinux was not allowing apache to serve the robots.txt file, so
also added an selinux rule to the fixture.

Change-Id: If724c51b72f634a95bbffd080a9d33234a5d7645
This commit is contained in:
Colleen Murphy 2016-05-23 10:12:31 -07:00
parent 863b2ffae7
commit aae5bb5a65
3 changed files with 35 additions and 70 deletions

View File

@ -33,79 +33,22 @@ describe 'puppet-bandersnatch module' do
apply_manifest(default_puppet_module, catch_changes: true)
end
describe cron do
it { should have_entry('*/5 * * * * flock -n /var/run/bandersnatch/mirror.lock timeout -k 2m 30m run-bandersnatch >>/var/log/bandersnatch/mirror.log 2>\&1').with_user('root') }
end
describe 'files and directories' do
describe file('/var/log/bandersnatch') do
it { should be_directory }
end
describe file('/var/run/bandersnatch') do
it { should be_directory }
end
describe file('/usr/local/bin/run-bandersnatch') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its(:content) { should match 'if __name__ == \'__main__\':' }
end
describe file('/srv/static/mirror/web/robots.txt') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its(:content) { should match 'User-agent: \*' }
its(:content) { should match 'Disallow: /' }
end
describe file('/etc/bandersnatch.conf') do
it { should be_file }
its(:content) { should match '[mirror]' }
its(:content) { should match 'directory = /srv/static/mirror' }
end
describe file('/srv/static') do
it { should be_directory }
end
describe 'directories belonging to root user and group' do
directories = [
file('/srv/static/mirror'),
file('/srv/static/mirror/web'),
]
directories.each do |dir|
describe dir do
it { should be_directory }
it { should be_owned_by 'root'}
it { should be_grouped_into 'root'}
end
end
end
end
describe 'required packages' do
packages = [
package('bandersnatch'),
]
packages.each do |package|
describe package do
it { should be_installed.by('pip') }
end
end
end
describe 'required services' do
describe port(80) do
it { should be_listening }
# Before bandersnatch has run
describe command('curl localhost') do
its(:stdout) { should contain('Index of /') }
its(:stdout) { should_not contain('simple/') }
end
describe command("curl localhost") do
# Wait for bandersnatch to run
describe command('sleep 480 && curl localhost') do
its(:stdout) { should contain('Index of /') }
its(:stdout) { should contain('simple/') }
end
describe command('curl localhost/robots.txt') do
its(:stdout) { should match 'User-agent: *' }
its(:stdout) { should match 'Disallow: /' }
end
end
end

View File

@ -1,7 +1,22 @@
class { '::bandersnatch':
}
class { '::bandersnatch::mirror':
class { '::bandersnatch::cron':
}
class { '::bandersnatch::httpd':
vhost_name => '127.0.0.1',
}
class { '::bandersnatch::mirror':
require => Class['::bandersnatch'],
}
if $::osfamily == 'RedHat' {
exec { 'manage selinux':
command => 'semanage fcontext -a -t httpd_sys_content_t "/srv/static(/.*)?" && restorecon -R -v /srv',
unless => 'ls -lZ /srv | grep httpd_sys_content_t',
path => '/bin:/sbin',
require => Class['::bandersnatch::mirror'],
}
}

View File

@ -11,3 +11,10 @@ exec { 'install pip using get-pip':
refreshonly => true,
subscribe => Exec['download get-pip.py'],
}
# Install selinux utils so that we can manage apache directory permissions for CentOS
if $::osfamily == 'RedHat' {
package { 'policycoreutils-python':
ensure => present,
}
}