Skip to content

Commit

Permalink
Replace deprecated validate_* functions
Browse files Browse the repository at this point in the history
  • Loading branch information
baurmatt committed Oct 29, 2018
1 parent 81e3715 commit 13b725d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 42 deletions.
48 changes: 20 additions & 28 deletions manifests/gunicorn.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]
Expand Down
8 changes: 1 addition & 7 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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')
}
Expand All @@ -100,8 +96,6 @@
default => $virtualenv,
}

validate_absolute_path($cwd)

$log = $virtualenv ? {
'system' => $log_dir,
default => $virtualenv,
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/pip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' } }
Expand Down

0 comments on commit 13b725d

Please sign in to comment.