Copy nodeset when making node requests

Nodesets are collections of nodes, but they, and the Node objects
they contain, have a dual role representing both the configuration
of a job and the actual nodes returned from nodepool.  So that
multiple jobs sharing the same nodeset configuration don't end up
sharing the same actual nodes, create a copy of a job's nodeset
for use in interacting with nodepool/zk.

Change-Id: I83f503ba22fc3f92b8c90b15ccfb6b07dc3c4709
This commit is contained in:
James E. Blair 2017-01-04 14:33:41 -08:00
parent 15be0e1e11
commit cbf4367837
2 changed files with 14 additions and 3 deletions

View File

@ -353,9 +353,10 @@ class Node(object):
def __init__(self, name, image):
self.name = name
self.image = image
self.id = None
def __repr__(self):
return '<Node %s:%s>' % (self.name, self.image)
return '<Node %s %s:%s>' % (self.id, self.name, self.image)
class NodeSet(object):
@ -372,6 +373,12 @@ class NodeSet(object):
self.name = name or ''
self.nodes = OrderedDict()
def copy(self):
n = NodeSet(self.name)
for name, node in self.nodes.items():
n.addNode(Node(node.name, node.image))
return n
def addNode(self, node):
if node.name in self.nodes:
raise Exception("Duplicate node in %s" % (self,))
@ -399,6 +406,7 @@ class NodeRequest(object):
self.state_time = time.time()
self.stat = None
self.uid = uuid4().hex
self.id = None
@property
def state(self):
@ -413,7 +421,7 @@ class NodeRequest(object):
self.state_time = time.time()
def __repr__(self):
return '<NodeRequest %s>' % (self.nodeset,)
return '<NodeRequest %s %s>' % (self.id, self.nodeset)
def toDict(self):
d = {}

View File

@ -23,7 +23,10 @@ class Nodepool(object):
self.sched = scheduler
def requestNodes(self, build_set, job):
req = NodeRequest(build_set, job, job.nodeset)
# Create a copy of the nodeset to represent the actual nodes
# returned by nodepool.
nodeset = job.nodeset.copy()
req = NodeRequest(build_set, job, nodeset)
self.requests[req.uid] = req
self.log.debug("Submitting node request: %s" % (req,))