Fix to better handle concurrent runs of module against same pool

reviewable/pr18780/r1
Matt Hite 11 years ago
parent 09e0e973d3
commit 4ca5e7b01d

@ -200,6 +200,10 @@ def pool_exists(api, pool):
return result return result
def create_pool(api, pool, lb_method): def create_pool(api, pool, lb_method):
# create requires lb_method but we don't want to default
# to a value on subsequent runs
if not lb_method:
lb_method = 'round_robin'
lb_method = "LB_METHOD_%s" % lb_method.strip().upper() lb_method = "LB_METHOD_%s" % lb_method.strip().upper()
api.LocalLB.Pool.create_v2(pool_names=[pool], lb_methods=[lb_method], api.LocalLB.Pool.create_v2(pool_names=[pool], lb_methods=[lb_method],
members=[[]]) members=[[]])
@ -390,29 +394,57 @@ def main():
elif pool_exists(api, pool): elif pool_exists(api, pool):
# no host/port supplied, must be pool removal # no host/port supplied, must be pool removal
if not module.check_mode: if not module.check_mode:
remove_pool(api, pool) # hack to handle concurrent runs of module
result = {'changed': True} # pool might be gone before we actually remove it
try:
remove_pool(api, pool)
result = {'changed': True}
except bigsuds.OperationFailed, e:
if "was not found" in str(e):
result = {'changed': False}
else:
# genuine exception
raise
else:
# check-mode return value
result = {'changed': True}
elif state == 'present': elif state == 'present':
update = False
if not pool_exists(api, pool): if not pool_exists(api, pool):
# pool does not exist -- need to create it # pool does not exist -- need to create it
if not module.check_mode: if not module.check_mode:
# create requires lb_method but we don't want to default # a bit of a hack to handle concurrent runs of this module.
# to a value on subsequent runs # even though we've checked the pool doesn't exist,
if not lb_method: # it may exist by the time we run create_pool().
lb_method = 'round_robin' # this catches the exception and does something smart
create_pool(api, pool, lb_method) # about it!
if monitors: try:
set_monitors(api, pool, monitor_type, quorum, monitors) create_pool(api, pool, lb_method)
if slow_ramp_time: result = {'changed': True}
set_slow_ramp_time(api, pool, slow_ramp_time) except bigsuds.OperationFailed, e:
if service_down_action: if "already exists" in str(e):
set_action_on_service_down(api, pool, service_down_action) update = True
if host and port: else:
add_pool_member(api, pool, address, port) # genuine exception
result = {'changed': True} raise
else:
if monitors:
set_monitors(api, pool, monitor_type, quorum, monitors)
if slow_ramp_time:
set_slow_ramp_time(api, pool, slow_ramp_time)
if service_down_action:
set_action_on_service_down(api, pool, service_down_action)
if host and port:
add_pool_member(api, pool, address, port)
else:
# check-mode return value
result = {'changed': True}
else: else:
# pool exists -- potentially modify attributes # pool exists -- potentially modify attributes
update = True
if update:
if lb_method and lb_method != get_lb_method(api, pool): if lb_method and lb_method != get_lb_method(api, pool):
if not module.check_mode: if not module.check_mode:
set_lb_method(api, pool, lb_method) set_lb_method(api, pool, lb_method)

Loading…
Cancel
Save