Make NodeSet fully serializable

This change makes the NodeSet fully serializable, so we are able to
store it in the job arguments and restore it on the executor server.

This is a preparation step to allow locking/unlocking the nodes on the
executor server.

Change-Id: I83c910c0190d8fd1ea17e29f82605508f9c6e2ae
This commit is contained in:
Felix Edel 2021-02-03 09:33:27 +01:00
parent ba7f81be2d
commit 2a74170633
2 changed files with 23 additions and 0 deletions

View File

@ -348,6 +348,7 @@ class TestWeb(BaseTestWeb):
'name': '',
'nodes': [{'comment': None,
'hold_job': None,
'id': None,
'label': 'label1',
'name': 'controller',
'aliases': [],
@ -394,6 +395,7 @@ class TestWeb(BaseTestWeb):
'name': '',
'nodes': [{'comment': None,
'hold_job': None,
'id': None,
'label': 'label2',
'name': 'controller',
'aliases': [],
@ -1017,6 +1019,7 @@ class TestWeb(BaseTestWeb):
'nodes': [{
'comment': None,
'hold_job': None,
'id': None,
'label': 'label1',
'name': ['controller'],
'state': 'unknown'

View File

@ -635,6 +635,7 @@ class Node(ConfigObject):
def toDict(self, internal_attributes=False):
d = {}
d["id"] = self.id
d['state'] = self.state
d['hold_job'] = self.hold_job
d['comment'] = self.comment
@ -657,6 +658,12 @@ class Node(ConfigObject):
setattr(self, k, v)
self._keys = keys
@classmethod
def fromDict(cls, data):
node = cls(data["name"], data["label"])
node.updateFromDict(data)
return node
class Group(ConfigObject):
"""A logical group of nodes for use by a job.
@ -689,6 +696,10 @@ class Group(ConfigObject):
'nodes': self.nodes
}
@classmethod
def fromDict(cls, data):
return cls(data["name"], data["nodes"])
class NodeSet(ConfigObject):
"""A set of nodes.
@ -726,6 +737,15 @@ class NodeSet(ConfigObject):
d['groups'].append(group.toDict())
return d
@classmethod
def fromDict(cls, data):
nodeset = cls(data["name"])
for node in data["nodes"]:
nodeset.addNode(Node.fromDict(node))
for group in data["groups"]:
nodeset.addGroup(Group.fromDict(group))
return nodeset
def copy(self):
n = NodeSet(self.name)
for name, node in self.nodes.items():