Commit b5f33afa authored by Michael Hanselmann's avatar Michael Hanselmann

QA: Convert instances from items to attributes

The new objects support attributes. Item access (like a dictionary) is
going away in a couple of patches.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarBernardo Dal Seno <bdalseno@google.com>
parent aecba21e
......@@ -276,8 +276,8 @@ def RunCommonInstanceTests(instance):
if qa_config.TestEnabled("instance-rename"):
tgt_instance = qa_config.AcquireInstance()
try:
rename_source = instance["name"]
rename_target = tgt_instance["name"]
rename_source = instance.name
rename_target = tgt_instance.name
# perform instance rename to the same name
RunTest(qa_instance.TestInstanceRenameAndBack,
rename_source, rename_source)
......
......@@ -546,7 +546,7 @@ def TestClusterBurnin():
cmd.append("--no-reboot")
else:
cmd.append("--reboot-types=%s" % ",".join(reboot_types))
cmd += [inst["name"] for inst in instances]
cmd += [inst.name for inst in instances]
AssertCommand(cmd)
finally:
AssertCommand(["rm", "-f", script])
......
......@@ -110,7 +110,7 @@ def TestInstanceAutomaticRestart(instance):
"""Test automatic restart of instance by ganeti-watcher.
"""
inst_name = qa_utils.ResolveInstanceName(instance["name"])
inst_name = qa_utils.ResolveInstanceName(instance.name)
_ResetWatcherDaemon()
_ShutdownInstance(inst_name)
......@@ -128,7 +128,7 @@ def TestInstanceConsecutiveFailures(instance):
"""Test five consecutive instance failures.
"""
inst_name = qa_utils.ResolveInstanceName(instance["name"])
inst_name = qa_utils.ResolveInstanceName(instance.name)
_ResetWatcherDaemon()
......
......@@ -71,11 +71,11 @@ def _DiskTest(node, disk_template):
"--disk-template=%s" % disk_template,
"--node=%s" % node] +
_GetGenericAddParameters(instance))
cmd.append(instance["name"])
cmd.append(instance.name)
AssertCommand(cmd)
_CheckSsconfInstanceList(instance["name"])
_CheckSsconfInstanceList(instance.name)
qa_config.SetInstanceTemplate(instance, disk_template)
return instance
......@@ -147,7 +147,7 @@ def _DestroyInstanceVolumes(instance):
@param instance: the instance
"""
info = _GetInstanceInfo(instance["name"])
info = _GetInstanceInfo(instance.name)
vols = info["volumes"]
for node in info["nodes"]:
AssertCommand(["lvremove", "-f"] + vols, node=node)
......@@ -208,19 +208,19 @@ def TestInstanceAddWithDrbdDisk(nodes):
@InstanceCheck(None, INST_DOWN, FIRST_ARG)
def TestInstanceRemove(instance):
"""gnt-instance remove"""
AssertCommand(["gnt-instance", "remove", "-f", instance["name"]])
AssertCommand(["gnt-instance", "remove", "-f", instance.name])
@InstanceCheck(INST_DOWN, INST_UP, FIRST_ARG)
def TestInstanceStartup(instance):
"""gnt-instance startup"""
AssertCommand(["gnt-instance", "startup", instance["name"]])
AssertCommand(["gnt-instance", "startup", instance.name])
@InstanceCheck(INST_UP, INST_DOWN, FIRST_ARG)
def TestInstanceShutdown(instance):
"""gnt-instance shutdown"""
AssertCommand(["gnt-instance", "shutdown", instance["name"]])
AssertCommand(["gnt-instance", "shutdown", instance.name])
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
......@@ -228,7 +228,7 @@ def TestInstanceReboot(instance):
"""gnt-instance reboot"""
options = qa_config.get("options", {})
reboot_types = options.get("reboot-types", constants.REBOOT_TYPES)
name = instance["name"]
name = instance.name
for rtype in reboot_types:
AssertCommand(["gnt-instance", "reboot", "--type=%s" % rtype, name])
......@@ -246,12 +246,12 @@ def TestInstanceReboot(instance):
@InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
def TestInstanceReinstall(instance):
"""gnt-instance reinstall"""
AssertCommand(["gnt-instance", "reinstall", "-f", instance["name"]])
AssertCommand(["gnt-instance", "reinstall", "-f", instance.name])
# Test with non-existant OS definition
AssertCommand(["gnt-instance", "reinstall", "-f",
"--os-type=NonExistantOsForQa",
instance["name"]],
instance.name],
fail=True)
......@@ -336,7 +336,7 @@ def TestInstanceFailover(instance):
" test")
return
cmd = ["gnt-instance", "failover", "--force", instance["name"]]
cmd = ["gnt-instance", "failover", "--force", instance.name]
# failover ...
AssertCommand(cmd)
......@@ -354,10 +354,10 @@ def TestInstanceMigrate(instance, toggle_always_failover=True):
" test")
return
cmd = ["gnt-instance", "migrate", "--force", instance["name"]]
cmd = ["gnt-instance", "migrate", "--force", instance.name]
af_par = constants.BE_ALWAYS_FAILOVER
af_field = "be/" + constants.BE_ALWAYS_FAILOVER
af_init_val = _GetBoolInstanceField(instance["name"], af_field)
af_init_val = _GetBoolInstanceField(instance.name, af_field)
# migrate ...
AssertCommand(cmd)
......@@ -368,21 +368,21 @@ def TestInstanceMigrate(instance, toggle_always_failover=True):
if toggle_always_failover:
AssertCommand(["gnt-instance", "modify", "-B",
("%s=%s" % (af_par, not af_init_val)),
instance["name"]])
instance.name])
AssertCommand(cmd)
# TODO: Verify the choice between failover and migration
qa_utils.RunInstanceCheck(instance, True)
if toggle_always_failover:
AssertCommand(["gnt-instance", "modify", "-B",
("%s=%s" % (af_par, af_init_val)), instance["name"]])
("%s=%s" % (af_par, af_init_val)), instance.name])
# TODO: Split into multiple tests
AssertCommand(["gnt-instance", "shutdown", instance["name"]])
AssertCommand(["gnt-instance", "shutdown", instance.name])
qa_utils.RunInstanceCheck(instance, False)
AssertCommand(cmd, fail=True)
AssertCommand(["gnt-instance", "migrate", "--force", "--allow-failover",
instance["name"]])
AssertCommand(["gnt-instance", "start", instance["name"]])
instance.name])
AssertCommand(["gnt-instance", "start", instance.name])
AssertCommand(cmd)
# @InstanceCheck enforces the check that the instance is running
qa_utils.RunInstanceCheck(instance, True)
......@@ -390,7 +390,7 @@ def TestInstanceMigrate(instance, toggle_always_failover=True):
AssertCommand(["gnt-instance", "modify", "-B",
("%s=%s" %
(constants.BE_ALWAYS_FAILOVER, constants.VALUE_TRUE)),
instance["name"]])
instance.name])
AssertCommand(cmd)
qa_utils.RunInstanceCheck(instance, True)
......@@ -400,7 +400,7 @@ def TestInstanceMigrate(instance, toggle_always_failover=True):
AssertCommand(["gnt-instance", "modify", "-B",
("%s=%s" %
(constants.BE_ALWAYS_FAILOVER, constants.VALUE_FALSE)),
instance["name"]])
instance.name])
AssertCommand(cmd)
qa_utils.RunInstanceCheck(instance, True)
......@@ -408,7 +408,7 @@ def TestInstanceMigrate(instance, toggle_always_failover=True):
def TestInstanceInfo(instance):
"""gnt-instance info"""
AssertCommand(["gnt-instance", "info", instance["name"]])
AssertCommand(["gnt-instance", "info", instance.name])
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
......@@ -456,23 +456,23 @@ def TestInstanceModify(instance):
])
for alist in args:
AssertCommand(["gnt-instance", "modify"] + alist + [instance["name"]])
AssertCommand(["gnt-instance", "modify"] + alist + [instance.name])
# check no-modify
AssertCommand(["gnt-instance", "modify", instance["name"]], fail=True)
AssertCommand(["gnt-instance", "modify", instance.name], fail=True)
# Marking offline while instance is running must fail...
AssertCommand(["gnt-instance", "modify", "--offline", instance["name"]],
AssertCommand(["gnt-instance", "modify", "--offline", instance.name],
fail=True)
# ...while making it online is ok, and should work
AssertCommand(["gnt-instance", "modify", "--online", instance["name"]])
AssertCommand(["gnt-instance", "modify", "--online", instance.name])
@InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
def TestInstanceStoppedModify(instance):
"""gnt-instance modify (stopped instance)"""
name = instance["name"]
name = instance.name
# Instance was not marked offline; try marking it online once more
AssertCommand(["gnt-instance", "modify", "--online", name])
......@@ -497,7 +497,7 @@ def TestInstanceStoppedModify(instance):
@InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
def TestInstanceConvertDiskToPlain(instance, inodes):
"""gnt-instance modify -t"""
name = instance["name"]
name = instance.name
template = qa_config.GetInstanceTemplate(instance)
if template != "drbd":
print qa_utils.FormatInfo("Unsupported template %s, skipping conversion"
......@@ -515,7 +515,7 @@ def TestInstanceGrowDisk(instance):
if qa_config.GetExclusiveStorage():
print qa_utils.FormatInfo("Test not supported with exclusive_storage")
return
name = instance["name"]
name = instance.name
all_size = qa_config.get("disk")
all_grow = qa_config.get("disk-growth")
if not all_grow:
......@@ -548,7 +548,7 @@ def TestInstanceListFields():
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestInstanceConsole(instance):
"""gnt-instance console"""
AssertCommand(["gnt-instance", "console", "--show-cmd", instance["name"]])
AssertCommand(["gnt-instance", "console", "--show-cmd", instance.name])
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
......@@ -557,7 +557,7 @@ def TestReplaceDisks(instance, curr_nodes, other_nodes):
def buildcmd(args):
cmd = ["gnt-instance", "replace-disks"]
cmd.extend(args)
cmd.append(instance["name"])
cmd.append(instance.name)
return cmd
if not IsDiskReplacingSupported(instance):
......@@ -589,13 +589,13 @@ def TestReplaceDisks(instance, curr_nodes, other_nodes):
AssertCommand(buildcmd(data))
AssertCommand(buildcmd(["-a"]))
AssertCommand(["gnt-instance", "stop", instance["name"]])
AssertCommand(["gnt-instance", "stop", instance.name])
AssertCommand(buildcmd(["-a"]), fail=True)
AssertCommand(["gnt-instance", "activate-disks", instance["name"]])
AssertCommand(["gnt-instance", "activate-disks", instance.name])
AssertCommand(["gnt-instance", "activate-disks", "--wait-for-sync",
instance["name"]])
instance.name])
AssertCommand(buildcmd(["-a"]))
AssertCommand(["gnt-instance", "start", instance["name"]])
AssertCommand(["gnt-instance", "start", instance.name])
def _AssertRecreateDisks(cmdargs, instance, fail=False, check=True,
......@@ -612,13 +612,13 @@ def _AssertRecreateDisks(cmdargs, instance, fail=False, check=True,
if destroy:
_DestroyInstanceVolumes(instance)
AssertCommand((["gnt-instance", "recreate-disks"] + cmdargs +
[instance["name"]]), fail)
[instance.name]), fail)
if not fail and check:
# Quick check that the disks are there
AssertCommand(["gnt-instance", "activate-disks", instance["name"]])
AssertCommand(["gnt-instance", "activate-disks", instance.name])
AssertCommand(["gnt-instance", "activate-disks", "--wait-for-sync",
instance["name"]])
AssertCommand(["gnt-instance", "deactivate-disks", instance["name"]])
instance.name])
AssertCommand(["gnt-instance", "deactivate-disks", instance.name])
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
......@@ -640,7 +640,7 @@ def TestRecreateDisks(instance, inodes, othernodes):
_AssertRecreateDisks(["-I", "hail"], instance, fail=True, destroy=False)
else:
_AssertRecreateDisks(["-n", other_seq], instance, fail=True, destroy=False)
AssertCommand(["gnt-instance", "stop", instance["name"]])
AssertCommand(["gnt-instance", "stop", instance.name])
# Disks exist: this should fail
_AssertRecreateDisks([], instance, fail=True, destroy=False)
# Recreate disks in place
......@@ -656,14 +656,14 @@ def TestRecreateDisks(instance, inodes, othernodes):
# Move disks back
_AssertRecreateDisks(["-n", orig_seq], instance, check=False)
# This and InstanceCheck decoration check that the disks are working
AssertCommand(["gnt-instance", "reinstall", "-f", instance["name"]])
AssertCommand(["gnt-instance", "start", instance["name"]])
AssertCommand(["gnt-instance", "reinstall", "-f", instance.name])
AssertCommand(["gnt-instance", "start", instance.name])
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestInstanceExport(instance, node):
"""gnt-backup export -n ..."""
name = instance["name"]
name = instance.name
AssertCommand(["gnt-backup", "export", "-n", node.primary, name])
return qa_utils.ResolveInstanceName(name)
......@@ -672,13 +672,13 @@ def TestInstanceExport(instance, node):
def TestInstanceExportWithRemove(instance, node):
"""gnt-backup export --remove-instance"""
AssertCommand(["gnt-backup", "export", "-n", node.primary,
"--remove-instance", instance["name"]])
"--remove-instance", instance.name])
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestInstanceExportNoTarget(instance):
"""gnt-backup export (without target node, should fail)"""
AssertCommand(["gnt-backup", "export", instance["name"]], fail=True)
AssertCommand(["gnt-backup", "export", instance.name], fail=True)
@InstanceCheck(None, INST_DOWN, FIRST_ARG)
......@@ -692,7 +692,7 @@ def TestInstanceImport(newinst, node, expnode, name):
"--src-dir=%s/%s" % (pathutils.EXPORT_DIR, name),
"--node=%s" % node.primary] +
_GetGenericAddParameters(newinst, force_mac=constants.VALUE_GENERATE))
cmd.append(newinst["name"])
cmd.append(newinst.name)
AssertCommand(cmd)
qa_config.SetInstanceTemplate(newinst, templ)
......@@ -719,7 +719,7 @@ def TestRemoveInstanceOfflineNode(instance, snode, set_offline, set_online):
@param set_online: function to call to set the node on-line
"""
info = _GetInstanceInfo(instance["name"])
info = _GetInstanceInfo(instance.name)
set_offline(snode)
try:
TestInstanceRemove(instance)
......
......@@ -377,19 +377,19 @@ def TestInstance(instance):
_VerifyInstance(instance_data)
_DoTests([
("/2/instances/%s" % instance["name"], _VerifyInstance, "GET", None),
("/2/instances/%s" % instance.name, _VerifyInstance, "GET", None),
("/2/instances", _VerifyInstancesList, "GET", None),
("/2/instances?bulk=1", _VerifyInstancesBulk, "GET", None),
("/2/instances/%s/activate-disks" % instance["name"],
("/2/instances/%s/activate-disks" % instance.name,
_VerifyReturnsJob, "PUT", None),
("/2/instances/%s/deactivate-disks" % instance["name"],
("/2/instances/%s/deactivate-disks" % instance.name,
_VerifyReturnsJob, "PUT", None),
])
# Test OpBackupPrepare
(job_id, ) = _DoTests([
("/2/instances/%s/prepare-export?mode=%s" %
(instance["name"], constants.EXPORT_MODE_REMOTE),
(instance.name, constants.EXPORT_MODE_REMOTE),
_VerifyReturnsJob, "PUT", None),
])
......@@ -571,7 +571,7 @@ def TestRapiInstanceAdd(node, use_client):
if use_client:
job_id = _rapi_client.CreateInstance(constants.INSTANCE_CREATE,
instance["name"],
instance.name,
constants.DT_PLAIN,
disks, nics,
os=qa_config.get("os"),
......@@ -581,7 +581,7 @@ def TestRapiInstanceAdd(node, use_client):
body = {
"__version__": 1,
"mode": constants.INSTANCE_CREATE,
"name": instance["name"],
"name": instance.name,
"os_type": qa_config.get("os"),
"disk_template": constants.DT_PLAIN,
"pnode": node.primary,
......@@ -606,10 +606,10 @@ def TestRapiInstanceAdd(node, use_client):
def TestRapiInstanceRemove(instance, use_client):
"""Test removing instance via RAPI"""
if use_client:
job_id = _rapi_client.DeleteInstance(instance["name"])
job_id = _rapi_client.DeleteInstance(instance.name)
else:
(job_id, ) = _DoTests([
("/2/instances/%s" % instance["name"], _VerifyReturnsJob, "DELETE", None),
("/2/instances/%s" % instance.name, _VerifyReturnsJob, "DELETE", None),
])
_WaitForRapiJob(job_id)
......@@ -623,10 +623,10 @@ def TestRapiInstanceMigrate(instance):
" test")
return
# Move to secondary node
_WaitForRapiJob(_rapi_client.MigrateInstance(instance["name"]))
_WaitForRapiJob(_rapi_client.MigrateInstance(instance.name))
qa_utils.RunInstanceCheck(instance, True)
# And back to previous primary
_WaitForRapiJob(_rapi_client.MigrateInstance(instance["name"]))
_WaitForRapiJob(_rapi_client.MigrateInstance(instance.name))
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
......@@ -637,22 +637,22 @@ def TestRapiInstanceFailover(instance):
" test")
return
# Move to secondary node
_WaitForRapiJob(_rapi_client.FailoverInstance(instance["name"]))
_WaitForRapiJob(_rapi_client.FailoverInstance(instance.name))
qa_utils.RunInstanceCheck(instance, True)
# And back to previous primary
_WaitForRapiJob(_rapi_client.FailoverInstance(instance["name"]))
_WaitForRapiJob(_rapi_client.FailoverInstance(instance.name))
@InstanceCheck(INST_UP, INST_DOWN, FIRST_ARG)
def TestRapiInstanceShutdown(instance):
"""Test stopping an instance via RAPI"""
_WaitForRapiJob(_rapi_client.ShutdownInstance(instance["name"]))
_WaitForRapiJob(_rapi_client.ShutdownInstance(instance.name))
@InstanceCheck(INST_DOWN, INST_UP, FIRST_ARG)
def TestRapiInstanceStartup(instance):
"""Test starting an instance via RAPI"""
_WaitForRapiJob(_rapi_client.StartupInstance(instance["name"]))
_WaitForRapiJob(_rapi_client.StartupInstance(instance.name))
@InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
......@@ -673,12 +673,12 @@ def TestRapiInstanceRenameAndBack(rename_source, rename_target):
@InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
def TestRapiInstanceReinstall(instance):
"""Test reinstalling an instance via RAPI"""
_WaitForRapiJob(_rapi_client.ReinstallInstance(instance["name"]))
_WaitForRapiJob(_rapi_client.ReinstallInstance(instance.name))
# By default, the instance is started again
qa_utils.RunInstanceCheck(instance, True)
# Reinstall again without starting
_WaitForRapiJob(_rapi_client.ReinstallInstance(instance["name"],
_WaitForRapiJob(_rapi_client.ReinstallInstance(instance.name,
no_startup=True))
......@@ -690,9 +690,9 @@ def TestRapiInstanceReplaceDisks(instance):
" skipping test")
return
fn = _rapi_client.ReplaceInstanceDisks
_WaitForRapiJob(fn(instance["name"],
_WaitForRapiJob(fn(instance.name,
mode=constants.REPLACE_DISK_AUTO, disks=[]))
_WaitForRapiJob(fn(instance["name"],
_WaitForRapiJob(fn(instance.name,
mode=constants.REPLACE_DISK_SEC, disks="0"))
......@@ -702,7 +702,7 @@ def TestRapiInstanceModify(instance):
default_hv = qa_config.GetDefaultHypervisor()
def _ModifyInstance(**kwargs):
_WaitForRapiJob(_rapi_client.ModifyInstance(instance["name"], **kwargs))
_WaitForRapiJob(_rapi_client.ModifyInstance(instance.name, **kwargs))
_ModifyInstance(beparams={
constants.BE_VCPUS: 3,
......@@ -731,17 +731,17 @@ def TestRapiInstanceModify(instance):
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestRapiInstanceConsole(instance):
"""Test getting instance console information via RAPI"""
result = _rapi_client.GetInstanceConsole(instance["name"])
result = _rapi_client.GetInstanceConsole(instance.name)
console = objects.InstanceConsole.FromDict(result)
AssertEqual(console.Validate(), True)
AssertEqual(console.instance, qa_utils.ResolveInstanceName(instance["name"]))
AssertEqual(console.instance, qa_utils.ResolveInstanceName(instance.name))
@InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
def TestRapiStoppedInstanceConsole(instance):
"""Test getting stopped instance's console information via RAPI"""
try:
_rapi_client.GetInstanceConsole(instance["name"])
_rapi_client.GetInstanceConsole(instance.name)
except rapi.client.GanetiApiError, err:
AssertEqual(err.code, 503)
else:
......@@ -782,9 +782,9 @@ def TestInterClusterInstanceMove(src_instance, dest_instance,
pnode = inodes[0]
# note: pnode:snode are the *current* nodes, so we move it first to
# tnode:pnode, then back to pnode:snode
for si, di, pn, sn in [(src_instance["name"], dest_instance["name"],
for si, di, pn, sn in [(src_instance.name, dest_instance.name,
tnode.primary, pnode.primary),
(dest_instance["name"], src_instance["name"],
(dest_instance.name, src_instance.name,
pnode.primary, snode.primary)]:
cmd = [
"../tools/move-instance",
......
......@@ -82,4 +82,4 @@ def TestGroupTags(group):
def TestInstanceTags(instance):
"""gnt-instance tags"""
_TestTags(constants.TAG_INSTANCE, instance["name"])
_TestTags(constants.TAG_INSTANCE, instance.name)
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