Revision e80edd3b
b/qa/qa_config.py | ||
---|---|---|
70 | 70 |
|
71 | 71 |
return cls(name=data["name"], nicmac=nicmac) |
72 | 72 |
|
73 |
def __repr__(self): |
|
74 |
status = [ |
|
75 |
"%s.%s" % (self.__class__.__module__, self.__class__.__name__), |
|
76 |
"name=%s" % self.name, |
|
77 |
"nicmac=%s" % self.nicmac, |
|
78 |
"used=%s" % self._used, |
|
79 |
"disk_template=%s" % self._disk_template, |
|
80 |
] |
|
81 |
|
|
82 |
return "<%s at %#x>" % (" ".join(status), id(self)) |
|
83 |
|
|
73 | 84 |
def Use(self): |
74 | 85 |
"""Marks instance as being in use. |
75 | 86 |
|
... | ... | |
150 | 161 |
""" |
151 | 162 |
return cls(primary=data["primary"], secondary=data.get("secondary")) |
152 | 163 |
|
164 |
def __repr__(self): |
|
165 |
status = [ |
|
166 |
"%s.%s" % (self.__class__.__module__, self.__class__.__name__), |
|
167 |
"primary=%s" % self.primary, |
|
168 |
"secondary=%s" % self.secondary, |
|
169 |
"added=%s" % self._added, |
|
170 |
"use_count=%s" % self._use_count, |
|
171 |
] |
|
172 |
|
|
173 |
return "<%s at %#x>" % (" ".join(status), id(self)) |
|
174 |
|
|
153 | 175 |
def Use(self): |
154 | 176 |
"""Marks a node as being in use. |
155 | 177 |
|
b/test/py/qa.qa_config_unittest.py | ||
---|---|---|
350 | 350 |
exclude=acquired, _cfg=self.config) |
351 | 351 |
|
352 | 352 |
|
353 |
class TestRepresentation(unittest.TestCase): |
|
354 |
def _Check(self, target, part): |
|
355 |
self.assertTrue(part in repr(target).split()) |
|
356 |
|
|
357 |
def testQaInstance(self): |
|
358 |
inst = qa_config._QaInstance("inst1.example.com", []) |
|
359 |
self._Check(inst, "name=inst1.example.com") |
|
360 |
self._Check(inst, "nicmac=[]") |
|
361 |
|
|
362 |
# Default values |
|
363 |
self._Check(inst, "disk_template=None") |
|
364 |
self._Check(inst, "used=None") |
|
365 |
|
|
366 |
# Use instance |
|
367 |
inst.Use() |
|
368 |
self._Check(inst, "used=True") |
|
369 |
|
|
370 |
# Disk template |
|
371 |
inst.SetDiskTemplate(constants.DT_DRBD8) |
|
372 |
self._Check(inst, "disk_template=%s" % constants.DT_DRBD8) |
|
373 |
|
|
374 |
# Release instance |
|
375 |
inst.Release() |
|
376 |
self._Check(inst, "used=False") |
|
377 |
self._Check(inst, "disk_template=None") |
|
378 |
|
|
379 |
def testQaNode(self): |
|
380 |
node = qa_config._QaNode("primary.example.com", "192.0.2.1") |
|
381 |
self._Check(node, "primary=primary.example.com") |
|
382 |
self._Check(node, "secondary=192.0.2.1") |
|
383 |
self._Check(node, "added=False") |
|
384 |
self._Check(node, "use_count=0") |
|
385 |
|
|
386 |
# Mark as added |
|
387 |
node.MarkAdded() |
|
388 |
self._Check(node, "added=True") |
|
389 |
|
|
390 |
# Use node |
|
391 |
for i in range(1, 5): |
|
392 |
node.Use() |
|
393 |
self._Check(node, "use_count=%s" % i) |
|
394 |
|
|
395 |
# Release node |
|
396 |
for i in reversed(range(1, 5)): |
|
397 |
node.Release() |
|
398 |
self._Check(node, "use_count=%s" % (i - 1)) |
|
399 |
|
|
400 |
self._Check(node, "use_count=0") |
|
401 |
|
|
402 |
# Mark as added |
|
403 |
node.MarkRemoved() |
|
404 |
self._Check(node, "added=False") |
|
405 |
|
|
406 |
|
|
353 | 407 |
if __name__ == "__main__": |
354 | 408 |
testutils.GanetiTestProgram() |
Also available in: Unified diff