Commit 2176724e authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

QA: Acquire instance via method



Also make “used” a property.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarBernardo Dal Seno <bdalseno@google.com>
parent 3234695b
...@@ -44,7 +44,7 @@ class _QaInstance(object): ...@@ -44,7 +44,7 @@ class _QaInstance(object):
__slots__ = [ __slots__ = [
"name", "name",
"nicmac", "nicmac",
"used", "_used",
"_disk_template", "_disk_template",
] ]
...@@ -54,7 +54,7 @@ class _QaInstance(object): ...@@ -54,7 +54,7 @@ class _QaInstance(object):
""" """
self.name = name self.name = name
self.nicmac = nicmac self.nicmac = nicmac
self.used = None self._used = None
self._disk_template = None self._disk_template = None
@classmethod @classmethod
...@@ -70,15 +70,24 @@ class _QaInstance(object): ...@@ -70,15 +70,24 @@ class _QaInstance(object):
return cls(name=data["name"], nicmac=nicmac) return cls(name=data["name"], nicmac=nicmac)
def Use(self):
"""Marks instance as being in use.
"""
assert not self._used
assert self._disk_template is None
self._used = True
def Release(self): def Release(self):
"""Releases instance and makes it available again. """Releases instance and makes it available again.
""" """
assert self.used, \ assert self._used, \
("Instance '%s' was never acquired or released more than once" % ("Instance '%s' was never acquired or released more than once" %
self.name) self.name)
self.used = False self._used = False
self._disk_template = None self._disk_template = None
def GetNicMacAddr(self, idx, default): def GetNicMacAddr(self, idx, default):
...@@ -102,6 +111,13 @@ class _QaInstance(object): ...@@ -102,6 +111,13 @@ class _QaInstance(object):
self._disk_template = template self._disk_template = template
@property
def used(self):
"""Returns boolean denoting whether instance is in use.
"""
return self._used
@property @property
def disk_template(self): def disk_template(self):
"""Returns the current disk template. """Returns the current disk template.
...@@ -485,14 +501,10 @@ def AcquireInstance(_cfg=None): ...@@ -485,14 +501,10 @@ def AcquireInstance(_cfg=None):
if not instances: if not instances:
raise qa_error.OutOfInstancesError("No instances left") raise qa_error.OutOfInstancesError("No instances left")
inst = instances[0] instance = instances[0]
instance.Use()
assert not inst.used
assert inst.disk_template is None
inst.used = True
return inst return instance
def SetExclusiveStorage(value): def SetExclusiveStorage(value):
......
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