From d9b3f61ba710fda9da8c885d5604e0876d2ec13b Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 2 Jan 2025 15:53:44 +0100 Subject: [PATCH] Fixing command error handling in lib/ansible/ds389_plugins_info.py --- lib/ansible/ds389_plugins_info.py | 78 +++++++++++++++---------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/ansible/ds389_plugins_info.py b/lib/ansible/ds389_plugins_info.py index b438c88..c9dc32d 100644 --- a/lib/ansible/ds389_plugins_info.py +++ b/lib/ansible/ds389_plugins_info.py @@ -55,6 +55,7 @@ config: # Standard modules import re +import shlex from subprocess import run # Third party modules @@ -135,11 +136,11 @@ class Ds389PluginsInfo(object): # -------------------------------------------------------------------------- def get_automember(self): """Get configuration, definitions and regular expressions of the automember plugnin.""" - proc = run( - [self.cmd, self.instance, 'plugin', 'automember', 'show'], - capture_output=True, encoding=self.encoding) + cmd = [self.cmd, self.instance, 'plugin', 'automember', 'show'] + proc = run(cmd, capture_output=True, encoding=self.encoding) if proc.stderr: - module.warn(proc.stderr) + msg = 'Error executing {!r}: '.format(shlex.join(cmd)) + proc.stderr + module.warn(msg) if proc.returncode: return @@ -181,11 +182,11 @@ class Ds389PluginsInfo(object): # -------------------------------------------------------------------------- def _get_automember_definitions(self): - proc = run( - [self.cmd, self.instance, 'plugin', 'automember', 'list', 'definitions'], - capture_output=True, encoding=self.encoding) + cmd = [self.cmd, self.instance, 'plugin', 'automember', 'list', 'definitions'] + proc = run(cmd, capture_output=True, encoding=self.encoding) if proc.stderr: - module.warn(proc.stderr) + msg = 'Error executing {!r}: '.format(shlex.join(cmd)) + proc.stderr + module.warn(msg) if proc.returncode: return @@ -208,12 +209,11 @@ class Ds389PluginsInfo(object): # -------------------------------------------------------------------------- def _get_automember_definition(self, def_name): - proc = run( - [self.cmd, self.instance, 'plugin', 'automember', 'definition', def_name, 'show'], - capture_output=True, encoding=self.encoding) - + cmd = [self.cmd, self.instance, 'plugin', 'automember', 'definition', def_name, 'show'] + proc = run(cmd, capture_output=True, encoding=self.encoding) if proc.stderr: - module.warn(proc.stderr) + msg = 'Error executing {!r}: '.format(shlex.join(cmd)) + proc.stderr + module.warn(msg) if proc.returncode: return @@ -250,11 +250,11 @@ class Ds389PluginsInfo(object): # -------------------------------------------------------------------------- def _get_automember_regexes(self, def_name): - proc = run( - [self.cmd, self.instance, 'plugin', 'automember', 'list', 'regexes', def_name], - capture_output=True, encoding=self.encoding) + cmd = [self.cmd, self.instance, 'plugin', 'automember', 'list', 'regexes', def_name] + proc = run(cmd, capture_output=True, encoding=self.encoding) if proc.stderr: - module.warn(proc.stderr) + msg = 'Error executing {!r}: '.format(shlex.join(cmd)) + proc.stderr + module.warn(msg) if proc.returncode: return @@ -274,13 +274,13 @@ class Ds389PluginsInfo(object): # -------------------------------------------------------------------------- def _get_automember_regex(self, def_name, re_name): - proc = run( - [self.cmd, self.instance, 'plugin', 'automember', 'definition', - 'regex', re_name, 'show'], - capture_output=True, encoding=self.encoding) - + cmd = [ + self.cmd, self.instance, 'plugin', 'automember', + 'definition', 'regex', re_name, 'show'] + proc = run(cmd, capture_output=True, encoding=self.encoding) if proc.stderr: - module.warn(proc.stderr) + msg = 'Error executing {!r}: '.format(shlex.join(cmd)) + proc.stderr + module.warn(msg) if proc.returncode: return @@ -312,11 +312,11 @@ class Ds389PluginsInfo(object): # -------------------------------------------------------------------------- def get_memberof(self): """Get config of memberof plugin.""" - proc = run( - [self.cmd, self.instance, 'plugin', 'memberof', 'show'], - capture_output=True, encoding=self.encoding) + cmd = [self.cmd, self.instance, 'plugin', 'memberof', 'show'] + proc = run(cmd, capture_output=True, encoding=self.encoding) if proc.stderr: - module.warn(proc.stderr) + msg = 'Error executing {!r}: '.format(shlex.join(cmd)) + proc.stderr + module.warn(msg) if proc.returncode: return @@ -397,11 +397,11 @@ class Ds389PluginsInfo(object): # -------------------------------------------------------------------------- def get_referint(self): """Get config of referential-integrity plugin.""" - proc = run( - [self.cmd, self.instance, 'plugin', 'referential-integrity', 'show'], - capture_output=True, encoding=self.encoding) + cmd = [self.cmd, self.instance, 'plugin', 'referential-integrity', 'show'] + proc = run(cmd, capture_output=True, encoding=self.encoding) if proc.stderr: - module.warn(proc.stderr) + msg = 'Error executing {!r}: '.format(shlex.join(cmd)) + proc.stderr + module.warn(msg) if proc.returncode: return @@ -473,11 +473,11 @@ class Ds389PluginsInfo(object): # -------------------------------------------------------------------------- def get_root_dn_access(self): """Get config of the plugin managing the access of the root_dn.""" - proc = run( - [self.cmd, self.instance, 'plugin', 'root-dn', 'show'], - capture_output=True, encoding=self.encoding) + cmd = [self.cmd, self.instance, 'plugin', 'root-dn', 'show'] + proc = run(cmd, capture_output=True, encoding=self.encoding) if proc.stderr: - module.warn(proc.stderr) + msg = 'Error executing {!r}: '.format(shlex.join(cmd)) + proc.stderr + module.warn(msg) if proc.returncode: return @@ -537,11 +537,11 @@ class Ds389PluginsInfo(object): # -------------------------------------------------------------------------- def get_account_policy(self): """Get config of the account-policy plugin.""" - proc = run( - [self.cmd, self.instance, 'plugin', 'account-policy', 'show'], - capture_output=True, encoding=self.encoding) + cmd = [self.cmd, self.instance, 'plugin', 'account-policy', 'show'] + proc = run(cmd, capture_output=True, encoding=self.encoding) if proc.stderr: - module.warn(proc.stderr) + msg = 'Error executing {!r}: '.format(shlex.join(cmd)) + proc.stderr + module.warn(msg) if proc.returncode: return -- 2.39.5