From 2a706db5a4bca9b61fe803281aee723c2fb0a408 Mon Sep 17 00:00:00 2001 From: Matthias Baur Date: Fri, 26 Oct 2018 11:55:46 +0200 Subject: [PATCH] Replace deprecated validate_* functions --- manifests/gunicorn.pp | 48 +++++++++++++++++----------------------- manifests/init.pp | 9 ++++---- manifests/pip.pp | 44 ++++++++++++++++-------------------- metadata.json | 2 +- spec/defines/pip_spec.rb | 2 +- 5 files changed, 45 insertions(+), 60 deletions(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index bc996e6e..f6c263e1 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -75,35 +75,27 @@ # Marc Fournier # define python::gunicorn ( - $ensure = present, - $config_dir = '/etc/gunicorn.d', - $manage_config_dir = false, - $virtualenv = false, - $mode = 'wsgi', - $dir = false, - $bind = false, - $environment = false, - $owner = 'www-data', - $group = 'www-data', - $appmodule = 'app:app', - $osenv = false, - $timeout = 30, - $workers = false, - $access_log_format = false, - $accesslog = false, - $errorlog = false, - $log_level = 'error', - $template = 'python/gunicorn.erb', - $args = [], + $ensure = present, + $config_dir = '/etc/gunicorn.d', + $manage_config_dir = false, + $virtualenv = false, + $mode = 'wsgi', + Stdlib::Absolutepath $dir = false, + $bind = false, + $environment = false, + $owner = 'www-data', + $group = 'www-data', + $appmodule = 'app:app', + $osenv = false, + $timeout = 30, + $workers = false, + $access_log_format = false, + $accesslog = false, + $errorlog = false, + Enum['debug', 'info', 'warning', 'error', 'critical'] $log_level = 'error', + $template = 'python/gunicorn.erb', + $args = [], ) { - - # Parameter validation - if ! $dir { - fail('python::gunicorn: dir parameter must not be empty') - } - - validate_re($log_level, 'debug|info|warning|error|critical', "Invalid \$log_level value ${log_level}") - if $manage_config_dir { file { $config_dir: ensure => directory, diff --git a/manifests/init.pp b/manifests/init.pp index 258d0677..0c0a5d8d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -95,11 +95,10 @@ default => '', } - #$allowed_versions = concat(['system', 'pypy'], $valid_versions) - #unless $version =~ Enum[allowed_versions] { - #fail("version needs to be within${allowed_versions}") - #} - validate_re($version, concat(['system', 'pypy'], $valid_versions)) + $allowed_versions = concat(['system', 'pypy'], $valid_versions) + unless $version =~ Enum[$allowed_versions] { + fail("version needs to be within${allowed_versions}") + } # Module compatibility check $compatible = [ 'Debian', 'RedHat', 'Suse', 'Gentoo' ] diff --git a/manifests/pip.pp b/manifests/pip.pp index e7aa6efe..92657c1e 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -72,25 +72,25 @@ # Daniel Quackenbush # define python::pip ( - $pkgname = $name, - $ensure = present, - $virtualenv = 'system', - Enum['pip', 'pip3'] $pip_provider = 'pip', - $url = false, - $owner = 'root', - $group = 'root', - $umask = undef, - $index = false, - $proxy = false, - $egg = false, - $editable = false, - $environment = [], - $extras = [], - $install_args = '', - $uninstall_args = '', - $timeout = 1800, - $log_dir = '/tmp', - $path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'], + $pkgname = $name, + $ensure = present, + Variant[Enum['system'], Stdlib::Absolutepath] $virtualenv = 'system', + Enum['pip', 'pip3'] $pip_provider = 'pip', + $url = false, + $owner = 'root', + $group = 'root', + $umask = undef, + $index = false, + $proxy = false, + $egg = false, + $editable = false, + $environment = [], + $extras = [], + $install_args = '', + $uninstall_args = '', + $timeout = 1800, + $log_dir = '/tmp', + $path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'], ) { $python_provider = getparam(Class['python'], 'provider') $python_version = getparam(Class['python'], 'version') @@ -109,10 +109,6 @@ } # Parameter validation - if ! $virtualenv { - fail('python::pip: virtualenv parameter must not be empty') - } - if $virtualenv == 'system' and $owner != 'root' { fail('python::pip: root user must be used when virtualenv is system') } @@ -122,8 +118,6 @@ default => $virtualenv, } - validate_absolute_path($cwd) - $log = $virtualenv ? { 'system' => $log_dir, default => $virtualenv, diff --git a/metadata.json b/metadata.json index c1c42664..3f3f2eaf 100644 --- a/metadata.json +++ b/metadata.json @@ -56,7 +56,7 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 4.6.0 < 6.0.0" + "version_requirement": ">= 4.13.1 < 6.0.0" }, { "name": "stahnma/epel", diff --git a/spec/defines/pip_spec.rb b/spec/defines/pip_spec.rb index a040beec..e7b0d59a 100644 --- a/spec/defines/pip_spec.rb +++ b/spec/defines/pip_spec.rb @@ -24,7 +24,7 @@ context 'fails with non qualified path' do let(:params) { { virtualenv: 'venv' } } - it { is_expected.to raise_error(%r{"venv" is not an absolute path.}) } + it { is_expected.to raise_error(/expects a match for Variant\[Enum\['system'\], Stdlib::Absolutepath = Variant\[Stdlib::Windowspath = Pattern\[\/.*\/\], Stdlib::Unixpath = Pattern\[\/.*\/\]\]/) } end context 'suceeds with qualified path' do let(:params) { { virtualenv: '/opt/venv' } }