Commit 02a5fe0e authored by Michael Hanselmann's avatar Michael Hanselmann

QA: Set disk template directly via instance object

Use a method on the instance object instead of going through
“qa_config.GetInstanceTemplate”. This provides for better encapsulation.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarBernardo Dal Seno <bdalseno@google.com>
parent 0afce24e
...@@ -45,7 +45,7 @@ class _QaInstance(object): ...@@ -45,7 +45,7 @@ class _QaInstance(object):
"name", "name",
"nicmac", "nicmac",
"used", "used",
"disk_template", "_disk_template",
] ]
def __init__(self, name, nicmac): def __init__(self, name, nicmac):
...@@ -55,7 +55,7 @@ class _QaInstance(object): ...@@ -55,7 +55,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
def FromDict(cls, data): def FromDict(cls, data):
...@@ -79,7 +79,7 @@ class _QaInstance(object): ...@@ -79,7 +79,7 @@ class _QaInstance(object):
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):
"""Returns MAC address for NIC. """Returns MAC address for NIC.
...@@ -94,6 +94,21 @@ class _QaInstance(object): ...@@ -94,6 +94,21 @@ class _QaInstance(object):
else: else:
return default return default
def SetDiskTemplate(self, template):
"""Set the disk template.
"""
assert template in constants.DISK_TEMPLATES
self._disk_template = template
@property
def disk_template(self):
"""Returns the current disk template.
"""
return self._disk_template
class _QaNode(object): class _QaNode(object):
__slots__ = [ __slots__ = [
...@@ -480,22 +495,6 @@ def AcquireInstance(_cfg=None): ...@@ -480,22 +495,6 @@ def AcquireInstance(_cfg=None):
return inst return inst
def GetInstanceTemplate(inst):
"""Return the disk template of an instance.
"""
templ = inst.disk_template
assert templ is not None
return templ
def SetInstanceTemplate(inst, template):
"""Set the disk template for an instance.
"""
inst.disk_template = template
def SetExclusiveStorage(value): def SetExclusiveStorage(value):
"""Wrapper for L{_QaConfig.SetExclusiveStorage}. """Wrapper for L{_QaConfig.SetExclusiveStorage}.
......
...@@ -77,7 +77,7 @@ def _DiskTest(node, disk_template): ...@@ -77,7 +77,7 @@ def _DiskTest(node, disk_template):
AssertCommand(cmd) AssertCommand(cmd)
_CheckSsconfInstanceList(instance.name) _CheckSsconfInstanceList(instance.name)
qa_config.SetInstanceTemplate(instance, disk_template) instance.SetDiskTemplate(disk_template)
return instance return instance
except: except:
...@@ -177,18 +177,15 @@ def _GetBoolInstanceField(instance, field): ...@@ -177,18 +177,15 @@ def _GetBoolInstanceField(instance, field):
def IsFailoverSupported(instance): def IsFailoverSupported(instance):
templ = qa_config.GetInstanceTemplate(instance) return instance.disk_template in constants.DTS_MIRRORED
return templ in constants.DTS_MIRRORED
def IsMigrationSupported(instance): def IsMigrationSupported(instance):
templ = qa_config.GetInstanceTemplate(instance) return instance.disk_template in constants.DTS_MIRRORED
return templ in constants.DTS_MIRRORED
def IsDiskReplacingSupported(instance): def IsDiskReplacingSupported(instance):
templ = qa_config.GetInstanceTemplate(instance) return instance.disk_template == constants.DT_DRBD8
return templ == constants.DT_DRBD8
@InstanceCheck(None, INST_UP, RETURN_VALUE) @InstanceCheck(None, INST_UP, RETURN_VALUE)
...@@ -500,7 +497,7 @@ def TestInstanceConvertDiskToPlain(instance, inodes): ...@@ -500,7 +497,7 @@ def TestInstanceConvertDiskToPlain(instance, inodes):
"""gnt-instance modify -t""" """gnt-instance modify -t"""
name = instance.name name = instance.name
template = qa_config.GetInstanceTemplate(instance) template = instance.disk_template
if template != constants.DT_DRBD8: if template != constants.DT_DRBD8:
print qa_utils.FormatInfo("Unsupported template %s, skipping conversion" print qa_utils.FormatInfo("Unsupported template %s, skipping conversion"
" test" % template) " test" % template)
...@@ -697,7 +694,7 @@ def TestInstanceImport(newinst, node, expnode, name): ...@@ -697,7 +694,7 @@ def TestInstanceImport(newinst, node, expnode, name):
_GetGenericAddParameters(newinst, force_mac=constants.VALUE_GENERATE)) _GetGenericAddParameters(newinst, force_mac=constants.VALUE_GENERATE))
cmd.append(newinst.name) cmd.append(newinst.name)
AssertCommand(cmd) AssertCommand(cmd)
qa_config.SetInstanceTemplate(newinst, templ) newinst.SetDiskTemplate(templ)
def TestBackupList(expnode): def TestBackupList(expnode):
......
...@@ -554,7 +554,7 @@ def TestRapiNodeGroups(): ...@@ -554,7 +554,7 @@ def TestRapiNodeGroups():
def TestRapiInstanceAdd(node, use_client): def TestRapiInstanceAdd(node, use_client):
"""Test adding a new instance via RAPI""" """Test adding a new instance via RAPI"""
instance = qa_config.AcquireInstance() instance = qa_config.AcquireInstance()
qa_config.SetInstanceTemplate(instance, constants.DT_PLAIN) instance.SetDiskTemplate(constants.DT_PLAIN)
try: try:
disk_sizes = [utils.ParseUnit(size) for size in qa_config.get("disk")] disk_sizes = [utils.ParseUnit(size) for size in qa_config.get("disk")]
disks = [{"size": size} for size in disk_sizes] disks = [{"size": size} for size in disk_sizes]
...@@ -764,8 +764,7 @@ def TestInterClusterInstanceMove(src_instance, dest_instance, ...@@ -764,8 +764,7 @@ def TestInterClusterInstanceMove(src_instance, dest_instance,
rapi_pw_file.write(_rapi_password) rapi_pw_file.write(_rapi_password)
rapi_pw_file.flush() rapi_pw_file.flush()
qa_config.SetInstanceTemplate(dest_instance, dest_instance.SetDiskTemplate(src_instance.disk_template)
qa_config.GetInstanceTemplate(src_instance))
# TODO: Run some instance tests before moving back # TODO: Run some instance tests before moving back
......
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