Commit 5d831182 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

qa_rapi: Test inter-cluster instance move script



This test moves an instance on the same cluster and, if successful,
moves it back. While not testing a real move between two clusters,
this is certainly better than nothing.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent af1d39b1
......@@ -208,6 +208,19 @@ def RunExportImportTests(instance, pnode):
finally:
qa_config.ReleaseNode(expnode)
if (qa_rapi.Enabled() and
qa_config.TestEnabled("inter-cluster-instance-move")):
newinst = qa_config.AcquireInstance()
try:
pnode2 = qa_config.AcquireNode(exclude=pnode)
try:
RunTest(qa_rapi.TestInterClusterInstanceMove, instance, newinst,
pnode2, pnode)
finally:
qa_config.ReleaseNode(pnode2)
finally:
qa_config.ReleaseInstance(newinst)
def RunDaemonTests(instance, pnode):
"""Test the ganeti-watcher script.
......
......@@ -87,6 +87,9 @@
"# Disabled by default because it takes rather long": null,
"instance-replace-disks": false,
"# Whether to test the tools/move-instance utility": null,
"inter-cluster-instance-move": false,
"# Make sure not to include the disk(s) required for Dom0 to be": null,
"# included in the volume group used for instances. Otherwise": null,
"# whole system may stop working until restarted.": null,
......
......@@ -39,11 +39,13 @@ import qa_utils
import qa_error
from qa_utils import (AssertEqual, AssertNotEqual, AssertIn, AssertMatch,
StartSSH)
StartLocalCommand)
_rapi_ca = None
_rapi_client = None
_rapi_username = None
_rapi_password = None
def Setup(username, password):
......@@ -52,6 +54,11 @@ def Setup(username, password):
"""
global _rapi_ca
global _rapi_client
global _rapi_username
global _rapi_password
_rapi_username = username
_rapi_password = password
master = qa_config.GetMasterNode()
......@@ -332,3 +339,32 @@ def TestRapiInstanceRemove(instance, use_client):
_WaitForRapiJob(job_id)
qa_config.ReleaseInstance(instance)
def TestInterClusterInstanceMove(src_instance, dest_instance, pnode, snode):
"""Test tools/move-instance"""
master = qa_config.GetMasterNode()
rapi_pw_file = tempfile.NamedTemporaryFile()
rapi_pw_file.write(_rapi_password)
rapi_pw_file.flush()
# TODO: Run some instance tests before moving back
for srcname, destname in [(src_instance["name"], dest_instance["name"]),
(dest_instance["name"], src_instance["name"])]:
cmd = [
"../tools/move-instance",
"--verbose",
"--src-ca-file=%s" % _rapi_ca.name,
"--src-username=%s" % _rapi_username,
"--src-password-file=%s" % rapi_pw_file.name,
"--dest-instance-name=%s" % destname,
"--dest-primary-node=%s" % pnode["primary"],
"--dest-secondary-node=%s" % snode["primary"],
master["primary"],
master["primary"],
srcname,
]
AssertEqual(StartLocalCommand(cmd).wait(), 0)
......@@ -122,25 +122,29 @@ def GetSSHCommand(node, cmd, strict=True):
args.append(node)
args.append(cmd)
print 'SSH:', utils.ShellQuoteArgs(args)
return args
def StartLocalCommand(cmd, **kwargs):
"""Starts a local command.
"""
print "Command: %s" % utils.ShellQuoteArgs(cmd)
return subprocess.Popen(cmd, shell=False, **kwargs)
def StartSSH(node, cmd, strict=True):
"""Starts SSH.
"""
return subprocess.Popen(GetSSHCommand(node, cmd, strict=strict),
shell=False)
return StartLocalCommand(GetSSHCommand(node, cmd, strict=strict))
def GetCommandOutput(node, cmd):
"""Returns the output of a command executed on the given node.
"""
p = subprocess.Popen(GetSSHCommand(node, cmd),
shell=False, stdout=subprocess.PIPE)
p = StartLocalCommand(GetSSHCommand(node, cmd), stdout=subprocess.PIPE)
AssertEqual(p.wait(), 0)
return p.stdout.read()
......
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