]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Merge pull request #667 from HelenCampbell/firstRelease
authorHunter Haugen <hunter@puppet.com>
Tue, 11 Apr 2017 22:50:45 +0000 (15:50 -0700)
committerGitHub <noreply@github.com>
Tue, 11 Apr 2017 22:50:45 +0000 (15:50 -0700)
First Release prep for Puppet 4 language update

38 files changed:
CHANGELOG.md
data/Debian-6.0.yaml [new file with mode: 0644]
data/Debian.yaml [new file with mode: 0644]
data/Ubuntu-10.04.yaml [new file with mode: 0644]
data/Ubuntu-12.04.yaml [new file with mode: 0644]
data/Ubuntu-14.04.yaml [new file with mode: 0644]
data/Ubuntu.yaml [new file with mode: 0644]
data/common.yaml [new file with mode: 0644]
hiera.yaml [new file with mode: 0644]
manifests/backports.pp
manifests/conf.pp
manifests/init.pp
manifests/key.pp
manifests/params.pp [deleted file]
manifests/pin.pp
manifests/ppa.pp
manifests/setting.pp
manifests/source.pp
metadata.json
spec/classes/apt_backports_spec.rb
spec/classes/apt_spec.rb
spec/classes/params_spec.rb [deleted file]
spec/defines/key_compat_spec.rb
spec/defines/key_spec.rb
spec/defines/pin_spec.rb
spec/defines/ppa_spec.rb
spec/defines/setting_spec.rb
spec/defines/source_spec.rb
templates/15update-stamp.epp [moved from templates/15update-stamp.erb with 100% similarity]
templates/_conf_header.epp [moved from templates/_conf_header.erb with 100% similarity]
templates/_header.epp [moved from templates/_header.erb with 100% similarity]
templates/conf.erb [deleted file]
templates/pin.pref.epp [new file with mode: 0644]
templates/pin.pref.erb [deleted file]
templates/proxy.epp [new file with mode: 0644]
templates/proxy.erb [deleted file]
templates/source.list.epp [new file with mode: 0644]
templates/source.list.erb [deleted file]

index 25fbd7bd21fe56812880df177cf8a649184987d8..86d474acb11ade991ac0ece7ec0d84f429cc2492 100644 (file)
@@ -1,3 +1,19 @@
+## Supported Release 3.0.0 and 4.0.0
+###Summary
+
+This release adds new Puppet 4 features: data in modules, EPP templates, the $facts hash, and data types. This release is fully backwards compatible to existing Puppet 4 configurations and provides you with deprecation warnings for every argument that will not work as expected with the final 4.0.0 release. See the stdlib docs here for an in-depth discussion of this: https://github.com/puppetlabs/puppetlabs-stdlib#validate_legacy
+
+If you want to learn more about the new features used or you wish to upgrade a module yourself, have a look at the NTP: A Puppet 4 language update blog post.
+
+If you're still running Puppet 3, remain on the latest puppetlabs-apt 2.x release for now, and see the documentation to upgrade to Puppet 4.
+
+Changes
+
+Data in modules: Moves all distribution and OS-dependent defaults into YAML files in data/, alleviating the need for a params class. Note that while this feature is currently still classed as experimental, the final implementation will support the changes here.
+EPP templating: Uses the Puppet language as a base for templates to create simpler and safer templates. No need for Ruby anymore!
+The $facts hash: Makes facts visibly distinct from other variables for more readable and maintainable code. This helps eliminate confusion if you use a local variable whose name happens to match that of a common fact.
+Data types for validation: Helps you find and replace deprecated code in existing validate functions with stricter, more readable data type notation. First upgrade to the 3.0.0 release of this module, and address all deprecation warnings before upgrading to the final 4.0.0 release. Please see the stdlib docs for an in-depth discussion of this process.
+
 ## Supported Release 2.4.0
 ### Summary
 A release that includes only a couple of additional features, but includes several cleanups and bugfixes around existing issues.
