From b553f77ead198df1e5a5bd42baab152444f762d0 Mon Sep 17 00:00:00 2001 From: Benjamin Bohard Date: Mon, 30 Aug 2021 11:37:09 +0200 Subject: [PATCH] =?UTF-8?q?Module=20instance=20sort=20en=20erreur=20si=20l?= =?UTF-8?q?a=20proc=C3=A9dure=20n=E2=80=99est=20pas=20all=C3=A9=20jusqu?= =?UTF-8?q?=E2=80=99au=20bout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cadoles/eole/plugins/modules/instance.py | 39 +++++++++++++----------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/cadoles/eole/plugins/modules/instance.py b/cadoles/eole/plugins/modules/instance.py index 3002a9d..721c7c2 100644 --- a/cadoles/eole/plugins/modules/instance.py +++ b/cadoles/eole/plugins/modules/instance.py @@ -335,24 +335,30 @@ def run_module(): for expectation_name, response in module.params['variables'].items(): expectations.set_expectation_response_by_name(expectation_name, response) - instance_process = pexpect.spawn(cmd, encoding='utf-8', timeout=60) + try: + instance_process = pexpect.spawn(cmd, encoding='utf-8', timeout=60) - some_index = 0 - while some_index < nb_expectations: - p = instance_process.expect(patterns) - if p == 0: - break - if p == 1: - print(f'Some missing expectations for {instance_process.before}{instance_process.after}') - break - pattern = patterns[p] - for expectation in expectations.get_expectations_by_pattern(patterns[p]): - if expectation.is_the_one(instance_process.before): - expectation.answer(instance_process) + some_index = 0 + while some_index < nb_expectations: + p = instance_process.expect(patterns) + if p == 0: break - some_index += 1 - result['changed'] = True - result['msg'] += f"Module {result['module']} instanciated" + if p == 1: + print(f'Some missing expectations for {instance_process.before}{instance_process.after}') + break + pattern = patterns[p] + for expectation in expectations.get_expectations_by_pattern(patterns[p]): + if expectation.is_the_one(instance_process.before): + expectation.answer(instance_process) + break + some_index += 1 + result['changed'] = True + result['msg'] += f"Module {result['module']} instanciated" + module.exit_json(**result) + except Exception as err: + result['msg'] += err + result['changed'] = True + module.fail_json(**result) @@ -369,7 +375,6 @@ def run_module(): # in the event of a successful module execution, you will want to # simple AnsibleModule.exit_json(), passing the key/value results - module.exit_json(**result) def main():