Merge "Use constants for state names" into feature/zuulv3

changes/88/422288/4
Jenkins 6 years ago committed by Gerrit Code Review
commit 0338b76917

@ -47,6 +47,32 @@ PRECEDENCE_MAP = {
'high': PRECEDENCE_HIGH,
}
# Request states
STATE_REQUESTED = 'requested'
STATE_PENDING = 'pending'
STATE_FULFILLED = 'fulfilled'
STATE_FAILED = 'failed'
REQUEST_STATES = set([STATE_REQUESTED,
STATE_PENDING,
STATE_FULFILLED,
STATE_FAILED])
# Node states
STATE_BUILDING = 'building'
STATE_TESTING = 'testing'
STATE_READY = 'ready'
STATE_IN_USE = 'in-use'
STATE_USED = 'used'
STATE_HOLD = 'hold'
STATE_DELETING = 'deleting'
NODE_STATES = set([STATE_BUILDING,
STATE_TESTING,
STATE_READY,
STATE_IN_USE,
STATE_USED,
STATE_HOLD,
STATE_DELETING])
def time_to_seconds(s):
if s.endswith('s'):
@ -369,9 +395,8 @@ class Node(object):
@state.setter
def state(self, value):
# TODOv3(jeblair): reinstate
# if value not in STATES:
# raise TypeError("'%s' is not a valid state" % value)
if value not in NODE_STATES:
raise TypeError("'%s' is not a valid state" % value)
self._state = value
self.state_time = time.time()
@ -439,7 +464,7 @@ class NodeRequest(object):
self.build_set = build_set
self.job = job
self.nodeset = nodeset
self._state = 'requested'
self._state = STATE_REQUESTED
self.state_time = time.time()
self.stat = None
self.uid = uuid4().hex
@ -454,9 +479,8 @@ class NodeRequest(object):
@state.setter
def state(self, value):
# TODOv3(jeblair): reinstate
# if value not in STATES:
# raise TypeError("'%s' is not a valid state" % value)
if value not in REQUEST_STATES:
raise TypeError("'%s' is not a valid state" % value)
self._state = value
self.state_time = time.time()

@ -12,7 +12,7 @@
import logging
from zuul.model import NodeRequest
from zuul import model
class Nodepool(object):
@ -26,7 +26,7 @@ class Nodepool(object):
# Create a copy of the nodeset to represent the actual nodes
# returned by nodepool.
nodeset = job.nodeset.copy()
req = NodeRequest(build_set, job, nodeset)
req = model.NodeRequest(build_set, job, nodeset)
self.requests[req.uid] = req
self.sched.zk.submitNodeRequest(req, self._updateNodeRequest)
@ -49,7 +49,7 @@ class Nodepool(object):
for node in nodeset.getNodes():
if node.lock is None:
raise Exception("Node %s is not locked" % (node,))
node.state = 'in-use'
node.state = model.STATE_IN_USE
self.sched.zk.storeNode(node)
def returnNodeset(self, nodeset):
@ -57,8 +57,8 @@ class Nodepool(object):
for node in nodeset.getNodes():
if node.lock is None:
raise Exception("Node %s is not locked" % (node,))
if node.state == 'in-use':
node.state = 'used'
if node.state == model.STATE_IN_USE:
node.state = model.STATE_USED
self.sched.zk.storeNode(node)
self._unlockNodes(nodeset.getNodes())
@ -98,7 +98,7 @@ class Nodepool(object):
if request.uid not in self.requests:
return False
if request.state == 'fulfilled':
if request.state == model.STATE_FULFILLED:
self.log.info("Node request %s fulfilled" % (request,))
# Give our results to the scheduler.

Loading…
Cancel
Save