From 2176724e608bbf15ea3db8d4b1ec6cd398aed2bb Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Wed, 6 Feb 2013 11:15:35 +0100 Subject: [PATCH] QA: Acquire instance via method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also make βusedβ a property. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Bernardo Dal Seno <bdalseno@google.com> --- qa/qa_config.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/qa/qa_config.py b/qa/qa_config.py index 6b0c5e106..1ff1dd115 100644 --- a/qa/qa_config.py +++ b/qa/qa_config.py @@ -44,7 +44,7 @@ class _QaInstance(object): __slots__ = [ "name", "nicmac", - "used", + "_used", "_disk_template", ] @@ -54,7 +54,7 @@ class _QaInstance(object): """ self.name = name self.nicmac = nicmac - self.used = None + self._used = None self._disk_template = None @classmethod @@ -70,15 +70,24 @@ class _QaInstance(object): 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): """Releases instance and makes it available again. """ - assert self.used, \ + assert self._used, \ ("Instance '%s' was never acquired or released more than once" % self.name) - self.used = False + self._used = False self._disk_template = None def GetNicMacAddr(self, idx, default): @@ -102,6 +111,13 @@ class _QaInstance(object): self._disk_template = template + @property + def used(self): + """Returns boolean denoting whether instance is in use. + + """ + return self._used + @property def disk_template(self): """Returns the current disk template. @@ -485,14 +501,10 @@ def AcquireInstance(_cfg=None): if not instances: raise qa_error.OutOfInstancesError("No instances left") - inst = instances[0] - - assert not inst.used - assert inst.disk_template is None - - inst.used = True + instance = instances[0] + instance.Use() - return inst + return instance def SetExclusiveStorage(value): -- GitLab