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):
"name",
"nicmac",
"used",
"disk_template",
"_disk_template",
]
def __init__(self, name, nicmac):
......@@ -55,7 +55,7 @@ class _QaInstance(object):
self.name = name
self.nicmac = nicmac
self.used = None
self.disk_template = None
self._disk_template = None
@classmethod
def FromDict(cls, data):
......@@ -79,7 +79,7 @@ class _QaInstance(object):
self.name)
self.used = False
self.disk_template = None
self._disk_template = None
def GetNicMacAddr(self, idx, default):
"""Returns MAC address for NIC.
......@@ -94,6 +94,21 @@ class _QaInstance(object):
else:
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):
__slots__ = [
......@@ -480,22 +495,6 @@ def AcquireInstance(_cfg=None):
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):
"""Wrapper for L{_QaConfig.SetExclusiveStorage}.
......
......@@ -77,7 +77,7 @@ def _DiskTest(node, disk_template):
AssertCommand(cmd)
_CheckSsconfInstanceList(instance.name)
qa_config.SetInstanceTemplate(instance, disk_template)
instance.SetDiskTemplate(disk_template)
return instance
except:
......@@ -177,18 +177,15 @@ def _GetBoolInstanceField(instance, field):
def IsFailoverSupported(instance):
templ = qa_config.GetInstanceTemplate(instance)
return templ in constants.DTS_MIRRORED
return instance.disk_template in constants.DTS_MIRRORED
def IsMigrationSupported(instance):
templ = qa_config.GetInstanceTemplate(instance)
return templ in constants.DTS_MIRRORED
return instance.disk_template in constants.DTS_MIRRORED
def IsDiskReplacingSupported(instance):
templ = qa_config.GetInstanceTemplate(instance)
return templ == constants.DT_DRBD8
return instance.disk_template == constants.DT_DRBD8
@InstanceCheck(None, INST_UP, RETURN_VALUE)
......@@ -500,7 +497,7 @@ def TestInstanceConvertDiskToPlain(instance, inodes):
"""gnt-instance modify -t"""
name = instance.name
template = qa_config.GetInstanceTemplate(instance)
template = instance.disk_template
if template != constants.DT_DRBD8:
print qa_utils.FormatInfo("Unsupported template %s, skipping conversion"
" test" % template)
......@@ -697,7 +694,7 @@ def TestInstanceImport(newinst, node, expnode, name):
_GetGenericAddParameters(newinst, force_mac=constants.VALUE_GENERATE))
cmd.append(newinst.name)
AssertCommand(cmd)
qa_config.SetInstanceTemplate(newinst, templ)
newinst.SetDiskTemplate(templ)
def TestBackupList(expnode):
......
......@@ -554,7 +554,7 @@ def TestRapiNodeGroups():
def TestRapiInstanceAdd(node, use_client):
"""Test adding a new instance via RAPI"""
instance = qa_config.AcquireInstance()
qa_config.SetInstanceTemplate(instance, constants.DT_PLAIN)
instance.SetDiskTemplate(constants.DT_PLAIN)
try:
disk_sizes = [utils.ParseUnit(size) for size in qa_config.get("disk")]
disks = [{"size": size} for size in disk_sizes]
......@@ -764,8 +764,7 @@ def TestInterClusterInstanceMove(src_instance, dest_instance,
rapi_pw_file.write(_rapi_password)
rapi_pw_file.flush()
qa_config.SetInstanceTemplate(dest_instance,
qa_config.GetInstanceTemplate(src_instance))
dest_instance.SetDiskTemplate(src_instance.disk_template)
# 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