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): ...@@ -276,8 +276,8 @@ def RunCommonInstanceTests(instance):
if qa_config.TestEnabled("instance-rename"): if qa_config.TestEnabled("instance-rename"):
tgt_instance = qa_config.AcquireInstance() tgt_instance = qa_config.AcquireInstance()
try: try:
rename_source = instance["name"] rename_source = instance.name
rename_target = tgt_instance["name"] rename_target = tgt_instance.name
# perform instance rename to the same name # perform instance rename to the same name
RunTest(qa_instance.TestInstanceRenameAndBack, RunTest(qa_instance.TestInstanceRenameAndBack,
rename_source, rename_source) rename_source, rename_source)
......
...@@ -546,7 +546,7 @@ def TestClusterBurnin(): ...@@ -546,7 +546,7 @@ def TestClusterBurnin():
cmd.append("--no-reboot") cmd.append("--no-reboot")
else: else:
cmd.append("--reboot-types=%s" % ",".join(reboot_types)) cmd.append("--reboot-types=%s" % ",".join(reboot_types))
cmd += [inst["name"] for inst in instances] cmd += [inst.name for inst in instances]
AssertCommand(cmd) AssertCommand(cmd)
finally: finally:
AssertCommand(["rm", "-f", script]) AssertCommand(["rm", "-f", script])
......
...@@ -110,7 +110,7 @@ def TestInstanceAutomaticRestart(instance): ...@@ -110,7 +110,7 @@ def TestInstanceAutomaticRestart(instance):
"""Test automatic restart of instance by ganeti-watcher. """Test automatic restart of instance by ganeti-watcher.
""" """
inst_name = qa_utils.ResolveInstanceName(instance["name"]) inst_name = qa_utils.ResolveInstanceName(instance.name)
_ResetWatcherDaemon() _ResetWatcherDaemon()
_ShutdownInstance(inst_name) _ShutdownInstance(inst_name)
...@@ -128,7 +128,7 @@ def TestInstanceConsecutiveFailures(instance): ...@@ -128,7 +128,7 @@ def TestInstanceConsecutiveFailures(instance):
"""Test five consecutive instance failures. """Test five consecutive instance failures.
""" """
inst_name = qa_utils.ResolveInstanceName(instance["name"]) inst_name = qa_utils.ResolveInstanceName(instance.name)
_ResetWatcherDaemon() _ResetWatcherDaemon()
......
This diff is collapsed.
...@@ -377,19 +377,19 @@ def TestInstance(instance): ...@@ -377,19 +377,19 @@ def TestInstance(instance):
_VerifyInstance(instance_data) _VerifyInstance(instance_data)
_DoTests([ _DoTests([
("/2/instances/%s" % instance["name"], _VerifyInstance, "GET", None), ("/2/instances/%s" % instance.name, _VerifyInstance, "GET", None),
("/2/instances", _VerifyInstancesList, "GET", None), ("/2/instances", _VerifyInstancesList, "GET", None),
("/2/instances?bulk=1", _VerifyInstancesBulk, "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), _VerifyReturnsJob, "PUT", None),
("/2/instances/%s/deactivate-disks" % instance["name"], ("/2/instances/%s/deactivate-disks" % instance.name,
_VerifyReturnsJob, "PUT", None), _VerifyReturnsJob, "PUT", None),
]) ])
# Test OpBackupPrepare # Test OpBackupPrepare
(job_id, ) = _DoTests([ (job_id, ) = _DoTests([
("/2/instances/%s/prepare-export?mode=%s" % ("/2/instances/%s/prepare-export?mode=%s" %
(instance["name"], constants.EXPORT_MODE_REMOTE), (instance.name, constants.EXPORT_MODE_REMOTE),
_VerifyReturnsJob, "PUT", None), _VerifyReturnsJob, "PUT", None),
]) ])
...@@ -571,7 +571,7 @@ def TestRapiInstanceAdd(node, use_client): ...@@ -571,7 +571,7 @@ def TestRapiInstanceAdd(node, use_client):
if use_client: if use_client:
job_id = _rapi_client.CreateInstance(constants.INSTANCE_CREATE, job_id = _rapi_client.CreateInstance(constants.INSTANCE_CREATE,
instance["name"], instance.name,
constants.DT_PLAIN, constants.DT_PLAIN,
disks, nics, disks, nics,
os=qa_config.get("os"), os=qa_config.get("os"),
...@@ -581,7 +581,7 @@ def TestRapiInstanceAdd(node, use_client): ...@@ -581,7 +581,7 @@ def TestRapiInstanceAdd(node, use_client):
body = { body = {
"__version__": 1, "__version__": 1,
"mode": constants.INSTANCE_CREATE, "mode": constants.INSTANCE_CREATE,
"name": instance["name"], "name": instance.name,
"os_type": qa_config.get("os"), "os_type": qa_config.get("os"),
"disk_template": constants.DT_PLAIN, "disk_template": constants.DT_PLAIN,
"pnode": node.primary, "pnode": node.primary,
...@@ -606,10 +606,10 @@ def TestRapiInstanceAdd(node, use_client): ...@@ -606,10 +606,10 @@ def TestRapiInstanceAdd(node, use_client):
def TestRapiInstanceRemove(instance, use_client): def TestRapiInstanceRemove(instance, use_client):
"""Test removing instance via RAPI""" """Test removing instance via RAPI"""
if use_client: if use_client:
job_id = _rapi_client.DeleteInstance(instance["name"]) job_id = _rapi_client.DeleteInstance(instance.name)
else: else:
(job_id, ) = _DoTests([ (job_id, ) = _DoTests([
("/2/instances/%s" % instance["name"], _VerifyReturnsJob, "DELETE", None), ("/2/instances/%s" % instance.name, _VerifyReturnsJob, "DELETE", None),
]) ])
_WaitForRapiJob(job_id) _WaitForRapiJob(job_id)
...@@ -623,10 +623,10 @@ def TestRapiInstanceMigrate(instance): ...@@ -623,10 +623,10 @@ def TestRapiInstanceMigrate(instance):
" test") " test")
return return
# Move to secondary node # Move to secondary node
_WaitForRapiJob(_rapi_client.MigrateInstance(instance["name"])) _WaitForRapiJob(_rapi_client.MigrateInstance(instance.name))
qa_utils.RunInstanceCheck(instance, True) qa_utils.RunInstanceCheck(instance, True)
# And back to previous primary # And back to previous primary
_WaitForRapiJob(_rapi_client.MigrateInstance(instance["name"])) _WaitForRapiJob(_rapi_client.MigrateInstance(instance.name))
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG) @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
...@@ -637,22 +637,22 @@ def TestRapiInstanceFailover(instance): ...@@ -637,22 +637,22 @@ def TestRapiInstanceFailover(instance):
" test") " test")
return return
# Move to secondary node # Move to secondary node
_WaitForRapiJob(_rapi_client.FailoverInstance(instance["name"])) _WaitForRapiJob(_rapi_client.FailoverInstance(instance.name))
qa_utils.RunInstanceCheck(instance, True) qa_utils.RunInstanceCheck(instance, True)
# And back to previous primary # And back to previous primary
_WaitForRapiJob(_rapi_client.FailoverInstance(instance["name"])) _WaitForRapiJob(_rapi_client.FailoverInstance(instance.name))
@InstanceCheck(INST_UP, INST_DOWN, FIRST_ARG) @InstanceCheck(INST_UP, INST_DOWN, FIRST_ARG)
def TestRapiInstanceShutdown(instance): def TestRapiInstanceShutdown(instance):
"""Test stopping an instance via RAPI""" """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) @InstanceCheck(INST_DOWN, INST_UP, FIRST_ARG)
def TestRapiInstanceStartup(instance): def TestRapiInstanceStartup(instance):
"""Test starting an instance via RAPI""" """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) @InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
...@@ -673,12 +673,12 @@ def TestRapiInstanceRenameAndBack(rename_source, rename_target): ...@@ -673,12 +673,12 @@ def TestRapiInstanceRenameAndBack(rename_source, rename_target):
@InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG) @InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
def TestRapiInstanceReinstall(instance): def TestRapiInstanceReinstall(instance):
"""Test reinstalling an instance via RAPI""" """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 # By default, the instance is started again
qa_utils.RunInstanceCheck(instance, True) qa_utils.RunInstanceCheck(instance, True)
# Reinstall again without starting # Reinstall again without starting
_WaitForRapiJob(_rapi_client.ReinstallInstance(instance["name"], _WaitForRapiJob(_rapi_client.ReinstallInstance(instance.name,
no_startup=True)) no_startup=True))
...@@ -690,9 +690,9 @@ def TestRapiInstanceReplaceDisks(instance): ...@@ -690,9 +690,9 @@ def TestRapiInstanceReplaceDisks(instance):
" skipping test") " skipping test")
return return
fn = _rapi_client.ReplaceInstanceDisks fn = _rapi_client.ReplaceInstanceDisks
_WaitForRapiJob(fn(instance["name"], _WaitForRapiJob(fn(instance.name,
mode=constants.REPLACE_DISK_AUTO, disks=[])) mode=constants.REPLACE_DISK_AUTO, disks=[]))
_WaitForRapiJob(fn(instance["name"], _WaitForRapiJob(fn(instance.name,
mode=constants.REPLACE_DISK_SEC, disks="0")) mode=constants.REPLACE_DISK_SEC, disks="0"))
...@@ -702,7 +702,7 @@ def TestRapiInstanceModify(instance): ...@@ -702,7 +702,7 @@ def TestRapiInstanceModify(instance):
default_hv = qa_config.GetDefaultHypervisor() default_hv = qa_config.GetDefaultHypervisor()
def _ModifyInstance(**kwargs): def _ModifyInstance(**kwargs):
_WaitForRapiJob(_rapi_client.ModifyInstance(instance["name"], **kwargs)) _WaitForRapiJob(_rapi_client.ModifyInstance(instance.name, **kwargs))
_ModifyInstance(beparams={ _ModifyInstance(beparams={
constants.BE_VCPUS: 3, constants.BE_VCPUS: 3,
...@@ -731,17 +731,17 @@ def TestRapiInstanceModify(instance): ...@@ -731,17 +731,17 @@ def TestRapiInstanceModify(instance):
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG) @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestRapiInstanceConsole(instance): def TestRapiInstanceConsole(instance):
"""Test getting instance console information via RAPI""" """Test getting instance console information via RAPI"""
result = _rapi_client.GetInstanceConsole(instance["name"]) result = _rapi_client.GetInstanceConsole(instance.name)
console = objects.InstanceConsole.FromDict(result) console = objects.InstanceConsole.FromDict(result)
AssertEqual(console.Validate(), True) 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) @InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
def TestRapiStoppedInstanceConsole(instance): def TestRapiStoppedInstanceConsole(instance):
"""Test getting stopped instance's console information via RAPI""" """Test getting stopped instance's console information via RAPI"""
try: try:
_rapi_client.GetInstanceConsole(instance["name"]) _rapi_client.GetInstanceConsole(instance.name)
except rapi.client.GanetiApiError, err: except rapi.client.GanetiApiError, err:
AssertEqual(err.code, 503) AssertEqual(err.code, 503)
else: else:
...@@ -782,9 +782,9 @@ def TestInterClusterInstanceMove(src_instance, dest_instance, ...@@ -782,9 +782,9 @@ def TestInterClusterInstanceMove(src_instance, dest_instance,
pnode = inodes[0] pnode = inodes[0]
# note: pnode:snode are the *current* nodes, so we move it first to # note: pnode:snode are the *current* nodes, so we move it first to
# tnode:pnode, then back to pnode:snode # 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), tnode.primary, pnode.primary),
(dest_instance["name"], src_instance["name"], (dest_instance.name, src_instance.name,
pnode.primary, snode.primary)]: pnode.primary, snode.primary)]:
cmd = [ cmd = [
"../tools/move-instance", "../tools/move-instance",
......
...@@ -82,4 +82,4 @@ def TestGroupTags(group): ...@@ -82,4 +82,4 @@ def TestGroupTags(group):
def TestInstanceTags(instance): def TestInstanceTags(instance):
"""gnt-instance tags""" """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