Skip to content
Snippets Groups Projects
Commit 180bdd1f authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

- Test “gnt-cluster copyfile”

- Run “gnt-cluster verify” and “gnt-cluster info” after adding all nodes
- Remove unused --cleanup option
- Remove --verbose option and always print executed SSH commands

Reviewed-by: iustinp
parent 82122173
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ import re ...@@ -26,7 +26,7 @@ import re
import sys import sys
import yaml import yaml
import time import time
import tempfile
from datetime import datetime from datetime import datetime
from optparse import OptionParser from optparse import OptionParser
...@@ -117,8 +117,7 @@ def GetSSHCommand(node, cmd, strict=True): ...@@ -117,8 +117,7 @@ def GetSSHCommand(node, cmd, strict=True):
args.append(prefix + cmd) args.append(prefix + cmd)
if options.verbose: print 'SSH:', utils.ShellQuoteArgs(args)
print 'SSH:', utils.ShellQuoteArgs(args)
return args return args
...@@ -134,14 +133,13 @@ def StartSSH(node, cmd, strict=True): ...@@ -134,14 +133,13 @@ def StartSSH(node, cmd, strict=True):
def UploadFile(node, file): def UploadFile(node, file):
"""Uploads a file to a node and returns the filename. """Uploads a file to a node and returns the filename.
Caller needs to remove the file when it's not needed anymore. Caller needs to remove the returned file on the node when it's not needed
anymore.
""" """
if os.stat(file).st_mode & 0100: # Make sure nobody else has access to it while preserving local permissions
mode = '0700' mode = os.stat(file).st_mode & 0700
else:
mode = '0600'
cmd = ('tmp=$(tempfile --mode %s --prefix gnt) && ' cmd = ('tmp=$(tempfile --mode %o --prefix gnt) && '
'[[ -f "${tmp}" ]] && ' '[[ -f "${tmp}" ]] && '
'cat > "${tmp}" && ' 'cat > "${tmp}" && '
'echo "${tmp}"') % mode 'echo "${tmp}"') % mode
...@@ -152,9 +150,8 @@ def UploadFile(node, file): ...@@ -152,9 +150,8 @@ def UploadFile(node, file):
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
AssertEqual(p.wait(), 0) AssertEqual(p.wait(), 0)
name = p.stdout.read().strip() # Return temporary filename
return p.stdout.read().strip()
return name
finally: finally:
f.close() f.close()
# }}} # }}}
...@@ -358,6 +355,31 @@ def TestClusterMasterFailover(): ...@@ -358,6 +355,31 @@ def TestClusterMasterFailover():
ReleaseNode(failovermaster) ReleaseNode(failovermaster)
def TestClusterCopyfile():
"""gnt-cluster copyfile"""
master = GetMasterNode()
# Create temporary file
f = tempfile.NamedTemporaryFile()
f.write("I'm a testfile.\n")
f.flush()
f.seek(0)
# Upload file to master node
testname = UploadFile(master['primary'], f.name)
try:
# Copy file to all nodes
cmd = ['gnt-cluster', 'copyfile', testname]
AssertEqual(StartSSH(master['primary'],
utils.ShellQuoteArgs(cmd)).wait(), 0)
finally:
# Remove file from all nodes
for node in cfg['nodes']:
cmd = ['rm', '-f', testname]
AssertEqual(StartSSH(node['primary'],
utils.ShellQuoteArgs(cmd)).wait(), 0)
def TestClusterDestroy(): def TestClusterDestroy():
"""gnt-cluster destroy""" """gnt-cluster destroy"""
cmd = ['gnt-cluster', 'destroy', '--yes-do-it'] cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
...@@ -605,15 +627,9 @@ def TestInstanceConsecutiveFailures(node, instance): ...@@ -605,15 +627,9 @@ def TestInstanceConsecutiveFailures(node, instance):
if __name__ == '__main__': if __name__ == '__main__':
# {{{ Option parsing # {{{ Option parsing
parser = OptionParser(usage="%prog [options] <configfile>") parser = OptionParser(usage="%prog [options] <configfile>")
parser.add_option('--cleanup', dest='cleanup',
action="store_true",
help="Clean up cluster after testing?")
parser.add_option('--dry-run', dest='dry_run', parser.add_option('--dry-run', dest='dry_run',
action="store_true", action="store_true",
help="Show what would be done") help="Show what would be done")
parser.add_option('--verbose', dest='verbose',
action="store_true",
help="Verbose output")
parser.add_option('--yes-do-it', dest='yes_do_it', parser.add_option('--yes-do-it', dest='yes_do_it',
action="store_true", action="store_true",
help="Really execute the tests") help="Really execute the tests")
...@@ -646,13 +662,16 @@ if __name__ == '__main__': ...@@ -646,13 +662,16 @@ if __name__ == '__main__':
RunTest(TestClusterInit) RunTest(TestClusterInit)
RunTest(TestNodeAddAll)
if TestEnabled('cluster-verify'): if TestEnabled('cluster-verify'):
RunTest(TestClusterVerify) RunTest(TestClusterVerify)
if TestEnabled('cluster-info'): if TestEnabled('cluster-info'):
RunTest(TestClusterInfo) RunTest(TestClusterInfo)
RunTest(TestNodeAddAll) if TestEnabled('cluster-copyfile'):
RunTest(TestClusterCopyfile)
if TestEnabled('node-info'): if TestEnabled('node-info'):
RunTest(TestNodeInfo) RunTest(TestNodeInfo)
......
...@@ -29,6 +29,7 @@ tests: ...@@ -29,6 +29,7 @@ tests:
cluster-verify: True cluster-verify: True
cluster-info: True cluster-info: True
cluster-burnin: True cluster-burnin: True
cluster-copyfile: True
cluster-master-failover: True cluster-master-failover: True
cluster-destroy: True cluster-destroy: True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment