]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Merge pull request #711 from icann-dns/fix_legacy_functions
authorEric Putnam <putnam.eric@gmail.com>
Fri, 27 Oct 2017 20:58:50 +0000 (13:58 -0700)
committerGitHub <noreply@github.com>
Fri, 27 Oct 2017 20:58:50 +0000 (13:58 -0700)
remove legacy functions

manifests/backports.pp
manifests/init.pp
manifests/key.pp
manifests/pin.pp
manifests/setting.pp
manifests/source.pp
spec/defines/key_compat_spec.rb
spec/defines/key_spec.rb
spec/defines/source_spec.rb

index 4faad6157a7f31664555471071c211e177e56ce2..afd4ee1c2f67077c851fb06ed694f789e1f660ee 100644 (file)
@@ -36,9 +36,9 @@ class apt::backports (
     }
   }
 
-  if is_hash($pin) {
+  if $pin =~ Hash {
     $_pin = $pin
-  } elsif is_numeric($pin) or is_string($pin) {
+  } elsif $pin =~ Numeric or $pin =~ String {
     # apt::source defaults to pinning to origin, but we should pin to release
     # for backports
     $_pin = {
index 44e66ce51ff2dd00980603ae05423c11d092cae3..319e0649cd74fc0695f13afc8119804f289db7fb 100644 (file)
@@ -35,10 +35,11 @@ class apt (
     fail('This module only works on Debian or derivatives like Ubuntu')
   }
 
-  $frequency_options = ['always','daily','weekly','reluctantly']
-
   if $update['frequency'] {
-    validate_re($update['frequency'], $frequency_options)
+    assert_type(
+      Enum['always','daily','weekly','reluctantly'],
+      $update['frequency'],
+    )
   }
   if $update['timeout'] {
     assert_type(Integer, $update['timeout'])
@@ -66,7 +67,7 @@ class apt (
   $_purge = merge($::apt::purge_defaults, $purge)
 
   if $proxy['ensure'] {
-    validate_re($proxy['ensure'], ['file', 'present', 'absent'])
+    assert_type(Enum['file', 'present', 'absent'], $proxy['ensure'])
   }
   if $proxy['host'] {
     assert_type(String, $proxy['host'])
index 8f9d66bcc9a1bf2b45742fec5007a9a849a98f31..0dad80b04c543797f6470f40aae251c0e6ea6568 100644 (file)
@@ -8,14 +8,19 @@ define apt::key (
     Optional[String] $options            = undef,
     ) {
 
-  validate_re($id, ['\A(0x)?[0-9a-fA-F]{8}\Z', '\A(0x)?[0-9a-fA-F]{16}\Z', '\A(0x)?[0-9a-fA-F]{40}\Z'])
+  assert_type(
+    Pattern[
+      /\A(0x)?[0-9a-fA-F]{8}\Z/,
+      /\A(0x)?[0-9a-fA-F]{16}\Z/,
+      /\A(0x)?[0-9a-fA-F]{40}\Z/,
+    ], $id)
 
   if $source {
-    validate_re($source, ['\Ahttps?:\/\/', '\Aftp:\/\/', '\A\/\w+'])
+    assert_type(Pattern[/\Ahttps?:\/\//, /\Aftp:\/\//, /\A\/\w+/], $source)
   }
 
   if $server {
-    validate_re($server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$'])
+    assert_type(Pattern[/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/], $server)
   }
 
   case $ensure {
index ee32de4694a5a50c7dda1cd48f89c8c1de214da7..831d75f03b50b6c4b41215ae71dfeae534910fc3 100644 (file)
@@ -40,7 +40,7 @@ define apt::pin(
   # Read the manpage 'apt_preferences(5)', especially the chapter
   # 'The Effect of APT Preferences' to understand the following logic
   # and the difference between specific and general form
-  if is_array($packages) {
+  if $packages =~ Array {
     $packages_string = join($packages, ' ')
   } else {
     $packages_string = $packages
index 507ec9495d66ac2e6d305f71596996d34e7e1973..91835cb1b2b88f15387b276660e50a26828bed91 100644 (file)
@@ -18,11 +18,15 @@ define apt::setting (
   $setting_type = $title_array[0]
   $base_name = join(delete_at($title_array, 0), '-')
 
-  validate_re($setting_type, ['\Aconf\z', '\Apref\z', '\Alist\z'], "apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
+  assert_type(Pattern[/\Aconf\z/, /\Apref\z/, /\Alist\z/], $setting_type) |$a, $b| {
+    fail("apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
+  }
 
-  unless is_integer($priority) {
+  if $priority !~ Integer {
     # need this to allow zero-padded priority.
-    validate_re($priority, '^\d+$', 'apt::setting priority must be an integer or a zero-padded integer')
+    assert_type(Pattern[/^\d+$/], $priority) |$a, $b| {
+      fail('apt::setting priority must be an integer or a zero-padded integer')
+    }
   }
 
   if ($setting_type == 'list') or ($setting_type == 'pref') {
index be743eb26ca207fc9a3c2b09f82a52caff3ae494..a95bc592f98d03749076786faae1f0932ff5da35 100644 (file)
@@ -1,17 +1,17 @@
 # source.pp
 # add an apt source
 define apt::source(
-  Optional[String] $location           = undef,
-  String $comment                      = $name,
-  String $ensure                       = present,
-  Optional[String] $release            = undef,
-  String $repos                        = 'main',
-  Optional[Variant[Hash]] $include     = {},
-  Optional[Variant[String, Hash]] $key = undef,
-  $pin                                 = undef,
-  Optional[String] $architecture       = undef,
-  Boolean $allow_unsigned              = false,
-  Boolean $notify_update               = true,
+  Optional[String] $location                    = undef,
+  String $comment                               = $name,
+  String $ensure                                = present,
+  Optional[String] $release                     = undef,
+  String $repos                                 = 'main',
+  Optional[Variant[Hash]] $include              = {},
+  Optional[Variant[String, Hash]] $key          = undef,
+  Optional[Variant[Hash, Numeric, String]] $pin = undef,
+  Optional[String] $architecture                = undef,
+  Boolean $allow_unsigned                       = false,
+  Boolean $notify_update                        = true,
 ) {
 
   # This is needed for compat with 1.8.x
@@ -36,14 +36,13 @@ define apt::source(
   $includes = merge($::apt::include_defaults, $include)
 
   if $key {
-    if is_hash($key) {
+    if $key =~ Hash {
       unless $key['id'] {
         fail('key hash must contain at least an id entry')
       }
       $_key = merge($::apt::source_key_defaults, $key)
     } else {
-      validate_legacy(String, 'validate_string', $key)
-      $_key = { 'id' => $key }
+      $_key = { 'id' => assert_type(String[1], $key) }
     }
   }
 
@@ -66,9 +65,9 @@ define apt::source(
   }
 
   if $pin {
-    if is_hash($pin) {
+    if $pin =~ Hash {
       $_pin = merge($pin, { 'ensure' => $ensure, 'before' => $_before })
-    } elsif (is_numeric($pin) or is_string($pin)) {
+    } elsif ($pin =~ Numeric or $pin =~ String) {
       $url_split = split($location, '[:\/]+')
       $host      = $url_split[1]
       $_pin = {
@@ -85,7 +84,7 @@ define apt::source(
 
   # We do not want to remove keys when the source is absent.
   if $key and ($ensure == 'present') {
-    if is_hash($_key) {
+    if $_key =~ Hash {
       apt::key { "Add key: ${$_key['id']} from Apt::Source ${title}":
         ensure  => present,
         id      => $_key['id'],
index 2d02bed531d79cff09a4a3e30d7366193e15ff51..61347685c184d61e68e7e978715ba99f899f4564 100644 (file)
@@ -146,7 +146,7 @@ describe 'apt::key', type: :define do
       end
 
       it 'fails' do
-        expect { subject.call } .to raise_error(%r{does not match})
+        expect { subject.call } .to raise_error(%r{expects a match})
       end
     end
 
@@ -158,7 +158,7 @@ describe 'apt::key', type: :define do
       end
 
       it 'fails' do
-        expect { subject.call } .to raise_error(%r{does not match})
+        expect { subject.call } .to raise_error(%r{expects a match})
       end
     end
 
@@ -170,7 +170,7 @@ describe 'apt::key', type: :define do
       end
 
       it 'fails' do
-        expect { subject.call } .to raise_error(%r{does not match})
+        expect { subject.call } .to raise_error(%r{expects a match})
       end
     end
     context 'exceed character url' do
@@ -181,7 +181,7 @@ describe 'apt::key', type: :define do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
     context 'incorrect port number url' do
@@ -192,7 +192,7 @@ describe 'apt::key', type: :define do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
     context 'incorrect protocol for  url' do
@@ -203,7 +203,7 @@ describe 'apt::key', type: :define do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
     context 'missing port number url' do
@@ -214,7 +214,7 @@ describe 'apt::key', type: :define do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
     context 'url ending with a dot' do
@@ -225,7 +225,7 @@ describe 'apt::key', type: :define do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
     context 'url begin with a dash' do
@@ -236,7 +236,7 @@ describe 'apt::key', type: :define do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
     context 'invalid key' do
@@ -245,7 +245,7 @@ describe 'apt::key', type: :define do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
 
@@ -257,7 +257,7 @@ describe 'apt::key', type: :define do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
 
@@ -281,7 +281,7 @@ describe 'apt::key', type: :define do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
 
index ce433a3bf3d89b86f87ea9ae2ad5eb3088b32da9..e9ec0c5c427ccd8b702ad9ca94c90aff8f9f0c2d 100644 (file)
@@ -151,7 +151,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        expect { subject.call } .to raise_error(%r{does not match})
+        expect { subject.call } .to raise_error(%r{expects a match})
       end
     end
 
@@ -163,7 +163,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        expect { subject.call } .to raise_error(%r{does not match})
+        expect { subject.call } .to raise_error(%r{expects a match})
       end
     end
 
@@ -175,7 +175,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        expect { subject.call } .to raise_error(%r{does not match})
+        expect { subject.call } .to raise_error(%r{expects a match})
       end
     end
     context 'exceed character url' do
@@ -186,7 +186,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
     context 'incorrect port number url' do
@@ -197,7 +197,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
     context 'incorrect protocol for  url' do
@@ -208,7 +208,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
     context 'missing port number url' do
@@ -219,7 +219,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
     context 'url ending with a dot' do
@@ -230,7 +230,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
     context 'url begin with a dash' do
@@ -241,7 +241,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
     context 'invalid key' do
@@ -250,7 +250,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
 
@@ -262,7 +262,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
 
@@ -286,7 +286,7 @@ describe 'apt::key' do
       end
 
       it 'fails' do
-        expect { subject.call }.to raise_error(%r{does not match})
+        expect { subject.call }.to raise_error(%r{expects a match})
       end
     end
 
index eaa08874ef932ca8b37fca6c94d119908d5e77c9..52a7ca9e9cf64b398df1b443e7c54e05fa33ec22 100644 (file)
@@ -389,7 +389,7 @@ describe 'apt::source' do
       it do
         expect {
           subject.call
-        }.to raise_error(Puppet::Error, %r{invalid value for pin})
+        }.to raise_error(Puppet::Error, %r{expects a value})
       end
     end