From f8e40583f274a79bb0187bdc80dd5c62dbd1ecb7 Mon Sep 17 00:00:00 2001 From: Serge van Ginderachter Date: Tue, 3 Sep 2013 22:00:43 +0200 Subject: [PATCH] improve changed result for race conditions --- net_infrastructure/bigip_monitor_http | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/net_infrastructure/bigip_monitor_http b/net_infrastructure/bigip_monitor_http index 0f26a0a3745..61c36105c2a 100644 --- a/net_infrastructure/bigip_monitor_http +++ b/net_infrastructure/bigip_monitor_http @@ -182,10 +182,11 @@ def create_monitor(api, monitor, template_attributes): api.LocalLB.Monitor.create_template(templates=[{'template_name': monitor, 'template_type': TEMPLATE_TYPE}], template_attributes=[template_attributes]) except bigsuds.OperationFailed, e: if "already exists" in str(e): - pass + return False else: # genuine exception raise + return True def delete_monitor(api, monitor): @@ -194,9 +195,12 @@ def delete_monitor(api, monitor): api.LocalLB.Monitor.delete_template(template_names=[monitor]) except bigsuds.OperationFailed, e: # maybe it was deleted since we checked - if not "was not found" in str(e): + if "was not found" in str(e): + return False + else: # genuine exception raise + return True def check_string_property(api, monitor, str_property): @@ -307,8 +311,11 @@ def main(): if state == 'absent': if monitor_exists: if not module.check_mode: - delete_monitor(api, monitor) - result['changed'] = True + # possible race condition if same task + # on other node deleted it first + result['changed'] = delete_monitor(api, monitor) + else: + result['changed'] = True else: ipport = {'address_type': address_type, @@ -353,10 +360,13 @@ def main(): result['changed'] = True elif not module.check_mode: - create_monitor(api, monitor, template_attributes) + # possible race condition if same task + # on other node deleted it first + result['changed'] = create_monitor(api, monitor, template_attributes) for str_property in template_string_properties: set_string_property(api, monitor, str_property) - result['changed'] = True + for int_property in template_integer_properties: + set_integer_property(api, monitor, int_property) else: # monitor does not exist and check mode result['changed'] = True