summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-11-29 09:50:57 +0000
committerGerrit Code Review <review@openstack.org>2018-11-29 09:50:57 +0000
commit00a81d63dc1a8051be0f8688bed89ac4be36313a (patch)
tree0f57de15ac96bab7325dce5970a232a97497e01d
parentc49cc46b6ec87f2c08d469332065c08aaf3d9f54 (diff)
parent1d278ffaee965f04c3a24dd99afa85ac15d73cf2 (diff)
Merge "Update node request during locking"
-rwxr-xr-xnodepool/launcher.py3
-rwxr-xr-xnodepool/zk.py39
2 files changed, 34 insertions, 8 deletions
diff --git a/nodepool/launcher.py b/nodepool/launcher.py
index dc80b9b..192651f 100755
--- a/nodepool/launcher.py
+++ b/nodepool/launcher.py
@@ -200,8 +200,7 @@ class PoolWorker(threading.Thread):
200 continue 200 continue
201 201
202 # Make sure the state didn't change on us after getting the lock 202 # Make sure the state didn't change on us after getting the lock
203 req2 = self.zk.getNodeRequest(req_id) 203 if req.state != zk.REQUESTED:
204 if req2 and req2.state != zk.REQUESTED:
205 self.zk.unlockNodeRequest(req) 204 self.zk.unlockNodeRequest(req)
206 continue 205 continue
207 206
diff --git a/nodepool/zk.py b/nodepool/zk.py
index abb0faf..66c2f38 100755
--- a/nodepool/zk.py
+++ b/nodepool/zk.py
@@ -475,13 +475,17 @@ class NodeRequest(BaseModel):
475 ''' 475 '''
476 o = NodeRequest(o_id) 476 o = NodeRequest(o_id)
477 super(NodeRequest, o).fromDict(d) 477 super(NodeRequest, o).fromDict(d)
478 o.declined_by = d.get('declined_by', []) 478 o.updateFromDict(d)
479 o.node_types = d.get('node_types', [])
480 o.nodes = d.get('nodes', [])
481 o.reuse = d.get('reuse', True)
482 o.requestor = d.get('requestor')
483 return o 479 return o
484 480
481 def updateFromDict(self, d):
482 super().fromDict(d)
483 self.declined_by = d.get('declined_by', [])
484 self.node_types = d.get('node_types', [])
485 self.nodes = d.get('nodes', [])
486 self.reuse = d.get('reuse', True)
487 self.requestor = d.get('requestor')
488
485 489
486class Node(BaseModel): 490class Node(BaseModel):
487 ''' 491 '''
@@ -1586,6 +1590,24 @@ class ZooKeeper(object):
1586 d.stat = stat 1590 d.stat = stat
1587 return d 1591 return d
1588 1592
1593 def updateNodeRequest(self, request):
1594 '''
1595 Update the data of a node request object in-place
1596
1597 :param request: the node request object to update
1598 '''
1599
1600 path = self._requestPath(request.id)
1601 data, stat = self.client.get(path)
1602
1603 if data:
1604 d = self._bytesToDict(data)
1605 else:
1606 d = {}
1607
1608 request.updateFromDict(d)
1609 request.stat = stat
1610
1589 def storeNodeRequest(self, request, priority="100"): 1611 def storeNodeRequest(self, request, priority="100"):
1590 ''' 1612 '''
1591 Store a new or existing node request. 1613 Store a new or existing node request.
@@ -1632,7 +1654,9 @@ class ZooKeeper(object):
1632 Lock a node request. 1654 Lock a node request.
1633 1655
1634 This will set the `lock` attribute of the request object when the 1656 This will set the `lock` attribute of the request object when the
1635 lock is successfully acquired. 1657 lock is successfully acquired. Also this will update the node request
1658 with the latest data after acquiring the lock in order to guarantee
1659 that it has the latest state if locking was successful.
1636 1660
1637 :param NodeRequest request: The request to lock. 1661 :param NodeRequest request: The request to lock.
1638 :param bool blocking: Whether or not to block on trying to 1662 :param bool blocking: Whether or not to block on trying to
@@ -1662,6 +1686,9 @@ class ZooKeeper(object):
1662 1686
1663 request.lock = lock 1687 request.lock = lock
1664 1688
1689 # Do an in-place update of the node request so we have the latest data
1690 self.updateNodeRequest(request)
1691
1665 def unlockNodeRequest(self, request): 1692 def unlockNodeRequest(self, request):
1666 ''' 1693 '''
1667 Unlock a node request. 1694 Unlock a node request.