From 04ca249ee0393858ac9acf8456fd4bf3afe8e48f Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 9 Jan 2014 18:26:32 -0500 Subject: [PATCH] Fixes to make the tests run under Debian as well as Ubuntu. --- spec/acceptance/apt_ppa_spec.rb | 190 +++++++++++---------- spec/acceptance/apt_source_spec.rb | 1 + spec/acceptance/backports_spec.rb | 14 +- spec/acceptance/force_spec.rb | 8 +- spec/acceptance/release_spec.rb | 6 + spec/acceptance/unattended_upgrade_spec.rb | 4 + 6 files changed, 123 insertions(+), 100 deletions(-) diff --git a/spec/acceptance/apt_ppa_spec.rb b/spec/acceptance/apt_ppa_spec.rb index f936980..c0d2161 100644 --- a/spec/acceptance/apt_ppa_spec.rb +++ b/spec/acceptance/apt_ppa_spec.rb @@ -1,61 +1,20 @@ require 'spec_helper_acceptance' -describe 'apt::ppa' do +if fact('operatingsystem') == 'Ubuntu' + describe 'apt::ppa' do - context 'reset' do - it 'removes ppa' do - shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0,1,2]) - shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*', :acceptable_exit_codes => [0,1,2]) - end - end - - context 'adding a ppa that doesnt exist' do - it 'should work with no errors' do - pp = <<-EOS - include '::apt' - apt::ppa { 'ppa:canonical-kernel-team/ppa': } - EOS - - apply_manifest(pp, :catch_failures => true) - end - - describe 'contains the source file' do - it 'contains a kernel ppa source' do - shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0]) + context 'reset' do + it 'removes ppa' do + shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0,1,2]) + shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*', :acceptable_exit_codes => [0,1,2]) end end - end - - context 'readding a removed ppa.' do - it 'setup' do - shell('add-apt-repository -y ppa:raravena80/collectd5') - # This leaves a blank file - shell('add-apt-repository --remove ppa:raravena80/collectd5') - end - - it 'should readd it successfully' do - pp = <<-EOS - include '::apt' - apt::ppa { 'ppa:raravena80/collectd5': } - EOS - - apply_manifest(pp, :catch_failures => true) - end - end - context 'reset' do - it 'removes added ppas' do - shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*') - shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*') - end - end - - context 'ensure' do - context 'present' do - it 'works without failure' do + context 'adding a ppa that doesnt exist' do + it 'should work with no errors' do pp = <<-EOS include '::apt' - apt::ppa { 'ppa:canonical-kernel-team/ppa': ensure => present } + apt::ppa { 'ppa:canonical-kernel-team/ppa': } EOS apply_manifest(pp, :catch_failures => true) @@ -67,72 +26,115 @@ describe 'apt::ppa' do end end end - end - context 'ensure' do - context 'absent' do - it 'works without failure' do + context 'readding a removed ppa.' do + it 'setup' do + shell('add-apt-repository -y ppa:raravena80/collectd5') + # This leaves a blank file + shell('add-apt-repository --remove ppa:raravena80/collectd5') + end + + it 'should readd it successfully' do pp = <<-EOS include '::apt' - apt::ppa { 'ppa:canonical-kernel-team/ppa': ensure => absent } + apt::ppa { 'ppa:raravena80/collectd5': } EOS apply_manifest(pp, :catch_failures => true) end + end - describe 'doesnt contain the source file' do - it 'fails' do - shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [2]) - end + context 'reset' do + it 'removes added ppas' do + shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*') + shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*') end end - end - context 'release' do - context 'precise' do - it 'works without failure' do - pp = <<-EOS - include '::apt' - apt::ppa { 'ppa:canonical-kernel-team/ppa': - ensure => present, - release => precise, - } - EOS + context 'ensure' do + context 'present' do + it 'works without failure' do + pp = <<-EOS + include '::apt' + apt::ppa { 'ppa:canonical-kernel-team/ppa': ensure => present } + EOS - shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2]) - apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_failures => true) + end + + describe 'contains the source file' do + it 'contains a kernel ppa source' do + shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0]) + end + end end + end + + context 'ensure' do + context 'absent' do + it 'works without failure' do + pp = <<-EOS + include '::apt' + apt::ppa { 'ppa:canonical-kernel-team/ppa': ensure => absent } + EOS - describe file('/etc/apt/sources.list.d/canonical-kernel-team-ppa-precise.list') do - it { should be_file } + apply_manifest(pp, :catch_failures => true) + end + + describe 'doesnt contain the source file' do + it 'fails' do + shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [2]) + end + end end end - end - context 'options' do - context '-y' do - it 'works without failure' do - pp = <<-EOS - include '::apt' - apt::ppa { 'ppa:canonical-kernel-team/ppa': - ensure => present, - release => precise, - options => '-y', - } - EOS + context 'release' do + context 'precise' do + it 'works without failure' do + pp = <<-EOS + include '::apt' + apt::ppa { 'ppa:canonical-kernel-team/ppa': + ensure => present, + release => precise, + } + EOS + + shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2]) + apply_manifest(pp, :catch_failures => true) + end - shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2]) - apply_manifest(pp, :catch_failures => true) + describe file('/etc/apt/sources.list.d/canonical-kernel-team-ppa-precise.list') do + it { should be_file } + end end + end + + context 'options' do + context '-y' do + it 'works without failure' do + pp = <<-EOS + include '::apt' + apt::ppa { 'ppa:canonical-kernel-team/ppa': + ensure => present, + release => precise, + options => '-y', + } + EOS + + shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2]) + apply_manifest(pp, :catch_failures => true) + end - describe file('/etc/apt/sources.list.d/canonical-kernel-team-ppa-precise.list') do - it { should be_file } + describe file('/etc/apt/sources.list.d/canonical-kernel-team-ppa-precise.list') do + it { should be_file } + end end end - end - context 'reset' do - it { shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2]) } - end + context 'reset' do + it { shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2]) } + end + end end diff --git a/spec/acceptance/apt_source_spec.rb b/spec/acceptance/apt_source_spec.rb index 273add5..6b026b8 100644 --- a/spec/acceptance/apt_source_spec.rb +++ b/spec/acceptance/apt_source_spec.rb @@ -255,6 +255,7 @@ describe 'apt::source' do apt::source { 'puppetlabs': ensure => present, location => 'http://apt.puppetlabs.com', + release => 'precise', repos => 'main', key => '4BD6EC30', key_source => 'http://apt.puppetlabs.com/pubkey.gpg', diff --git a/spec/acceptance/backports_spec.rb b/spec/acceptance/backports_spec.rb index ffb14ce..80e2093 100644 --- a/spec/acceptance/backports_spec.rb +++ b/spec/acceptance/backports_spec.rb @@ -1,5 +1,13 @@ require 'spec_helper_acceptance' +codename = fact('lsbdistcodename') +case fact('operatingsystem') +when 'Ubuntu' + repos = 'main universe multiverse restricted' +when 'Debian' + repos = 'main contrib non-free' +end + describe 'apt::backports class' do context 'defaults' do it 'should work with no errors' do @@ -14,7 +22,7 @@ describe 'apt::backports class' do context 'release' do it 'should work with no errors' do pp = <<-EOS - class { 'apt::backports': release => 'precise' } + class { 'apt::backports': release => '#{codename}' } EOS apply_manifest(pp, :catch_failures => true) @@ -22,7 +30,7 @@ describe 'apt::backports class' do describe file('/etc/apt/sources.list.d/backports.list') do it { should be_file } - it { should contain 'precise-backports main universe multiverse restricted' } + it { should contain "#{codename}-backports #{repos}" } end end @@ -37,7 +45,7 @@ describe 'apt::backports class' do describe file('/etc/apt/sources.list.d/backports.list') do it { should be_file } - it { should contain 'deb http://localhost/ubuntu precise-backports main universe multiverse restricted' } + it { should contain "deb http://localhost/ubuntu precise-backports #{repos}" } end end diff --git a/spec/acceptance/force_spec.rb b/spec/acceptance/force_spec.rb index f7e374b..c364d5f 100644 --- a/spec/acceptance/force_spec.rb +++ b/spec/acceptance/force_spec.rb @@ -1,5 +1,7 @@ require 'spec_helper_acceptance' +codename = fact('lsbdistcodename') + describe 'apt::force define' do context 'defaults' do it 'should work with no errors' do @@ -21,12 +23,12 @@ describe 'apt::force define' do it 'should work with no errors' do pp = <<-EOS include apt - apt::force { 'vim': release => 'precise' } + apt::force { 'vim': release => '#{codename}' } EOS shell('apt-get remove -y vim') apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/apt-get -y -t precise install vim/) + expect(r.stdout).to match(/apt-get -y -t #{codename} install vim/) end end @@ -57,7 +59,7 @@ describe 'apt::force define' do it 'should work with no errors' do pp = <<-EOS include apt - apt::force { 'tomcat7': timeout => '1' } + apt::force { 'vim': timeout => '1' } EOS shell('apt-get clean') diff --git a/spec/acceptance/release_spec.rb b/spec/acceptance/release_spec.rb index 44491e3..81d7ca0 100644 --- a/spec/acceptance/release_spec.rb +++ b/spec/acceptance/release_spec.rb @@ -17,4 +17,10 @@ describe 'apt::release class' do end end + context 'reset' do + it 'cleans up' do + shell('rm -rf /etc/apt/apt.conf.d/01release') + end + end + end diff --git a/spec/acceptance/unattended_upgrade_spec.rb b/spec/acceptance/unattended_upgrade_spec.rb index 287e5ec..a0349d4 100644 --- a/spec/acceptance/unattended_upgrade_spec.rb +++ b/spec/acceptance/unattended_upgrade_spec.rb @@ -8,6 +8,10 @@ describe 'apt::unattended_upgrades class' do include apt::unattended_upgrades EOS + # Attempted workaround for problems seen on debian with + # something holding the package database open. + #shell('killall -9 apt-get') + #shell('killall -9 dpkg') apply_manifest(pp, :catch_failures => true) end -- 2.45.2