Commit 5fa0375e authored by Michael Hanselmann's avatar Michael Hanselmann

QA: Decorate tests with instance checks

Start using “InstanceCheck” decorator where appropriate. Use direct call
for check in places where the instance status changes during the test.

The parameters of “TestInstanceImport” had to be re-ordered to have the
instance as the first argument.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent c9e05005
......@@ -354,7 +354,7 @@ def RunExportImportTests(instance, pnode, snode):
if qa_config.TestEnabled("instance-import"):
newinst = qa_config.AcquireInstance()
try:
RunTest(qa_instance.TestInstanceImport, pnode, newinst,
RunTest(qa_instance.TestInstanceImport, newinst, pnode,
expnode, name)
RunTest(qa_instance.TestInstanceRemove, newinst)
finally:
......
......@@ -35,6 +35,7 @@ import qa_utils
import qa_error
from qa_utils import AssertIn, AssertCommand, AssertEqual
from qa_utils import InstanceCheck, INST_DOWN, INST_UP, FIRST_ARG, RETURN_VALUE
def _GetDiskStatePath(disk):
......@@ -72,17 +73,20 @@ def _DiskTest(node, disk_template):
raise
@InstanceCheck(None, INST_UP, RETURN_VALUE)
def TestInstanceAddWithPlainDisk(node):
"""gnt-instance add -t plain"""
return _DiskTest(node["primary"], "plain")
@InstanceCheck(None, INST_UP, RETURN_VALUE)
def TestInstanceAddWithDrbdDisk(node, node2):
"""gnt-instance add -t drbd"""
return _DiskTest("%s:%s" % (node["primary"], node2["primary"]),
"drbd")
@InstanceCheck(None, INST_DOWN, FIRST_ARG)
def TestInstanceRemove(instance):
"""gnt-instance remove"""
AssertCommand(["gnt-instance", "remove", "-f", instance["name"]])
......@@ -90,16 +94,19 @@ def TestInstanceRemove(instance):
qa_config.ReleaseInstance(instance)
@InstanceCheck(INST_DOWN, INST_UP, FIRST_ARG)
def TestInstanceStartup(instance):
"""gnt-instance startup"""
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"]])
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestInstanceReboot(instance):
"""gnt-instance reboot"""
options = qa_config.get("options", {})
......@@ -109,6 +116,7 @@ def TestInstanceReboot(instance):
AssertCommand(["gnt-instance", "reboot", "--type=%s" % rtype, name])
AssertCommand(["gnt-instance", "shutdown", name])
qa_utils.RunInstanceCheck(instance, False)
AssertCommand(["gnt-instance", "reboot", name])
master = qa_config.GetMasterNode()
......@@ -118,6 +126,7 @@ def TestInstanceReboot(instance):
AssertEqual(result_output.strip(), constants.INSTST_RUNNING)
@InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
def TestInstanceReinstall(instance):
"""gnt-instance reinstall"""
AssertCommand(["gnt-instance", "reinstall", "-f", instance["name"]])
......@@ -147,6 +156,7 @@ def _CheckSsconfInstanceList(instance):
_ReadSsconfInstanceList())
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestInstanceRenameAndBack(rename_source, rename_target):
"""gnt-instance rename
......@@ -155,6 +165,7 @@ def TestInstanceRenameAndBack(rename_source, rename_target):
"""
_CheckSsconfInstanceList(rename_source)
# first do a rename to a different actual name, expecting it to fail
qa_utils.AddToEtcHosts(["meeeeh-not-exists", rename_target])
try:
......@@ -163,48 +174,72 @@ def TestInstanceRenameAndBack(rename_source, rename_target):
_CheckSsconfInstanceList(rename_source)
finally:
qa_utils.RemoveFromEtcHosts(["meeeeh-not-exists", rename_target])
# and now rename instance to rename_target...
AssertCommand(["gnt-instance", "rename", rename_source, rename_target])
_CheckSsconfInstanceList(rename_target)
qa_utils.RunInstanceCheck(rename_source, False)
qa_utils.RunInstanceCheck(rename_target, True)
# and back
AssertCommand(["gnt-instance", "rename", rename_target, rename_source])
_CheckSsconfInstanceList(rename_source)
qa_utils.RunInstanceCheck(rename_target, False)
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestInstanceFailover(instance):
"""gnt-instance failover"""
cmd = ["gnt-instance", "failover", "--force", instance["name"]]
# failover ...
AssertCommand(cmd)
qa_utils.RunInstanceCheck(instance, True)
# ... and back
AssertCommand(cmd)
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestInstanceMigrate(instance):
"""gnt-instance migrate"""
cmd = ["gnt-instance", "migrate", "--force", instance["name"]]
# migrate ...
AssertCommand(cmd)
qa_utils.RunInstanceCheck(instance, True)
# ... and back
AssertCommand(cmd)
# TODO: Split into multiple tests
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"]])
AssertCommand(cmd)
qa_utils.RunInstanceCheck(instance, True)
AssertCommand(["gnt-instance", "modify", "-B",
("%s=%s" %
(constants.BE_ALWAYS_FAILOVER, constants.VALUE_TRUE)),
instance["name"]])
AssertCommand(cmd, fail=True)
qa_utils.RunInstanceCheck(instance, True)
AssertCommand(["gnt-instance", "migrate", "--force", "--allow-failover",
instance["name"]])
# TODO: Verify whether the default value is restored here (not hardcoded)
AssertCommand(["gnt-instance", "modify", "-B",
("%s=%s" %
(constants.BE_ALWAYS_FAILOVER, constants.VALUE_FALSE)),
instance["name"]])
AssertCommand(cmd)
qa_utils.RunInstanceCheck(instance, True)
def TestInstanceInfo(instance):
......@@ -212,6 +247,7 @@ def TestInstanceInfo(instance):
AssertCommand(["gnt-instance", "info", instance["name"]])
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestInstanceModify(instance):
"""gnt-instance modify"""
# Assume /sbin/init exists on all systems
......@@ -257,6 +293,7 @@ def TestInstanceModify(instance):
AssertCommand(["gnt-instance", "modify", arg, instance["name"]], fail=True)
@InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
def TestInstanceStoppedModify(instance):
"""gnt-instance modify (stopped instance)"""
name = instance["name"]
......@@ -271,6 +308,7 @@ def TestInstanceStoppedModify(instance):
AssertCommand(["gnt-instance", "modify", "--online", name])
@InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
def TestInstanceConvertDisk(instance, snode):
"""gnt-instance modify -t"""
name = instance["name"]
......@@ -279,6 +317,7 @@ def TestInstanceConvertDisk(instance, snode):
"-n", snode["primary"], name])
@InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
def TestInstanceGrowDisk(instance):
"""gnt-instance grow-disk"""
name = instance["name"]
......@@ -311,11 +350,13 @@ def TestInstanceListFields():
qa_utils.GenericQueryFieldsTest("gnt-instance", query.INSTANCE_FIELDS.keys())
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestInstanceConsole(instance):
"""gnt-instance console"""
AssertCommand(["gnt-instance", "console", "--show-cmd", instance["name"]])
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestReplaceDisks(instance, pnode, snode, othernode):
"""gnt-instance replace-disks"""
# pylint: disable=W0613
......@@ -344,6 +385,7 @@ def TestReplaceDisks(instance, pnode, snode, othernode):
AssertCommand(["gnt-instance", "start", instance["name"]])
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestInstanceExport(instance, node):
"""gnt-backup export -n ..."""
name = instance["name"]
......@@ -351,18 +393,21 @@ def TestInstanceExport(instance, node):
return qa_utils.ResolveInstanceName(name)
@InstanceCheck(INST_UP, None, FIRST_ARG)
def TestInstanceExportWithRemove(instance, node):
"""gnt-backup export --remove-instance"""
AssertCommand(["gnt-backup", "export", "-n", node["primary"],
"--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)
def TestInstanceImport(node, newinst, expnode, name):
@InstanceCheck(None, INST_UP, FIRST_ARG)
def TestInstanceImport(newinst, node, expnode, name):
"""gnt-backup import"""
cmd = (["gnt-backup", "import",
"--disk-template=plain",
......
......@@ -44,6 +44,7 @@ import qa_utils
import qa_error
from qa_utils import (AssertEqual, AssertIn, AssertMatch, StartLocalCommand)
from qa_utils import InstanceCheck, INST_DOWN, INST_UP, FIRST_ARG
_rapi_ca = None
......@@ -349,6 +350,7 @@ def TestRapiQuery():
])
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestInstance(instance):
"""Testing getting instance(s) info via remote API.
......@@ -577,6 +579,7 @@ def TestRapiInstanceAdd(node, use_client):
raise
@InstanceCheck(None, INST_DOWN, FIRST_ARG)
def TestRapiInstanceRemove(instance, use_client):
"""Test removing instance via RAPI"""
if use_client:
......@@ -591,32 +594,39 @@ def TestRapiInstanceRemove(instance, use_client):
qa_config.ReleaseInstance(instance)
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestRapiInstanceMigrate(instance):
"""Test migrating instance via RAPI"""
# Move to secondary node
_WaitForRapiJob(_rapi_client.MigrateInstance(instance["name"]))
qa_utils.RunInstanceCheck(instance, True)
# And back to previous primary
_WaitForRapiJob(_rapi_client.MigrateInstance(instance["name"]))
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestRapiInstanceFailover(instance):
"""Test failing over instance via RAPI"""
# Move to secondary node
_WaitForRapiJob(_rapi_client.FailoverInstance(instance["name"]))
qa_utils.RunInstanceCheck(instance, True)
# And back to previous primary
_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"]))
@InstanceCheck(INST_DOWN, INST_UP, FIRST_ARG)
def TestRapiInstanceStartup(instance):
"""Test starting an instance via RAPI"""
_WaitForRapiJob(_rapi_client.StartupInstance(instance["name"]))
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestRapiInstanceRenameAndBack(rename_source, rename_target):
"""Test renaming instance via RAPI
......@@ -625,14 +635,19 @@ def TestRapiInstanceRenameAndBack(rename_source, rename_target):
"""
_WaitForRapiJob(_rapi_client.RenameInstance(rename_source, rename_target))
qa_utils.RunInstanceCheck(rename_source, False)
qa_utils.RunInstanceCheck(rename_target, True)
_WaitForRapiJob(_rapi_client.RenameInstance(rename_target, rename_source))
qa_utils.RunInstanceCheck(rename_target, False)
@InstanceCheck(INST_DOWN, INST_DOWN, FIRST_ARG)
def TestRapiInstanceReinstall(instance):
"""Test reinstalling an instance via RAPI"""
_WaitForRapiJob(_rapi_client.ReinstallInstance(instance["name"]))
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestRapiInstanceReplaceDisks(instance):
"""Test replacing instance disks via RAPI"""
_WaitForRapiJob(_rapi_client.ReplaceInstanceDisks(instance["name"],
......@@ -641,6 +656,7 @@ def TestRapiInstanceReplaceDisks(instance):
mode=constants.REPLACE_DISK_SEC, disks="0"))
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def TestRapiInstanceModify(instance):
"""Test modifying instance via RAPI"""
def _ModifyInstance(**kwargs):
......@@ -663,6 +679,7 @@ 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"])
......@@ -671,6 +688,7 @@ def TestRapiInstanceConsole(instance):
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:
......@@ -727,4 +745,7 @@ def TestInterClusterInstanceMove(src_instance, dest_instance,
si,
]
qa_utils.RunInstanceCheck(di, False)
AssertEqual(StartLocalCommand(cmd).wait(), 0)
qa_utils.RunInstanceCheck(si, False)
qa_utils.RunInstanceCheck(di, True)
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