Move variable attempts_count to local scope
This variable is concurrently read and write, so it needs to be local. In addition, it needs to be incremented on each 'poll_and_check'. Change-Id: I02ab50c7c005e11df9b9b84b0241323e24b9c295 Closes-Bug: 1419586
This commit is contained in:
parent
6a84010253
commit
ada97c347a
|
@ -118,11 +118,7 @@ class Handler(object):
|
|||
bay.stack_id = created_stack['stack']['id']
|
||||
bay.create()
|
||||
|
||||
self.attempts_count = 0
|
||||
|
||||
lc = loopingcall.FixedIntervalLoopingCall(self._poll_and_check,
|
||||
osc, bay)
|
||||
lc.start(cfg.CONF.k8s_heat.wait_interval, True)
|
||||
self._poll_and_check(osc, bay)
|
||||
|
||||
return bay
|
||||
|
||||
|
@ -154,23 +150,30 @@ class Handler(object):
|
|||
return None
|
||||
|
||||
def _poll_and_check(self, osc, bay):
|
||||
attempts = {'count': 0}
|
||||
|
||||
# TODO(yuanying): temporary implementation of updating master_address
|
||||
stack = osc.heat().stacks.get(bay.stack_id)
|
||||
if stack.stack_status == 'CREATE_COMPLETE':
|
||||
parsed_outputs = _parse_stack_outputs(stack.outputs)
|
||||
master_address = parsed_outputs["kube_master"]
|
||||
minion_address = parsed_outputs["kube_minions_external"]
|
||||
bay.master_address = master_address
|
||||
bay.minions_address = minion_address
|
||||
bay.save()
|
||||
raise loopingcall.LoopingCallDone()
|
||||
# poll_and_check is detached and polling long time to check status,
|
||||
# so another user/client can call delete bay/stack.
|
||||
if stack.stack_status == 'DELETE_COMPLETE':
|
||||
LOG.info('Bay has been deleted, stack_id: %s' % bay.stack_id)
|
||||
raise loopingcall.LoopingCallDone()
|
||||
if ((stack.status == 'FAILED') or
|
||||
(self.attempts_count > cfg.CONF.k8s_heat.max_attempts)):
|
||||
# TODO(yuanying): update status to failed
|
||||
LOG.error('Unable to create bay, stack_id: %s' % bay.stack_id)
|
||||
raise loopingcall.LoopingCallDone()
|
||||
def poll_and_check():
|
||||
stack = osc.heat().stacks.get(bay.stack_id)
|
||||
attempts['count'] += 1
|
||||
if stack.stack_status == 'CREATE_COMPLETE':
|
||||
parsed_outputs = _parse_stack_outputs(stack.outputs)
|
||||
master_address = parsed_outputs["kube_master"]
|
||||
minion_address = parsed_outputs["kube_minions_external"]
|
||||
bay.master_address = master_address
|
||||
bay.minions_address = minion_address
|
||||
bay.save()
|
||||
raise loopingcall.LoopingCallDone()
|
||||
# poll_and_check is detached and polling long time to check status,
|
||||
# so another user/client can call delete bay/stack.
|
||||
if stack.stack_status == 'DELETE_COMPLETE':
|
||||
LOG.info('Bay has been deleted, stack_id: %s' % bay.stack_id)
|
||||
raise loopingcall.LoopingCallDone()
|
||||
if ((stack.status == 'FAILED') or
|
||||
(attempts['count'] > cfg.CONF.k8s_heat.max_attempts)):
|
||||
# TODO(yuanying): update status to failed
|
||||
LOG.error('Unable to create bay, stack_id: %s' % bay.stack_id)
|
||||
raise loopingcall.LoopingCallDone()
|
||||
|
||||
lc = loopingcall.FixedIntervalLoopingCall(f=poll_and_check)
|
||||
lc.start(cfg.CONF.k8s_heat.wait_interval, True)
|
||||
|
|
Loading…
Reference in New Issue