Commit 24c530df authored by Jose A. Lopes's avatar Jose A. Lopes

Add QA tests for instance shutdown detection

Add QA tests for instance shutdown detection with Xen PVM and HVM
hypervisors.
Signed-off-by: default avatarJose A. Lopes <jabolopes@google.com>
Reviewed-by: default avatarHrvoje Ribicic <riba@google.com>
parent 70f25a49
...@@ -722,6 +722,8 @@ def RunInstanceTests(): ...@@ -722,6 +722,8 @@ def RunInstanceTests():
try: try:
instance = RunTest(create_fun, inodes) instance = RunTest(create_fun, inodes)
try: try:
RunTestIf("instance-user-down", qa_instance.TestInstanceUserDown,
instance, qa_config.GetMasterNode())
RunTestIf("cluster-epo", qa_cluster.TestClusterEpo) RunTestIf("cluster-epo", qa_cluster.TestClusterEpo)
RunDaemonTests(instance) RunDaemonTests(instance)
for node in inodes: for node in inodes:
......
...@@ -230,6 +230,7 @@ ...@@ -230,6 +230,7 @@
"instance-shutdown": true, "instance-shutdown": true,
"instance-device-names": true, "instance-device-names": true,
"instance-device-hotplug": false, "instance-device-hotplug": false,
"instance-user-down": true,
"job-list": true, "job-list": true,
......
...@@ -1094,6 +1094,91 @@ def TestInstanceCreationRestrictedByDiskTemplates(): ...@@ -1094,6 +1094,91 @@ def TestInstanceCreationRestrictedByDiskTemplates():
",".join(enabled_disk_templates)], ",".join(enabled_disk_templates)],
fail=False) fail=False)
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def _TestInstanceUserDown(instance, master, hv_shutdown_fn):
# Shutdown instance in Xen and bring instance status to 'USER_down'
hv_shutdown_fn()
cmd = ["gnt-instance", "list", "--no-headers", "-o", "status", instance.name]
result_output = qa_utils.GetCommandOutput(master.primary,
utils.ShellQuoteArgs(cmd))
AssertEqual(result_output.strip(), constants.INSTST_USERDOWN)
# Fail to bring instance status to 'running'
AssertCommand(["gnt-instance", "start", instance.name], fail=True)
cmd = ["gnt-instance", "list", "--no-headers", "-o", "status", instance.name]
result_output = qa_utils.GetCommandOutput(master.primary,
utils.ShellQuoteArgs(cmd))
AssertEqual(result_output.strip(), constants.INSTST_USERDOWN)
# Bring instance status to 'ADMIN_down'
AssertCommand(["gnt-instance", "shutdown", instance.name])
cmd = ["gnt-instance", "list", "--no-headers", "-o", "status", instance.name]
result_output = qa_utils.GetCommandOutput(master.primary,
utils.ShellQuoteArgs(cmd))
AssertEqual(result_output.strip(), constants.INSTST_ADMINDOWN)
# Bring instance status to 'running'
AssertCommand(["gnt-instance", "start", instance.name])
cmd = ["gnt-instance", "list", "--no-headers", "-o", "status", instance.name]
result_output = qa_utils.GetCommandOutput(master.primary,
utils.ShellQuoteArgs(cmd))
AssertEqual(result_output.strip(), constants.INSTST_RUNNING)
# Bring instance status to 'ADMIN_down' forcibly
AssertCommand(["gnt-instance", "shutdown", "-f", instance.name])
cmd = ["gnt-instance", "list", "--no-headers", "-o", "status", instance.name]
result_output = qa_utils.GetCommandOutput(master.primary,
utils.ShellQuoteArgs(cmd))
AssertEqual(result_output.strip(), constants.INSTST_ADMINDOWN)
# Bring instance status to 'running'
AssertCommand(["gnt-instance", "start", instance.name])
cmd = ["gnt-instance", "list", "--no-headers", "-o", "status", instance.name]
result_output = qa_utils.GetCommandOutput(master.primary,
utils.ShellQuoteArgs(cmd))
AssertEqual(result_output.strip(), constants.INSTST_RUNNING)
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
def _TestInstanceUserDownXen(instance, master):
primary = _GetInstanceField(instance.name, "pnode")
fn = lambda: AssertCommand(["xm", "shutdown", "-w", instance.name],
fail=False, node=primary)
_TestInstanceUserDown(instance, master, fn)
# FIXME: User shutdown is not implemented for KVM yet
#
# @InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
# def _TestInstanceUserDownKvm(instance, master):
# fn = lambda: hv_kvm.KVMHypervisor._StopInstance(None, True, instance.name)
# _TestInstanceUserDown(instance, master, fn)
#
def _TestInstanceUserDownKvm(_1, _2):
pass
def TestInstanceUserDown(instance, master):
"""Tests user shutdown"""
enabled_hypervisors = qa_config.GetEnabledHypervisors()
for (hv, fn) in [(constants.HT_XEN_PVM, _TestInstanceUserDownXen),
(constants.HT_XEN_HVM, _TestInstanceUserDownXen),
(constants.HT_KVM, _TestInstanceUserDownKvm)]:
if hv in enabled_hypervisors:
fn(instance, master)
else:
print "%s hypervisor is not enabled, skipping test for this hypervisor" \
% hv
available_instance_tests = [ available_instance_tests = [
("instance-add-plain-disk", constants.DT_PLAIN, ("instance-add-plain-disk", constants.DT_PLAIN,
TestInstanceAddWithPlainDisk, 1), TestInstanceAddWithPlainDisk, 1),
......
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