From 944ae47701967e0b62fe9cf48498e6d11ce266d0 Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Tue, 16 Jan 2018 20:10:36 -0800 Subject: [PATCH] Detects errors in bigip_config (#34965) There are changes that the merge config can fail, but the module will still report success. This adds a blob of code to start collecting those failures and bubbling up a module failure accordingly. --- lib/ansible/modules/network/f5/bigip_config.py | 11 +++++++++++ test/units/modules/network/f5/test_bigip_config.py | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/network/f5/bigip_config.py b/lib/ansible/modules/network/f5/bigip_config.py index 28412a6d45..ae3ba07ab5 100644 --- a/lib/ansible/modules/network/f5/bigip_config.py +++ b/lib/ansible/modules/network/f5/bigip_config.py @@ -211,12 +211,23 @@ class ModuleManager(object): response = self.save() responses.append(response) + self._detect_errors(responses) changes = { 'stdout': responses, 'stdout_lines': self._to_lines(responses) } self.changes = Parameters(params=changes) + def _detect_errors(self, stdout): + errors = [ + 'Unexpected Error:' + ] + + msg = [x for x in stdout for y in errors if y in x] + if msg: + # Error only contains the lines that include the error + raise F5ModuleError(' '.join(msg)) + def reset(self): if self.module.check_mode: return True diff --git a/test/units/modules/network/f5/test_bigip_config.py b/test/units/modules/network/f5/test_bigip_config.py index a4053fa8d4..e5c13d1b06 100644 --- a/test/units/modules/network/f5/test_bigip_config.py +++ b/test/units/modules/network/f5/test_bigip_config.py @@ -100,12 +100,12 @@ class TestManager(unittest.TestCase): # Override methods to force specific logic in the module to happen mm.exit_json = Mock(return_value=True) - mm.reset_device = Mock(return_value=True) + mm.reset_device = Mock(return_value='reset output') mm.upload_to_device = Mock(return_value=True) mm.move_on_device = Mock(return_value=True) - mm.merge_on_device = Mock(return_value=True) + mm.merge_on_device = Mock(return_value='merge output') mm.remove_temporary_file = Mock(return_value=True) - mm.save_on_device = Mock(return_value=True) + mm.save_on_device = Mock(return_value='save output') results = mm.exec_module()