From 13b725d99c2f35fcea32d2ebf3179b6fce2550a5 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 | 8 +------ metadata.json | 2 +- spec/defines/pip_spec.rb | 2 +- 5 files changed, 27 insertions(+), 42 deletions(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index da14dd0e..9daa7ff1 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -34,35 +34,27 @@ # } # define python::gunicorn ( - Enum['present', 'absent'] $ensure = present, - $config_dir = '/etc/gunicorn.d', - $manage_config_dir = false, - $virtualenv = false, - Enum['wsgi', 'django'] $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 = [], + Stdlib::Absolutepath $dir, + Enum['present', 'absent'] $ensure = present, + $config_dir = '/etc/gunicorn.d', + $manage_config_dir = false, + $virtualenv = false, + Enum['wsgi', 'django'] $mode = 'wsgi', + $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 583c2d59..7ac93c0b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -61,11 +61,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 333455a6..7c61cc25 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -52,7 +52,7 @@ define python::pip ( String $pkgname = $name, Variant[Enum[present, absent, latest], String[1]] $ensure = present, - String $virtualenv = 'system', + Variant[Enum['system'], Stdlib::Absolutepath] $virtualenv = 'system', Enum['pip', 'pip3'] $pip_provider = 'pip', Variant[Boolean, String] $url = false, String[1] $owner = 'root', @@ -87,10 +87,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') } @@ -100,8 +96,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..087395f3 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(%r{expects a match for Variant\[Enum\['system'\].*Stdlib::Windowspath = Pattern\[\/.*\/\], Stdlib::Unixpath = Pattern\[\/.*\/\]\]}) } end context 'suceeds with qualified path' do let(:params) { { virtualenv: '/opt/venv' } }