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

Enhance QA.

- Test “gnt-backup export” and “gnt-backup import”.
- Move “ResolveInstanceName” to qa_utils.py.
- Fix tests for “ganeti-watcher”.
- Make instance shutdown and startup configurable.

Reviewed-by: schreiberal
parent 24d48647
......@@ -119,8 +119,10 @@ def main():
try:
if qa_config.TestEnabled('instance-add-plain-disk'):
instance = RunTest(qa_instance.TestInstanceAddWithPlainDisk, node)
RunTest(qa_instance.TestInstanceShutdown, instance)
RunTest(qa_instance.TestInstanceStartup, instance)
if qa_config.TestEnabled('instance-shutdown'):
RunTest(qa_instance.TestInstanceShutdown, instance)
RunTest(qa_instance.TestInstanceStartup, instance)
if qa_config.TestEnabled('instance-info'):
RunTest(qa_instance.TestInstanceInfo, instance)
......@@ -131,6 +133,22 @@ def main():
if qa_config.TestEnabled('instance-consecutive-failures'):
RunTest(qa_daemon.TestInstanceConsecutiveFailures, node, instance)
if qa_config.TestEnabled('instance-export'):
expnode = qa_config.AcquireNode(exclude=node)
try:
name = RunTest(qa_instance.TestInstanceExport, instance, expnode)
if qa_config.TestEnabled('instance-import'):
newinst = qa_config.AcquireInstance()
try:
RunTest(qa_instance.TestInstanceImport, node, newinst,
expnode, name)
RunTest(qa_instance.TestInstanceRemove, newinst)
finally:
qa_config.ReleaseInstance(newinst)
finally:
qa_config.ReleaseNode(expnode)
if qa_config.TestEnabled('node-volumes'):
RunTest(qa_node.TestNodeVolumes)
......@@ -139,8 +157,10 @@ def main():
if qa_config.TestEnabled('instance-add-local-mirror-disk'):
instance = RunTest(qa_instance.TestInstanceAddWithLocalMirrorDisk, node)
RunTest(qa_instance.TestInstanceShutdown, instance)
RunTest(qa_instance.TestInstanceStartup, instance)
if qa_config.TestEnabled('instance-shutdown'):
RunTest(qa_instance.TestInstanceShutdown, instance)
RunTest(qa_instance.TestInstanceStartup, instance)
if qa_config.TestEnabled('instance-info'):
RunTest(qa_instance.TestInstanceInfo, instance)
......@@ -156,8 +176,10 @@ def main():
try:
instance = RunTest(qa_instance.TestInstanceAddWithRemoteRaidDisk,
node, node2)
RunTest(qa_instance.TestInstanceShutdown, instance)
RunTest(qa_instance.TestInstanceStartup, instance)
if qa_config.TestEnabled('instance-shutdown'):
RunTest(qa_instance.TestInstanceShutdown, instance)
RunTest(qa_instance.TestInstanceStartup, instance)
if qa_config.TestEnabled('instance-info'):
RunTest(qa_instance.TestInstanceInfo, instance)
......
......@@ -41,6 +41,9 @@ tests:
instance-add-remote-raid-disk: True
instance-failover: True
instance-info: True
instance-export: True
instance-import: True
instance-shutdown: True
# This test takes up to 6 minutes to complete
instance-automatic-restart: False
......
......@@ -21,7 +21,6 @@
"""
import time
import subprocess
from ganeti import utils
from ganeti import constants
......@@ -33,23 +32,6 @@ import qa_error
from qa_utils import AssertEqual, StartSSH
def _ResolveInstanceName(instance):
"""Gets the full Xen name of an instance.
"""
master = qa_config.GetMasterNode()
info_cmd = utils.ShellQuoteArgs(['gnt-instance', 'info', instance['name']])
sed_cmd = utils.ShellQuoteArgs(['sed', '-n', '-e', 's/^Instance name: *//p'])
cmd = '%s | %s' % (info_cmd, sed_cmd)
ssh_cmd = qa_utils.GetSSHCommand(master['primary'], cmd)
p = subprocess.Popen(ssh_cmd, shell=False, stdout=subprocess.PIPE)
AssertEqual(p.wait(), 0)
return p.stdout.read().strip()
def _InstanceRunning(node, name):
"""Checks whether an instance is running.
......@@ -72,7 +54,7 @@ def _XmShutdownInstance(node, name):
master = qa_config.GetMasterNode()
cmd = ['xm', 'shutdown', name]
AssertEqual(StartSSH(master['primary'],
AssertEqual(StartSSH(node['primary'],
utils.ShellQuoteArgs(cmd)).wait(), 0)
# Wait up to a minute
......@@ -102,7 +84,7 @@ def TestInstanceAutomaticRestart(node, instance):
Note: takes up to 6 minutes to complete.
"""
master = qa_config.GetMasterNode()
inst_name = _ResolveInstanceName(instance)
inst_name = qa_utils.ResolveInstanceName(instance)
_ResetWatcherDaemon(node)
_XmShutdownInstance(node, inst_name)
......@@ -129,7 +111,7 @@ def TestInstanceConsecutiveFailures(node, instance):
Note: takes at least 35 minutes to complete.
"""
master = qa_config.GetMasterNode()
inst_name = _ResolveInstanceName(instance)
inst_name = qa_utils.ResolveInstanceName(instance)
_ResetWatcherDaemon(node)
_XmShutdownInstance(node, inst_name)
......
......@@ -21,23 +21,29 @@
"""
from ganeti import utils
from ganeti import constants
import qa_config
import qa_utils
from qa_utils import AssertEqual, StartSSH
def _GetGenericAddParameters():
return ['--os-size=%s' % qa_config.get('os-size'),
'--swap-size=%s' % qa_config.get('swap-size'),
'--memory=%s' % qa_config.get('mem')]
def _DiskTest(node, args):
master = qa_config.GetMasterNode()
instance = qa_config.AcquireInstance()
try:
cmd = ['gnt-instance', 'add',
'--os-type=%s' % qa_config.get('os'),
'--os-size=%s' % qa_config.get('os-size'),
'--swap-size=%s' % qa_config.get('swap-size'),
'--memory=%s' % qa_config.get('mem'),
'--node=%s' % node['primary']]
cmd = (['gnt-instance', 'add',
'--os-type=%s' % qa_config.get('os'),
'--node=%s' % node['primary']] +
_GetGenericAddParameters())
if args:
cmd += args
cmd.append(instance['name'])
......@@ -112,3 +118,30 @@ def TestInstanceInfo(instance):
cmd = ['gnt-instance', 'info', instance['name']]
AssertEqual(StartSSH(master['primary'],
utils.ShellQuoteArgs(cmd)).wait(), 0)
def TestInstanceExport(instance, node):
"""gnt-backup export"""
master = qa_config.GetMasterNode()
cmd = ['gnt-backup', 'export', '-n', node['primary'], instance['name']]
AssertEqual(StartSSH(master['primary'],
utils.ShellQuoteArgs(cmd)).wait(), 0)
return qa_utils.ResolveInstanceName(instance)
def TestInstanceImport(node, newinst, expnode, name):
"""gnt-backup import"""
master = qa_config.GetMasterNode()
cmd = (['gnt-backup', 'import',
'--disk-template=plain',
'--no-ip-check',
'--src-node=%s' % expnode['primary'],
'--src-dir=%s/%s' % (constants.EXPORT_DIR, name),
'--node=%s' % node['primary']] +
_GetGenericAddParameters())
cmd.append(newinst['name'])
AssertEqual(StartSSH(master['primary'],
utils.ShellQuoteArgs(cmd)).wait(), 0)
......@@ -96,4 +96,20 @@ def UploadFile(node, src):
return p.stdout.read().strip()
finally:
f.close()
# }}}
def ResolveInstanceName(instance):
"""Gets the full name of an instance.
"""
master = qa_config.GetMasterNode()
info_cmd = utils.ShellQuoteArgs(['gnt-instance', 'info', instance['name']])
sed_cmd = utils.ShellQuoteArgs(['sed', '-n', '-e', 's/^Instance name: *//p'])
cmd = '%s | %s' % (info_cmd, sed_cmd)
ssh_cmd = GetSSHCommand(master['primary'], cmd)
p = subprocess.Popen(ssh_cmd, shell=False, stdout=subprocess.PIPE)
AssertEqual(p.wait(), 0)
return p.stdout.read().strip()
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