From 1e156c6c866318abaf3d48dda34bf71fac975f72 Mon Sep 17 00:00:00 2001 From: Hans Moulron Date: Mon, 15 Jan 2024 13:21:31 +0100 Subject: [PATCH 1/2] remove deprecated && update module stdlib --- manifests/ctlplugin.pp | 5 +- manifests/eventlistener.pp | 127 ++++++++------------- manifests/fcgi_program.pp | 130 ++++++++------------- manifests/group.pp | 13 +-- manifests/init.pp | 228 +++++++++++++++---------------------- manifests/program.pp | 107 ++++++----------- manifests/rpcinterface.pp | 13 +-- manifests/supervisorctl.pp | 7 +- metadata.json | 12 +- 9 files changed, 240 insertions(+), 402 deletions(-) diff --git a/manifests/ctlplugin.pp b/manifests/ctlplugin.pp index cceb9c9..91a62c6 100644 --- a/manifests/ctlplugin.pp +++ b/manifests/ctlplugin.pp @@ -10,14 +10,11 @@ # http://supervisord.org/configuration.html#program-x-section-settings # define supervisord::ctlplugin( - $ctl_factory, + String $ctl_factory, $ensure = present, ) { include supervisord - # parameter validation - validate_string($ctl_factory) - concat::fragment { "ctlplugin:${name}": target => $supervisord::config_file, content => template('supervisord/conf/ctlplugin.erb'), diff --git a/manifests/eventlistener.pp b/manifests/eventlistener.pp index 7fe3024..8c7e721 100644 --- a/manifests/eventlistener.pp +++ b/manifests/eventlistener.pp @@ -5,96 +5,63 @@ # Documentation on parameters available at: # http://supervisord.org/configuration.html#eventlistener-x-section-settings # -define supervisord::eventlistener( - $command, - $ensure = present, - $ensure_process = 'running', - $cfgreload = undef, - $buffer_size = 10, - $events = undef, - $result_handler = undef, - $env_var = undef, - $process_name = undef, - $numprocs = undef, - $numprocs_start = undef, - $priority = undef, - $autostart = undef, - $autorestart = undef, - $startsecs = undef, - $startretries = undef, - $exitcodes = undef, - $stopsignal = undef, - $stopwaitsecs = undef, - $stopasgroup = undef, - $killasgroup = undef, - $user = undef, - $redirect_stderr = undef, - $stdout_logfile = "eventlistener_${name}.log", - $stdout_logfile_maxbytes = undef, - $stdout_logfile_backups = undef, - $stdout_events_enabled = undef, - $stderr_logfile = "eventlistener_${name}.error", - $stderr_logfile_maxbytes = undef, - $stderr_logfile_backups = undef, - $stderr_events_enabled = undef, - $environment = undef, - $event_environment = undef, - $directory = undef, - $umask = undef, - $serverurl = undef, - $config_file_mode = '0644' +define supervisord::eventlistener ( + String $command, + $ensure = present, + Enum['running', 'stopped', 'removed', 'unmanaged'] $ensure_process = 'running', + Optional[Boolean] $cfgreload = undef, + Integer $buffer_size = 10, + Optional[Array] $events = undef, + Optional[String] $result_handler = undef, + $env_var = undef, + Optional[String] $process_name = undef, + Optional[Integer] $numprocs = undef, + Optional[Integer] $numprocs_start = undef, + Optional[Integer] $priority = undef, + Optional[Boolean] $autostart = undef, + Optional[Boolean] $autorestart = undef, + Optional[Integer] $startsecs = undef, + Optional[Integer] $startretries = undef, + Optional[String] $exitcodes = undef, + Optional[Enum['TERM', 'HUP', 'INT', 'QUIT', 'KILL', 'USR1', 'USR2']] $stopsignal = undef, + Optional[Integer] $stopwaitsecs = undef, + Optional[Boolean] $stopasgroup = undef, + Optional[Boolean] $killasgroup = undef, + Optional[String] $user = undef, + Optional[Boolean] $redirect_stderr = undef, + String $stdout_logfile = "eventlistener_${name}.log", + Optional[String] $stdout_logfile_maxbytes = undef, + Optional[Integer] $stdout_logfile_backups = undef, + Optional[Boolean] $stdout_events_enabled = undef, + String $stderr_logfile = "eventlistener_${name}.error", + Optional[String] $stderr_logfile_maxbytes = undef, + Optional[Integer] $stderr_logfile_backups = undef, + Optional[Boolean] $stderr_events_enabled = undef, + $environment = undef, + $event_environment = undef, + Optional[Stdlib::AbsolutePath] $directory = undef, + Optional[Stdlib::Filemode] $umask = undef, + Optional[Variant[Stdlib::HTTPSUrl, Stdlib::HTTPUrl]] $serverurl = undef, + Stdlib::Filemode $config_file_mode = '0644' ) { include supervisord - # parameter validation - validate_string($command) - validate_re($ensure_process, ['running', 'stopped', 'removed', 'unmanaged']) - if $cfgreload { validate_bool($cfgreload) } - if !is_integer($buffer_size) { validate_re($buffer_size, '^\d+')} - if $events { validate_array($events) } - if $result_handler { validate_string($result_handler) } - if $numprocs { if !is_integer($numprocs) { validate_re($numprocs, '^\d+')} } - if $numprocs_start { if !is_integer($numprocs_start) { validate_re($numprocs_start, '^\d+')} } - if $priority { if !is_integer($priority) { validate_re($priority, '^\d+') } } - if $autostart { if !is_bool($autostart) { validate_re($autostart, ['true', 'false']) } } - if $autorestart { if !is_bool($autorestart) { validate_re($autorestart, ['true', 'false', 'unexpected']) } } - if $startsecs { if !is_integer($startsecs) { validate_re($startsecs, '^\d+')} } - if $startretries { if !is_integer($startretries) { validate_re($startretries, '^\d+')} } - if $exitcodes { validate_string($exitcodes)} - if $stopsignal { validate_re($stopsignal, ['TERM', 'HUP', 'INT', 'QUIT', 'KILL', 'USR1', 'USR2']) } - if $stopwaitsecs { if !is_integer($stopwaitsecs) { validate_re($stopwaitsecs, '^\d+')} } - if $stopasgroup { validate_bool($stopasgroup) } - if $killasgroup { validate_bool($killasgroup) } - if $user { validate_string($user) } - if $redirect_stderr { validate_bool($redirect_stderr) } - validate_string($stdout_logfile) - if $stdout_logfile_maxbytes { validate_string($stdout_logfile_maxbytes) } - if $stdout_logfile_backups { if !is_integer($stdout_logfile_backups) { validate_re($stdout_logfile_backups, '^\d+')} } - if $stdout_events_enabled { validate_bool($stdout_events_enabled) } - validate_string($stderr_logfile) - if $stderr_logfile_maxbytes { validate_string($stderr_logfile_maxbytes) } - if $stderr_logfile_backups { if !is_integer($stderr_logfile_backups) { validate_re($stderr_logfile_backups, '^\d+')} } - if $stderr_events_enabled { validate_bool($stderr_events_enabled) } - if $directory { validate_absolute_path($directory) } - if $umask { validate_re($umask, '^[0-7][0-7][0-7]$') } - validate_re($config_file_mode, '^0[0-7][0-7][0-7]$') - # create the correct log variables $stdout_logfile_path = $stdout_logfile ? { - /(NONE|AUTO|syslog)/ => $stdout_logfile, - /^\// => $stdout_logfile, - default => "${supervisord::log_path}/${stdout_logfile}", + /(NONE|AUTO|syslog)/ => $stdout_logfile, + /^\// => $stdout_logfile, + default => "${supervisord::log_path}/${stdout_logfile}", } $stderr_logfile_path = $stderr_logfile ? { - /(NONE|AUTO|syslog)/ => $stderr_logfile, - /^\// => $stderr_logfile, - default => "${supervisord::log_path}/${stderr_logfile}", + /(NONE|AUTO|syslog)/ => $stderr_logfile, + /^\// => $stderr_logfile, + default => "${supervisord::log_path}/${stderr_logfile}", } # Handle deprecated $environment variable - if $environment { notify {'[supervisord] *** DEPRECATED WARNING ***: $event_environment has replaced $environment':}} + if $environment { notify { '[supervisord] *** DEPRECATED WARNING ***: $event_environment has replaced $environment': } } $_event_environment = $event_environment ? { undef => $environment, default => $event_environment @@ -103,11 +70,9 @@ # convert environment data into a csv if $env_var { $env_hash = hiera_hash($env_var) - validate_hash($env_hash) $env_string = hash2csv($env_hash) } elsif $_event_environment { - validate_hash($_event_environment) $env_string = hash2csv($_event_environment) } @@ -156,6 +121,6 @@ unless => 'running' } } - default: { } + default: {} } } diff --git a/manifests/fcgi_program.pp b/manifests/fcgi_program.pp index 5685339..acabfc2 100644 --- a/manifests/fcgi_program.pp +++ b/manifests/fcgi_program.pp @@ -5,99 +5,63 @@ # Documentation on parameters available at: # http://supervisord.org/configuration.html#fcgi-program-x-section-settings # -define supervisord::fcgi_program( - $command, - $socket, - $ensure = present, - $ensure_process = 'running', - $cfgreload = undef, - $socket_owner = undef, - $socket_mode = undef, - $env_var = undef, - $process_name = undef, - $numprocs = undef, - $numprocs_start = undef, - $priority = undef, - $autostart = undef, - $autorestart = undef, - $startsecs = undef, - $startretries = undef, - $exitcodes = undef, - $stopsignal = undef, - $stopwaitsecs = undef, - $stopasgroup = undef, - $killasgroup = undef, - $user = undef, - $redirect_stderr = undef, - $stdout_logfile = "fcgi-program_${name}.log", - $stdout_logfile_maxbytes = undef, - $stdout_logfile_backups = undef, - $stdout_capture_maxbytes = undef, - $stdout_events_enabled = undef, - $stderr_logfile = "fcgi-program_${name}.error", - $stderr_logfile_maxbytes = undef, - $stderr_logfile_backups = undef, - $stderr_capture_maxbytes = undef, - $stderr_events_enabled = undef, - $environment = undef, - $program_environment = undef, - $directory = undef, - $umask = undef, - $serverurl = undef, - $config_file_mode = '0644' +define supervisord::fcgi_program ( + String $command, + $ensure = present, + Enum['running', 'stopped', 'removed', 'unmanaged'] $ensure_process = 'running', + Optional[Boolean] $cfgreload = undef, + Integer $buffer_size = 10, + Optional[Array] $events = undef, + Optional[String] $result_handler = undef, + $env_var = undef, + Optional[String] $process_name = undef, + Optional[Integer] $numprocs = undef, + Optional[Integer] $numprocs_start = undef, + Optional[Integer] $priority = undef, + Optional[Boolean] $autostart = undef, + Optional[Boolean] $autorestart = undef, + Optional[Integer] $startsecs = undef, + Optional[Integer] $startretries = undef, + Optional[String] $exitcodes = undef, + Optional[Enum['TERM', 'HUP', 'INT', 'QUIT', 'KILL', 'USR1', 'USR2']] $stopsignal = undef, + Optional[Integer] $stopwaitsecs = undef, + Optional[Boolean] $stopasgroup = undef, + Optional[Boolean] $killasgroup = undef, + Optional[String] $user = undef, + Optional[Boolean] $redirect_stderr = undef, + String $stdout_logfile = "eventlistener_${name}.log", + Optional[String] $stdout_logfile_maxbytes = undef, + Optional[Integer] $stdout_logfile_backups = undef, + Optional[Boolean] $stdout_events_enabled = undef, + String $stderr_logfile = "eventlistener_${name}.error", + Optional[String] $stderr_logfile_maxbytes = undef, + Optional[Integer] $stderr_logfile_backups = undef, + Optional[Boolean] $stderr_events_enabled = undef, + $environment = undef, + $program_environment = undef, + Optional[Stdlib::AbsolutePath] $directory = undef, + Optional[Stdlib::Filemode] $umask = undef, + Optional[Variant[Stdlib::HTTPSUrl, Stdlib::HTTPUrl]] $serverurl = undef, + Stdlib::Filemode $config_file_mode = '0644' ) { include supervisord - # parameter validation - validate_string($command) - validate_re($ensure_process, ['running', 'stopped', 'removed', 'unmanaged']) - validate_re($socket, ['^tcp:\/\/.*:\d+$', '^unix:\/\/\/']) - if $cfgreload { validate_bool($cfgreload) } - if $process_name { validate_string($process_name) } - if $numprocs { if !is_integer($numprocs) { validate_re($numprocs, '^\d+')} } - if $numprocs_start { if !is_integer($numprocs_start) { validate_re($numprocs_start, '^\d+')} } - if $priority { if !is_integer($priority) { validate_re($priority, '^\d+') } } - if $autostart { if !is_bool($autostart) { validate_re($autostart, ['true', 'false']) } } - if $autorestart { if !is_bool($autorestart) { validate_re($autorestart, ['true', 'false', 'unexpected']) } } - if $startsecs { if !is_integer($startsecs) { validate_re($startsecs, '^\d+')} } - if $startretries { if !is_integer($startretries) { validate_re($startretries, '^\d+')} } - if $exitcodes { validate_string($exitcodes)} - if $stopsignal { validate_re($stopsignal, ['TERM', 'HUP', 'INT', 'QUIT', 'KILL', 'USR1', 'USR2']) } - if $stopwaitsecs { if !is_integer($stopwaitsecs) { validate_re($stopwaitsecs, '^\d+')} } - if $stopasgroup { validate_bool($stopasgroup) } - if $killasgroup { validate_bool($killasgroup) } - if $user { validate_string($user) } - if $redirect_stderr { validate_bool($redirect_stderr) } - validate_string($stdout_logfile) - if $stdout_logfile_maxbytes { validate_string($stdout_logfile_maxbytes) } - if $stdout_logfile_backups { if !is_integer($stdout_logfile_backups) { validate_re($stdout_logfile_backups, '^\d+')} } - if $stdout_capture_maxbytes { validate_string($stdout_capture_maxbytes) } - if $stdout_events_enabled { validate_bool($stdout_events_enabled) } - validate_string($stderr_logfile) - if $stderr_logfile_maxbytes { validate_string($stderr_logfile_maxbytes) } - if $stderr_logfile_backups { if !is_integer($stderr_logfile_backups) { validate_re($stderr_logfile_backups, '^\d+')} } - if $stderr_capture_maxbytes { validate_string($stderr_capture_maxbytes) } - if $stderr_events_enabled { validate_bool($stderr_events_enabled) } - if $directory { validate_absolute_path($directory) } - if $umask { validate_re($umask, '^[0-7][0-7][0-7]$') } - validate_re($config_file_mode, '^0[0-7][0-7][0-7]$') - # create the correct log variables $stdout_logfile_path = $stdout_logfile ? { - /(NONE|AUTO|syslog)/ => $stdout_logfile, - /^\// => $stdout_logfile, - default => "${supervisord::log_path}/${stdout_logfile}", + /(NONE|AUTO|syslog)/ => $stdout_logfile, + /^\// => $stdout_logfile, + default => "${supervisord::log_path}/${stdout_logfile}", } $stderr_logfile_path = $stderr_logfile ? { - /(NONE|AUTO|syslog)/ => $stderr_logfile, - /^\// => $stderr_logfile, - default => "${supervisord::log_path}/${stderr_logfile}", + /(NONE|AUTO|syslog)/ => $stderr_logfile, + /^\// => $stderr_logfile, + default => "${supervisord::log_path}/${stderr_logfile}", } # Handle deprecated $environment variable - if $environment { notify {'[supervisord] *** DEPRECATED WARNING ***: $program_environment has replaced $environment':}} + if $environment { notify { '[supervisord] *** DEPRECATED WARNING ***: $program_environment has replaced $environment': } } $_program_environment = $program_environment ? { undef => $environment, default => $program_environment @@ -106,11 +70,9 @@ # convert environment data into a csv if $env_var { $env_hash = hiera_hash($env_var) - validate_hash($env_hash) $env_string = hash2csv($env_hash) } elsif $_program_environment { - validate_hash($_program_environment) $env_string = hash2csv($_program_environment) } @@ -155,6 +117,6 @@ unless => 'running' } } - default: { } + default: {} } } diff --git a/manifests/group.pp b/manifests/group.pp index 5504819..8da30fd 100644 --- a/manifests/group.pp +++ b/manifests/group.pp @@ -6,19 +6,14 @@ # http://supervisord.org/configuration.html#group-x-section-settings # define supervisord::group ( - $programs, - $ensure = present, - $priority = undef, - $config_file_mode = '0644' + Array $programs, + $ensure = present, + Integer $priority = undef, + Stdlib::Filemode $config_file_mode = '0644' ) { include supervisord - # parameter validation - validate_array($programs) - if $priority { if !is_integer($priority) { validate_re($priority, '^\d+', "invalid priority value of: ${priority}") } } - validate_re($config_file_mode, '^0[0-7][0-7][0-7]$') - $progstring = array2csv($programs) $conf = "${supervisord::config_include}/group_${name}.conf" diff --git a/manifests/init.pp b/manifests/init.pp index 881be98..f45fe7c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -2,126 +2,95 @@ # # This class installs supervisord via pip # -class supervisord( - $package_ensure = $supervisord::params::package_ensure, - $package_name = $supervisord::params::package_name, - $package_provider = $supervisord::params::package_provider, - $package_install_options = $supervisord::params::package_install_options, - $service_manage = $supervisord::params::service_manage, - $service_ensure = $supervisord::params::service_ensure, - $service_enable = $supervisord::params::service_enable, - $service_name = $supervisord::params::service_name, - $service_restart = $supervisord::params::service_restart, - $install_pip = false, - $pip_proxy = undef, - $install_init = $supervisord::params::install_init, - $init_type = $supervisord::params::init_type, - $init_mode = $supervisord::params::init_mode, - $init_script = $supervisord::params::init_script, - $init_script_template = $supervisord::params::init_script_template, - $init_defaults = $supervisord::params::init_defaults, - $init_defaults_template = $supervisord::params::init_defaults_template, - $setuptools_url = $supervisord::params::setuptools_url, - $executable = $supervisord::params::executable, - $executable_ctl = $supervisord::params::executable_ctl, - - $scl_enabled = $supervisord::params::scl_enabled, - $scl_script = $supervisord::params::scl_script, - - $log_path = $supervisord::params::log_path, - $log_file = $supervisord::params::log_file, - $log_level = $supervisord::params::log_level, - $logfile_maxbytes = $supervisord::params::logfile_maxbytes, - $logfile_backups = $supervisord::params::logfile_backups, - - $cfgreload_program = $supervisord::params::cfgreload_program, - $cfgreload_fcgi_program = $supervisord::params::cfgreload_fcgi_program, - $cfgreload_eventlistener = $supervisord::params::cfgreload_eventlistener, - $cfgreload_rpcinterface = $supervisord::params::cfgreload_rpcinterface, - - $run_path = $supervisord::params::run_path, - $pid_file = $supervisord::params::pid_file, - $nodaemon = $supervisord::params::nodaemon, - $minfds = $supervisord::params::minfds, - $minprocs = $supervisord::params::minprocs, - $manage_config = $supervisord::params::manage_config, - $config_include = $supervisord::params::config_include, - $config_include_purge = false, - $config_file = $supervisord::params::config_file, - $config_file_mode = $supervisord::params::config_file_mode, - $config_dirs = undef, - $umask = $supervisord::params::umask, - - $ctl_socket = $supervisord::params::ctl_socket, - - $unix_socket = $supervisord::params::unix_socket, - $unix_socket_file = $supervisord::params::unix_socket_file, - $unix_socket_mode = $supervisord::params::unix_socket_mode, - $unix_socket_owner = $supervisord::params::unix_socket_owner, - $unix_socket_group = $supervisord::params::unix_socket_group, - $unix_auth = $supervisord::params::unix_auth, - $unix_username = $supervisord::params::unix_username, - $unix_password = $supervisord::params::unix_password, - - $inet_server = $supervisord::params::inet_server, - $inet_server_hostname = $supervisord::params::inet_server_hostname, - $inet_server_port = $supervisord::params::inet_server_port, - $inet_auth = $supervisord::params::inet_auth, - $inet_username = $supervisord::params::inet_username, - $inet_password = $supervisord::params::inet_password, - - $user = $supervisord::params::user, - $group = $supervisord::params::group, - $identifier = undef, - $childlogdir = undef, - $environment = undef, - $global_environment = undef, - $env_var = undef, - $directory = undef, - $strip_ansi = false, - $nocleanup = false, - - $eventlisteners = {}, - $fcgi_programs = {}, - $groups = {}, - $programs = {} - +class supervisord ( + $package_ensure = $supervisord::params::package_ensure, + $package_name = $supervisord::params::package_name, + $package_provider = $supervisord::params::package_provider, + $package_install_options = $supervisord::params::package_install_options, + $service_manage = $supervisord::params::service_manage, + $service_ensure = $supervisord::params::service_ensure, + $service_enable = $supervisord::params::service_enable, + $service_name = $supervisord::params::service_name, + $service_restart = $supervisord::params::service_restart, + Boolean $install_pip = false, + Variant[Stdlib::HTTPSUrl, Stdlib::HTTPUrl] $pip_proxy = undef, + Boolean $install_init = $supervisord::params::install_init, + $init_type = $supervisord::params::init_type, + $init_mode = $supervisord::params::init_mode, + $init_script = $supervisord::params::init_script, + $init_script_template = $supervisord::params::init_script_template, + $init_defaults = $supervisord::params::init_defaults, + $init_defaults_template = $supervisord::params::init_defaults_template, + $setuptools_url = $supervisord::params::setuptools_url, + $executable = $supervisord::params::executable, + $executable_ctl = $supervisord::params::executable_ctl, + + $scl_enabled = $supervisord::params::scl_enabled, + $scl_script = $supervisord::params::scl_script, + + Stdlib::AbsolutePath $log_path = $supervisord::params::log_path, + $log_file = $supervisord::params::log_file, + $log_level = $supervisord::params::log_level, + $logfile_maxbytes = $supervisord::params::logfile_maxbytes, + Integer $logfile_backups = $supervisord::params::logfile_backups, + + $cfgreload_program = $supervisord::params::cfgreload_program, + $cfgreload_fcgi_program = $supervisord::params::cfgreload_fcgi_program, + $cfgreload_eventlistener = $supervisord::params::cfgreload_eventlistener, + $cfgreload_rpcinterface = $supervisord::params::cfgreload_rpcinterface, + + Stdlib::AbsolutePath $run_path = $supervisord::params::run_path, + $pid_file = $supervisord::params::pid_file, + Boolean $nodaemon = $supervisord::params::nodaemon, + Integer $minfds = $supervisord::params::minfds, + Integer $minprocs = $supervisord::params::minprocs, + $manage_config = $supervisord::params::manage_config, + Stdlib::AbsolutePath $config_include = $supervisord::params::config_include, + $config_include_purge = false, + $config_file = $supervisord::params::config_file, + Stdlib::Filemode $config_file_mode = $supervisord::params::config_file_mode, + Optional[Array]$config_dirs = undef, + $umask = $supervisord::params::umask, + + Enum['unix', 'inet'] $ctl_socket = $supervisord::params::ctl_socket, + + Boolean $unix_socket = $supervisord::params::unix_socket, + $unix_socket_file = $supervisord::params::unix_socket_file, + Stdlib::Filemode $unix_socket_mode = $supervisord::params::unix_socket_mode, + $unix_socket_owner = $supervisord::params::unix_socket_owner, + $unix_socket_group = $supervisord::params::unix_socket_group, + Boolean $unix_auth = $supervisord::params::unix_auth, + String $unix_username = $supervisord::params::unix_username, + String $unix_password = $supervisord::params::unix_password, + + Boolean $inet_server = $supervisord::params::inet_server, + $inet_server_hostname = $supervisord::params::inet_server_hostname, + Stdlib::Port $inet_server_port = $supervisord::params::inet_server_port, + Boolean $inet_auth = $supervisord::params::inet_auth, + String $inet_username = $supervisord::params::inet_username, + String $inet_password = $supervisord::params::inet_password, + + $user = $supervisord::params::user, + $group = $supervisord::params::group, + $identifier = undef, + Optional[Stdlib::AbsolutePath] $childlogdir = undef, + Optional[Hash] $environment = undef, + Optional[Hash] $global_environment = undef, + $env_var = undef, + Optional[Stdlib::AbsolutePath] $directory = undef, + Boolean $strip_ansi = false, + Boolean $nocleanup = false, + + Hash $eventlisteners = {}, + Hash $fcgi_programs = {}, + Hash $groups = {}, + Hash $programs = {} ) inherits supervisord::params { - validate_bool($install_pip) - validate_bool($install_init) - validate_bool($nodaemon) - validate_bool($unix_socket) - validate_bool($unix_auth) - validate_bool($inet_server) - validate_bool($inet_auth) - validate_bool($strip_ansi) - validate_bool($nocleanup) - - validate_hash($eventlisteners) - validate_hash($fcgi_programs) - validate_hash($groups) - validate_hash($programs) - - validate_absolute_path($config_include) - validate_absolute_path($log_path) - validate_absolute_path($run_path) - if $childlogdir { validate_absolute_path($childlogdir) } - if $directory { validate_absolute_path($directory) } - $log_levels = ['^critical$', '^error$', '^warn$', '^info$', '^debug$', '^trace$', '^blather$'] validate_re($log_level, $log_levels, "invalid log_level: ${log_level}") - validate_re($logfile_maxbytes,'^[0-9]*(?:KB|MB|GB)?', "invalid logfile_maxbytes: ${$logfile_maxbytes}") + validate_re($logfile_maxbytes, '^[0-9]*(?:KB|MB|GB)?', "invalid logfile_maxbytes: ${$logfile_maxbytes}") validate_re($umask, '^0[0-7][0-7]$', "invalid umask: ${umask}.") - validate_re($unix_socket_mode, '^[0-7][0-7][0-7][0-7]$', "invalid unix_socket_mode: ${unix_socket_mode}") - validate_re($ctl_socket, ['^unix$', '^inet$'], "invalid ctl_socket: ${ctl_socket}") - validate_re($config_file_mode, '^0[0-7][0-7][0-7]$') - if $pip_proxy { validate_re($pip_proxy, ['^https?:\/\/.*$'], "invalid pip_proxy: ${pip_proxy}") } - - if ! is_integer($logfile_backups) { fail("invalid logfile_backups: ${logfile_backups}.")} - if ! is_integer($minfds) { fail("invalid minfds: ${minfds}.")} - if ! is_integer($minprocs) { fail("invalid minprocs: ${minprocs}.")} - if ! is_integer($inet_server_port) { fail("invalid inet_server_port: ${inet_server_port}.")} if $unix_socket and $inet_server { $use_ctl_socket = $ctl_socket @@ -135,46 +104,33 @@ if $use_ctl_socket == 'unix' { $ctl_serverurl = "unix://${supervisord::run_path}/${supervisord::unix_socket_file}" - $ctl_auth = $supervisord::unix_auth - $ctl_username = $supervisord::unix_username - $ctl_password = $supervisord::unix_password + $ctl_auth = $supervisord::unix_auth + $ctl_username = $supervisord::unix_username + $ctl_password = $supervisord::unix_password } elsif $use_ctl_socket == 'inet' { $ctl_serverurl = "http://${supervisord::inet_server_hostname}:${supervisord::inet_server_port}" - $ctl_auth = $supervisord::inet_auth - $ctl_username = $supervisord::inet_username - $ctl_password = $supervisord::inet_password - } - - if $unix_auth { - validate_string($unix_username) - validate_string($unix_password) - } - - if $inet_auth { - validate_string($inet_username) - validate_string($inet_password) + $ctl_auth = $supervisord::inet_auth + $ctl_username = $supervisord::inet_username + $ctl_password = $supervisord::inet_password } # Handle deprecated $environment variable - if $environment { notify {'[supervisord] *** DEPRECATED WARNING ***: $global_environment has replaced $environment':}} + if $environment { notify { '[supervisord] *** DEPRECATED WARNING ***: $global_environment has replaced $environment': } } $_global_environment = $global_environment ? { undef => $environment, default => $global_environment } if $env_var { - validate_hash($env_var) $env_hash = hiera($env_var) $env_string = hash2csv($env_hash) } elsif $_global_environment { - validate_hash($_global_environment) $env_string = hash2csv($_global_environment) } if $config_dirs { - validate_array($config_dirs) $config_include_string = join($config_dirs, ' ') } else { @@ -207,6 +163,6 @@ Class['supervisord::service'] -> Supervisord::Eventlistener <| |> Class['supervisord::service'] -> Supervisord::Group <| |> Class['supervisord::service'] -> Supervisord::Rpcinterface <| |> - Class['supervisord::reload'] -> Supervisord::Supervisorctl <| |> + Class['supervisord::reload'] -> Supervisord::Supervisorctl <| |> } diff --git a/manifests/program.pp b/manifests/program.pp index 5a8bec6..8a5273b 100644 --- a/manifests/program.pp +++ b/manifests/program.pp @@ -6,79 +6,46 @@ # http://supervisord.org/configuration.html#program-x-section-settings # define supervisord::program( - $command, - $ensure = present, - $ensure_process = 'running', - $cfgreload = undef, - $env_var = undef, - $process_name = undef, - $numprocs = undef, - $numprocs_start = undef, - $priority = undef, - $autostart = undef, - $autorestart = undef, - $startsecs = undef, - $startretries = undef, - $exitcodes = undef, - $stopsignal = undef, - $stopwaitsecs = undef, - $stopasgroup = undef, - $killasgroup = undef, - $user = undef, - $redirect_stderr = undef, - $stdout_logfile = "program_${name}.log", - $stdout_logfile_maxbytes = undef, - $stdout_logfile_backups = undef, - $stdout_capture_maxbytes = undef, - $stdout_events_enabled = undef, - $stderr_logfile = "program_${name}.error", - $stderr_logfile_maxbytes = undef, - $stderr_logfile_backups = undef, - $stderr_capture_maxbytes = undef, - $stderr_events_enabled = undef, - $program_environment = undef, - $environment = undef, - $directory = undef, - $umask = undef, - $serverurl = undef, - $config_file_mode = '0644' + String $command, + $ensure = present, + Enum['running', 'stopped', 'removed', 'unmanaged'] $ensure_process = 'running', + Optional[Boolean] $cfgreload = undef, + Integer $buffer_size = 10, + Optional[Array] $events = undef, + Optional[String] $result_handler = undef, + $env_var = undef, + Optional[String] $process_name = undef, + Optional[Integer] $numprocs = undef, + Optional[Integer] $numprocs_start = undef, + Optional[Integer] $priority = undef, + Optional[Boolean] $autostart = undef, + Optional[Boolean] $autorestart = undef, + Optional[Integer] $startsecs = undef, + Optional[Integer] $startretries = undef, + Optional[String] $exitcodes = undef, + Optional[Enum['TERM', 'HUP', 'INT', 'QUIT', 'KILL', 'USR1', 'USR2']] $stopsignal = undef, + Optional[Integer] $stopwaitsecs = undef, + Optional[Boolean] $stopasgroup = undef, + Optional[Boolean] $killasgroup = undef, + Optional[String] $user = undef, + Optional[Boolean] $redirect_stderr = undef, + String $stdout_logfile = "eventlistener_${name}.log", + Optional[String] $stdout_logfile_maxbytes = undef, + Optional[Integer] $stdout_logfile_backups = undef, + Optional[Boolean] $stdout_events_enabled = undef, + String $stderr_logfile = "eventlistener_${name}.error", + Optional[String] $stderr_logfile_maxbytes = undef, + Optional[Integer] $stderr_logfile_backups = undef, + Optional[Boolean] $stderr_events_enabled = undef, + $environment = undef, + Optional[Stdlib::AbsolutePath] $directory = undef, + Optional[Stdlib::Filemode] $umask = undef, + Optional[Variant[Stdlib::HTTPSUrl, Stdlib::HTTPUrl]] $serverurl = undef, + Stdlib::Filemode $config_file_mode = '0644' ) { include supervisord -# parameter validation - validate_string($command) - validate_re($ensure_process, ['running', 'stopped', 'removed', 'unmanaged']) - if $cfgreload { validate_bool($cfgreload) } - if $process_name { validate_string($process_name) } - if $numprocs { if !is_integer($numprocs) { validate_re($numprocs, '^\d+')} } - if $numprocs_start { if !is_integer($numprocs_start) { validate_re($numprocs_start, '^\d+')} } - if $priority { if !is_integer($priority) { validate_re($priority, '^\d+') } } - if $autostart { if !is_bool($autostart) { validate_re($autostart, ['true', 'false']) } } - if $autorestart { if !is_bool($autorestart) { validate_re($autorestart, ['true', 'false', 'unexpected']) } } - if $startsecs { if !is_integer($startsecs) { validate_re($startsecs, '^\d+')} } - if $startretries { if !is_integer($startretries) { validate_re($startretries, '^\d+')} } - if $exitcodes { validate_string($exitcodes)} - if $stopsignal { validate_re($stopsignal, ['TERM', 'HUP', 'INT', 'QUIT', 'KILL', 'USR1', 'USR2']) } - if $stopwaitsecs { if !is_integer($stopwaitsecs) { validate_re($stopwaitsecs, '^\d+')} } - if $stopasgroup { validate_bool($stopasgroup) } - if $killasgroup { validate_bool($killasgroup) } - if $user { validate_string($user) } - if $redirect_stderr { validate_bool($redirect_stderr) } - validate_string($stdout_logfile) - if $stdout_logfile_maxbytes { validate_string($stdout_logfile_maxbytes) } - if $stdout_logfile_backups { if !is_integer($stdout_logfile_backups) { validate_re($stdout_logfile_backups, '^\d+')} } - if $stdout_capture_maxbytes { validate_string($stdout_capture_maxbytes) } - if $stdout_events_enabled { validate_bool($stdout_events_enabled) } - validate_string($stderr_logfile) - if $stderr_logfile_maxbytes { validate_string($stderr_logfile_maxbytes) } - if $stderr_logfile_backups { if !is_integer($stderr_logfile_backups) { validate_re($stderr_logfile_backups, '^\d+')} } - if $stderr_capture_maxbytes { validate_string($stderr_capture_maxbytes) } - if $stderr_events_enabled { validate_bool($stderr_events_enabled) } - if $directory { validate_absolute_path($directory) } - if $umask { validate_re($umask, '^[0-7][0-7][0-7]$') } - validate_re($config_file_mode, '^0[0-7][0-7][0-7]$') - # create the correct log variables $stdout_logfile_path = $stdout_logfile ? { /(NONE|AUTO|syslog)/ => $stdout_logfile, @@ -102,11 +69,9 @@ # convert environment data into a csv if $env_var { $env_hash = hiera_hash($env_var) - validate_hash($env_hash) $env_string = hash2csv($env_hash) } elsif $_program_environment { - validate_hash($_program_environment) $env_string = hash2csv($_program_environment) } diff --git a/manifests/rpcinterface.pp b/manifests/rpcinterface.pp index b2a3562..27ffba4 100644 --- a/manifests/rpcinterface.pp +++ b/manifests/rpcinterface.pp @@ -7,19 +7,14 @@ # define supervisord::rpcinterface ( $rpcinterface_factory, - $ensure = present, - $cfgreload = undef, - $retries = undef, - $config_file_mode = '0644' + $ensure = present, + Boolean $cfgreload = undef, + Optional[Integer] $retries = undef, + Stdlib::Filemode $config_file_mode = '0644' ) { include supervisord - # parameter validation - if $retries { if !is_integer($retries) { validate_re($retries, '^\d+')}} - validate_re($config_file_mode, '^0[0-7][0-7][0-7]$') - if $cfgreload { validate_bool($cfgreload) } - # Reload default with override $_cfgreload = $cfgreload ? { undef => $supervisord::cfgreload_rpcinterface, diff --git a/manifests/supervisorctl.pp b/manifests/supervisorctl.pp index 67dd3b1..57c2c89 100644 --- a/manifests/supervisorctl.pp +++ b/manifests/supervisorctl.pp @@ -3,15 +3,12 @@ # This define executes command with the supervisorctl tool # define supervisord::supervisorctl( - $command, - $process = undef, + String $command, + Optional[String] $process = undef, $refreshonly = false, $unless = undef ) { - validate_string($command) - validate_string($process) - $supervisorctl = $::supervisord::executable_ctl if $process { diff --git a/metadata.json b/metadata.json index f6b172e..6bb8171 100644 --- a/metadata.json +++ b/metadata.json @@ -8,6 +8,12 @@ "project_page": "https://forge.puppetlabs.com/ajcrowe/supervisord", "issues_url": "https://github.com/ajcrowe/puppet-supervisord/issues", "tags": ["supervisor", "supervisord", "python", "process", "management" ], + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 7.0.0 < 9.0.0" + } + ], "operatingsystem_support": [ { "operatingsystem":"RedHat", @@ -23,11 +29,11 @@ }, { "operatingsystem": "Debian", - "operatingsystemrelease": [ "6", "7", "8" ] + "operatingsystemrelease": [ "9", "10", "11", "12" ] } ], "dependencies": [ - { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.4.0 <5.0.0" }, - { "name": "puppetlabs/concat", "version_requirement": ">= 1.0.0 <5.0.0" } + { "name": "puppetlabs/stdlib", "version_requirement": ">= 7.0.0 <10.0.0" }, + { "name": "puppetlabs/concat", "version_requirement": ">= 1.0.0 <8.0.0" } ] } From 94981d395a59e406b79d7e9825cedb74bbfab213 Mon Sep 17 00:00:00 2001 From: Hans Moulron Date: Mon, 15 Jan 2024 16:49:27 +0100 Subject: [PATCH 2/2] remove deprecated && update module stdlib --- .fixtures.yml | 10 +- .puppet-lint.rc | 14 + Gemfile | 82 +++- {tests => examples}/ctlplugin.pp | 0 {tests => examples}/group.pp | 2 +- {tests => examples}/init.pp | 0 {tests => examples}/program.pp | 2 +- {tests => examples}/rpcinterface.pp | 0 manifests/config.pp | 5 +- manifests/ctlplugin.pp | 7 +- manifests/eventlistener.pp | 11 +- manifests/fcgi_program.pp | 14 +- manifests/group.pp | 5 +- manifests/init.pp | 183 ++++--- manifests/install.pp | 13 +- manifests/params.pp | 187 +++---- manifests/pip.pp | 4 +- manifests/program.pp | 32 +- manifests/reload.pp | 1 - manifests/rpcinterface.pp | 6 +- manifests/service.pp | 2 +- manifests/supervisorctl.pp | 9 +- metadata.json | 50 +- spec/classes/supervisord_spec.rb | 733 ++++++++++++++++------------ spec/defines/ctlplugin_spec.rb | 33 +- spec/defines/eventlistener_spec.rb | 207 ++++---- spec/defines/fcgi_program_spec.rb | 215 ++++---- spec/defines/group_spec.rb | 45 +- spec/defines/program_spec.rb | 209 ++++---- spec/defines/rpcinterface_spec.rb | 52 +- spec/defines/supervisorctl.rb | 49 +- spec/spec_helper.rb | 25 + templates/init/Debian/init.erb | 137 ------ templates/init/RedHat/init.erb | 124 ----- templates/init/Suse/defaults.erb | 8 - templates/init/Suse/init.erb | 131 ----- types/maxbytes.pp | 1 + types/umask.pp | 1 + 38 files changed, 1232 insertions(+), 1377 deletions(-) create mode 100644 .puppet-lint.rc rename {tests => examples}/ctlplugin.pp (100%) rename {tests => examples}/group.pp (98%) rename {tests => examples}/init.pp (100%) rename {tests => examples}/program.pp (99%) rename {tests => examples}/rpcinterface.pp (100%) delete mode 100644 templates/init/Debian/init.erb delete mode 100644 templates/init/RedHat/init.erb delete mode 100644 templates/init/Suse/defaults.erb delete mode 100644 templates/init/Suse/init.erb create mode 100644 types/maxbytes.pp create mode 100644 types/umask.pp diff --git a/.fixtures.yml b/.fixtures.yml index 8e8e32d..2592251 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,10 +1,6 @@ fixtures: - repositories: - 'stdlib': - repo: 'git://github.com/puppetlabs/puppetlabs-stdlib' - ref: '4.9.0' - 'concat': - repo: 'git://github.com/puppetlabs/puppetlabs-concat' - ref: '1.2.4' symlinks: supervisord: "#{source_dir}" + forge_modules: + concat: puppetlabs-concat + stdlib: puppetlabs-stdlib diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..ff711d5 --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,14 @@ +--relative +--no-lookup_in_parameter-check +--no-parameter_documentation-check +--no-parameter_types-check +--no-params_empty_string_assignment-check +--no-relative_classname_inclusion-check +--no-relative_classname_reference-check +--no-strict_indent-check +--no-top_scope_facts-check +--no-topscope_variable-check +--no-trailing_comma-check +--no-selector_inside_resource-check +--no-documentation-check +--no-140chars-check diff --git a/Gemfile b/Gemfile index 11dea38..237c966 100644 --- a/Gemfile +++ b/Gemfile @@ -1,26 +1,70 @@ -source 'https://rubygems.org' - -group :test do - gem 'rake', '10.5.0' - gem 'puppet-lint' - gem 'puppet-syntax' - gem 'puppetlabs_spec_helper', '1.0.1' - gem 'rspec-puppet', '2.2.0' - gem 'rspec', '2.99.0' +source ENV['GEM_SOURCE'] || 'https://gems.ftven.net' + +def location_for(place_or_version, fake_version = nil) + git_url_regex = %r{\A(?(https?|git)[:@][^#]*)(#(?.*))?} + file_url_regex = %r{\Afile:\/\/(?.*)} + + if place_or_version && (git_url = place_or_version.match(git_url_regex)) + [fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact + elsif place_or_version && (file_url = place_or_version.match(file_url_regex)) + ['>= 0', { path: File.expand_path(file_url[:path]), require: false }] + else + [place_or_version, { require: false }] + end end group :development do - gem 'travis' - gem 'travis-lint' - gem 'beaker' - gem 'beaker-rspec' - gem 'pry' - gem 'guard-rake' + gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "voxpupuli-puppet-lint-plugins", '~> 4.0', require: false + gem "facterdb", '~> 1.18', require: false + gem "metadata-json-lint", '>= 2.0.2', '< 4.0.0', require: false + gem "puppetlabs_spec_helper", '~> 5.0', require: false + gem "rspec-puppet-facts", '~> 2.0', require: false + gem "codecov", '~> 0.2', require: false + gem "dependency_checker", '~> 0.2', require: false + gem "parallel_tests", '= 3.12.1', require: false + gem "pry", '~> 0.10', require: false + gem "simplecov-console", '~> 0.5', require: false + gem "puppet-debugger", '~> 1.0', require: false + gem "rubocop", '= 1.6.1', require: false + gem "rubocop-performance", '= 1.9.1', require: false + gem "rubocop-rspec", '= 2.0.1', require: false + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "rspec-puppet-utils", require: false + gem "webmock", require: false + gem "ipaddress", require: false + gem "hashie", require: false + gem "vault", require: false + gem "debouncer", require: false + gem "concurrent-ruby", require: false + gem "sdk_api", '= 0.4.0.9', require: false + gem "minitest", '= 5.15.0', require: false + gem "net-ssh", '= 6.1.0', require: false end +group :system_tests do + gem "puppet_litmus", '< 1.0.0', require: false, platforms: [:ruby, :x64_mingw] + gem "serverspec", '~> 2.41', require: false +end + +puppet_version = ENV['PUPPET_GEM_VERSION'] +facter_version = ENV['FACTER_GEM_VERSION'] +hiera_version = ENV['HIERA_GEM_VERSION'] + +gems = {} + +gems['puppet'] = location_for(puppet_version) + +# If facter or hiera versions have been specified via the environment +# variables +gems['facter'] = location_for(facter_version) if facter_version +gems['hiera'] = location_for(hiera_version) if hiera_version -if puppetversion = ENV['PUPPET_VERSION'] - gem 'puppet', puppetversion -else - gem 'puppet', '~> 3.8.0' +gems.each do |gem_name, gem_params| + gem gem_name, *gem_params end +# vim: syntax=ruby diff --git a/tests/ctlplugin.pp b/examples/ctlplugin.pp similarity index 100% rename from tests/ctlplugin.pp rename to examples/ctlplugin.pp diff --git a/tests/group.pp b/examples/group.pp similarity index 98% rename from tests/group.pp rename to examples/group.pp index 3d34046..c13bf20 100644 --- a/tests/group.pp +++ b/examples/group.pp @@ -1,4 +1,4 @@ supervisord::group { 'mygroup': priority => 100, program => ['program1', 'program2', 'program3'] -} \ No newline at end of file +} diff --git a/tests/init.pp b/examples/init.pp similarity index 100% rename from tests/init.pp rename to examples/init.pp diff --git a/tests/program.pp b/examples/program.pp similarity index 99% rename from tests/program.pp rename to examples/program.pp index 0d45ebe..0f8c3df 100644 --- a/tests/program.pp +++ b/examples/program.pp @@ -32,4 +32,4 @@ directory => undef, umask => '022', serverurl => 'AUTO' -} \ No newline at end of file +} diff --git a/tests/rpcinterface.pp b/examples/rpcinterface.pp similarity index 100% rename from tests/rpcinterface.pp rename to examples/rpcinterface.pp diff --git a/manifests/config.pp b/manifests/config.pp index e1a2007..b2c165b 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -3,7 +3,6 @@ # Configuration class for supervisor init and conf directories # class supervisord::config inherits supervisord { - if ($supervisord::manage_config) { file { $supervisord::config_include: ensure => directory, @@ -34,7 +33,7 @@ if $supervisord::install_init { file { $supervisord::init_script: - ensure => present, + ensure => file, owner => 'root', mode => $supervisord::init_mode, content => template($supervisord::init_script_template), @@ -43,7 +42,7 @@ if $supervisord::init_defaults { file { $supervisord::init_defaults: - ensure => present, + ensure => file, owner => 'root', mode => '0755', content => template($supervisord::init_defaults_template), diff --git a/manifests/ctlplugin.pp b/manifests/ctlplugin.pp index 91a62c6..0d22b09 100644 --- a/manifests/ctlplugin.pp +++ b/manifests/ctlplugin.pp @@ -9,16 +9,13 @@ # Documentation on parameters available at: # http://supervisord.org/configuration.html#program-x-section-settings # -define supervisord::ctlplugin( +define supervisord::ctlplugin ( String $ctl_factory, - $ensure = present, + $ensure = present, ) { - include supervisord - concat::fragment { "ctlplugin:${name}": target => $supervisord::config_file, content => template('supervisord/conf/ctlplugin.erb'), order => 70, } - } diff --git a/manifests/eventlistener.pp b/manifests/eventlistener.pp index 8c7e721..3d86aa2 100644 --- a/manifests/eventlistener.pp +++ b/manifests/eventlistener.pp @@ -19,7 +19,7 @@ Optional[Integer] $numprocs_start = undef, Optional[Integer] $priority = undef, Optional[Boolean] $autostart = undef, - Optional[Boolean] $autorestart = undef, + Optional[Variant[Boolean, Enum['unexpected']]] $autorestart = undef, Optional[Integer] $startsecs = undef, Optional[Integer] $startretries = undef, Optional[String] $exitcodes = undef, @@ -30,23 +30,20 @@ Optional[String] $user = undef, Optional[Boolean] $redirect_stderr = undef, String $stdout_logfile = "eventlistener_${name}.log", - Optional[String] $stdout_logfile_maxbytes = undef, + Optional[Supervisord::Maxbytes] $stdout_logfile_maxbytes = undef, Optional[Integer] $stdout_logfile_backups = undef, Optional[Boolean] $stdout_events_enabled = undef, String $stderr_logfile = "eventlistener_${name}.error", - Optional[String] $stderr_logfile_maxbytes = undef, + Optional[Supervisord::Maxbytes] $stderr_logfile_maxbytes = undef, Optional[Integer] $stderr_logfile_backups = undef, Optional[Boolean] $stderr_events_enabled = undef, $environment = undef, $event_environment = undef, Optional[Stdlib::AbsolutePath] $directory = undef, Optional[Stdlib::Filemode] $umask = undef, - Optional[Variant[Stdlib::HTTPSUrl, Stdlib::HTTPUrl]] $serverurl = undef, + Optional[String] $serverurl = undef, Stdlib::Filemode $config_file_mode = '0644' ) { - - include supervisord - # create the correct log variables $stdout_logfile_path = $stdout_logfile ? { /(NONE|AUTO|syslog)/ => $stdout_logfile, diff --git a/manifests/fcgi_program.pp b/manifests/fcgi_program.pp index acabfc2..5251716 100644 --- a/manifests/fcgi_program.pp +++ b/manifests/fcgi_program.pp @@ -7,6 +7,7 @@ # define supervisord::fcgi_program ( String $command, + $socket, $ensure = present, Enum['running', 'stopped', 'removed', 'unmanaged'] $ensure_process = 'running', Optional[Boolean] $cfgreload = undef, @@ -19,7 +20,7 @@ Optional[Integer] $numprocs_start = undef, Optional[Integer] $priority = undef, Optional[Boolean] $autostart = undef, - Optional[Boolean] $autorestart = undef, + Optional[Variant[Boolean, Enum['unexpected']]] $autorestart = undef, Optional[Integer] $startsecs = undef, Optional[Integer] $startretries = undef, Optional[String] $exitcodes = undef, @@ -30,23 +31,22 @@ Optional[String] $user = undef, Optional[Boolean] $redirect_stderr = undef, String $stdout_logfile = "eventlistener_${name}.log", - Optional[String] $stdout_logfile_maxbytes = undef, + Optional[Supervisord::Maxbytes] $stdout_logfile_maxbytes = undef, + Optional[Supervisord::Maxbytes] $stdout_capture_maxbytes = undef, Optional[Integer] $stdout_logfile_backups = undef, Optional[Boolean] $stdout_events_enabled = undef, String $stderr_logfile = "eventlistener_${name}.error", - Optional[String] $stderr_logfile_maxbytes = undef, + Optional[Supervisord::Maxbytes] $stderr_logfile_maxbytes = undef, + Optional[Supervisord::Maxbytes] $stderr_capture_maxbytes = undef, Optional[Integer] $stderr_logfile_backups = undef, Optional[Boolean] $stderr_events_enabled = undef, $environment = undef, $program_environment = undef, Optional[Stdlib::AbsolutePath] $directory = undef, Optional[Stdlib::Filemode] $umask = undef, - Optional[Variant[Stdlib::HTTPSUrl, Stdlib::HTTPUrl]] $serverurl = undef, + Optional[String] $serverurl = undef, Stdlib::Filemode $config_file_mode = '0644' ) { - - include supervisord - # create the correct log variables $stdout_logfile_path = $stdout_logfile ? { /(NONE|AUTO|syslog)/ => $stdout_logfile, diff --git a/manifests/group.pp b/manifests/group.pp index 8da30fd..a846bda 100644 --- a/manifests/group.pp +++ b/manifests/group.pp @@ -8,12 +8,9 @@ define supervisord::group ( Array $programs, $ensure = present, - Integer $priority = undef, + Optional[Integer] $priority = undef, Stdlib::Filemode $config_file_mode = '0644' ) { - - include supervisord - $progstring = array2csv($programs) $conf = "${supervisord::config_include}/group_${name}.conf" diff --git a/manifests/init.pp b/manifests/init.pp index f45fe7c..792a847 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -3,103 +3,97 @@ # This class installs supervisord via pip # class supervisord ( - $package_ensure = $supervisord::params::package_ensure, - $package_name = $supervisord::params::package_name, - $package_provider = $supervisord::params::package_provider, - $package_install_options = $supervisord::params::package_install_options, - $service_manage = $supervisord::params::service_manage, - $service_ensure = $supervisord::params::service_ensure, - $service_enable = $supervisord::params::service_enable, - $service_name = $supervisord::params::service_name, - $service_restart = $supervisord::params::service_restart, - Boolean $install_pip = false, - Variant[Stdlib::HTTPSUrl, Stdlib::HTTPUrl] $pip_proxy = undef, - Boolean $install_init = $supervisord::params::install_init, - $init_type = $supervisord::params::init_type, - $init_mode = $supervisord::params::init_mode, - $init_script = $supervisord::params::init_script, - $init_script_template = $supervisord::params::init_script_template, - $init_defaults = $supervisord::params::init_defaults, - $init_defaults_template = $supervisord::params::init_defaults_template, - $setuptools_url = $supervisord::params::setuptools_url, - $executable = $supervisord::params::executable, - $executable_ctl = $supervisord::params::executable_ctl, - - $scl_enabled = $supervisord::params::scl_enabled, - $scl_script = $supervisord::params::scl_script, - - Stdlib::AbsolutePath $log_path = $supervisord::params::log_path, - $log_file = $supervisord::params::log_file, - $log_level = $supervisord::params::log_level, - $logfile_maxbytes = $supervisord::params::logfile_maxbytes, - Integer $logfile_backups = $supervisord::params::logfile_backups, - - $cfgreload_program = $supervisord::params::cfgreload_program, - $cfgreload_fcgi_program = $supervisord::params::cfgreload_fcgi_program, - $cfgreload_eventlistener = $supervisord::params::cfgreload_eventlistener, - $cfgreload_rpcinterface = $supervisord::params::cfgreload_rpcinterface, - - Stdlib::AbsolutePath $run_path = $supervisord::params::run_path, - $pid_file = $supervisord::params::pid_file, - Boolean $nodaemon = $supervisord::params::nodaemon, - Integer $minfds = $supervisord::params::minfds, - Integer $minprocs = $supervisord::params::minprocs, - $manage_config = $supervisord::params::manage_config, - Stdlib::AbsolutePath $config_include = $supervisord::params::config_include, - $config_include_purge = false, - $config_file = $supervisord::params::config_file, - Stdlib::Filemode $config_file_mode = $supervisord::params::config_file_mode, - Optional[Array]$config_dirs = undef, - $umask = $supervisord::params::umask, - - Enum['unix', 'inet'] $ctl_socket = $supervisord::params::ctl_socket, - - Boolean $unix_socket = $supervisord::params::unix_socket, - $unix_socket_file = $supervisord::params::unix_socket_file, - Stdlib::Filemode $unix_socket_mode = $supervisord::params::unix_socket_mode, - $unix_socket_owner = $supervisord::params::unix_socket_owner, - $unix_socket_group = $supervisord::params::unix_socket_group, - Boolean $unix_auth = $supervisord::params::unix_auth, - String $unix_username = $supervisord::params::unix_username, - String $unix_password = $supervisord::params::unix_password, - - Boolean $inet_server = $supervisord::params::inet_server, - $inet_server_hostname = $supervisord::params::inet_server_hostname, - Stdlib::Port $inet_server_port = $supervisord::params::inet_server_port, - Boolean $inet_auth = $supervisord::params::inet_auth, - String $inet_username = $supervisord::params::inet_username, - String $inet_password = $supervisord::params::inet_password, - - $user = $supervisord::params::user, - $group = $supervisord::params::group, - $identifier = undef, - Optional[Stdlib::AbsolutePath] $childlogdir = undef, - Optional[Hash] $environment = undef, - Optional[Hash] $global_environment = undef, - $env_var = undef, - Optional[Stdlib::AbsolutePath] $directory = undef, - Boolean $strip_ansi = false, - Boolean $nocleanup = false, - - Hash $eventlisteners = {}, - Hash $fcgi_programs = {}, - Hash $groups = {}, - Hash $programs = {} + $package_ensure = $supervisord::params::package_ensure, + $package_name = $supervisord::params::package_name, + $package_provider = $supervisord::params::package_provider, + $package_install_options = $supervisord::params::package_install_options, + Boolean $service_manage = $supervisord::params::service_manage, + $service_ensure = $supervisord::params::service_ensure, + $service_enable = $supervisord::params::service_enable, + String $service_name = $supervisord::params::service_name, + $service_restart = $supervisord::params::service_restart, + Boolean $install_pip = false, + Optional[String] $pip_proxy = undef, + Boolean $install_init = $supervisord::params::install_init, + $init_type = $supervisord::params::init_type, + $init_mode = $supervisord::params::init_mode, + $init_script = $supervisord::params::init_script, + $init_script_template = $supervisord::params::init_script_template, + $init_defaults = $supervisord::params::init_defaults, + $init_defaults_template = $supervisord::params::init_defaults_template, + $setuptools_url = $supervisord::params::setuptools_url, + $executable = $supervisord::params::executable, + $executable_ctl = $supervisord::params::executable_ctl, + + $scl_enabled = $supervisord::params::scl_enabled, + $scl_script = $supervisord::params::scl_script, + + Stdlib::AbsolutePath $log_path = $supervisord::params::log_path, + $log_file = $supervisord::params::log_file, + Enum['critical', 'error', 'warn', 'info', 'debug', 'trace', 'blather'] $log_level = $supervisord::params::log_level, + Supervisord::Maxbytes $logfile_maxbytes = $supervisord::params::logfile_maxbytes, + Integer $logfile_backups = $supervisord::params::logfile_backups, + + $cfgreload_program = $supervisord::params::cfgreload_program, + $cfgreload_fcgi_program = $supervisord::params::cfgreload_fcgi_program, + $cfgreload_eventlistener = $supervisord::params::cfgreload_eventlistener, + $cfgreload_rpcinterface = $supervisord::params::cfgreload_rpcinterface, + + Stdlib::AbsolutePath $run_path = $supervisord::params::run_path, + $pid_file = $supervisord::params::pid_file, + Boolean $nodaemon = $supervisord::params::nodaemon, + Integer $minfds = $supervisord::params::minfds, + Integer $minprocs = $supervisord::params::minprocs, + Boolean $manage_config = $supervisord::params::manage_config, + Stdlib::AbsolutePath $config_include = $supervisord::params::config_include, + Boolean $config_include_purge = false, + Stdlib::AbsolutePath $config_file = $supervisord::params::config_file, + Stdlib::Filemode $config_file_mode = $supervisord::params::config_file_mode, + Optional[Array] $config_dirs = undef, + Supervisord::Umask $umask = $supervisord::params::umask, + + Enum['unix', 'inet'] $ctl_socket = $supervisord::params::ctl_socket, + + Boolean $unix_socket = $supervisord::params::unix_socket, + $unix_socket_file = $supervisord::params::unix_socket_file, + Stdlib::Filemode $unix_socket_mode = $supervisord::params::unix_socket_mode, + $unix_socket_owner = $supervisord::params::unix_socket_owner, + $unix_socket_group = $supervisord::params::unix_socket_group, + Boolean $unix_auth = $supervisord::params::unix_auth, + String $unix_username = $supervisord::params::unix_username, + String $unix_password = $supervisord::params::unix_password, + + Boolean $inet_server = $supervisord::params::inet_server, + $inet_server_hostname = $supervisord::params::inet_server_hostname, + Stdlib::Port $inet_server_port = $supervisord::params::inet_server_port, + Boolean $inet_auth = $supervisord::params::inet_auth, + String $inet_username = $supervisord::params::inet_username, + String $inet_password = $supervisord::params::inet_password, + + String $user = $supervisord::params::user, + String $group = $supervisord::params::group, + Optional[String] $identifier = undef, + Optional[Stdlib::AbsolutePath] $childlogdir = undef, + Optional[Hash] $environment = undef, + Optional[Hash] $global_environment = undef, + $env_var = undef, + Optional[Stdlib::AbsolutePath] $directory = undef, + Boolean $strip_ansi = false, + Boolean $nocleanup = false, + + Hash $eventlisteners = {}, + Hash $fcgi_programs = {}, + Hash $groups = {}, + Hash $programs = {} ) inherits supervisord::params { - - $log_levels = ['^critical$', '^error$', '^warn$', '^info$', '^debug$', '^trace$', '^blather$'] - validate_re($log_level, $log_levels, "invalid log_level: ${log_level}") - validate_re($logfile_maxbytes, '^[0-9]*(?:KB|MB|GB)?', "invalid logfile_maxbytes: ${$logfile_maxbytes}") - validate_re($umask, '^0[0-7][0-7]$', "invalid umask: ${umask}.") - if $unix_socket and $inet_server { $use_ctl_socket = $ctl_socket - } - elsif $unix_socket { + } elsif $unix_socket { $use_ctl_socket = 'unix' - } - elsif $inet_server { + } elsif $inet_server { $use_ctl_socket = 'inet' + } else { + $use_ctl_socket = '' } if $use_ctl_socket == 'unix' { @@ -116,7 +110,9 @@ } # Handle deprecated $environment variable - if $environment { notify { '[supervisord] *** DEPRECATED WARNING ***: $global_environment has replaced $environment': } } + if $environment { + notify { '[supervisord] *** DEPRECATED WARNING ***: $global_environment has replaced $environment': } + } $_global_environment = $global_environment ? { undef => $environment, default => $global_environment @@ -164,5 +160,4 @@ Class['supervisord::service'] -> Supervisord::Group <| |> Class['supervisord::service'] -> Supervisord::Rpcinterface <| |> Class['supervisord::reload'] -> Supervisord::Supervisorctl <| |> - } diff --git a/manifests/install.pp b/manifests/install.pp index 26cfb37..d401401 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -6,13 +6,18 @@ if $::supervisord::pip_proxy and $::supervisord::package_provider == 'pip' { exec { 'pip-install-supervisor': user => root, - path => ['/usr/bin','/bin'], - environment => [ "http_proxy=${supervisord::pip_proxy}", "https_proxy=${supervisord::pip_proxy}" ], + path => [ + '/usr/bin', + '/bin' + ], + environment => [ + "http_proxy=${supervisord::pip_proxy}", + "https_proxy=${supervisord::pip_proxy}" + ], command => "pip install ${supervisord::package_name}", unless => 'which supervisorctl', } - } - else { + } else { package { $supervisord::package_name: ensure => $supervisord::package_ensure, provider => $supervisord::package_provider, diff --git a/manifests/params.pp b/manifests/params.pp index f0cdbee..f67822d 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,79 +4,36 @@ # class supervisord::params { # sort out init params for different OS families - case $::osfamily { + case $facts['os']['family'] { 'RedHat': { $unix_socket_group = 'nobody' - $install_init = true - case $::operatingsystem { - 'Amazon': { - $init_type = 'init' - $init_script = '/etc/init.d/supervisord' - $init_defaults = '/etc/sysconfig/supervisord' - $executable_path = '/usr/local/bin' - } - default: { - case $::operatingsystemmajrelease { - '7': { - $init_type = 'systemd' - $init_script = '/etc/systemd/system/supervisord.service' - $init_defaults = false - } - default: { - $init_type = 'init' - $init_script = '/etc/init.d/supervisord' - $init_defaults = '/etc/sysconfig/supervisord' - } - } - $executable_path = '/usr/bin' - } - } - } - 'Suse': { - $init_type = 'init' - $init_defaults = '/etc/sysconfig/supervisor' - $init_script = '/etc/init.d/supervisord' - $unix_socket_group = 'nobody' - $install_init = true - $executable_path = '/usr/local/bin' + $install_init = true + $init_type = 'systemd' + $init_script = '/etc/systemd/system/supervisord.service' + $init_defaults = false + $executable_path = '/usr/bin' } 'Debian': { - case $::operatingsystem { - 'Ubuntu': { - if versioncmp($::operatingsystemmajrelease, '15.10') > 0 { - $init_type = 'systemd' - $init_script = '/etc/systemd/system/supervisord.service' - $init_defaults = false - } else { - $init_type = 'init' - $init_script = '/etc/init.d/supervisord' - $init_defaults = '/etc/default/supervisor' - } - } - default: { - case $::operatingsystemmajrelease { - '8': { - $init_type = 'systemd' - $init_script = '/etc/systemd/system/supervisord.service' - $init_defaults = false - } - default: { - $init_type = 'init' - $init_script = '/etc/init.d/supervisord' - $init_defaults = '/etc/default/supervisor' - } - } - } - } + $init_type = 'systemd' + $init_script = '/etc/systemd/system/supervisord.service' + $init_defaults = false + $unix_socket_group = 'nogroup' + $install_init = true + $executable_path = '/usr/local/bin' + } + 'Ubuntu': { + $init_type = 'systemd' + $init_script = '/etc/systemd/system/supervisord.service' + $init_defaults = false $unix_socket_group = 'nogroup' - $install_init = true - $executable_path = '/usr/local/bin' + $install_init = true + $executable_path = '/usr/local/bin' } - default: { - $init_defaults = false + default: { + $init_defaults = false $unix_socket_group = 'nogroup' - $install_init = false - $executable_path = '/usr/local/bin' + $install_init = false + $executable_path = '/usr/local/bin' } } @@ -86,63 +43,63 @@ default => '0755' } - $init_script_template = "supervisord/init/${::osfamily}/${init_type}.erb" - $init_defaults_template = "supervisord/init/${::osfamily}/defaults.erb" + $init_script_template = "supervisord/init/${facts['os']['family']}/${init_type}.erb" + $init_defaults_template = "supervisord/init/${facts['os']['family']}/defaults.erb" # default supervisord params - $package_ensure = 'installed' - $package_provider = 'pip' + $package_ensure = 'installed' + $package_provider = 'pip' $package_install_options = undef - $service_manage = true - $service_ensure = 'running' - $service_enable = true - $service_name = 'supervisord' - $service_restart = undef - $package_name = 'supervisor' - $executable = "${executable_path}/supervisord" - $executable_ctl = "${executable_path}/supervisorctl" + $service_manage = true + $service_ensure = 'running' + $service_enable = true + $service_name = 'supervisord' + $service_restart = undef + $package_name = 'supervisor' + $executable = "${executable_path}/supervisord" + $executable_ctl = "${executable_path}/supervisorctl" - $scl_enabled = false - $scl_script = '/opt/rh/python27/enable' + $scl_enabled = false + $scl_script = '/opt/rh/python27/enable' - $run_path = '/var/run' - $pid_file = 'supervisord.pid' - $log_path = '/var/log/supervisor' - $log_file = 'supervisord.log' - $logfile_maxbytes = '50MB' - $logfile_backups = '10' - $log_level = 'info' - $nodaemon = false - $minfds = '1024' - $minprocs = '200' - $umask = '022' - $manage_config = true - $config_include = '/etc/supervisor.d' - $config_file = '/etc/supervisord.conf' - $config_file_mode = '0644' - $setuptools_url = 'https://bootstrap.pypa.io/ez_setup.py' + $run_path = '/var/run' + $pid_file = 'supervisord.pid' + $log_path = '/var/log/supervisor' + $log_file = 'supervisord.log' + $logfile_maxbytes = '50MB' + $logfile_backups = 10 + $log_level = 'info' + $nodaemon = false + $minfds = 1024 + $minprocs = 200 + $umask = '022' + $manage_config = true + $config_include = '/etc/supervisor.d' + $config_file = '/etc/supervisord.conf' + $config_file_mode = '0644' + $setuptools_url = 'https://bootstrap.pypa.io/ez_setup.py' - $cfgreload_program = true - $cfgreload_fcgi_program = true + $cfgreload_program = true + $cfgreload_fcgi_program = true $cfgreload_eventlistener = true - $cfgreload_rpcinterface = true + $cfgreload_rpcinterface = true - $ctl_socket = 'unix' + $ctl_socket = 'unix' - $unix_socket = true - $unix_socket_file = 'supervisor.sock' - $unix_socket_mode = '0700' - $unix_socket_owner = 'nobody' - $unix_auth = false - $unix_username = undef - $unix_password = undef + $unix_socket = true + $unix_socket_file = 'supervisor.sock' + $unix_socket_mode = '0700' + $unix_socket_owner = 'nobody' + $unix_auth = false + $unix_username = undef + $unix_password = undef - $inet_server = false - $inet_server_hostname = '127.0.0.1' - $inet_server_port = '9001' - $inet_auth = false - $inet_username = undef - $inet_password = undef - $user = 'root' - $group = 'root' + $inet_server = false + $inet_server_hostname = '127.0.0.1' + $inet_server_port = 9001 + $inet_auth = false + $inet_username = undef + $inet_password = undef + $user = 'root' + $group = 'root' } diff --git a/manifests/pip.pp b/manifests/pip.pp index 02d44dd..1d89707 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -3,7 +3,6 @@ # Optional class to install setuptool and pip # class supervisord::pip inherits supervisord { - Exec { path => '/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin' } @@ -23,12 +22,11 @@ unless => 'which pip' } - if $::osfamily == 'RedHat' { + if $facts['os']['family'] == 'RedHat' { exec { 'pip_provider_name_fix': command => 'alternatives --install /usr/bin/pip-python pip-python /usr/bin/pip 1', subscribe => Exec['install_pip'], unless => 'which pip-python' } } - } diff --git a/manifests/program.pp b/manifests/program.pp index 8a5273b..5f55351 100644 --- a/manifests/program.pp +++ b/manifests/program.pp @@ -5,7 +5,7 @@ # Documentation on parameters available at: # http://supervisord.org/configuration.html#program-x-section-settings # -define supervisord::program( +define supervisord::program ( String $command, $ensure = present, Enum['running', 'stopped', 'removed', 'unmanaged'] $ensure_process = 'running', @@ -19,7 +19,7 @@ Optional[Integer] $numprocs_start = undef, Optional[Integer] $priority = undef, Optional[Boolean] $autostart = undef, - Optional[Boolean] $autorestart = undef, + Optional[Variant[Boolean, Enum['unexpected']]] $autorestart = undef, Optional[Integer] $startsecs = undef, Optional[Integer] $startretries = undef, Optional[String] $exitcodes = undef, @@ -30,37 +30,37 @@ Optional[String] $user = undef, Optional[Boolean] $redirect_stderr = undef, String $stdout_logfile = "eventlistener_${name}.log", - Optional[String] $stdout_logfile_maxbytes = undef, + Optional[Supervisord::Maxbytes] $stdout_logfile_maxbytes = undef, + Optional[Supervisord::Maxbytes] $stdout_capture_maxbytes = undef, Optional[Integer] $stdout_logfile_backups = undef, Optional[Boolean] $stdout_events_enabled = undef, String $stderr_logfile = "eventlistener_${name}.error", - Optional[String] $stderr_logfile_maxbytes = undef, + Optional[Supervisord::Maxbytes] $stderr_logfile_maxbytes = undef, + Optional[Supervisord::Maxbytes] $stderr_capture_maxbytes = undef, Optional[Integer] $stderr_logfile_backups = undef, Optional[Boolean] $stderr_events_enabled = undef, $environment = undef, + $program_environment = undef, Optional[Stdlib::AbsolutePath] $directory = undef, Optional[Stdlib::Filemode] $umask = undef, - Optional[Variant[Stdlib::HTTPSUrl, Stdlib::HTTPUrl]] $serverurl = undef, + Optional[String] $serverurl = undef, Stdlib::Filemode $config_file_mode = '0644' ) { - - include supervisord - # create the correct log variables $stdout_logfile_path = $stdout_logfile ? { - /(NONE|AUTO|syslog)/ => $stdout_logfile, - /^\// => $stdout_logfile, - default => "${supervisord::log_path}/${stdout_logfile}", + /(NONE|AUTO|syslog)/ => $stdout_logfile, + /^\// => $stdout_logfile, + default => "${supervisord::log_path}/${stdout_logfile}", } $stderr_logfile_path = $stderr_logfile ? { - /(NONE|AUTO|syslog)/ => $stderr_logfile, - /^\// => $stderr_logfile, - default => "${supervisord::log_path}/${stderr_logfile}", + /(NONE|AUTO|syslog)/ => $stderr_logfile, + /^\// => $stderr_logfile, + default => "${supervisord::log_path}/${stderr_logfile}", } # Handle deprecated $environment variable - if $environment { notify {'[supervisord] *** DEPRECATED WARNING ***: $program_environment has replaced $environment':}} + if $environment { notify { '[supervisord] *** DEPRECATED WARNING ***: $program_environment has replaced $environment': } } $_program_environment = $program_environment ? { undef => $environment, default => $program_environment @@ -123,6 +123,6 @@ unless => 'running' } } - default: { } + default: {} } } diff --git a/manifests/reload.pp b/manifests/reload.pp index 0fc68f8..aafc09c 100644 --- a/manifests/reload.pp +++ b/manifests/reload.pp @@ -18,4 +18,3 @@ } } } - diff --git a/manifests/rpcinterface.pp b/manifests/rpcinterface.pp index 27ffba4..2273290 100644 --- a/manifests/rpcinterface.pp +++ b/manifests/rpcinterface.pp @@ -8,13 +8,10 @@ define supervisord::rpcinterface ( $rpcinterface_factory, $ensure = present, - Boolean $cfgreload = undef, + Optional[Boolean] $cfgreload = undef, Optional[Integer] $retries = undef, Stdlib::Filemode $config_file_mode = '0644' ) { - - include supervisord - # Reload default with override $_cfgreload = $cfgreload ? { undef => $supervisord::cfgreload_rpcinterface, @@ -35,5 +32,4 @@ notify => Class['supervisord::reload'], } } - } diff --git a/manifests/service.pp b/manifests/service.pp index ba81823..dfdb981 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -2,7 +2,7 @@ # # Class for the supervisord service # -class supervisord::service inherits supervisord { +class supervisord::service () inherits supervisord { if $::supervisord::service_manage { if $::supervisord::init_type == 'systemd' { exec { 'refresh_supervisord_unit': diff --git a/manifests/supervisorctl.pp b/manifests/supervisorctl.pp index 57c2c89..6fb1cbc 100644 --- a/manifests/supervisorctl.pp +++ b/manifests/supervisorctl.pp @@ -2,13 +2,12 @@ # # This define executes command with the supervisorctl tool # -define supervisord::supervisorctl( +define supervisord::supervisorctl ( String $command, - Optional[String] $process = undef, - $refreshonly = false, - $unless = undef + Optional[String] $process = undef, + Boolean $refreshonly = false, + $unless = undef ) { - $supervisorctl = $::supervisord::executable_ctl if $process { diff --git a/metadata.json b/metadata.json index 6bb8171..8670a59 100644 --- a/metadata.json +++ b/metadata.json @@ -7,7 +7,13 @@ "source": "https://github.com/ajcrowe/puppet-supervisord", "project_page": "https://forge.puppetlabs.com/ajcrowe/supervisord", "issues_url": "https://github.com/ajcrowe/puppet-supervisord/issues", - "tags": ["supervisor", "supervisord", "python", "process", "management" ], + "tags": [ + "supervisor", + "supervisord", + "python", + "process", + "management" + ], "requirements": [ { "name": "puppet", @@ -16,24 +22,44 @@ ], "operatingsystem_support": [ { - "operatingsystem":"RedHat", - "operatingsystemrelease":[ "5", "6", "7" ] + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "7", + "8" + ] }, { - "operatingsystem":"CentOS", - "operatingsystemrelease":[ "5", "6", "7" ] + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "7", + "8" + ] }, { - "operatingsystem": "Ubuntu", - "operatingsystemrelease": [ "16.04", "14.04", "12.04", "10.04" ] + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "18.04", + "20.04", + "22.04" + ] }, { - "operatingsystem": "Debian", - "operatingsystemrelease": [ "9", "10", "11", "12" ] + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "10", + "11", + "12" + ] } - ], + ], "dependencies": [ - { "name": "puppetlabs/stdlib", "version_requirement": ">= 7.0.0 <10.0.0" }, - { "name": "puppetlabs/concat", "version_requirement": ">= 1.0.0 <8.0.0" } + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 7.0.0 <10.0.0" + }, + { + "name": "puppetlabs/concat", + "version_requirement": ">= 1.0.0 <8.0.0" + } ] } diff --git a/spec/classes/supervisord_spec.rb b/spec/classes/supervisord_spec.rb index 8a5a607..a285921 100644 --- a/spec/classes/supervisord_spec.rb +++ b/spec/classes/supervisord_spec.rb @@ -1,353 +1,458 @@ require 'spec_helper' describe 'supervisord' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:concatdir) { '/var/lib/puppet/concat' } + let(:facts) do + os_facts.merge( + concat_basedir: concatdir + ) + end + let(:params) do + { + unix_username: 'foo', + unix_password: 'bar', + inet_username: 'foo', + inet_password: 'bar', + } + end - concatdir = '/var/lib/puppet/concat' - let(:facts) {{ :concat_basedir => concatdir }} - - it { should contain_class('supervisord') } - it { should contain_class('supervisord::install') } - it { should contain_class('supervisord::config') } - it { should contain_class('supervisord::service') } - it { should contain_class('supervisord::params') } - it { should contain_class('supervisord::reload') } - it { should contain_package('supervisor') } - - describe '#service_name' do - context 'default' do - it { should contain_service('supervisord') } - end - - context 'specified' do - let(:params) {{ :service_name => 'myservicename' }} - it { should contain_service('myservicename') } - end - end + it { is_expected.to contain_class('supervisord') } + it { is_expected.to contain_class('supervisord::install') } + it { is_expected.to contain_class('supervisord::config') } + it { is_expected.to contain_class('supervisord::service') } + it { is_expected.to contain_class('supervisord::params') } + it { is_expected.to contain_class('supervisord::reload') } + it { is_expected.to contain_package('supervisor') } - describe '#install_pip' do - context 'default' do - it { should_not contain_class('supervisord::pip') } - end + describe '#service_name' do + context 'default' do + it { is_expected.to contain_service('supervisord') } + end - context 'true' do - let(:params) {{ :install_pip => true }} - it { should contain_class('supervisord::pip') } - it { should contain_exec('install_setuptools') } - it { should contain_exec('install_pip') } - end + context 'specified' do + let(:params) do + super().merge( + service_name: 'myservicename', + ) + end + it { is_expected.to contain_service('myservicename') } + end + end - context 'true and RedHat' do - let(:params) {{ :install_pip => true }} - let(:facts) {{ :osfamily => 'RedHat', :concat_basedir => concatdir }} - it { should contain_exec('pip_provider_name_fix') } - end - context 'true and package_install_options not specified' do - let(:params) {{ :install_pip => true, :package_install_options => false }} - it { should contain_package('supervisor').with_install_options(false) } - end - end + describe '#install_pip' do + context 'default' do + it { is_expected.not_to contain_class('supervisord::pip') } + end - describe '#env_var' do - context 'default' do - it { should contain_class('supervisord').without_env_hash } - it { should contain_class('supervisord').without_env_string } - end - end + context 'true' do + let(:params) do + super().merge( + install_pip: true, + ) + end + it { is_expected.to contain_class('supervisord::pip') } + it { is_expected.to contain_exec('install_setuptools') } + it { is_expected.to contain_exec('install_pip') } + end - describe '#global_environment' do - context 'default' do - it { should contain_class('supervisord').without_env_string } - end - context 'is specified' do - let(:params) {{ :global_environment => { 'key1' => 'value1', 'key2' => 'value2' } }} - it { should contain_concat__fragment('supervisord_main')\ - .with_content(/environment=key1='value1',key2='value2'/) } - end - end + context 'true and RedHat' do + let(:params) do + super().merge( + install_pip: true, + ) + end + case os_facts[:os][:family] + when 'RedHat' + it { is_expected.to contain_exec('pip_provider_name_fix') } + end + end - describe '#install_init' do - context 'false' do - it { should_not contain_file('/etc/init.d/supervisord') } - end + context 'true and package_install_options not specified' do + let(:params) do + super().merge( + install_pip: true, + package_install_options: false, + ) + end + it { is_expected.to contain_package('supervisor').with_install_options(false) } + end + end - context 'with custom init script' do - let(:params) {{ :init_script => '/etc/init/supervisord', :init_script_template => 'supervisord/init/Debian/systemd.erb', :init_defaults => false, :install_init => true }} - it { should contain_file('/etc/init/supervisord')} - end + describe '#env_var' do + context 'default' do + it { is_expected.to contain_class('supervisord').without_env_hash } + it { is_expected.to contain_class('supervisord').without_env_string } + end + end - describe 'on supported OS' do - describe 'with Debian' do - context 'Wheezy (7.x)' do - let(:facts) {{ :osfamily => 'Debian', :operatingsystemmajrelease => '7', :concat_basedir => concatdir }} - it { should contain_file('/etc/init.d/supervisord') } - it { should contain_file('/etc/default/supervisor') } - end - context 'Jessie (8.x)' do - let(:facts) {{ :osfamily => 'Debian', :operatingsystemmajrelease => '8', :concat_basedir => concatdir }} - it { should contain_file('/etc/systemd/system/supervisord.service') } - it { should_not contain_file('/etc/default/supervisor') } + describe '#global_environment' do + context 'default' do + it { is_expected.to contain_class('supervisord').without_env_string } + end + context 'is specified' do + let(:params) do + super().merge( + global_environment: { 'key1' => 'value1', 'key2' => 'value2' }, + ) + end + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/environment=key1='value1',key2='value2'/) } end end - describe 'with RedHat' do - context 'Centos 6' do - let(:facts) {{ :osfamily => 'RedHat', :operatingsystemmajrelease => '6', :concat_basedir => concatdir }} - it { should contain_file('/etc/init.d/supervisord') } - it { should contain_file('/etc/sysconfig/supervisord') } - end - context 'Centos 7' do - let(:facts) {{ :osfamily => 'RedHat', :operatingsystemmajrelease => '7', :concat_basedir => concatdir }} - it { should contain_file('/etc/systemd/system/supervisord.service') } - it { should_not contain_file('/etc/default/supervisor') } - it { should contain_file('/etc/systemd/system/supervisord.service').with_content(/LimitNOFILE=1024$/) } - end - context 'Amazon' do - let(:facts) {{ :osfamily => 'RedHat', :operatingsystem => 'Amazon', :concat_basedir => concatdir }} - it { should contain_file('/etc/init.d/supervisord') } - it { should contain_file('/etc/sysconfig/supervisord') } + + describe '#install_init' do + context 'with custom init script' do + let(:params) do + super().merge( + init_script: '/etc/init/supervisord', + init_script_template: 'supervisord/init/Debian/systemd.erb', + init_defaults: false, + install_init: true, + ) + end + it { is_expected.to contain_file('/etc/init/supervisord') } end + context 'on supported OS' do + case os_facts[:os][:family] + when 'RedHat' + context 'with RedHat' do + it { is_expected.to contain_file('/etc/systemd/system/supervisord.service') } + it { is_expected.to contain_file('/etc/sysconfig/supervisord') } + it { is_expected.to contain_file('/etc/systemd/system/supervisord.service').with_content(/LimitNOFILE=1024$/) } + end + when 'Debian' + context 'with Debian' do + it { is_expected.to contain_file('/etc/systemd/system/supervisord.service') } + it { is_expected.not_to contain_file('/etc/default/supervisor') } + it { is_expected.to contain_file('/etc/systemd/system/supervisord.service').with_content(/LimitNOFILE=1024$/) } + end + end + end end - context 'with Suse' do - let(:facts) {{ :osfamily => 'Suse', :concat_basedir => concatdir }} - it { should contain_file('/etc/init.d/supervisord') } - it { should contain_file('/etc/sysconfig/supervisor') } - end - describe 'with Ubuntu' do - context 'Trusty (14.04)' do - let(:facts) {{ :osfamily => 'Debian', :operatingsystem => 'Ubuntu', :operatingsystemmajrelease => '14.04', :concat_basedir => concatdir }} - it { should contain_file('/etc/init.d/supervisord') } - it { should contain_file('/etc/default/supervisor') } + + describe '#unix_socket' do + context 'default' do + it { is_expected.to contain_concat__fragment('supervisord_unix') } end - context 'Xenial (16.04)' do - let(:facts) {{ :osfamily => 'Debian', :operatingsystem => 'Ubuntu', :operatingsystemmajrelease => '16.04', :concat_basedir => concatdir }} - it { should contain_file('/etc/systemd/system/supervisord.service') } - it { should_not contain_file('/etc/default/supervisor') } + context 'false' do + let(:params) do + super().merge( + unix_socket: false, + ) + end + it { is_expected.not_to contain_concat__fragment('supervisord_unix') } end end - end - end - describe '#unix_socket' do - context 'default' do - it { should contain_concat__fragment('supervisord_unix')} - end - context 'false' do - let(:params) {{ :unix_socket => false }} - it { should_not contain_concat__fragment('supervisord_unix')} - end - end - - describe '#inet_server' do - context 'default' do - it { should_not contain_concat__fragment('supervisord_inet')} - end - context 'true' do - let(:params) {{ :inet_server => true }} - it { should contain_concat__fragment('supervisord_inet')} - end - end + describe '#inet_server' do + context 'default' do + it { is_expected.not_to contain_concat__fragment('supervisord_inet') } + end + context 'true' do + let(:params) do + super().merge( + inet_server: true, + ) + end + it { is_expected.to contain_concat__fragment('supervisord_inet') } + end + end - describe '#ctl_socket' do - context 'default' do - it { should contain_concat__fragment('supervisord_ctl')\ - .with_content(/serverurl=unix:\/\/\/var\/run\/supervisor.sock$/)} - end - context 'http' do - let(:params) {{ :inet_server => true, :ctl_socket => 'inet'}} - it { should contain_concat__fragment('supervisord_ctl')\ - .with_content(/serverurl=http:\/\/127.0.0.1:9001$/)} - end - end + describe '#ctl_socket' do + context 'default' do + it { is_expected.to contain_concat__fragment('supervisord_ctl') + .with_content(/serverurl=unix:\/\/\/var\/run\/supervisor\.sock$/) } + end + context 'http' do + let(:params) do + super().merge( + inet_server: true, + ctl_socket: 'inet' + ) + end + it { is_expected.to contain_concat__fragment('supervisord_ctl') + .with_content(/serverurl=http:\/\/127\.0\.0\.1:9001$/) } + end + end - describe '#run_path' do - context 'default' do - it { should_not contain_file('/var/run') } - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/pidfile=\/var\/run\/supervisord.pid$/) } - end - context 'is specified' do - let(:params) {{ :run_path => '/opt/supervisord/run' }} - it { should contain_file('/opt/supervisord/run') } - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/pidfile=\/opt\/supervisord\/run\/supervisord.pid$/) } - end - end + describe '#run_path' do + context 'default' do + it { is_expected.not_to contain_file('/var/run') } + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/pidfile=\/var\/run\/supervisord.pid$/) } + end + context 'is specified' do + let(:params) do + super().merge( + run_path: '/opt/supervisord/run', + ) + end + it { is_expected.to contain_file('/opt/supervisord/run') } + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/pidfile=\/opt\/supervisord\/run\/supervisord.pid$/) } + end + end - describe '#log_path' do - context 'default' do - it { should contain_file('/var/log/supervisor') } - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/logfile=\/var\/log\/supervisor\/supervisord.log$/) } - end - context 'is specified' do - let(:params) {{ :log_path => '/opt/supervisord/logs' }} - it { should contain_file('/opt/supervisord/logs')} - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/logfile=\/opt\/supervisord\/logs\/supervisord.log$/) } - end - end + describe '#log_path' do + context 'default' do + it { is_expected.to contain_file('/var/log/supervisor') } + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/logfile=\/var\/log\/supervisor\/supervisord.log$/) } + end + context 'is specified' do + let(:params) do + super().merge( + log_path: '/opt/supervisord/logs', + ) + end + it { is_expected.to contain_file('/opt/supervisord/logs') } + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/logfile=\/opt\/supervisord\/logs\/supervisord.log$/) } + end + end - describe '#config_include' do - context 'default' do - it { should contain_file('/etc/supervisor.d') } - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/files=\/etc\/supervisor.d\/\*.conf$/) } - end - context 'is specified' do - let(:params) {{ :config_include => '/opt/supervisord/conf.d' }} - it { should contain_file('/opt/supervisord/conf.d') } - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/files=\/opt\/supervisord\/conf.d\/\*.conf$/) } - end - end + describe '#config_include' do + context 'default' do + it { is_expected.to contain_file('/etc/supervisor.d') } + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/files=\/etc\/supervisor.d\/\*.conf$/) } + end + context 'is specified' do + let(:params) do + super().merge( + config_include: '/opt/supervisord/conf.d', + ) + end + it { is_expected.to contain_file('/opt/supervisord/conf.d') } + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/files=\/opt\/supervisord\/conf.d\/\*.conf$/) } + end + end - describe '#config_dirs' do - context 'is specified' do - let(:params) {{ :config_dirs => ['/etc/supervisor.d/*.conf', '/opt/supervisor.d/*', '/usr/share/supervisor.d/*.config'] }} - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/files=\/etc\/supervisor.d\/\*.conf \/opt\/supervisor.d\/\* \/usr\/share\/supervisor.d\/\*.config$/) } - end - end + describe '#config_dirs' do + context 'is specified' do + let(:params) do + super().merge( + config_dirs: [ + '/etc/supervisor.d/*.conf', + '/opt/supervisor.d/*', + '/usr/share/supervisor.d/*.config' + ], + ) + end + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/files=\/etc\/supervisor.d\/\*.conf \/opt\/supervisor.d\/\* \/usr\/share\/supervisor.d\/\*.config$/) } + end + end - describe '#config_file' do - context 'default' do - it { should contain_file('/etc/supervisord.conf') } - end - context 'is specified' do - let(:params) {{ :config_file => '/opt/supervisord/supervisor.conf' }} - it { should contain_file('/opt/supervisord/supervisor.conf') } - end - end + describe '#config_file' do + context 'default' do + it { is_expected.to contain_concat('/etc/supervisord.conf') } + end + context 'is specified' do + let(:params) do + super().merge( + config_file: '/opt/supervisord/supervisor.conf', + ) + end + it { is_expected.to contain_concat('/opt/supervisord/supervisor.conf') } + end + end - describe '#nodaemon' do - context 'default' do - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/nodaemon=false$/) } - end - context 'true' do - let(:params) {{ :nodaemon => true }} - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/nodaemon=true$/) } - end - context 'invalid' do - let(:params) {{ :nodaemon => 'invalid' }} - it { expect { raise_error(Puppet::Error, /is not a boolean/) }} - end - end + describe '#nodaemon' do + context 'default' do + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/nodaemon=false$/) } + end + context 'true' do + let(:params) do + super().merge( + nodaemon: true, + ) + end + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/nodaemon=true$/) } + end + context 'invalid' do + let(:params) do + super().merge( + nodaemon: 'invalid', + ) + end + it { expect { raise_error(Puppet::Error, /is not a boolean/) } } + end + end - describe '#minfds' do - context 'default' do - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/minfds=1024$/) } - end - context 'specified' do - let(:params) {{ :minfds => 2048 }} - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/minfds=2048$/) } - end - context 'invalid' do - let(:params) {{ :minfds => 'string' }} - it { expect { raise_error(Puppet::Error, /invalid minfds/) }} - end - end + describe '#minfds' do + context 'default' do + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/minfds=1024$/) } + end + context 'specified' do + let(:params) do + super().merge( + minfds: 2048, + ) + end + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/minfds=2048$/) } + end + context 'invalid' do + let(:params) do + super().merge( + minfds: 'string', + ) + end + it { expect { raise_error(Puppet::Error, /invalid minfds/) } } + end + end - describe '#minprocs' do - context 'default' do - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/minprocs=200$/) } - end - context 'specified' do - let(:params) {{ :minprocs => 300 }} - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/minprocs=300$/) } - end - context 'invalid' do - let(:params) {{ :minfds => 'string' }} - it { expect { raise_error(Puppet::Error, /invalid minprocs/) }} - end - end + describe '#minprocs' do + context 'default' do + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/minprocs=200$/) } + end + context 'specified' do + let(:params) do + super().merge( + minprocs: 300, + ) + end + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/minprocs=300$/) } + end + context 'invalid' do + let(:params) do + super().merge( + minprocs: 'string', + ) + end + it { expect { raise_error(Puppet::Error, /invalid minprocs/) } } + end + end - describe '#strip_ansi' do - context 'default' do - it { should_not contain_concat__fragment('supervisord_main') \ - .with_content(/strip_ansi$/) } - end - context 'true' do - let(:params) {{ :strip_ansi => true }} - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/strip_ansi=true$/) } - end - context 'invalid' do - let(:params) {{ :strip_ansi => 'string' }} - it { expect { raise_error(Puppet::Error, /is not a boolean/) }} - end - end + describe '#strip_ansi' do + context 'default' do + it { is_expected.not_to contain_concat__fragment('supervisord_main') + .with_content(/strip_ansi$/) } + end + context 'true' do + let(:params) do + super().merge( + strip_ansi: true, + ) + end + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/strip_ansi=true$/) } + end + context 'invalid' do + let(:params) do + super().merge( + strip_ansi: 'string', + ) + end + it { expect { raise_error(Puppet::Error, /is not a boolean/) } } + end + end - describe '#user' do - context 'default' do - it { should_not contain_concat__fragment('supervisord_main') \ - .with_content(/user$/) } - end - context 'specified' do - let(:params) {{ :user => 'myuser' }} - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/user=myuser$/) } - end - end + describe '#user' do + context 'default' do + it { is_expected.not_to contain_concat__fragment('supervisord_main') + .with_content(/user$/) } + end + context 'specified' do + let(:params) do + super().merge( + user: 'myuser', + ) + end + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/user=myuser$/) } + end + end - describe '#identifier' do - context 'default' do - it { should_not contain_concat__fragment('supervisord_main') \ - .with_content(/identifier$/) } - end - context 'specified' do - let(:params) {{ :identifier => 'myidentifier' }} - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/identifier=myidentifier$/) } - end - end + describe '#identifier' do + context 'default' do + it { is_expected.not_to contain_concat__fragment('supervisord_main') + .with_content(/identifier$/) } + end + context 'specified' do + let(:params) do + super().merge( + identifier: 'myidentifier', + ) + end + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/identifier=myidentifier$/) } + end + end - describe '#directory' do - context 'default' do - it { should_not contain_concat__fragment('supervisord_main') \ - .with_content(/directory$/) } - end - context 'specified' do - let(:params) {{ :directory => '/opt/supervisord' }} - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/directory=\/opt\/supervisord$/) } - end - end + describe '#directory' do + context 'default' do + it { is_expected.not_to contain_concat__fragment('supervisord_main') + .with_content(/directory$/) } + end + context 'specified' do + let(:params) do + super().merge( + directory: '/opt/supervisord', + ) + end + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/directory=\/opt\/supervisord$/) } + end + end - describe '#nocleanup' do - context 'default' do - it { should_not contain_concat__fragment('supervisord_main') \ - .with_content(/nocleanup$/) } - end - context 'true' do - let(:params) {{ :nocleanup => true }} - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/nocleanup=true$/) } - end - context 'invalid' do - let(:params) {{ :nocleanup => 'string' }} - it { expect { raise_error(Puppet::Error, /is not a boolean/) }} - end - end + describe '#nocleanup' do + context 'default' do + it { is_expected.not_to contain_concat__fragment('supervisord_main') + .with_content(/nocleanup$/) } + end + context 'true' do + let(:params) do + super().merge( + nocleanup: true, + ) + end + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/nocleanup=true$/) } + end + context 'invalid' do + let(:params) do + super().merge( + nocleanup: 'string', + ) + end + it { expect { raise_error(Puppet::Error, /is not a boolean/) } } + end + end - describe '#childlogdir' do - context 'default' do - it { should_not contain_concat__fragment('supervisord_main') \ - .with_content(/childlogdir$/) } - end - context 'specified' do - let(:params) {{ :childlogdir => '/opt/supervisord/logdir' }} - it { should contain_concat__fragment('supervisord_main') \ - .with_content(/childlogdir=\/opt\/supervisord\/logdir$/) } - end - context 'invalid' do - let(:params) {{ :childlogdir => 'not_a_path' }} - it { expect { raise_error(Puppet::Error, /is not an absolute path/) }} + describe '#childlogdir' do + context 'default' do + it { is_expected.not_to contain_concat__fragment('supervisord_main') + .with_content(/childlogdir$/) } + end + context 'specified' do + let(:params) do + super().merge( + childlogdir: '/opt/supervisord/logdir', + ) + end + it { is_expected.to contain_concat__fragment('supervisord_main') + .with_content(/childlogdir=\/opt\/supervisord\/logdir$/) } + end + context 'invalid' do + let(:params) do + super().merge( + childlogdir: 'not_a_path', + ) + end + it { expect { raise_error(Puppet::Error, /is not an absolute path/) } } + end + end end end end diff --git a/spec/defines/ctlplugin_spec.rb b/spec/defines/ctlplugin_spec.rb index 0ec80ee..05aa009 100644 --- a/spec/defines/ctlplugin_spec.rb +++ b/spec/defines/ctlplugin_spec.rb @@ -1,13 +1,30 @@ require 'spec_helper' -describe 'supervisord::ctlplugin', :type => :define do - let(:title) {'foo'} - let (:facts) {{ :concat_basedir => '/var/lib/puppet/concat' }} +describe 'supervisord::ctlplugin' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:title) { 'foo' } + let(:facts) do + os_facts.merge( + concat_basedir: '/var/lib/puppet/concat' + ) + end + let(:pre_condition) do + [ + "class { 'supervisord': unix_username => 'foo', unix_password => 'bar', inet_username => 'foo', inet_password => 'bar' }", + ] + end - context 'default' do - let(:params) { { :ctl_factory => 'bar.baz:make_bat' } } - it { should contain_supervisord__ctlplugin('foo') } - it { should contain_concat__fragment('ctlplugin:foo') \ - .with_content(/supervisor\.ctl_factory = bar\.baz:make_bat/) } + context 'default' do + let(:params) do + { :ctl_factory => 'bar.baz:make_bat' } + end + it { is_expected.to contain_supervisord__ctlplugin('foo') } + it do + is_expected.to contain_concat__fragment('ctlplugin:foo') + .with_content(/supervisor\.ctl_factory = bar\.baz:make_bat/) + end + end + end end end diff --git a/spec/defines/eventlistener_spec.rb b/spec/defines/eventlistener_spec.rb index 878eae1..481ba41 100644 --- a/spec/defines/eventlistener_spec.rb +++ b/spec/defines/eventlistener_spec.rb @@ -1,106 +1,121 @@ require 'spec_helper' -describe 'supervisord::eventlistener', :type => :define do - let(:title) {'foo'} - let(:facts) {{ :concat_basedir => '/var/lib/puppet/concat' }} - let(:default_params) do - { - :command => 'bar', - :process_name => '%(process_num)s', - :events => ['PROCESS_STATE', 'PROCESS_STATE_STARTING'], - :buffer_size => 10, - :numprocs => '1', - :numprocs_start => '0', - :priority => '999', - :autostart => true, - :autorestart => 'unexpected', - :startsecs => '1', - :startretries => '3', - :exitcodes => '0,2', - :stopsignal => 'TERM', - :stopwaitsecs => '10', - :stopasgroup => true, - :killasgroup => true, - :user => 'baz', - :redirect_stderr => true, - :stdout_logfile => 'eventlistener_foo.log', - :stdout_logfile_maxbytes => '50MB', - :stdout_logfile_backups => '10', - :stdout_events_enabled => true, - :stderr_logfile => 'eventlistener_foo.error', - :stderr_logfile_maxbytes => '50MB', - :stderr_logfile_backups => '10', - :stderr_events_enabled => true, - :event_environment => { 'env1' => 'value1', 'env2' => 'value2' }, - :directory => '/opt/supervisord/chroot', - :umask => '022', - :serverurl => 'AUTO' - } - end +describe 'supervisord::eventlistener' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:title) { 'foo' } + let(:facts) do + os_facts.merge( + concat_basedir: '/var/lib/puppet/concat' + ) + end + let(:pre_condition) do + [ + "class { 'supervisord': unix_username => 'foo', unix_password => 'bar', inet_username => 'foo', inet_password => 'bar' }", + ] + end + let(:default_params) do + { + :command => 'bar', + :process_name => '%(process_num)s', + :events => ['PROCESS_STATE', 'PROCESS_STATE_STARTING'], + :buffer_size => 10, + :numprocs => 1, + :numprocs_start => 0, + :priority => 999, + :autostart => true, + :autorestart => 'unexpected', + :startsecs => 1, + :startretries => 3, + :exitcodes => '0,2', + :stopsignal => 'TERM', + :stopwaitsecs => 10, + :stopasgroup => true, + :killasgroup => true, + :user => 'baz', + :redirect_stderr => true, + :stdout_logfile => 'eventlistener_foo.log', + :stdout_logfile_maxbytes => '50MB', + :stdout_logfile_backups => 10, + :stdout_events_enabled => true, + :stderr_logfile => 'eventlistener_foo.error', + :stderr_logfile_maxbytes => '50MB', + :stderr_logfile_backups => 10, + :stderr_events_enabled => true, + :event_environment => { 'env1' => 'value1', 'env2' => 'value2' }, + :directory => '/opt/supervisord/chroot', + :umask => '022', + :serverurl => 'AUTO' + } + end - context 'default' do - let(:params) { default_params } + context 'default' do + let(:params) { default_params } - it { should contain_supervisord__eventlistener('foo') } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/\[eventlistener:foo\]/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/command=bar/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/process_name=\%\(process_num\)s/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/events=PROCESS_STATE,PROCESS_STATE_STARTING/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/buffer_size=10/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/numprocs=1/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/numprocs_start=0/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/priority=999/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/autostart=true/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/startsecs=1/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/startretries=3/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/exitcodes=0,2/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stopsignal=TERM/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stopwaitsecs=10/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stopasgroup=true/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/killasgroup=true/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/user=baz/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/redirect_stderr=true/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stdout_logfile=\/var\/log\/supervisor\/eventlistener_foo.log/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stdout_logfile_maxbytes=50MB/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stdout_logfile_backups=10/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stdout_events_enabled=true/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stderr_logfile=\/var\/log\/supervisor\/eventlistener_foo.error/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stderr_logfile_maxbytes=50MB/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stderr_logfile_backups=10/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stderr_events_enabled=true/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/environment=env1='value1',env2='value2'/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/directory=\/opt\/supervisord\/chroot/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/umask=022/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/serverurl=AUTO/) } - end + it { is_expected.to contain_supervisord__eventlistener('foo') } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/\[eventlistener:foo\]/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/command=bar/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/process_name=\%\(process_num\)s/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/events=PROCESS_STATE,PROCESS_STATE_STARTING/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/buffer_size=10/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/numprocs=1/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/numprocs_start=0/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/priority=999/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/autostart=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/startsecs=1/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/startretries=3/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/exitcodes=0,2/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stopsignal=TERM/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stopwaitsecs=10/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stopasgroup=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/killasgroup=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/user=baz/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/redirect_stderr=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stdout_logfile=\/var\/log\/supervisor\/eventlistener_foo.log/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stdout_logfile_maxbytes=50MB/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stdout_logfile_backups=10/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stdout_events_enabled=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stderr_logfile=\/var\/log\/supervisor\/eventlistener_foo.error/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stderr_logfile_maxbytes=50MB/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stderr_logfile_backups=10/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stderr_events_enabled=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/environment=env1='value1',env2='value2'/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/directory=\/opt\/supervisord\/chroot/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/umask=022/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/serverurl=AUTO/) } + end - context 'ensure_process_stopped' do - let(:params) { default_params.merge({ :ensure_process => 'stopped' }) } - it { should contain_supervisord__supervisorctl('stop_foo') } - end + context 'ensure_process_stopped' do + let(:params) { default_params.merge({ ensure_process: 'stopped' }) } + it { is_expected.to contain_supervisord__supervisorctl('stop_foo') } + end - context 'ensure_process_removed' do - let(:params) { default_params.merge({ :ensure_process => 'removed' }) } - it { should contain_supervisord__supervisorctl('remove_foo') } - end + context 'ensure_process_removed' do + let(:params) { default_params.merge({ ensure_process: 'removed' }) } + it { is_expected.to contain_supervisord__supervisorctl('remove_foo') } + end - context 'change_process_name_on_numprocs_gt_1' do - let(:params) do - { - :command => 'bar', - :numprocs => '2', - } - end - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/numprocs=2/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/process_name=\%\(program_name\)s_\%\(process_num\)02d/) } - end + context 'change_process_name_on_numprocs_gt_1' do + let(:params) do + { + command: 'bar', + numprocs: 2, + } + end + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/numprocs=2/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/process_name=\%\(program_name\)s_\%\(process_num\)02d/) } + end - context 'absolute_log_paths' do - let(:params) { default_params.merge({ - :stdout_logfile => '/path/to/program_foo.log', - :stderr_logfile => '/path/to/program_foo.error', - }) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stdout_logfile=\/path\/to\/program_foo.log/) } - it { should contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stderr_logfile=\/path\/to\/program_foo.error/) } + context 'absolute_log_paths' do + let(:params) do + default_params.merge( + stdout_logfile: '/path/to/program_foo.log', + stderr_logfile: '/path/to/program_foo.error', + ) + end + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stdout_logfile=\/path\/to\/program_foo.log/) } + it { is_expected.to contain_file('/etc/supervisor.d/eventlistener_foo.conf').with_content(/stderr_logfile=\/path\/to\/program_foo.error/) } + end + end end end diff --git a/spec/defines/fcgi_program_spec.rb b/spec/defines/fcgi_program_spec.rb index 7e2c1e5..8bec2ae 100644 --- a/spec/defines/fcgi_program_spec.rb +++ b/spec/defines/fcgi_program_spec.rb @@ -1,109 +1,126 @@ require 'spec_helper' -describe 'supervisord::fcgi_program', :type => :define do - let(:title) {'foo'} - let(:facts) {{ :concat_basedir => '/var/lib/puppet/concat' }} - let(:default_params) do - { - :command => 'bar', - :socket => 'tcp://localhost:1000', - :process_name => '%(process_num)s', - :numprocs => '1', - :numprocs_start => '0', - :priority => '999', - :autostart => true, - :autorestart => 'unexpected', - :startsecs => '1', - :startretries => '3', - :exitcodes => '0,2', - :stopsignal => 'TERM', - :stopwaitsecs => '10', - :stopasgroup => true, - :killasgroup => true, - :user => 'baz', - :redirect_stderr => true, - :stdout_logfile => 'fcgi-program_foo.log', - :stdout_logfile_maxbytes => '50MB', - :stdout_logfile_backups => '10', - :stdout_capture_maxbytes => '0', - :stdout_events_enabled => true, - :stderr_logfile => 'fcgi-program_foo.error', - :stderr_logfile_maxbytes => '50MB', - :stderr_logfile_backups => '10', - :stderr_capture_maxbytes => '0', - :stderr_events_enabled => true, - :program_environment => { 'env1' => 'value1', 'env2' => 'value2' }, - :directory => '/opt/supervisord/chroot', - :umask => '022', - :serverurl => 'AUTO' - } - end +describe 'supervisord::fcgi_program' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:title) { 'foo' } + let(:facts) do + os_facts.merge( + concat_basedir: '/var/lib/puppet/concat' + ) + end + let(:pre_condition) do + [ + "class { 'supervisord': unix_username => 'foo', unix_password => 'bar', inet_username => 'foo', inet_password => 'bar' }", + ] + end + let(:default_params) do + { + :command => 'bar', + :socket => 'tcp://localhost:1000', + :process_name => '%(process_num)s', + :events => ['PROCESS_STATE', 'PROCESS_STATE_STARTING'], + :buffer_size => 10, + :numprocs => 1, + :numprocs_start => 0, + :priority => 999, + :autostart => true, + :autorestart => 'unexpected', + :startsecs => 1, + :startretries => 3, + :exitcodes => '0,2', + :stopsignal => 'TERM', + :stopwaitsecs => 10, + :stopasgroup => true, + :killasgroup => true, + :user => 'baz', + :redirect_stderr => true, + :stdout_logfile => 'fcgi-program_foo.log', + :stdout_logfile_maxbytes => '50MB', + :stdout_logfile_backups => 10, + :stdout_capture_maxbytes => '0', + :stdout_events_enabled => true, + :stderr_logfile => 'fcgi-program_foo.error', + :stderr_logfile_maxbytes => '50MB', + :stderr_logfile_backups => 10, + :stderr_capture_maxbytes => '0', + :stderr_events_enabled => true, + :program_environment => { 'env1' => 'value1', 'env2' => 'value2' }, + :directory => '/opt/supervisord/chroot', + :umask => '022', + :serverurl => 'AUTO' + } + end - context 'default' do - let(:params) { default_params } + context 'default' do + let(:params) { default_params } - it { should contain_supervisord__fcgi_program('foo') } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/\[fcgi-program:foo\]/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/socket=tcp:\/\/localhost:1000/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/command=bar/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/process_name=\%\(process_num\)s/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/numprocs=1/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/numprocs_start=0/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/priority=999/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/autostart=true/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/startsecs=1/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/startretries=3/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/exitcodes=0,2/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stopsignal=TERM/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stopwaitsecs=10/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stopasgroup=true/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/killasgroup=true/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/user=baz/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/redirect_stderr=true/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stdout_logfile=\/var\/log\/supervisor\/fcgi-program_foo.log/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stdout_logfile_maxbytes=50MB/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stdout_logfile_backups=10/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stdout_capture_maxbytes=0/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stdout_events_enabled=true/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stderr_logfile=\/var\/log\/supervisor\/fcgi-program_foo.error/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stderr_logfile_maxbytes=50MB/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stderr_logfile_backups=10/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stderr_capture_maxbytes=0/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stderr_events_enabled=true/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/environment=env1='value1',env2='value2'/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/directory=\/opt\/supervisord\/chroot/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/umask=022/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/serverurl=AUTO/) } - end + it { is_expected.to contain_supervisord__fcgi_program('foo') } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/\[fcgi-program:foo\]/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/socket=tcp:\/\/localhost:1000/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/command=bar/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/process_name=\%\(process_num\)s/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/numprocs=1/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/numprocs_start=0/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/priority=999/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/autostart=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/startsecs=1/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/startretries=3/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/exitcodes=0,2/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stopsignal=TERM/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stopwaitsecs=10/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stopasgroup=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/killasgroup=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/user=baz/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/redirect_stderr=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stdout_logfile=\/var\/log\/supervisor\/fcgi-program_foo.log/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stdout_logfile_maxbytes=50MB/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stdout_logfile_backups=10/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stdout_capture_maxbytes=0/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stdout_events_enabled=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stderr_logfile=\/var\/log\/supervisor\/fcgi-program_foo.error/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stderr_logfile_maxbytes=50MB/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stderr_logfile_backups=10/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stderr_capture_maxbytes=0/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stderr_events_enabled=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/environment=env1='value1',env2='value2'/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/directory=\/opt\/supervisord\/chroot/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/umask=022/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/serverurl=AUTO/) } + end - context 'ensure_process_stopped' do - let(:params) { default_params.merge({ :ensure_process => 'stopped' }) } - it { should contain_supervisord__supervisorctl('stop_foo') } - end + context 'ensure_process_stopped' do + let(:params) { default_params.merge({ ensure_process: 'stopped' }) } + it { is_expected.to contain_supervisord__supervisorctl('stop_foo') } + end - context 'ensure_process_removed' do - let(:params) { default_params.merge({ :ensure_process => 'removed' }) } - it { should contain_supervisord__supervisorctl('remove_foo') } - end + context 'ensure_process_removed' do + let(:params) { default_params.merge({ ensure_process: 'removed' }) } + it { is_expected.to contain_supervisord__supervisorctl('remove_foo') } + end - context 'change_process_name_on_numprocs_gt_1' do - let(:params) do - { - :numprocs => '2', - :command => 'bar', - :socket => 'tcp://localhost:1000', - } - end - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/numprocs=2/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/process_name=\%\(program_name\)s_\%\(process_num\)02d/) } - end + context 'change_process_name_on_numprocs_gt_1' do + let(:params) do + { + numprocs: 2, + command: 'bar', + socket: 'tcp://localhost:1000', + } + end + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/numprocs=2/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/process_name=\%\(program_name\)s_\%\(process_num\)02d/) } + end - context 'absolute_log_paths' do - let(:params) { default_params.merge({ - :stdout_logfile => '/path/to/program_foo.log', - :stderr_logfile => '/path/to/program_foo.error', - }) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stdout_logfile=\/path\/to\/program_foo.log/) } - it { should contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stderr_logfile=\/path\/to\/program_foo.error/) } + context 'absolute_log_paths' do + let(:params) do + default_params.merge( + stdout_logfile: '/path/to/program_foo.log', + stderr_logfile: '/path/to/program_foo.error', + ) + end + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stdout_logfile=\/path\/to\/program_foo.log/) } + it { is_expected.to contain_file('/etc/supervisor.d/fcgi-program_foo.conf').with_content(/stderr_logfile=\/path\/to\/program_foo.error/) } + end + end end end diff --git a/spec/defines/group_spec.rb b/spec/defines/group_spec.rb index ba8d701..39d25b3 100644 --- a/spec/defines/group_spec.rb +++ b/spec/defines/group_spec.rb @@ -1,22 +1,35 @@ require 'spec_helper' -describe 'supervisord::group', :type => :define do - let(:title) {'foo'} - let(:params) {{ :programs => ['bar', 'baz'] }} - let(:facts) {{ :concat_basedir => '/var/lib/puppet/concat' }} +describe 'supervisord::group' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:title) { 'foo' } + let(:params) { { programs: ['bar', 'baz'] } } + let(:facts) do + os_facts.merge( + concat_basedir: '/var/lib/puppet/concat' + ) + end + let(:pre_condition) do + [ + "class { 'supervisord': unix_username => 'foo', unix_password => 'bar', inet_username => 'foo', inet_password => 'bar' }", + ] + end - it { should contain_supervisord__group('foo').with_program } - it { should contain_file('/etc/supervisor.d/group_foo.conf').with_content(/programs=bar,baz/) } + it { is_expected.to contain_supervisord__group('foo').with_program } + it { is_expected.to contain_file('/etc/supervisor.d/group_foo.conf').with_content(/programs=bar,baz/) } - describe '#priority' do - it 'should default to undef' do - should_not contain_file('/etc/supervisor.d/group_foo.conf').with_content(/priority/) - should contain_file('/etc/supervisor.d/group_foo.conf').with_content(/programs=bar,baz/) - end - context '100' do - let(:params) {{ :priority => '100', :programs => ['bar', 'baz'] }} - it { should contain_file('/etc/supervisor.d/group_foo.conf').with_content(/priority=100/) } - it { should contain_file('/etc/supervisor.d/group_foo.conf').with_content(/programs=bar,baz/) } + describe '#priority' do + it 'is_expected.to default to undef' do + is_expected.not_to contain_file('/etc/supervisor.d/group_foo.conf').with_content(/priority/) + is_expected.to contain_file('/etc/supervisor.d/group_foo.conf').with_content(/programs=bar,baz/) + end + context '100' do + let(:params) { { priority: 100, programs: ['bar', 'baz'] } } + it { is_expected.to contain_file('/etc/supervisor.d/group_foo.conf').with_content(/priority=100/) } + it { is_expected.to contain_file('/etc/supervisor.d/group_foo.conf').with_content(/programs=bar,baz/) } + end + end end end -end \ No newline at end of file +end diff --git a/spec/defines/program_spec.rb b/spec/defines/program_spec.rb index 2009f3f..a177afd 100644 --- a/spec/defines/program_spec.rb +++ b/spec/defines/program_spec.rb @@ -1,106 +1,123 @@ require 'spec_helper' -describe 'supervisord::program', :type => :define do - let(:title) {'foo'} - let(:facts) {{ :concat_basedir => '/var/lib/puppet/concat' }} - let(:default_params) do - { - :command => 'bar', - :process_name => '%(process_num)s', - :numprocs => '1', - :numprocs_start => '0', - :priority => '999', - :autostart => true, - :autorestart => 'unexpected', - :startsecs => '1', - :startretries => '3', - :exitcodes => '0,2', - :stopsignal => 'TERM', - :stopwaitsecs => '10', - :stopasgroup => true, - :killasgroup => true, - :user => 'baz', - :redirect_stderr => true, - :stdout_logfile => 'program_foo.log', - :stdout_logfile_maxbytes => '50MB', - :stdout_logfile_backups => '10', - :stdout_capture_maxbytes => '0', - :stdout_events_enabled => true, - :stderr_logfile => 'program_foo.error', - :stderr_logfile_maxbytes => '50MB', - :stderr_logfile_backups => '10', - :stderr_capture_maxbytes => '0', - :stderr_events_enabled => true, - :program_environment => { 'env1' => 'value1', 'env2' => 'value2' }, - :directory => '/opt/supervisord/chroot', - :umask => '022', - :serverurl => 'AUTO' - } - end +describe 'supervisord::program' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:title) { 'foo' } + let(:facts) do + os_facts.merge( + concat_basedir: '/var/lib/puppet/concat' + ) + end + let(:pre_condition) do + [ + "class { 'supervisord': unix_username => 'foo', unix_password => 'bar', inet_username => 'foo', inet_password => 'bar' }", + ] + end + let(:default_params) do + { + :command => 'bar', + :process_name => '%(process_num)s', + :events => ['PROCESS_STATE', 'PROCESS_STATE_STARTING'], + :buffer_size => 10, + :numprocs => 1, + :numprocs_start => 0, + :priority => 999, + :autostart => true, + :autorestart => 'unexpected', + :startsecs => 1, + :startretries => 3, + :exitcodes => '0,2', + :stopsignal => 'TERM', + :stopwaitsecs => 10, + :stopasgroup => true, + :killasgroup => true, + :user => 'baz', + :redirect_stderr => true, + :stdout_logfile => 'program_foo.log', + :stdout_logfile_maxbytes => '50MB', + :stdout_logfile_backups => 10, + :stdout_capture_maxbytes => '0', + :stdout_events_enabled => true, + :stderr_logfile => 'program_foo.error', + :stderr_logfile_maxbytes => '50MB', + :stderr_logfile_backups => 10, + :stderr_capture_maxbytes => '0', + :stderr_events_enabled => true, + :program_environment => { 'env1' => 'value1', 'env2' => 'value2' }, + :directory => '/opt/supervisord/chroot', + :umask => '022', + :serverurl => 'AUTO' + } + end - context 'default' do - let(:params) { default_params } + context 'default' do + let(:params) { default_params } - it { should contain_supervisord__program('foo') } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/\[program:foo\]/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/command=bar/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/process_name=\%\(process_num\)s/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/numprocs=1/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/numprocs_start=0/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/priority=999/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/autostart=true/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/startsecs=1/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/startretries=3/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/exitcodes=0,2/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stopsignal=TERM/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stopwaitsecs=10/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stopasgroup=true/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/killasgroup=true/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/user=baz/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/redirect_stderr=true/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stdout_logfile=\/var\/log\/supervisor\/program_foo.log/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stdout_logfile_maxbytes=50MB/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stdout_logfile_backups=10/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stdout_capture_maxbytes=0/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stdout_events_enabled=true/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stderr_logfile=\/var\/log\/supervisor\/program_foo.error/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stderr_logfile_maxbytes=50MB/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stderr_logfile_backups=10/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stderr_capture_maxbytes=0/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stderr_events_enabled=true/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/environment=env1='value1',env2='value2'/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/directory=\/opt\/supervisord\/chroot/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/umask=022/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/serverurl=AUTO/) } - end + it { is_expected.to contain_supervisord__program('foo') } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/\[program:foo\]/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/command=bar/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/process_name=\%\(process_num\)s/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/numprocs=1/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/numprocs_start=0/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/priority=999/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/autostart=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/startsecs=1/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/startretries=3/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/exitcodes=0,2/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stopsignal=TERM/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stopwaitsecs=10/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stopasgroup=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/killasgroup=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/user=baz/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/redirect_stderr=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stdout_logfile=\/var\/log\/supervisor\/program_foo.log/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stdout_logfile_maxbytes=50MB/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stdout_logfile_backups=10/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stdout_capture_maxbytes=0/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stdout_events_enabled=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stderr_logfile=\/var\/log\/supervisor\/program_foo.error/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stderr_logfile_maxbytes=50MB/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stderr_logfile_backups=10/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stderr_capture_maxbytes=0/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stderr_events_enabled=true/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/environment=env1='value1',env2='value2'/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/directory=\/opt\/supervisord\/chroot/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/umask=022/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/serverurl=AUTO/) } + end - context 'ensure_process_stopped' do - let(:params) { default_params.merge({ :ensure_process => 'stopped' }) } - it { should contain_supervisord__supervisorctl('stop_foo') } - end + context 'ensure_process_stopped' do + let(:params) { default_params.merge({ ensure_process: 'stopped' }) } + it { is_expected.to contain_supervisord__supervisorctl('stop_foo') } + end - context 'ensure_process_removed' do - let(:params) { default_params.merge({ :ensure_process => 'removed' }) } - it { should contain_supervisord__supervisorctl('remove_foo') } - end + context 'ensure_process_removed' do + let(:params) { default_params.merge({ ensure_process: 'removed' }) } + it { is_expected.to contain_supervisord__supervisorctl('remove_foo') } + end - context 'change_process_name_on_numprocs_gt_1' do - let(:params) do - { - :command => 'bar', - :numprocs => '2', - } - end - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/numprocs=2/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/process_name=\%\(program_name\)s_\%\(process_num\)02d/) } - end + context 'change_process_name_on_numprocs_gt_1' do + let(:params) do + { + command: 'bar', + numprocs: 2, + } + end + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/numprocs=2/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/process_name=\%\(program_name\)s_\%\(process_num\)02d/) } + end - context 'absolute_log_paths' do - let(:params) { default_params.merge({ - :stdout_logfile => '/path/to/program_foo.log', - :stderr_logfile => '/path/to/program_foo.error', - }) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stdout_logfile=\/path\/to\/program_foo.log/) } - it { should contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stderr_logfile=\/path\/to\/program_foo.error/) } + context 'absolute_log_paths' do + let(:params) do + default_params.merge( + stdout_logfile: '/path/to/program_foo.log', + stderr_logfile: '/path/to/program_foo.error', + ) + end + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stdout_logfile=\/path\/to\/program_foo.log/) } + it { is_expected.to contain_file('/etc/supervisor.d/program_foo.conf').with_content(/stderr_logfile=\/path\/to\/program_foo.error/) } + end + end end end diff --git a/spec/defines/rpcinterface_spec.rb b/spec/defines/rpcinterface_spec.rb index 96acf5c..723c71d 100644 --- a/spec/defines/rpcinterface_spec.rb +++ b/spec/defines/rpcinterface_spec.rb @@ -1,26 +1,38 @@ require 'spec_helper' -describe 'supervisord::rpcinterface', :type => :define do - let(:title) {'foo'} - let(:facts) {{ :concat_basedir => '/var/lib/puppet/concat' }} - let(:default_params) do - { :rpcinterface_factory => 'bar:baz' } - end +describe 'supervisord::rpcinterface', :type => :define do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:title) { 'foo' } + let(:facts) do + os_facts.merge( + concat_basedir: '/var/lib/puppet/concat' + ) + end + let(:pre_condition) do + [ + "class { 'supervisord': unix_username => 'foo', unix_password => 'bar', inet_username => 'foo', inet_password => 'bar' }", + ] + end + let(:default_params) do + { rpcinterface_factory: 'bar:baz' } + end - context 'default' do - let(:params) { default_params } - it { should contain_supervisord__rpcinterface('foo') } - it { should contain_file('/etc/supervisor.d/rpcinterface_foo.conf').with_content(/\[rpcinterface:foo\]/) } - it { should contain_file('/etc/supervisor.d/rpcinterface_foo.conf').with_content(/supervisor\.rpcinterface_factory = bar:baz/) } - it { should contain_file('/etc/supervisor.d/rpcinterface_foo.conf').without_content(/retries/) } - end + context 'default' do + let(:params) { default_params } + it { is_expected.to contain_supervisord__rpcinterface('foo') } + it { is_expected.to contain_file('/etc/supervisor.d/rpcinterface_foo.conf').with_content(/\[rpcinterface:foo\]/) } + it { is_expected.to contain_file('/etc/supervisor.d/rpcinterface_foo.conf').with_content(/supervisor\.rpcinterface_factory = bar:baz/) } + it { is_expected.to contain_file('/etc/supervisor.d/rpcinterface_foo.conf').without_content(/retries/) } + end - context 'retries' do - let(:params) { { :retries => 2 }.merge(default_params) } - it { should contain_supervisord__rpcinterface('foo') } - it { should contain_file('/etc/supervisor.d/rpcinterface_foo.conf').with_content(/\[rpcinterface:foo\]/) } - it { should contain_file('/etc/supervisor.d/rpcinterface_foo.conf').with_content(/supervisor\.rpcinterface_factory = bar:baz/) } - it { should contain_file('/etc/supervisor.d/rpcinterface_foo.conf').with_content(/retries = 2/) } + context 'retries' do + let(:params) { { retries: 2 }.merge(default_params) } + it { is_expected.to contain_supervisord__rpcinterface('foo') } + it { is_expected.to contain_file('/etc/supervisor.d/rpcinterface_foo.conf').with_content(/\[rpcinterface:foo\]/) } + it { is_expected.to contain_file('/etc/supervisor.d/rpcinterface_foo.conf').with_content(/supervisor\.rpcinterface_factory = bar:baz/) } + it { is_expected.to contain_file('/etc/supervisor.d/rpcinterface_foo.conf').with_content(/retries = 2/) } + end + end end - end diff --git a/spec/defines/supervisorctl.rb b/spec/defines/supervisorctl.rb index e69c819..0344aab 100644 --- a/spec/defines/supervisorctl.rb +++ b/spec/defines/supervisorctl.rb @@ -1,24 +1,37 @@ require 'spec_helper' -describe 'supervisord::supervisorctl', :type => :define do - let(:default_params) {{ - :command => 'command' - }} +describe 'supervisord::supervisorctl' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:default_params) do + { + command: 'command', + } + end + let(:facts) do + os_facts.merge( + concat_basedir: '/var/lib/puppet/concat' + ) + end + let(:pre_condition) do + [ + "class { 'supervisord': unix_username => 'foo', unix_password => 'bar', inet_username => 'foo', inet_password => 'bar' }", + ] + end - let(:facts) {{ :concat_basedir => '/var/lib/puppet/concat' }} + context 'without process' do + let(:title) { 'command' } + let(:params) { default_params } + it { is_expected.to contain_supervisord__supervisorctl('command') } + it { is_expected.to contain_exec('supervisorctl_command_command').with_command(/supervisorctl command/) } + end - context 'without process' do - let(:title) {'command'} - let(:params) { default_params } - it { should contain_supervisord__supervisorctl('command') } - it { should contain_exec('supervisorctl_command_command').with_command(/supervisorctl command/) } + context 'with process' do + let(:title) { 'command_foo' } + let(:params) { default_params.merge({ process: 'foo' }) } + it { is_expected.to contain_supervisord__supervisorctl('command_foo') } + it { is_expected.to contain_exec('supervisorctl_command_command_foo').with_command(/supervisorctl command foo/) } + end + end end - - context 'with process' do - let(:title) {'command_foo'} - let(:params) { default_params.merge({ :process => 'foo' }) } - it { should contain_supervisord__supervisorctl('command_foo') } - it { should contain_exec('supervisorctl_command_command_foo').with_command(/supervisorctl command foo/) } - end - end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 745ad4a..5d12e7c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,35 @@ +require 'rspec-puppet-utils' require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' + +include RspecPuppetFacts fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) RSpec.configure do |c| + c.mock_with :rspec + c.expect_with :rspec c.module_path = File.join(fixture_path, 'modules') c.manifest_dir = File.join(fixture_path, 'manifests') + + c.before :each do + # set to strictest setting for testing + # by default Puppet runs at warning level + Puppet.settings[:strict] = :warning + Puppet.settings[:strict_variables] = true + end + + # Filter backtrace noise + backtrace_exclusion_patterns = [ + %r{spec_helper}, + %r{gems}, + ] + + if c.respond_to?(:backtrace_exclusion_patterns) + c.backtrace_exclusion_patterns = backtrace_exclusion_patterns + elsif c.respond_to?(:backtrace_clean_patterns) + c.backtrace_clean_patterns = backtrace_exclusion_patterns + end end at_exit { RSpec::Puppet::Coverage.report! } diff --git a/templates/init/Debian/init.erb b/templates/init/Debian/init.erb deleted file mode 100644 index f8bdb5f..0000000 --- a/templates/init/Debian/init.erb +++ /dev/null @@ -1,137 +0,0 @@ -#! /bin/sh -### BEGIN INIT INFO -# Provides: supervisor -# Required-Start: $remote_fs $network $named -# Required-Stop: $remote_fs $network $named -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Start/stop supervisor -# Description: Start/stop supervisor daemon and its configured -# subprocesses. -### END INIT INFO - - -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -DAEMON=<%= @executable %> -NAME=supervisord -DESC=supervisor - -# Tests if executable exists -if [ ! -x $DAEMON ] ; then - echo "Executable not found ${DAEMON}" - exit 1 -fi - -LOGDIR=<%= @log_path %> -PIDFILE=<%= @run_path %>/<%= @pid_file %> -DODTIME=5 # Time to wait for the server to die, in seconds - # If this value is set too low you might not - # let some servers to die gracefully and - # 'restart' will not work - -# Include supervisor defaults if available -if [ -f <%= @init_defaults %> ] ; then - . <%= @init_defaults %> -fi - -set -e - -running_pid() -{ - # Check if a given process pid's cmdline matches a given name - pid=$1 - name=$2 - [ -z "$pid" ] && return 1 - [ ! -d /proc/$pid ] && return 1 - (cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1 - return 0 -} - -running() -{ -# Check if the process is running looking at /proc -# (works for all users) - - # No pidfile, probably no daemon present - [ ! -f "$PIDFILE" ] && return 1 - # Obtain the pid and check it against the binary name - pid=`cat $PIDFILE` - running_pid $pid $DAEMON || return 1 - return 0 -} - -force_stop() { -# Forcefully kill the process - [ ! -f "$PIDFILE" ] && return - if running ; then - kill -15 $pid - # Is it really dead? - [ -n "$DODTIME" ] && sleep "$DODTIME"s - if running ; then - kill -9 $pid - [ -n "$DODTIME" ] && sleep "$DODTIME"s - if running ; then - echo "Cannot kill $DESC (pid=$pid)!" - exit 1 - fi - fi - fi - rm -f $PIDFILE - return 0 -} - -case "$1" in - start) - if [ -e $PIDFILE ]; then - echo "$DESC already running with pid: `cat $PIDFILE`" - exit 0 - fi - echo -n "Starting $DESC: " - start-stop-daemon --start --quiet --pidfile $PIDFILE \ - --exec $DAEMON -- $DAEMON_OPTS - test -f $PIDFILE || sleep 1 - if running ; then - echo "$NAME." - else - echo " ERROR." - fi - ;; - stop) - echo -n "Stopping $DESC: " - start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE - echo "$NAME." - ;; - force-stop) - echo -n "Forcefully stopping $DESC: " - force_stop - if ! running ; then - echo "$NAME." - else - echo " ERROR." - fi - ;; - restart) - echo -n "Restarting $DESC: " - start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE - [ -n "$DODTIME" ] && sleep $DODTIME - start-stop-daemon --start --quiet --pidfile \ - $PIDFILE --exec $DAEMON -- $DAEMON_OPTS - echo "$NAME." - ;; - status) - echo -n "$DESC is " - if running ; then - echo "running" - else - echo "not running." - exit 1 - fi - ;; - *) - N=/etc/init.d/$NAME - echo "Usage: $N {start|stop|restart|status|force-stop}" >&2 - exit 1 - ;; -esac - -exit 0 diff --git a/templates/init/RedHat/init.erb b/templates/init/RedHat/init.erb deleted file mode 100644 index 40c72b9..0000000 --- a/templates/init/RedHat/init.erb +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/bash -# -# supervisord This scripts turns supervisord on -# -# Author: Mike McGrath (based off yumupdatesd) -# Jason Koppe adjusted to read sysconfig, -# use supervisord tools to start/stop, conditionally wait -# for child processes to shutdown, and startup later -# -# chkconfig: 345 83 04 -# -# description: supervisor is a process control utility. It has a web based -# xmlrpc interface as well as a few other nifty features. -# processname: supervisord -# config: <%= @config_file %> -# pidfile: <%= @run_path %>/<%= @pid_file %> -# - -<% if @scl_enabled -%> -[ -e <%= @scl_script %> ] && . <%= @scl_script %> -<% end -%> - -# source function library -. /etc/rc.d/init.d/functions - -# source system settings -[ -e <%= @init_defaults %> ] && . <%= @init_defaults %> - -RETVAL=0 -DAEMON=<%= @executable %> -CTL=<%= @executable_ctl %> -DESC=supervisord -PIDFILE=<%= @run_path %>/<%= @pid_file %> - -# Tests if executable exists -if [ ! -x $DAEMON ] ; then - echo "Executable not found ${DAEMON}" - exit 1 -fi - -running_pid() -{ - # Check if a given process pid's cmdline matches a given name - pid=$1 - name=$2 - [ -z "$pid" ] && return 1 - [ ! -d /proc/$pid ] && return 1 - (cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1 - return 0 -} - -running() -{ -# Check if the process is running looking at /proc -# (works for all users) - - # No pidfile, probably no daemon present - [ ! -f "$PIDFILE" ] && return 1 - # Obtain the pid and check it against the binary name - pid=`cat $PIDFILE` - running_pid $pid $DAEMON || return 1 - return 0 -} - -start() { - echo -n "Starting $DESC: " - if [ -e $PIDFILE ]; then - echo "ALREADY STARTED" - return 1 - else - # start supervisord with options from sysconfig (stuff like -c) - daemon $DAEMON $OPTIONS - # only create the subsyslock if we created the PIDFILE - [ -e $PIDFILE ] && touch /var/lock/subsys/supervisord - return 0 - fi -} - -stop() { - echo -n "Stopping supervisord: " - killproc -p $PIDFILE $DESC - # always remove the subsys. we might have waited a while, but just remove it at this point. - rm -f /var/lock/subsys/supervisord - return 0 -} - -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart|force-reload) - restart - ;; - reload) - $CTL $OPTIONS reload - RETVAL=$? - ;; - condrestart) - [ -f /var/lock/subsys/supervisord ] && restart - RETVAL=$? - ;; - status) - echo -n "supervisord is " - if running ; then - echo "running" - else - echo "not running." - exit 1 - fi - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" - exit 1 -esac - -exit $RETVAL diff --git a/templates/init/Suse/defaults.erb b/templates/init/Suse/defaults.erb deleted file mode 100644 index affaaad..0000000 --- a/templates/init/Suse/defaults.erb +++ /dev/null @@ -1,8 +0,0 @@ -# this is sourced by the supervisord init script -# written by jkoppe - -set -a - -# should probably put both of these options as runtime arguments -OPTIONS="-c <%= @config_file %>" -PIDFILE=<%= @run_path %>/<%= @pid_file %> diff --git a/templates/init/Suse/init.erb b/templates/init/Suse/init.erb deleted file mode 100644 index f6987a6..0000000 --- a/templates/init/Suse/init.erb +++ /dev/null @@ -1,131 +0,0 @@ -#!/bin/bash -# -# supervisord This scripts turns supervisord on -# -# Author: Mike McGrath (based off yumupdatesd) -# Jason Koppe adjusted to read sysconfig, -# use supervisord tools to start/stop, conditionally wait -# for child processes to shutdown, and startup later -# -# chkconfig: 345 83 04 -# -# description: supervisor is a process control utility. It has a web based -# xmlrpc interface as well as a few other nifty features. -# processname: supervisord -# config: <%= @config_file %> -# pidfile: <%= @run_path %>/<%= @pid_file %> -# - -<% if @scl_enabled -%> -[ -e <%= @scl_script %> ] && . <%= @scl_script %> -<% end -%> - -if [ -f /etc/rc.status ]; then - . /etc/rc.status - rc_reset -fi - -# source function library -if [ -f /etc/rc.d/init.d/functions ]; then - . /etc/rc.d/init.d/functions -fi - -# source system settings -[ -e <%= @init_defaults %> ] && . <%= @init_defaults %> - -RETVAL=0 -DAEMON=<%= @executable %> -CTL=<%= @executable_ctl %> -DESC=supervisord -PIDFILE=<%= @run_path %>/<%= @pid_file %> - -# Tests if executable exists -if [ ! -x $DAEMON ] ; then - echo "Executable not found ${DAEMON}" - exit 1 -fi - -running_pid() -{ - # Check if a given process pid's cmdline matches a given name - pid=$1 - name=$2 - [ -z "$pid" ] && return 1 - [ ! -d /proc/$pid ] && return 1 - (cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1 - return 0 -} - -running() -{ -# Check if the process is running looking at /proc -# (works for all users) - - # No pidfile, probably no daemon present - [ ! -f "$PIDFILE" ] && return 1 - # Obtain the pid and check it against the binary name - pid=`cat $PIDFILE` - running_pid $pid $DAEMON || return 1 - return 0 -} - -start() { - echo -n "Starting $DESC: " - if [ -e $PIDFILE ]; then - echo "ALREADY STARTED" - return 1 - else - # start supervisord with options from sysconfig (stuff like -c) - startproc -p $PIDFILE $DAEMON $OPTIONS - # only create the subsyslock if we created the PIDFILE - [ -e $PIDFILE ] && touch /var/lock/subsys/supervisord - return 0 - fi -} - -stop() { - echo -n "Stopping supervisord: " - killproc -p $PIDFILE $DESC - # always remove the subsys. we might have waited a while, but just remove it at this point. - rm -f /var/lock/subsys/supervisord - return 0 -} - -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart|force-reload) - restart - ;; - reload) - $CTL $OPTIONS reload - RETVAL=$? - ;; - condrestart) - [ -f /var/lock/subsys/supervisord ] && restart - RETVAL=$? - ;; - status) - echo -n "supervisord is " - if running ; then - echo "running" - else - echo "not running." - exit 1 - fi - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" - exit 1 -esac - -exit $RETVAL diff --git a/types/maxbytes.pp b/types/maxbytes.pp new file mode 100644 index 0000000..297a33e --- /dev/null +++ b/types/maxbytes.pp @@ -0,0 +1 @@ +type Supervisord::Maxbytes = Pattern[/\A(^[0-9]*(?:KB|MB|GB)?)\z/] diff --git a/types/umask.pp b/types/umask.pp new file mode 100644 index 0000000..ba8ce91 --- /dev/null +++ b/types/umask.pp @@ -0,0 +1 @@ +type Supervisord::Umask = Pattern[/\A([0-7]{1,3})\z/]