-
-def TestNodeInfo():
- """gnt-node info"""
- cmd = ['gnt-node', 'info']
- AssertEqual(StartSSH(GetMasterNode()['primary'],
- utils.ShellQuoteArgs(cmd)).wait(), 0)
-
-
-def TestNodeVolumes():
- """gnt-node volumes"""
- cmd = ['gnt-node', 'volumes']
- AssertEqual(StartSSH(GetMasterNode()['primary'],
- utils.ShellQuoteArgs(cmd)).wait(), 0)
-# }}}
-
-# {{{ Instance tests
-def _DiskTest(node, instance, args):
- cmd = ['gnt-instance', 'add',
- '--os-type=%s' % cfg['os'],
- '--os-size=%s' % cfg['os-size'],
- '--swap-size=%s' % cfg['swap-size'],
- '--memory=%s' % cfg['mem'],
- '--node=%s' % node['primary']]
- if args:
- cmd += args
- cmd.append(instance['name'])
-
- AssertEqual(StartSSH(GetMasterNode()['primary'],
- utils.ShellQuoteArgs(cmd)).wait(), 0)
- return instance
-
-
-def TestInstanceAddWithPlainDisk(node):
- """gnt-instance add -t plain"""
- return _DiskTest(node, AcquireInstance(), ['--disk-template=plain'])
-
-
-def TestInstanceAddWithLocalMirrorDisk(node):
- """gnt-instance add -t local_raid1"""
- return _DiskTest(node, AcquireInstance(), ['--disk-template=local_raid1'])
-
-
-def TestInstanceAddWithRemoteRaidDisk(node, node2):
- """gnt-instance add -t remote_raid1"""
- return _DiskTest(node, AcquireInstance(),
- ['--disk-template=remote_raid1',
- '--secondary-node=%s' % node2['primary']])
-
-
-def TestInstanceRemove(instance):
- """gnt-instance remove"""
- cmd = ['gnt-instance', 'remove', '-f', instance['name']]
- AssertEqual(StartSSH(GetMasterNode()['primary'],
- utils.ShellQuoteArgs(cmd)).wait(), 0)
-
- ReleaseInstance(instance)
-
-
-def TestInstanceStartup(instance):
- """gnt-instance startup"""
- cmd = ['gnt-instance', 'startup', instance['name']]
- AssertEqual(StartSSH(GetMasterNode()['primary'],
- utils.ShellQuoteArgs(cmd)).wait(), 0)
-
-
-def TestInstanceShutdown(instance):
- """gnt-instance shutdown"""
- cmd = ['gnt-instance', 'shutdown', instance['name']]
- AssertEqual(StartSSH(GetMasterNode()['primary'],
- utils.ShellQuoteArgs(cmd)).wait(), 0)
-
-
-def TestInstanceFailover(instance):
- """gnt-instance failover"""
- cmd = ['gnt-instance', 'failover', '--force', instance['name']]
- AssertEqual(StartSSH(GetMasterNode()['primary'],
- utils.ShellQuoteArgs(cmd)).wait(), 0)
-
-
-def TestInstanceInfo(instance):
- """gnt-instance info"""
- cmd = ['gnt-instance', 'info', instance['name']]
- AssertEqual(StartSSH(GetMasterNode()['primary'],
- utils.ShellQuoteArgs(cmd)).wait(), 0)
-# }}}
-
-# {{{ Daemon tests
-def _ResolveInstanceName(instance):
- """Gets the full Xen name of an instance.
-
- """
- master = 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)
- p = subprocess.Popen(GetSSHCommand(master['primary'], 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.
-
- Args:
- node: Node the instance runs on
- name: Full name of Xen instance
- """
- cmd = utils.ShellQuoteArgs(['xm', 'list', name]) + ' >/dev/null'
- ret = StartSSH(node['primary'], cmd).wait()
- return ret == 0
-
-
-def _XmShutdownInstance(node, name):
- """Shuts down instance using "xm" and waits for completion.
-
- Args:
- node: Node the instance runs on
- name: Full name of Xen instance
- """
- cmd = ['xm', 'shutdown', name]
- AssertEqual(StartSSH(GetMasterNode()['primary'],
- utils.ShellQuoteArgs(cmd)).wait(), 0)
-
- # Wait up to a minute
- end = time.time() + 60
- while time.time() <= end:
- if not _InstanceRunning(node, name):
- break
- time.sleep(5)
- else:
- raise Error("xm shutdown failed")
-
-
-def _ResetWatcherDaemon(node):
- """Removes the watcher daemon's state file.
-
- Args:
- node: Node to be reset