]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Merge pull request #433 from mhaskel/ppa
authorDaniele Sluijters <daenney@users.noreply.github.com>
Mon, 23 Feb 2015 19:21:10 +0000 (20:21 +0100)
committerDaniele Sluijters <daenney@users.noreply.github.com>
Mon, 23 Feb 2015 19:21:10 +0000 (20:21 +0100)
PPA Cleanup, pt 1

manifests/params.pp
manifests/ppa.pp
spec/defines/ppa_spec.rb

index 3aba99e3112b1ae68761a2f57ca149bffbb0fc98..765677f314a68ca8e1c5ef799e8f25183f6b7723 100644 (file)
@@ -64,12 +64,19 @@ class apt::params {
       case $distcodename {
         'lucid': {
           $ppa_options        = undef
+          $ppa_package        = 'python-software-properties'
         }
-        'precise', 'trusty', 'utopic', 'vivid': {
+        'precise': {
           $ppa_options        = '-y'
+          $ppa_package        = 'python-software-properties'
+        }
+        'trusty', 'utopic', 'vivid': {
+          $ppa_options        = '-y'
+          $ppa_package        = 'software-properties-common'
         }
         default: {
           $ppa_options        = '-y'
+          $ppa_package        = 'software-properties-common'
         }
       }
     }
index 3a11ede779799401a68e42d318774bc8c428b486..4181b5811d3686fa4f0f9744e2f1d289a7913023 100644 (file)
@@ -1,10 +1,11 @@
 # ppa.pp
 define apt::ppa(
-  $ensure  = 'present',
-  $release = $::lsbdistcodename,
-  $options = $::apt::ppa_options,
+  $ensure         = 'present',
+  $release        = $::lsbdistcodename,
+  $options        = $::apt::ppa_options,
+  $package_name   = $::apt::ppa_package,
+  $package_manage = false,
 ) {
-
   if ! $release {
     fail('lsbdistcodename fact not available: release parameter required')
   }
@@ -19,52 +20,42 @@ define apt::ppa(
   $sources_list_d_filename  = "${filename_without_ppa}-${release}.list"
 
   if $ensure == 'present' {
-    $package = $::lsbdistrelease ? {
-        /^[1-9]\..*|1[01]\..*|12.04$/ => 'python-software-properties',
-        default  => 'software-properties-common',
-    }
+    if $package_manage {
+      package { $package_name: }
 
-    if ! defined(Package[$package]) {
-        package { $package: }
+      $_require = [File['sources.list.d'], Package[$package_name]]
+    } else {
+      $_require = File['sources.list.d']
     }
 
-    if defined(Class[apt]) {
-        $proxy_host = $apt::proxy_host
-        $proxy_port = $apt::proxy_port
-        case $proxy_host {
-          false, '', undef: {
-            $proxy_env = []
-          }
-          default: {
-            $proxy_env = ["http_proxy=http://${proxy_host}:${proxy_port}", "https_proxy=http://${proxy_host}:${proxy_port}"]
-          }
-        }
-    } else {
-        $proxy_env = []
+    case $::apt::proxy_host {
+      false, '', undef: {
+        $_proxy_env = []
+      }
+      default: {
+        $_proxy_env = ["http_proxy=http://${::apt::proxy_host}:${::apt::proxy_port}", "https_proxy=http://${::apt::proxy_host}:${::apt::proxy_port}"]
+      }
     }
+
     exec { "add-apt-repository-${name}":
-        environment => $proxy_env,
-        command     => "/usr/bin/add-apt-repository ${options} ${name}",
-        unless      => "/usr/bin/test -s ${::apt::sources_list_d}/${sources_list_d_filename}",
-        user        => 'root',
-        logoutput   => 'on_failure',
-        notify      => Exec['apt_update'],
-        require     => [
-        File['sources.list.d'],
-        Package[$package],
-        ],
+      environment => $_proxy_env,
+      command     => "/usr/bin/add-apt-repository ${options} ${name}",
+      unless      => "/usr/bin/test -s ${::apt::sources_list_d}/${sources_list_d_filename}",
+      user        => 'root',
+      logoutput   => 'on_failure',
+      notify      => Exec['apt_update'],
+      require     => $_require,
     }
 
     file { "${::apt::sources_list_d}/${sources_list_d_filename}":
-        ensure  => file,
-        require => Exec["add-apt-repository-${name}"],
+      ensure  => file,
+      require => Exec["add-apt-repository-${name}"],
     }
   }
   else {
-
     file { "${::apt::sources_list_d}/${sources_list_d_filename}":
-        ensure => 'absent',
-        notify => Exec['apt_update'],
+      ensure => 'absent',
+      notify => Exec['apt_update'],
     }
   }
 
index f078204ed8ba39213a869b031a8b97d3d6412e45..d57c1a5895aca720b4d5466754885411a0468491 100644 (file)
@@ -16,7 +16,7 @@ describe 'apt::ppa', :type => :define do
     end
 
     let(:title) { 'ppa:needs/such.substitution/wow' }
-    it { is_expected.to contain_package('python-software-properties') }
+    it { is_expected.to_not contain_package('python-software-properties') }
     it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({
       'environment' => [],
       'command'     => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
@@ -25,11 +25,6 @@ describe 'apt::ppa', :type => :define do
       'logoutput'   => 'on_failure',
     })
     }
-
-    it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({
-      'ensure' => 'file',
-    })
-    }
   end
 
   describe 'apt included, no proxy' do
@@ -48,6 +43,7 @@ describe 'apt::ppa', :type => :define do
     let :params do
       {
         'options' => '',
+        'package_manage' => true,
       }
     end
     let(:title) { 'ppa:foo' }
@@ -60,11 +56,6 @@ describe 'apt::ppa', :type => :define do
       'logoutput'   => 'on_failure',
     })
     }
-
-    it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({
-      'ensure' => 'file',
-    })
-    }
   end
 
   describe 'ensure absent' do