diff --git a/.gitignore b/.gitignore index dade81e..ea90996 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ Gemfile.lock .bundled_gems/ +log/ +junit/ +.vagrant/ diff --git a/Gemfile b/Gemfile index 96912da..d69f807 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,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 diff --git a/spec/acceptance/basic_spec.rb b/spec/acceptance/basic_spec.rb new file mode 100644 index 0000000..e4e8a00 --- /dev/null +++ b/spec/acceptance/basic_spec.rb @@ -0,0 +1,111 @@ +require 'spec_helper_acceptance' + +describe 'puppet-bandersnatch module' 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 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', :if => ['debian', 'ubuntu'].include?(os[:family]) do + apply_manifest(default_puppet_module, catch_changes: true) + end + + it 'should be idempotent', :if => ['fedora', 'redhat'].include?(os[:family]) do + pending('this module is not idempotent on CentOS yet') + 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 } + end + + describe command("curl localhost") do + its(:stdout) { should contain('Index of /') } + end + end +end diff --git a/spec/acceptance/fixtures/default.pp b/spec/acceptance/fixtures/default.pp new file mode 100644 index 0000000..06ffe7a --- /dev/null +++ b/spec/acceptance/fixtures/default.pp @@ -0,0 +1,7 @@ +class { '::bandersnatch': +} + +class { '::bandersnatch::mirror': + vhost_name => '127.0.0.1', + require => Class['::bandersnatch'], +} diff --git a/spec/acceptance/fixtures/preconditions.pp b/spec/acceptance/fixtures/preconditions.pp new file mode 100644 index 0000000..01e9cba --- /dev/null +++ b/spec/acceptance/fixtures/preconditions.pp @@ -0,0 +1,13 @@ +# Installing pip since bandersnatch dependencies are managed by it +exec { 'download get-pip.py': + command => 'wget https://bootstrap.pypa.io/get-pip.py -O /tmp/get-pip.py', + path => '/bin:/usr/bin:/usr/local/bin', + creates => '/tmp/get-pip.py', +} + +exec { 'install pip using get-pip': + command => 'python /tmp/get-pip.py', + path => '/bin:/usr/bin:/usr/local/bin', + refreshonly => true, + subscribe => Exec['download get-pip.py'], +}