Commit 565cb4bf authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

QA: Release nodes through method



Instead of having a module-level function in “qa_config” to release a
node, a new method on node objects is used.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarBernardo Dal Seno <bdalseno@google.com>
parent dbdb0594
......@@ -377,7 +377,7 @@ def RunExportImportTests(instance, inodes):
finally:
newinst.Release()
finally:
qa_config.ReleaseNode(expnode)
expnode.Release()
if qa_config.TestEnabled(["rapi", "inter-cluster-instance-move"]):
newinst = qa_config.AcquireInstance()
......@@ -387,7 +387,7 @@ def RunExportImportTests(instance, inodes):
RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
inodes, tnode)
finally:
qa_config.ReleaseNode(tnode)
tnode.Release()
finally:
newinst.Release()
......@@ -499,10 +499,10 @@ def RunExclusiveStorageTests():
finally:
instance.Release()
finally:
qa_config.ReleaseNode(snode)
snode.Release()
qa_cluster.TestSetExclStorCluster(old_es)
finally:
qa_config.ReleaseNode(node)
node.Release()
def RunInstanceTests():
......@@ -580,7 +580,7 @@ def RunQa():
RunTestIf("node-modify", qa_node.TestNodeModify, pnode)
RunTestIf("delay", qa_cluster.TestDelay, pnode)
finally:
qa_config.ReleaseNode(pnode)
pnode.Release()
# Make sure the cluster is clean before running instance tests
qa_cluster.AssertClusterVerify()
......@@ -605,7 +605,7 @@ def RunQa():
del rapi_instance
finally:
qa_config.ReleaseNode(pnode)
pnode.Release()
config_list = [
("default-instance-tests", lambda: None, lambda _: None),
......@@ -633,7 +633,7 @@ def RunQa():
RunTest(qa_instance.TestInstanceExportWithRemove, instance, expnode)
RunTest(qa_instance.TestBackupList, expnode)
finally:
qa_config.ReleaseNode(expnode)
expnode.Release()
finally:
instance.Release()
del expnode
......@@ -641,7 +641,7 @@ def RunQa():
qa_cluster.AssertClusterVerify()
finally:
qa_config.ReleaseNode(pnode)
pnode.Release()
RunExclusiveStorageTests()
......@@ -658,9 +658,9 @@ def RunQa():
RunTest(qa_instance.TestRemoveInstanceOfflineNode, instance, snode,
set_offline, set_online)
finally:
qa_config.ReleaseNode(pnode)
pnode.Release()
finally:
qa_config.ReleaseNode(snode)
snode.Release()
qa_cluster.AssertClusterVerify()
RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
......
......@@ -567,7 +567,7 @@ def TestClusterMasterFailover():
# Back to original master node
AssertCommand(cmd, node=master)
finally:
qa_config.ReleaseNode(failovermaster)
failovermaster.Release()
def TestClusterMasterFailoverWithDrainedQueue():
......@@ -594,7 +594,7 @@ def TestClusterMasterFailoverWithDrainedQueue():
# Back to original master node
AssertCommand(cmd, node=master)
finally:
qa_config.ReleaseNode(failovermaster)
failovermaster.Release()
AssertCommand(drain_check, fail=True)
AssertCommand(drain_check, node=failovermaster, fail=True)
......
......@@ -118,7 +118,7 @@ class _QaNode(object):
"primary",
"secondary",
"_added",
"use_count",
"_use_count",
]
def __init__(self, primary, secondary):
......@@ -127,8 +127,8 @@ class _QaNode(object):
"""
self.primary = primary
self.secondary = secondary
self.use_count = 0
self._added = False
self._use_count = 0
@classmethod
def FromDict(cls, data):
......@@ -161,12 +161,20 @@ class _QaNode(object):
"""Marks a node as being in use.
"""
assert self.use_count >= 0
assert self._use_count >= 0
self.use_count += 1
self._use_count += 1
return self
def Release(self):
"""Release a node (opposite of L{Use}).
"""
assert self.use_count > 0
self._use_count -= 1
def MarkAdded(self):
"""Marks node as having been added to a cluster.
......@@ -188,6 +196,13 @@ class _QaNode(object):
"""
return self._added
@property
def use_count(self):
"""Returns number of current uses (controlled by L{Use} and L{Release}).
"""
return self._use_count
_RESOURCE_CONVERTER = {
"instances": _QaInstance.FromDict,
......@@ -616,12 +631,6 @@ def AcquireManyNodes(num, exclude=None):
return nodes
def ReleaseNode(node):
assert node.use_count > 0
node.use_count -= 1
def ReleaseManyNodes(nodes):
for n in nodes:
ReleaseNode(n)
for node in nodes:
node.Release()
......@@ -205,7 +205,7 @@ def TestNodeEvacuate(node, node2):
AssertCommand(["gnt-node", "evacuate", "-f",
"--new-secondary=%s" % node2["primary"], node3["primary"]])
finally:
qa_config.ReleaseNode(node3)
node3.Release()
def TestNodeModify(node):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment