Fix UnboundLocalError in error handling of runStateMachine
This fixes an UnboundLocalError that can arise while hanlding other errors. ``` [...] Traceback (most recent call last): File "/opt/nodepool/lib/python3.11/site-packages/nodepool/driver/statemachine.py", line 741, in _runStateMachines sm.runStateMachine() File "/opt/nodepool/lib/python3.11/site-packages/nodepool/driver/statemachine.py", line 326, in runStateMachine if state_machine and state_machine.external_id: ^^^^^^^^^^^^^ UnboundLocalError: cannot access local variable 'state_machine' where it is not associated with a value ``` Change-Id: I06ab0851cb2803f67d1d35fc12fabea9ea931501
This commit is contained in:
parent
e4a0acf7c5
commit
9249e125a7
@ -309,25 +309,25 @@ class StateMachineNodeLauncher(stats.StatsReporter):
|
||||
"Lost ZooKeeper session trying to launch for node %s",
|
||||
node.id)
|
||||
node.state = zk.FAILED
|
||||
if state_machine:
|
||||
node.external_id = state_machine.external_id
|
||||
if self.state_machine:
|
||||
node.external_id = self.state_machine.external_id
|
||||
statsd_key = 'error.zksession'
|
||||
except exceptions.QuotaException:
|
||||
self.log.info("Aborting node %s due to quota failure", node.id)
|
||||
node.state = zk.ABORTED
|
||||
if state_machine:
|
||||
node.external_id = state_machine.external_id
|
||||
if self.state_machine:
|
||||
node.external_id = self.state_machine.external_id
|
||||
self.zk.storeNode(node)
|
||||
statsd_key = 'error.quota'
|
||||
self.manager.invalidateQuotaCache()
|
||||
except Exception as e:
|
||||
self.log.exception("Launch attempt %d/%d for node %s, failed:",
|
||||
self.attempts, self.retries, node.id)
|
||||
if state_machine and state_machine.external_id:
|
||||
if self.state_machine and self.state_machine.external_id:
|
||||
# If we're deleting, don't overwrite the node external
|
||||
# id, because we may make another delete state machine
|
||||
# below.
|
||||
node.external_id = state_machine.external_id
|
||||
node.external_id = self.state_machine.external_id
|
||||
self.zk.storeNode(node)
|
||||
|
||||
if hasattr(e, 'statsd_key'):
|
||||
|
Loading…
x
Reference in New Issue
Block a user