Skip to content

Commit

Permalink
improve error handling when applying plugin options
Browse files Browse the repository at this point in the history
  • Loading branch information
fraenki committed Nov 4, 2020
1 parent bdd6e8f commit 0bfc4c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,8 @@ Default value: `'enabled'`
Data type: `Array`

An array containing additional plugin options. See `man 8 dsconf` for a
complete list. Optional.
complete list. Note that several options can only be applied once,
further attempts will fail. Optional.

Default value: `[]`

Expand Down
11 changes: 7 additions & 4 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#
# @param options
# An array containing additional plugin options. See `man 8 dsconf` for a
# complete list. Optional.
# complete list. Note that several options can only be applied once,
# further attempts will fail. Optional.
#
# @param protocol
# The protocol to use when calling ldapadd. Default: 'ldap'
Expand Down Expand Up @@ -103,16 +104,18 @@
$options.each |$option| {
# Command to set the specified plugin option.
$plugin_option_command = join([
# Rename the options file. This way a failed command is retried
# and if the error persists the user is encouraged to fix it.
"mv -f ${plugin_options_file} ${plugin_options_file}.error &&",
'dsconf',
"-D \'${root_dn}\'",
"-w \'${root_dn_pass}\'",
"${protocol}://${server_host}:${server_port}",
'plugin',
$name,
$option,
# Remove the options file in case of failure. This way a failed command
# is retried and if the error persists the user is encouraged to fix it.
"|| rm -f ${plugin_options_file}",
# If the plugin command succeeds, move the options file back.
"&& mv -f ${plugin_options_file}.error ${plugin_options_file}",
], ' ')

exec { "Set plugin ${name} options (${option}): ${server_id}":
Expand Down
7 changes: 3 additions & 4 deletions spec/defines/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,21 @@

it {
is_expected.to contain_exec('Set plugin specplugin options (set --groupattr uniqueMember): specdirectory').with(
command: "dsconf -D 'cn=Directory Manager' -w 'supersecret' ldap://ldap.test.org:1389 plugin specplugin set --groupattr uniqueMember || rm -f /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options", # rubocop:disable LineLength
command: "mv -f /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options.error && dsconf -D 'cn=Directory Manager' -w 'supersecret' ldap://ldap.test.org:1389 plugin specplugin set --groupattr uniqueMember && mv -f /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options.error /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options", # rubocop:disable LineLength
path: '/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin',
refreshonly: true,
).that_subscribes_to('File[/etc/dirsrv/slapd-specdirectory/plugin_specplugin_options]')
#).that_requires('Exec[Set plugin specplugin state to enabled: specdirectory]').that_subscribes_to('File[/etc/dirsrv/slapd-specdirectory/plugin_specplugin_options]')
}
it {
is_expected.to contain_exec('Set plugin specplugin options (set --allbackends on): specdirectory').with(
command: "dsconf -D 'cn=Directory Manager' -w 'supersecret' ldap://ldap.test.org:1389 plugin specplugin set --allbackends on || rm -f /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options", # rubocop:disable LineLength
command: "mv -f /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options.error && dsconf -D 'cn=Directory Manager' -w 'supersecret' ldap://ldap.test.org:1389 plugin specplugin set --allbackends on && mv -f /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options.error /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options", # rubocop:disable LineLength
path: '/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin',
refreshonly: true,
).that_subscribes_to('File[/etc/dirsrv/slapd-specdirectory/plugin_specplugin_options]')
}
it {
is_expected.to contain_exec('Set plugin specplugin options (set --skipnested off): specdirectory').with(
command: "dsconf -D 'cn=Directory Manager' -w 'supersecret' ldap://ldap.test.org:1389 plugin specplugin set --skipnested off || rm -f /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options", # rubocop:disable LineLength
command: "mv -f /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options.error && dsconf -D 'cn=Directory Manager' -w 'supersecret' ldap://ldap.test.org:1389 plugin specplugin set --skipnested off && mv -f /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options.error /etc/dirsrv/slapd-specdirectory/plugin_specplugin_options", # rubocop:disable LineLength
path: '/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin',
refreshonly: true,
).that_subscribes_to('File[/etc/dirsrv/slapd-specdirectory/plugin_specplugin_options]')
Expand Down

0 comments on commit 0bfc4c7

Please sign in to comment.