Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated validate_* functions #443

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be unless $version in $allowed_versions if it's an array? Not sure what the data type of $valid_versions is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$valid_versions, when taken from python::params, is an array. But even if it would be a string, the concat() would generate an array for $allowed_versions. I guess one could also use the in syntax you suggested. Not sure that the performance difference is.

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