diff --git a/data/Debian-6.0.yaml b/data/Debian-6.0.yaml
new file mode 100644 (file)
index 0000000..f03bccd
--- /dev/null
@@ -0,0 +1,5 @@
+---
+#Squeeze
+apt::backports: { location: 'http://httpredir.debian.org/debian-backports', key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', repos: 'main contrib non-free' }
+apt::ppa_options: ~
+apt::ppa_package: ~
diff --git a/data/Debian.yaml b/data/Debian.yaml
new file mode 100644 (file)
index 0000000..823bc02
--- /dev/null
@@ -0,0 +1,4 @@
+---
+apt::backports: { location: 'http://httpredir.debian.org/debian', key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', repos: 'main contrib non-free' }
+apt::ppa_options: ~
+apt::ppa_package: ~
diff --git a/data/Ubuntu-10.04.yaml b/data/Ubuntu-10.04.yaml
new file mode 100644 (file)
index 0000000..567548b
--- /dev/null
@@ -0,0 +1,4 @@
+---
+#Lucid
+apt::ppa_options: ~
+apt::ppa_package: 'python-software-properties'
diff --git a/data/Ubuntu-12.04.yaml b/data/Ubuntu-12.04.yaml
new file mode 100644 (file)
index 0000000..992cb25
--- /dev/null
@@ -0,0 +1,4 @@
+---
+#Precise
+apt::ppa_options: '-y'
+apt::ppa_package: 'python-software-properties'
diff --git a/data/Ubuntu-14.04.yaml b/data/Ubuntu-14.04.yaml
new file mode 100644 (file)
index 0000000..d168164
--- /dev/null
@@ -0,0 +1,4 @@
+---
+#Trusty
+apt::ppa_options: '-y'
+apt::ppa_package: 'software-properties-common'
diff --git a/data/Ubuntu.yaml b/data/Ubuntu.yaml
new file mode 100644 (file)
index 0000000..ee62a25
--- /dev/null
@@ -0,0 +1,4 @@
+---
+apt::backports: { location: 'http://archive.ubuntu.com/ubuntu', key: '630239CC130E1A7FD81A27B140976EAF437D05B5', repos: 'main universe multiverse restricted' }
+apt::ppa_options: '-y'
+apt::ppa_package: 'python-software-properties'
diff --git a/data/common.yaml b/data/common.yaml
new file mode 100644 (file)
index 0000000..2ed9e16
--- /dev/null
@@ -0,0 +1,11 @@
+---
+apt::provider: '/usr/bin/apt-get'
+apt::keyserver: 'keyserver.ubuntu.com'
+apt::update_defaults: { frequency: 'reluctantly', timeout: ~, tries: ~ }
+apt::proxy_defaults: { ensure: ~, host: ~, port: 8080, https: false }
+apt::purge_defaults: { sources.list: false, sources.list.d: false, preferences: false, preferences.d: false }
+apt::proxy_defaults: { ensure: ~, host: ~, port: 8080, https: false }
+apt::include_defaults: { deb: true, src: false }
+apt::ppa_options: ~
+apt::ppa_package: ~
+apt::backports: ~
diff --git a/hiera.yaml b/hiera.yaml
new file mode 100644 (file)
index 0000000..4bfe502
--- /dev/null
@@ -0,0 +1,22 @@
+---
+version: 4
+datadir: data
+hierarchy:
+  - name: "Full Version"
+    backend: yaml
+    path: "%{facts.os.name}-%{facts.os.release.full}"
+
+  - name: "Major Version"
+    backend: yaml
+    path: "%{facts.os.name}-%{facts.os.release.major}"
+
+  - name: "Distribution Name"
+    backend: yaml
+    path: "%{facts.os.name}"
+
+  - name: "Operating System Family"
+    backend: yaml
+    path: "%{facts.os.family}"
+
+  - name: "common"
+    backend: yaml
index f7e85f59ed9744fdaaaa8ce7b46d9b788e23ce60..06165b6c2210433522beb0804378861630bfd902 100644 (file)
@@ -1,34 +1,34 @@
 class apt::backports (
-  $location = undef,
-  $release  = undef,
-  $repos    = undef,
-  $key      = undef,
-  $pin      = 200,
+  Optional[Variant[String, Stdlib::Compat::String]] $location = undef,
+  Optional[Variant[String, Stdlib::Compat::String]] $release = undef,
+  Optional[Variant[String, Stdlib::Compat::String]] $repos = undef,
+  Optional[Variant[String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $key = undef,
+  Optional[Variant[Integer, Stdlib::Compat::Integer, String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $pin  = 200,
 ){
   if $location {
-    validate_string($location)
+    validate_legacy(String, 'validate_string', $location)
     $_location = $location
   }
   if $release {
-    validate_string($release)
+    validate_legacy(String, 'validate_string', $release)
     $_release = $release
   }
   if $repos {
-    validate_string($repos)
+    validate_legacy(String, 'validate_string', $repos)
     $_repos = $repos
   }
   if $key {
     unless is_hash($key) {
-      validate_string($key)
+      validate_legacy(String, 'validate_string', $key)
     }
     $_key = $key
   }
-  if ($::apt::xfacts['lsbdistid'] == 'debian' or $::apt::xfacts['lsbdistid'] == 'ubuntu') {
+  if ($facts['lsbdistid'] == 'Debian' or $facts['lsbdistid'] == 'Ubuntu') {
     unless $location {
       $_location = $::apt::backports['location']
     }
     unless $release {
-      $_release = "${::apt::xfacts['lsbdistcodename']}-backports"
+      $_release = "${facts['lsbdistcodename']}-backports"
     }
     unless $repos {
       $_repos = $::apt::backports['repos']
index 8cd9c64e7841064ffa5c92e451daba8a48dd3090..364cae383ce346a86d00524763a5a09c1caa35b0 100644 (file)
@@ -1,8 +1,8 @@
 define apt::conf (
-  $content       = undef,
-  $ensure        = present,
-  $priority      = 50,
-  $notify_update = undef,
+  Optional[Variant[String, Stdlib::Compat::String]] $content                          = undef,
+  Enum['present', 'absent'] $ensure                                                   = present,
+  Variant[String, Stdlib::Compat::String, Integer, Stdlib::Compat::Integer] $priority = 50,
+  Optional[Boolean] $notify_update                                                    = undef,
 ) {
 
   unless $ensure == 'absent' {
@@ -11,10 +11,11 @@ define apt::conf (
     }
   }
 
+  $confheadertmp = epp('apt/_conf_header.epp')
   apt::setting { "conf-${name}":
     ensure        => $ensure,
     priority      => $priority,
-    content       => template('apt/_conf_header.erb', 'apt/conf.erb'),
+    content       => "${confheadertmp}${content}",
     notify_update => $notify_update,
   }
 }
index 5664edeed5220192b10bc1b0974e8ab98f557d78..40a40aff07650e457eabd3d56d1960f33176607a 100644 (file)
@@ -3,19 +3,40 @@
 # Manage APT (Advanced Packaging Tool)
 #
 class apt (
-  $confs    = {},
-  $update   = {},
-  $purge    = {},
-  $proxy    = {},
-  $sources  = {},
-  $keys     = {},
-  $ppas     = {},
-  $pins     = {},
-  $settings = {},
-) inherits ::apt::params {
+  Variant[Hash, Stdlib::Compat::Hash] $update_defaults,
+  Variant[Hash, Stdlib::Compat::Hash] $purge_defaults,
+  Variant[Hash, Stdlib::Compat::Hash] $proxy_defaults,
+  Variant[Hash, Stdlib::Compat::Hash] $include_defaults,
+  Variant[String, Stdlib::Compat::String] $provider,
+  Variant[String, Stdlib::Compat::String] $keyserver,
+  Optional[Variant[String, Stdlib::Compat::String]] $ppa_options,
+  Optional[Variant[String, Stdlib::Compat::String]] $ppa_package,
+  Optional[Variant[Hash, Stdlib::Compat::Hash]] $backports,
+  Variant[Hash, Stdlib::Compat::Hash] $confs                = {},
+  Variant[Hash, Stdlib::Compat::Hash] $update               = {},
+  Variant[Hash, Stdlib::Compat::Hash] $purge                = {},
+  Variant[Hash, Stdlib::Compat::Hash] $proxy                = {},
+  Variant[Hash, Stdlib::Compat::Hash] $sources              = {},
+  Variant[Hash, Stdlib::Compat::Hash] $keys                 = {},
+  Variant[Hash, Stdlib::Compat::Hash] $ppas                 = {},
+  Variant[Hash, Stdlib::Compat::Hash] $pins                 = {},
+  Variant[Hash, Stdlib::Compat::Hash] $settings             = {},
+  Variant[String, Stdlib::Compat::String] $root             = '/etc/apt',
+  Variant[String, Stdlib::Compat::String] $sources_list     = "${root}/sources.list",
+  Variant[String, Stdlib::Compat::String] $sources_list_d   = "${root}/sources.list.d",
+  Variant[String, Stdlib::Compat::String] $conf_d           = "${root}/apt.conf.d",
+  Variant[String, Stdlib::Compat::String] $preferences      = "${root}/preferences",
+  Variant[String, Stdlib::Compat::String] $preferences_d    = "${root}/preferences.d",
+  Variant[Hash, Stdlib::Compat::Hash] $config_files         = { conf => { path => $conf_d, ext => '' }, pref => { path => $preferences_d, ext => '.pref' }, list => { path => $sources_list_d, ext => '.list' } },
+  Variant[Hash, Stdlib::Compat::Hash] $source_key_defaults  = { 'server' => $keyserver, 'options' => undef, 'content' => undef, 'source' => undef },
+) {
+
+  if $facts['osfamily'] != 'Debian' {
+    fail('This module only works on Debian or derivatives like Ubuntu')
+  }
 
   $frequency_options = ['always','daily','weekly','reluctantly']
-  validate_hash($update)
+  validate_legacy(Hash, 'validate_hash', $update)
   if $update['frequency'] {
     validate_re($update['frequency'], $frequency_options)
   }
@@ -33,18 +54,18 @@ class apt (
   $_update = merge($::apt::update_defaults, $update)
   include ::apt::update
 
-  validate_hash($purge)
+  validate_legacy(Hash, 'validate_hash', $purge)
   if $purge['sources.list'] {
-    validate_bool($purge['sources.list'])
+    validate_legacy(Boolean, 'validate_bool', $purge['sources.list'])
   }
   if $purge['sources.list.d'] {
-    validate_bool($purge['sources.list.d'])
+    validate_legacy(Boolean, 'validate_bool', $purge['sources.list.d'])
   }
   if $purge['preferences'] {
-    validate_bool($purge['preferences'])
+    validate_legacy(Boolean, 'validate_bool', $purge['preferences'])
   }
   if $purge['preferences.d'] {
-    validate_bool($purge['preferences.d'])
+    validate_legacy(Boolean, 'validate_bool', $purge['preferences.d'])
   }
 
   $_purge = merge($::apt::purge_defaults, $purge)
@@ -54,7 +75,7 @@ class apt (
     validate_re($proxy['ensure'], ['file', 'present', 'absent'])
   }
   if $proxy['host'] {
-    validate_string($proxy['host'])
+    validate_legacy(String, 'validate_string', $proxy['host'])
   }
   if $proxy['port'] {
     unless is_integer($proxy['port']) {
@@ -62,23 +83,27 @@ class apt (
     }
   }
   if $proxy['https'] {
-    validate_bool($proxy['https'])
+    validate_legacy(Boolean, 'validate_bool', $proxy['https'])
   }
 
   $_proxy = merge($apt::proxy_defaults, $proxy)
 
-  validate_hash($confs)
-  validate_hash($sources)
-  validate_hash($keys)
-  validate_hash($settings)
-  validate_hash($ppas)
-  validate_hash($pins)
+  validate_legacy(Hash, 'validate_hash', $confs)
+  validate_legacy(Hash, 'validate_hash', $sources)
+  validate_legacy(Hash, 'validate_hash', $keys)
+  validate_legacy(Hash, 'validate_hash', $settings)
+  validate_legacy(Hash, 'validate_hash', $ppas)
+  validate_legacy(Hash, 'validate_hash', $pins)
+
+  $confheadertmp = epp('apt/_conf_header.epp')
+  $proxytmp = epp('apt/proxy.epp', {'proxies' => $_proxy})
+  $updatestamptmp = epp('apt/15update-stamp.epp')
 
   if $_proxy['ensure'] == 'absent' or $_proxy['host'] {
     apt::setting { 'conf-proxy':
       ensure   => $_proxy['ensure'],
       priority => '01',
-      content  => template('apt/_conf_header.erb', 'apt/proxy.erb'),
+      content  => "${confheadertmp}${proxytmp}",
     }
   }
 
@@ -100,7 +125,7 @@ class apt (
 
   apt::setting { 'conf-update-stamp':
     priority => 15,
-    content  => template('apt/_conf_header.erb', 'apt/15update-stamp.erb'),
+    content  => "${confheadertmp}${updatestamptmp}",
   }
 
   file { 'sources.list':
index d4a1d802adfa75089417362dd56fb15bf45e1228..9a244b5065ac049c58722fb8e56e8fb6258f1669 100644 (file)
@@ -1,17 +1,17 @@
 # == Define: apt::key
 define apt::key (
-  $id          = $title,
-  $ensure      = present,
-  $content     = undef,
-  $source      = undef,
-  $server      = $::apt::keyserver,
-  $options     = undef,
-  $key         = undef,
-  $key_content = undef,
-  $key_source  = undef,
-  $key_server  = undef,
-  $key_options = undef,
-) {
+    Variant[String, Stdlib::Compat::String] $id                                         = $title,
+    Enum['present', 'absent'] $ensure                                                   = present,
+    Optional[Variant[String, Stdlib::Compat::String]] $content                          = undef,
+    Optional[Variant[String, Stdlib::Compat::String]] $source                           = undef,
+    Variant[String, Stdlib::Compat::String] $server                                     = $::apt::keyserver,
+    Optional[Variant[String, Stdlib::Compat::String]] $options                          = undef,
+    Optional[Variant[String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $key  = undef,
+    Optional[Variant[String, Stdlib::Compat::String]] $key_content                      = undef,
+    Optional[Variant[String, Stdlib::Compat::String]] $key_source                       = undef,
+    Optional[Variant[String, Stdlib::Compat::String]] $key_server                       = undef,
+    Optional[Variant[String, Stdlib::Compat::String]] $key_options                      = undef,
+    ) {
 
   if $key != undef {
     deprecation('apt $key', '$key is deprecated and will be removed in the next major release. Please use $id instead.')
@@ -52,7 +52,7 @@ define apt::key (
   validate_re($ensure, ['\A(absent|present)\Z',])
 
   if $_content {
-    validate_string($_content)
+    validate_legacy(String, 'validate_string', $_content)
   }
 
   if $_source {
@@ -64,7 +64,7 @@ define apt::key (
   }
 
   if $_options {
-    validate_string($_options)
+    validate_legacy(String, 'validate_string', $_options)
   }
 
   case $ensure {
@@ -81,8 +81,7 @@ define apt::key (
           content => $_content,
           server  => $_server,
           options => $_options,
-        }
-        -> anchor { "apt_key ${_id} present": }
+        } -> anchor { "apt_key ${_id} present": }
       }
     }
 
@@ -99,8 +98,7 @@ define apt::key (
           content => $_content,
           server  => $_server,
           options => $_options,
-        }
-        -> anchor { "apt_key ${_id} absent": }
+        } -> anchor { "apt_key ${_id} absent": }
       }
     }
 
diff --git a/manifests/params.pp b/manifests/params.pp
deleted file mode 100644 (file)
index ea1087e..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-class apt::params {
-
-  if $::osfamily != 'Debian' {
-    fail('This module only works on Debian or derivatives like Ubuntu')
-  }
-
-  # prior to puppet 3.5.0, defined() couldn't test if a variable was defined.
-  # strict_variables wasn't added until 3.5.0, so this should be fine.
-  if $::puppetversion and versioncmp($::puppetversion, '3.5.0') < 0 {
-    $xfacts = {
-      'lsbdistcodename'     => $::lsbdistcodename,
-      'lsbdistrelease'      => $::lsbdistrelease,
-      'lsbdistid'           => $::lsbdistid,
-    }
-  } else {
-    # Strict variables facts lookup compatibility
-    $xfacts = {
-      'lsbdistcodename' => defined('$lsbdistcodename') ? {
-        true    => $::lsbdistcodename,
-        default => undef,
-      },
-      'lsbdistrelease' => defined('$lsbdistrelease') ? {
-        true    => $::lsbdistrelease,
-        default => undef,
-      },
-      'lsbdistid' => defined('$lsbdistid') ? {
-        true    => $::lsbdistid,
-        default => undef,
-      },
-    }
-  }
-
-  $root           = '/etc/apt'
-  $provider       = '/usr/bin/apt-get'
-  $sources_list   = "${root}/sources.list"
-  $sources_list_d = "${root}/sources.list.d"
-  $conf_d         = "${root}/apt.conf.d"
-  $preferences    = "${root}/preferences"
-  $preferences_d  = "${root}/preferences.d"
-  $keyserver      = 'keyserver.ubuntu.com'
-
-  $config_files = {
-    'conf'   => {
-      'path' => $conf_d,
-      'ext'  => '',
-    },
-    'pref'   => {
-      'path' => $preferences_d,
-      'ext'  => '.pref',
-    },
-    'list'   => {
-      'path' => $sources_list_d,
-      'ext'  => '.list',
-    }
-  }
-
-  $update_defaults = {
-    'frequency' => 'reluctantly',
-    'timeout'   => undef,
-    'tries'     => undef,
-  }
-
-  $proxy_defaults = {
-    'ensure' => undef,
-    'host'   => undef,
-    'port'   => 8080,
-    'https'  => false,
-  }
-
-  $purge_defaults = {
-    'sources.list'   => false,
-    'sources.list.d' => false,
-    'preferences'    => false,
-    'preferences.d'  => false,
-  }
-
-  $source_key_defaults = {
-    'server'  => $keyserver,
-    'options' => undef,
-    'content' => undef,
-    'source'  => undef,
-  }
-
-  $include_defaults = {
-    'deb' => true,
-    'src' => false,
-  }
-
-  case $xfacts['lsbdistid'] {
-    'debian': {
-      case $xfacts['lsbdistcodename'] {
-        'squeeze': {
-          $backports = {
-            'location' => 'http://httpredir.debian.org/debian-backports',
-            'key'      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
-            'repos'    => 'main contrib non-free',
-          }
-        }
-        default: {
-          $backports = {
-            'location' => 'http://httpredir.debian.org/debian',
-            'key'      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
-            'repos'    => 'main contrib non-free',
-          }
-        }
-      }
-
-      $ppa_options = undef
-      $ppa_package = undef
-
-    }
-    'ubuntu': {
-      $backports = {
-        'location' => 'http://archive.ubuntu.com/ubuntu',
-        'key'      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
-        'repos'    => 'main universe multiverse restricted',
-      }
-
-      if $xfacts['lsbdistcodename'] == 'lucid' {
-          $ppa_options        = undef
-          $ppa_package        = 'python-software-properties'
-      } elsif $xfacts['lsbdistcodename'] == 'precise' {
-          $ppa_options        = '-y'
-          $ppa_package        = 'python-software-properties'
-      } elsif versioncmp($xfacts['lsbdistrelease'], '14.04') >= 0 {
-          $ppa_options        = '-y'
-          $ppa_package        = 'software-properties-common'
-      } else {
-          $ppa_options        = '-y'
-          $ppa_package        = 'python-software-properties'
-      }
-    }
-    undef: {
-      fail('Unable to determine lsbdistid, please install lsb-release first')
-    }
-    default: {
-      $ppa_options = undef
-      $ppa_package = undef
-      $backports   = undef
-    }
-  }
-}
index dff2c297c0c08b3d6f353e69a1d88732dbc904a2..5b9dc1d408e2daf8068c70a046c5e9d0074f5f9e 100644 (file)
@@ -2,23 +2,20 @@
 # pin a release in apt, useful for unstable repositories
 
 define apt::pin(
-  $ensure          = present,
-  $explanation     = undef,
-  $order           = 50,
-  $packages        = '*',
-  $priority        = 0,
-  $release         = '', # a=
-  $origin          = '',
-  $version         = '',
-  $codename        = '', # n=
-  $release_version = '', # v=
-  $component       = '', # c=
-  $originator      = '', # o=
-  $label           = ''  # l=
+  Optional[Enum['file', 'present', 'absent']] $ensure                             = present,
+  Optional[Variant[String, Stdlib::Compat::String]] $explanation                  = undef,
+  Variant[Integer,  Stdlib::Compat::Integer] $order                               = 50,
+  Variant[String, Stdlib::Compat::String, Stdlib::Compat::Array, Array] $packages = '*',
+  Variant[Numeric, String, Stdlib::Compat::String] $priority                      = 0,
+  Optional[Variant[String, Stdlib::Compat::String]] $release                      = '', # a=
+  Optional[Variant[String, Stdlib::Compat::String]] $origin                       = '',
+  Optional[Variant[String, Stdlib::Compat::String]] $version                      = '',
+  Optional[Variant[String, Stdlib::Compat::String]] $codename                     = '', # n=
+  Optional[Variant[String, Stdlib::Compat::String]] $release_version              = '', # v=
+  Optional[Variant[String, Stdlib::Compat::String]] $component                    = '', # c=
+  Optional[Variant[String, Stdlib::Compat::String]] $originator                   = '', # o=
+  Optional[Variant[String, Stdlib::Compat::String]] $label                        = '',  # l=
 ) {
-  if $order and !is_integer($order) {
-    fail('Only integers are allowed in the apt::pin order param')
-  }
 
   if $explanation {
     $_explanation = $explanation
@@ -36,7 +33,8 @@ define apt::pin(
     $release_version,
     $component,
     $originator,
-    $label]
+    $label,
+  ]
   $pin_release = join($pin_release_array, '')
 
   # Read the manpage 'apt_preferences(5)', especially the chapter
@@ -71,10 +69,28 @@ define apt::pin(
   # be silently ignored.
   $file_name = regsubst($title, '[^0-9a-z\-_\.]', '_', 'IG')
 
+  $headertmp = epp('apt/_header.epp')
+
+  $pinpreftmp = epp('apt/pin.pref.epp', {
+      'name'            => $name,
+      'pin_release'     => $pin_release,
+      'release'         => $release,
+      'codename'        => $codename,
+      'release_version' => $release_version,
+      'component'       => $component,
+      'originator'      => $originator,
+      'label'           => $label,
+      'version'         => $version,
+      'origin'          => $origin,
+      'explanation'     => $_explanation,
+      'packages_string' => $packages_string,
+      'priority'        => $priority,
+  })
+
   apt::setting { "pref-${file_name}":
     ensure        => $ensure,
     priority      => $order,
-    content       => template('apt/_header.erb', 'apt/pin.pref.erb'),
+    content       => "${headertmp}${pinpreftmp}",
     notify_update => false,
   }
 }
index 6b025d7a72bea1ff2fb18701cc9d481375bd4560..adce47cae0645fdc4e7ef87ed88740a96bae8c27 100644 (file)
@@ -1,21 +1,21 @@
 # ppa.pp
 define apt::ppa(
-  $ensure         = 'present',
-  $options        = $::apt::ppa_options,
-  $release        = $::apt::xfacts['lsbdistcodename'],
-  $package_name   = $::apt::ppa_package,
-  $package_manage = false,
+  Variant[String, Stdlib::Compat::String] $ensure                 = 'present',
+  Optional[Variant[String, Stdlib::Compat::String]] $options      = $::apt::ppa_options,
+  Optional[Variant[String, Stdlib::Compat::String]] $release      = $facts['lsbdistcodename'],
+  Optional[Variant[String, Stdlib::Compat::String]] $package_name = $::apt::ppa_package,
+  Boolean $package_manage                                         = false,
 ) {
   unless $release {
     fail('lsbdistcodename fact not available: release parameter required')
   }
 
-  if $::apt::xfacts['lsbdistid'] == 'Debian' {
+  if $facts['lsbdistid'] == 'Debian' {
     fail('apt::ppa is not currently supported on Debian.')
   }
 
-  if versioncmp($::apt::xfacts['lsbdistrelease'], '15.10') >= 0 {
-    $distid = downcase($::apt::xfacts['lsbdistid'])
+  if versioncmp($facts['lsbdistrelease'], '15.10') >= 0 {
+    $distid = downcase($facts['lsbdistid'])
     $filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2-${release}")
   } else {
     $filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2-${release}")
@@ -28,7 +28,6 @@ define apt::ppa(
   if $ensure == 'present' {
     if $package_manage {
       ensure_packages($package_name)
-
       $_require = [File['sources.list.d'], Package[$package_name]]
     } else {
       $_require = File['sources.list.d']
index b0fb62b1debd8fb5d90c1f86cb0f0bdc5e778a7f..123bb2f70e29e9c2c559c1c3fd455e252b39863b 100644 (file)
@@ -1,12 +1,12 @@
 define apt::setting (
-  $priority      = 50,
-  $ensure        = file,
-  $source        = undef,
-  $content       = undef,
-  $notify_update = true,
+  Variant[String, Stdlib::Compat::String, Integer, Stdlib::Compat::Integer, Array, Stdlib::Compat::Array] $priority = 50,
+  Optional[Enum['file', 'present', 'absent']] $ensure                                                               = file,
+  Optional[Variant[String, Stdlib::Compat::String]] $source                                                         = undef,
+  Optional[Variant[String, Stdlib::Compat::String]] $content                                                        = undef,
+  Optional[Boolean] $notify_update                                                                                  = true,
+
 ) {
 
-  include 'apt::params'
   if $content and $source {
     fail('apt::setting cannot have both content and source')
   }
@@ -15,8 +15,9 @@ define apt::setting (
     fail('apt::setting needs either of content or source')
   }
 
-  validate_re($ensure,  ['file', 'present', 'absent'])
-  validate_bool($notify_update)
+  if $notify_update {
+    validate_legacy(Boolean, 'validate_bool', $notify_update)
+  }
 
   $title_array = split($title, '-')
   $setting_type = $title_array[0]
@@ -30,11 +31,11 @@ define apt::setting (
   }
 
   if $source {
-    validate_string($source)
+    validate_legacy(String, 'validate_string', $source)
   }
 
   if $content {
-    validate_string($content)
+    validate_legacy(String, 'validate_string', $content)
   }
 
   if ($setting_type == 'list') or ($setting_type == 'pref') {
@@ -43,8 +44,8 @@ define apt::setting (
     $_priority = $priority
   }
 
-  $_path = $::apt::params::config_files[$setting_type]['path']
-  $_ext  = $::apt::params::config_files[$setting_type]['ext']
+  $_path = $::apt::config_files[$setting_type]['path']
+  $_ext  = $::apt::config_files[$setting_type]['ext']
 
   if $notify_update {
     $_notify = Class['apt::update']
index 5b8e4b18ce36eb2e5ab20a115c83434c9fe17677..8db3b28ef12457c501f498017372fe4cd6720458 100644 (file)
@@ -1,46 +1,39 @@
 # source.pp
 # add an apt source
 define apt::source(
-  $location          = undef,
-  $comment           = $name,
-  $ensure            = present,
-  $release           = undef,
-  $repos             = 'main',
-  $include           = {},
-  $key               = undef,
-  $pin               = undef,
-  $architecture      = undef,
-  $allow_unsigned    = false,
-  $include_src       = undef,
-  $include_deb       = undef,
-  $required_packages = undef,
-  $key_server        = undef,
-  $key_content       = undef,
-  $key_source        = undef,
-  $trusted_source    = undef,
-  $notify_update     = true,
+  Optional[Variant[String, Stdlib::Compat::String]] $location                         = undef,
+  Variant[String, Stdlib::Compat::String] $comment                                    = $name,
+  Variant[String, Stdlib::Compat::String] $ensure                                     = present,
+  Optional[Variant[String, Stdlib::Compat::String]] $release                          = undef,
+  Variant[String, Stdlib::Compat::String] $repos                                      = 'main',
+  Optional[Variant[Hash, Stdlib::Compat::Hash]] $include                              = {},
+  Optional[Variant[String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $key  = undef,
+  $pin                                                                                = undef,
+  Optional[Variant[String, Stdlib::Compat::String]] $architecture                     = undef,
+  Boolean $allow_unsigned                                                             = false,
+  Boolean $notify_update                                                              = true,
+  Optional[Variant[String, Stdlib::Compat::String]] $key_server                       = undef,
+  Optional[Variant[String, Stdlib::Compat::String]] $key_content                      = undef,
+  Optional[Variant[String, Stdlib::Compat::String]] $key_source                       = undef,
+  Optional[Boolean] $include_src                                                      = undef,
+  Optional[Boolean] $include_deb                                                      = undef,
+  $required_packages                                                                  = undef,
+  $trusted_source                                                                     = undef,
 ) {
-  validate_string($architecture, $comment, $location, $repos)
-  validate_bool($allow_unsigned)
-  validate_hash($include)
+
+  validate_legacy(String, 'validate_string', $architecture, $comment, $location, $repos)
+  validate_legacy(Boolean, 'validate_bool', $allow_unsigned)
+  validate_legacy(Hash, 'validate_hash', $include)
 
   # This is needed for compat with 1.8.x
   include ::apt
 
   $_before = Apt::Setting["list-${title}"]
 
-  if $include_src != undef {
-    deprecation('apt $include_src', "\$include_src is deprecated and will be removed in the next major release, please use \$include => { 'src' => ${include_src} } instead")
-  }
-
-  if $include_deb != undef {
-    deprecation('apt $include_deb', "\$include_deb is deprecated and will be removed in the next major release, please use \$include => { 'deb' => ${include_deb} } instead")
-  }
-
   if $required_packages != undef {
     deprecation('apt $required_packages', '$required_packages is deprecated and will be removed in the next major release, please use package resources instead.')
     exec { "Required packages: '${required_packages}' for ${name}":
-      command     => "${::apt::params::provider} -y install ${required_packages}",
+      command     => "${::apt::provider} -y install ${required_packages}",
       logoutput   => 'on_failure',
       refreshonly => true,
       tries       => 3,
@@ -49,18 +42,6 @@ define apt::source(
     }
   }
 
-  if $key_server != undef {
-    deprecation('apt $key_server', "\$key_server is deprecated and will be removed in the next major release, please use \$key => { 'server' => ${key_server} } instead.")
-  }
-
-  if $key_content != undef {
-    deprecation('apt $key_content', "\$key_content is deprecated and will be removed in the next major release, please use \$key => { 'content' => ${key_content} } instead.")
-  }
-
-  if $key_source != undef {
-    deprecation('apt $key_source', "\$key_source is deprecated and will be removed in the next major release, please use \$key => { 'source' => ${key_source} } instead.")
-  }
-
   if $trusted_source != undef {
     deprecation('apt $trusted_source', '$trusted_source is deprecated and will be removed in the next major release, please use $allow_unsigned instead.')
     $_allow_unsigned = $trusted_source
@@ -69,8 +50,9 @@ define apt::source(
   }
 
   if ! $release {
-    $_release = $::apt::params::xfacts['lsbdistcodename']
-    unless $_release {
+    if $facts['lsbdistcodename'] {
+      $_release = $facts['lsbdistcodename']
+    } else {
       fail('lsbdistcodename fact not available: release parameter required')
     }
   } else {
@@ -94,7 +76,7 @@ define apt::source(
     $_deprecated_include = {}
   }
 
-  $_include = merge($::apt::params::include_defaults, $_deprecated_include, $include)
+  $includes = merge($::apt::include_defaults, $_deprecated_include, $include)
 
   $_deprecated_key = {
     'key_server'  => $key_server,
@@ -107,16 +89,28 @@ define apt::source(
       unless $key['id'] {
         fail('key hash must contain at least an id entry')
       }
-      $_key = merge($::apt::params::source_key_defaults, $_deprecated_key, $key)
+      $_key = merge($::apt::source_key_defaults, $_deprecated_key, $key)
     } else {
-      validate_string($key)
+      validate_legacy(String, 'validate_string', $key)
       $_key = merge( { 'id' => $key }, $_deprecated_key)
     }
   }
 
+  $header = epp('apt/_header.epp')
+
+  $sourcelist = epp('apt/source.list.epp', {
+    'comment'        => $comment,
+    'includes'       => $includes,
+    'architecture'   => $architecture,
+    'allow_unsigned' => $_allow_unsigned,
+    'location'       => $location,
+    'release'        => $_release,
+    'repos'          => $repos,
+  })
+
   apt::setting { "list-${name}":
     ensure        => $ensure,
-    content       => template('apt/_header.erb', 'apt/source.list.erb'),
+    content       => "${header}${sourcelist}",
     notify_update => $notify_update,
   }
 
index 4f3875b5d1389d87e2253580068a3ffe281fec11..c4f9bb7cf9708488c3a7750ef0537b5172e2cf6d 100644 (file)
@@ -1,6 +1,6 @@
 {
   "name": "puppetlabs-apt",
-  "version": "2.4.0",
+  "version": "3.0.0",
   "author": "Puppet Labs",
   "summary": "Provides an interface for managing Apt source, key, and definitions with Puppet",
   "license": "Apache-2.0",
@@ -8,8 +8,9 @@
   "project_page": "https://github.com/puppetlabs/puppetlabs-apt",
   "issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
   "dependencies": [
-    {"name":"puppetlabs/stdlib","version_requirement":">= 4.13.0 < 5.0.0"}
+    {"name":"puppetlabs/stdlib","version_requirement":">= 4.16.0 < 5.0.0"}
   ],
+  "data_provider": "hiera",
   "operatingsystem_support": [
     {
       "operatingsystem": "Debian",
@@ -32,7 +33,7 @@
   "requirements": [
     {
       "name": "puppet",
-      "version_requirement": ">= 3.0.0 < 5.0.0"
+      "version_requirement": ">= 4.7.0 < 5.0.0"
     }
   ]
 }
index 5762025eaff44ad5002bc3d58e7ad983f4589084..5c65b57fdc43c34d2973adfbaeb171280edf8835 100644 (file)
@@ -7,6 +7,7 @@ describe 'apt::backports', :type => :class do
     context 'defaults on deb' do
       let(:facts) do
         {
+          :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
           :lsbdistid       => 'Debian',
           :osfamily        => 'Debian',
           :lsbdistcodename => 'wheezy',
@@ -25,6 +26,7 @@ describe 'apt::backports', :type => :class do
     context 'defaults on squeeze' do
       let(:facts) do
         {
+          :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '6', :full => '6.0' }},
           :lsbdistid       => 'Debian',
           :osfamily        => 'Debian',
           :lsbdistcodename => 'squeeze',
@@ -43,6 +45,7 @@ describe 'apt::backports', :type => :class do
     context 'defaults on ubuntu' do
       let(:facts) do
         {
+          :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
           :lsbdistid       => 'Ubuntu',
           :osfamily        => 'Debian',
           :lsbdistcodename => 'trusty',
@@ -90,6 +93,7 @@ describe 'apt::backports', :type => :class do
     context 'set things with hashes' do
       let(:facts) do
         {
+          :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
           :lsbdistid       => 'Ubuntu',
           :osfamily        => 'Debian',
           :lsbdistcodename => 'trusty',
@@ -217,7 +221,7 @@ describe 'apt::backports', :type => :class do
       it do
         expect {
           subject.call
-        }.to raise_error(Puppet::Error, /is not a string/)
+        }.to raise_error(Puppet::Error, /expects a String value/)
       end
     end
     context 'invalid release' do
@@ -229,7 +233,7 @@ describe 'apt::backports', :type => :class do
       it do
         expect {
           subject.call
-        }.to raise_error(Puppet::Error, /is not a string/)
+        }.to raise_error(Puppet::Error, /expects a String value/)
       end
     end
     context 'invalid repos' do
@@ -241,7 +245,7 @@ describe 'apt::backports', :type => :class do
       it do
         expect {
           subject.call
-        }.to raise_error(Puppet::Error, /is not a string/)
+        }.to raise_error(Puppet::Error, /expects a String value/)
       end
     end
     context 'invalid key' do
@@ -253,7 +257,7 @@ describe 'apt::backports', :type => :class do
       it do
         expect {
           subject.call
-        }.to raise_error(Puppet::Error, /is not a string/)
+        }.to raise_error(Puppet::Error, /expects a value of type String, Hash,/)
       end
     end
     context 'invalid pin' do
@@ -265,7 +269,7 @@ describe 'apt::backports', :type => :class do
       it do
         expect {
           subject.call
-        }.to raise_error(Puppet::Error, /pin must be either a string, number or hash/)
+        }.to raise_error(Puppet::Error, /parameter 'pin' expects a value of type Integer, Pattern/)
       end
     end
   end
index 53ef7bea49a1805ced7de19670db36464dd499b9..8ecf4185e1a4fc13b1dc14e27b93fedfe6f43ef5 100644 (file)
@@ -1,7 +1,12 @@
 require 'spec_helper'
 describe 'apt' do
-  let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version} }
-
+  let(:facts) do
+  { :lsbdistid       => 'Debian',
+    :osfamily        => 'Debian',
+    :lsbdistcodename => 'wheezy',
+    :puppetversion   => Puppet.version,
+  }
+  end
   context 'defaults' do
     it { is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with({
       :ensure  => 'file',
@@ -137,9 +142,11 @@ describe 'apt' do
 
   context 'with sources defined on valid osfamily' do
     let :facts do
-      { :osfamily        => 'Debian',
+      { :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '12', :full => '12.04' }},
+        :osfamily        => 'Debian',
         :lsbdistcodename => 'precise',
-        :lsbdistid       => 'Debian',
+        :lsbdistid       => 'Ubuntu',
+        :lsbdistrelease  => '12.04',
         :puppetversion   => Puppet.version,
       }
     end
diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb
deleted file mode 100644 (file)
index 3161cf0..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-require 'spec_helper'
-describe 'apt::params', :type => :class do
-  let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version, } }
-
-  # There are 4 resources in this class currently
-  # there should not be any more resources because it is a params class
-  # The resources are class[apt::params], class[main], class[settings], stage[main]
-  it "Should not contain any resources" do
-    expect(subject.call.resources.size).to eq(4)
-  end
-
-  describe "With lsb-release not installed" do
-    let(:facts) { { :osfamily => 'Debian', :puppetversion => Puppet.version, } }
-    let (:title) { 'my_package' }
-
-    it do
-      expect {
-        subject.call
-      }.to raise_error(Puppet::Error, /Unable to determine lsbdistid, please install lsb-release first/)
-    end
-  end
-end
index eaf53fca45e495ccf0c52e44fae974ed3e6c3c97..02b97547400f774e532e97a33827eccee88e99df 100644 (file)
@@ -248,7 +248,7 @@ describe 'apt::key', :type => :define do
         :key_content => [],
       } end
       it 'fails' do
-        expect { subject.call }.to raise_error(/is not a string/)
+        expect { subject.call }.to raise_error(/expects a String value/)
       end
     end
 
@@ -266,7 +266,7 @@ describe 'apt::key', :type => :define do
         :key_options => {},
       } end
       it 'fails' do
-        expect { subject.call }.to raise_error(/is not a string/)
+        expect { subject.call }.to raise_error(/expects a String value/)
       end
     end
 
@@ -277,7 +277,7 @@ describe 'apt::key', :type => :define do
         }
       end
       it 'fails' do
-        expect { subject.call }.to raise_error(/does not match/)
+        expect { subject.call }.to raise_error(/a match for Enum\['absent', 'present'\], got 'foo'/)
       end
     end
 
index 1ebcfc7af0c655b2637e84f449b86190c062a39e..a7334d8115e2973b936940c2c908a9cd275ceb1e 100644 (file)
@@ -245,7 +245,7 @@ describe 'apt::key' do
         :content => [],
       } end
       it 'fails' do
-        expect { subject.call }.to raise_error(/is not a string/)
+        expect { subject.call }.to raise_error(/expects a String value/)
       end
     end
 
@@ -263,7 +263,7 @@ describe 'apt::key' do
         :options => {},
       } end
       it 'fails' do
-        expect { subject.call }.to raise_error(/is not a string/)
+        expect { subject.call }.to raise_error(/expects a String value/)
       end
     end
 
@@ -275,7 +275,7 @@ describe 'apt::key' do
           }
           end
         it 'fails' do
-          expect { subject.call }.to raise_error(/does not match/)
+          expect { subject.call }.to raise_error(/for Enum\['absent', 'present'\], got/)
         end
       end
     end
index 9fb28c66523ec3816c24d3b7de57b5115a4b9c49..550d89e4816b67cee6fe586b5c1a7c490448c355 100644 (file)
@@ -8,18 +8,16 @@ describe 'apt::pin', :type => :define do
 
   context 'defaults' do
     it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: \*\nPin: release a=my_pin\nPin-Priority: 0\n/)}
-    it { is_expected.to contain_apt__setting("pref-my_pin") }
   end
 
   context 'set version' do
     let :params do
       {
         'packages' => 'vim',
-        'version'  => '1',
+        'version'  => "1",
       }
     end
     it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: version 1\nPin-Priority: 0\n/)}
-    it { is_expected.to contain_apt__setting("pref-my_pin") }
   end
 
   context 'set origin' do
@@ -30,7 +28,6 @@ describe 'apt::pin', :type => :define do
       }
     end
     it { is_expected.to contain_apt__setting("pref-my_pin").with_content(/Explanation: : my_pin\nPackage: vim\nPin: origin test\nPin-Priority: 0\n/)}
-    it { is_expected.to contain_apt__setting("pref-my_pin") }
   end
 
   context 'not defaults' do
@@ -81,7 +78,7 @@ describe 'apt::pin', :type => :define do
       it do
         expect {
           subject.call
-        }.to raise_error(Puppet::Error, /Only integers are allowed/)
+        }.to raise_error(Puppet::Error, /expects a value of type Integer/)
       end
     end
 
index a4c30142e872b7edf17fe507933a9235967d5025..ae66087e88ada8af3afa81127b73590292ca9138 100644 (file)
@@ -7,6 +7,7 @@ describe 'apt::ppa' do
   describe 'defaults' do
     let :facts do
       {
+        :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }},
         :lsbdistrelease  => '11.04',
         :lsbdistcodename => 'natty',
         :operatingsystem => 'Ubuntu',
@@ -31,6 +32,7 @@ describe 'apt::ppa' do
   describe 'Ubuntu 15.10 sources.list filename' do
     let :facts do
       {
+        :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '15', :full => '15.10' }},
         :lsbdistrelease  => '15.10',
         :lsbdistcodename => 'wily',
         :operatingsystem => 'Ubuntu',
@@ -69,6 +71,7 @@ describe 'apt::ppa' do
     end
     let :facts do
       {
+        :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }},
         :lsbdistrelease  => '11.04',
         :lsbdistcodename => 'natty',
         :operatingsystem => 'Ubuntu',
@@ -104,6 +107,7 @@ describe 'apt::ppa' do
     end
     let :facts do
       {
+        :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }},
         :lsbdistrelease  => '11.04',
         :lsbdistcodename => 'natty',
         :operatingsystem => 'Ubuntu',
@@ -141,6 +145,7 @@ describe 'apt::ppa' do
     end
     let :facts do
       {
+        :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '11', :full => '11.04' }},
         :lsbdistrelease  => '11.04',
         :lsbdistcodename => 'natty',
         :operatingsystem => 'Ubuntu',
@@ -180,6 +185,7 @@ describe 'apt::ppa' do
     end
     let :facts do
       {
+        :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
         :lsbdistrelease  => '14.04',
         :lsbdistcodename => 'trusty',
         :operatingsystem => 'Ubuntu',
@@ -216,6 +222,7 @@ describe 'apt::ppa' do
     end
     let :facts do
       {
+        :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
         :lsbdistrelease  => '14.04',
         :lsbdistcodename => 'trusty',
         :operatingsystem => 'Ubuntu',
@@ -250,6 +257,7 @@ describe 'apt::ppa' do
     end
     let :facts do
       {
+        :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
         :lsbdistrelease  => '14.04',
         :lsbdistcodename => 'trusty',
         :operatingsystem => 'Ubuntu',
@@ -284,6 +292,7 @@ describe 'apt::ppa' do
     end
     let :facts do
       {
+        :os => { :family => 'Debian', :name => 'Ubuntu', :release => { :major => '14', :full => '14.04' }},
         :lsbdistrelease  => '14.04',
         :lsbdistcodename => 'trusty',
         :operatingsystem => 'Ubuntu',
index c0aad8e4601200c62061d085f401f1abaff33771..bf361fa5984626a7ba9dea73d146dfd5e9eec8c4 100644 (file)
@@ -2,7 +2,17 @@ require 'spec_helper'
 
 describe 'apt::setting' do
   let(:pre_condition) { 'class { "apt": }' }
-  let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => Puppet.version, } }
+  let :facts do
+    {
+      :os => { :distro => { :codename => 'wheezy' }, :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
+      :lsbdistrelease  => '7.0',
+      :lsbdistcodename => 'wheezy',
+      :operatingsystem => 'Debian',
+      :osfamily        => 'Debian',
+      :lsbdistid       => 'Debian',
+      :puppetversion   => Puppet.version,
+    }
+  end
   let(:title) { 'conf-teddybear' }
 
   let(:default_params) { { :content => 'di' } }
@@ -82,21 +92,21 @@ describe 'apt::setting' do
       let(:title) { 'ext-teddybear' }
       let(:params) { default_params }
       it do
-        expect { subject.call }.to raise_error(Puppet::Error, /must start with /)
+        expect { subject.call }.to raise_error(Puppet::Error, /must start with either/)
       end
     end
 
     context 'with ensure=banana' do
       let(:params) { default_params.merge({ :ensure => 'banana' }) }
       it do
-        expect { subject.call }.to raise_error(Puppet::Error, /"banana" does not /)
+        expect { subject.call }.to raise_error(Puppet::Error, /Enum\['absent', 'file', 'present'\], got 'banana'/)
       end
     end
 
     context 'with priority=1.2' do
       let(:params) { default_params.merge({ :priority => 1.2 }) }
       if Puppet::Util::Package.versioncmp(Puppet.version, '4.0') >= 0 || ENV["FUTURE_PARSER"] == 'yes'
-        it { is_expected.to compile.and_raise_error(/input needs to be a String/) }
+        it { is_expected.to compile.and_raise_error(/expects a value of type/) }
       else
         it { is_expected.to compile.and_raise_error(/priority must be an integer or a zero-padded integer/) }
       end
index bf6977a39dd0e0f4cf456bf890615f1010391bc2..b89a4f0d7c23286aec08d8836747df59eceea9b3 100644 (file)
@@ -15,9 +15,9 @@ describe 'apt::source' do
     context 'without location' do
       let :facts do
         {
-          :lsbdistid       => 'Debian',
-          :lsbdistcodename => 'wheezy',
+          :os => { :family => 'Debian' },
           :osfamily        => 'Debian',
+          :lsbdistcodename => 'wheezy',
           :puppetversion   => Puppet.version,
         }
       end
@@ -48,9 +48,12 @@ describe 'apt::source' do
   describe 'no defaults' do
     let :facts do
       {
+        :os => { :family => 'Debian', :name => 'Debian', :release => { :major => '7', :full => '7.0' }},
         :lsbdistid       => 'Debian',
         :lsbdistcodename => 'wheezy',
         :osfamily        => 'Debian',
+        :operatingsystem => 'Debian',
+        :lsbdistrelease  => '7.0',
         :puppetversion   => Puppet.version,
       }
     end
similarity index 100%
rename from templates/_header.erb
rename to templates/_header.epp
diff --git a/templates/conf.erb b/templates/conf.erb
deleted file mode 100644 (file)
index a35d1d4..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<%= @content -%>
diff --git a/templates/pin.pref.epp b/templates/pin.pref.epp
new file mode 100644 (file)
index 0000000..7991332
--- /dev/null
@@ -0,0 +1,26 @@
+<%- | $name, $pin_release, $release, $codename, $release_version, $component, $originator, $label, $version, $origin, $explanation, $packages_string, $priority | -%>
+<%-
+$pin =
+if $pin_release.length > 0 {
+  $options = [
+    if $release         { "a=${release}" },
+    if $codename        { "n=${codename}" },
+    if $release_version { "v=${release_version}"},
+    if $component       { "c=${component}" },
+    if $originator      { "o=${originator}" },
+    if $label           { "l=${label}" },
+    ].filter |$x| { $x != undef }
+   "release ${options.join(', ')}" }
+
+elsif $version and "${version}".length > 0 {
+   "version ${version}" }
+elsif $origin and $origin.length > 0 {
+   "origin ${origin}" }
+else {
+  "release a=${name}" #Default value
+}
+-%>
+Explanation: <%= $explanation %>
+Package: <%= $packages_string %>
+Pin: <%= $pin %>
+Pin-Priority: <%= $priority %>
diff --git a/templates/pin.pref.erb b/templates/pin.pref.erb
deleted file mode 100644 (file)
index 76936d7..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<%-
-@pin = "release a=#{@name}" # default value
-if @pin_release.length > 0
-  options = []
-  options.push("a=#{@release}") if @release.length > 0
-  options.push("n=#{@codename}") if @codename.length > 0
-  options.push("v=#{@release_version}") if @release_version.length > 0
-  options.push("c=#{@component}") if @component.length > 0
-  options.push("o=#{@originator}") if @originator.length > 0
-  options.push("l=#{@label}") if @label.length > 0
-  @pin = "release #{options.join(', ')}"
-elsif @version.length > 0
-  @pin = "version #{@version}"
-elsif @origin.length > 0
-  @pin = "origin #{@origin}"
-end
--%>
-Explanation: <%= @_explanation %>
-Package: <%= @packages_string %>
-Pin: <%= @pin %>
-Pin-Priority: <%= @priority %>
diff --git a/templates/proxy.epp b/templates/proxy.epp
new file mode 100644 (file)
index 0000000..0cbccb8
--- /dev/null
@@ -0,0 +1,5 @@
+<%- | Hash $proxies | -%>
+Acquire::http::proxy "http://<%= $proxies['host'] %>:<%= $proxies['port'] %>/";
+<%- if $proxies['https'] { %>
+Acquire::https::proxy "https://<%= $proxies['host'] %>:<%= $proxies['port'] %>/";
+<%- } -%>
diff --git a/templates/proxy.erb b/templates/proxy.erb
deleted file mode 100644 (file)
index 670e3a7..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-Acquire::http::proxy "http://<%= @_proxy['host'] %>:<%= @_proxy['port'] %>/";
-<%- if @_proxy['https'] %>
-Acquire::https::proxy "https://<%= @_proxy['host'] %>:<%= @_proxy['port'] %>/";
-<%- end -%>
diff --git a/templates/source.list.epp b/templates/source.list.epp
new file mode 100644 (file)
index 0000000..727766c
--- /dev/null
@@ -0,0 +1,10 @@
+<%- | String $comment, Hash $includes, $architecture, Boolean $allow_unsigned, $location, $release, String $repos | -%>
+# <%= $comment %>
+<%- if $includes['deb'] { -%>
+deb <%- if ($architecture or $allow_unsigned) {-%>
+ [<%- if ($architecture) {%>arch=<%= $architecture %><% } %><%if ($architecture and $allow_unsigned) {%> <% }%><% if ($allow_unsigned) {%>trusted=yes<% } %>] <%- } %> <%= $location %> <%= $release %> <%= $repos %>
+<%- } -%>
+<%- if $includes['src'] { -%>
+deb-src <%- if $architecture or $allow_unsigned { -%>
+ [<%- if ($architecture) {%>arch=<%= $architecture %><% } %><%if ($architecture and $allow_unsigned) {%> <% }%><% if ($allow_unsigned) {%>trusted=yes<% } %>] <%- } %> <%= $location %> <%= $release %> <%= $repos %>
+<%- } -%>
diff --git a/templates/source.list.erb b/templates/source.list.erb
deleted file mode 100644 (file)
index 84cd2cf..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-# <%= @comment %>
-<%- if @_include['deb'] then -%>
-deb <%- if @architecture or @_allow_unsigned -%>
-[<%- if @architecture %>arch=<%= @architecture %><% end %><%if @architecture and @_allow_unsigned %> <% end%><% if @_allow_unsigned %>trusted=yes<% end %>] <%- end %><%= @location %> <%= @_release %> <%= @repos %>
-<%- end -%>
-<%- if @_include['src'] then -%>
-deb-src <%- if @architecture or @_allow_unsigned -%>
-[<%- if @architecture %>arch=<%= @architecture %><% end %><%if @architecture and @_allow_unsigned %> <% end%><% if @_allow_unsigned %>trusted=yes<% end %>] <%- end %><%= @location %> <%= @_release %> <%= @repos %>
-<%- end -%>