From 2f9c16a2736e1de4eda3250984e2b1125efd849e Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 2 Oct 2013 13:56:06 -0400 Subject: [PATCH 1/2] This switches us to doing a `test -s` instead of checking for the files existence as add-apt-repository --remove leaves a 0 byte file behind instead of deleting everything properly. --- manifests/ppa.pp | 2 +- spec/defines/ppa_spec.rb | 6 +++--- spec/system/apt_ppa_spec.rb | 25 +++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/manifests/ppa.pp b/manifests/ppa.pp index 61b9b3a..e6954af 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -42,7 +42,7 @@ define apt::ppa( exec { "add-apt-repository-${name}": environment => $proxy_env, command => "/usr/bin/add-apt-repository ${options} ${name}", - creates => "${sources_list_d}/${sources_list_d_filename}", + onlyif => "/usr/bin/test -s ${sources_list_d}/${sources_list_d_filename}", logoutput => 'on_failure', notify => Exec['apt_update'], require => [ diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index dfaf09c..853fdb6 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -45,7 +45,7 @@ describe 'apt::ppa', :type => :define do it { should contain_exec("add-apt-repository-#{t}").with( 'command' => "/usr/bin/add-apt-repository #{options} #{t}", - 'creates' => "/etc/apt/sources.list.d/#{filename}", + 'onlyif' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}", 'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"], 'notify' => "Exec[apt_update]" ) @@ -74,7 +74,7 @@ describe 'apt::ppa', :type => :define do it { should contain_exec("add-apt-repository-#{title}").with( 'environment' => [], 'command' => "/usr/bin/add-apt-repository #{options} #{title}", - 'creates' => "/etc/apt/sources.list.d/#{filename}", + 'onlyif' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}", 'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"], 'notify' => "Exec[apt_update]" ) @@ -100,7 +100,7 @@ describe 'apt::ppa', :type => :define do "https_proxy=http://user:pass@proxy:8080", ], 'command' => "/usr/bin/add-apt-repository #{options} #{title}", - 'creates' => "/etc/apt/sources.list.d/#{filename}", + 'onlyif' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}", 'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"], 'notify' => "Exec[apt_update]" ) diff --git a/spec/system/apt_ppa_spec.rb b/spec/system/apt_ppa_spec.rb index 8e7090b..2e2baf5 100644 --- a/spec/system/apt_ppa_spec.rb +++ b/spec/system/apt_ppa_spec.rb @@ -5,10 +5,11 @@ describe 'apt::ppa' do context 'reset' do it 'removes ppa' do shell('rm /etc/apt/sources.list.d/drizzle-developers-ppa*') + shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*') end end - context 'apt::ppa' do + context 'adding a ppa that doesnt exist' do it 'should work with no errors' do pp = <<-EOS include '::apt' @@ -29,9 +30,29 @@ describe 'apt::ppa' do 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 + + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + end + end + end + context 'reset' do - it 'removes ppa' do + it 'removes added ppas' do shell('rm /etc/apt/sources.list.d/drizzle-developers-ppa*') + shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*') end end From ee24679f6d234952832bd014d98f7d9884ffbf60 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 2 Oct 2013 14:04:51 -0400 Subject: [PATCH 2/2] Fix other tests to include apt appropriately. --- spec/system/apt_builddep_spec.rb | 1 + spec/system/apt_key_spec.rb | 1 + spec/system/apt_source_spec.rb | 1 + 3 files changed, 3 insertions(+) diff --git a/spec/system/apt_builddep_spec.rb b/spec/system/apt_builddep_spec.rb index 2fb7487..fa16ab4 100644 --- a/spec/system/apt_builddep_spec.rb +++ b/spec/system/apt_builddep_spec.rb @@ -12,6 +12,7 @@ describe 'apt::builddep' do context 'apt::builddep' do it 'should work with no errors' do pp = <<-EOS + include '::apt' apt::builddep { 'glusterfs-server': } EOS diff --git a/spec/system/apt_key_spec.rb b/spec/system/apt_key_spec.rb index 2acc317..4842cb5 100644 --- a/spec/system/apt_key_spec.rb +++ b/spec/system/apt_key_spec.rb @@ -12,6 +12,7 @@ describe 'apt::key' do context 'apt::key' do it 'should work with no errors' do pp = <<-EOS + include '::apt' apt::key { 'puppetlabs': key => '4BD6EC30', key_server => 'pgp.mit.edu', diff --git a/spec/system/apt_source_spec.rb b/spec/system/apt_source_spec.rb index 8c79f6f..6a445e1 100644 --- a/spec/system/apt_source_spec.rb +++ b/spec/system/apt_source_spec.rb @@ -12,6 +12,7 @@ describe 'apt::source' do context 'apt::source' do it 'should work with no errors' do pp = <<-EOS + include '::apt' apt::source { 'puppetlabs': location => 'http://apt.puppetlabs.com', repos => 'main',