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 26, 2018
1 parent eac8ea6 commit 2a706db
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 60 deletions.
48 changes: 20 additions & 28 deletions manifests/gunicorn.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]
Expand Down
44 changes: 19 additions & 25 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
}
Expand All @@ -122,8 +118,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(/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' } }
Expand Down

0 comments on commit 2a706db

Please sign in to comment.