Commit ae8419a2 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Merge branch 'devel-2.2'

* devel-2.2:
  cli: Use list of options shared between commands
  jqueue: Use separate function for encoding errors
  Fix some epydoc warnings
  Fix breakage introduced by commit 8044bf65


  Remove “dry_run” from opcodes.OpCreateInstance
  Disable the RAPI CA checks in watcher
  move-instance: Fix parameter order in _CreateInstance

Conflicts:
	daemons/ganeti-watcher: Trivial
	lib/cli.py: Trivial
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parents 24f6a6e6 fa697271
......@@ -575,11 +575,14 @@ def GetCommands(filename, module):
help_option = cli.cli_option("-h", "--help", default=False,
action="store_true")
for (_, _, optdef, _, _) in commands.itervalues():
for name, (_, _, optdef, _, _) in commands.items():
if help_option not in optdef:
optdef.append(help_option)
if cli.DEBUG_OPT not in optdef:
optdef.append(cli.DEBUG_OPT)
for opt in cli.COMMON_OPTS:
if opt in optdef:
raise Exception("Common option '%s' listed for command '%s' in %s" %
(opt, name, filename))
optdef.append(opt)
# Use aliases
aliases = getattr(module, "aliases", {})
......
#!/usr/bin/python
#
# Copyright (C) 2006, 2007, 2008, 2010 Google Inc.
# Copyright (C) 2006, 2007, 2008, 2009, 2010 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -641,7 +641,7 @@ def IsRapiResponding(hostname):
@return: Whether RAPI is working properly
"""
curl_config = rapi.client.GenericCurlConfig(cafile=constants.RAPI_CERT_FILE)
curl_config = rapi.client.GenericCurlConfig()
rapi_client = rapi.client.GanetiRapiClient(hostname,
curl_config_fn=curl_config)
try:
......
......@@ -1037,6 +1037,9 @@ PRIMARY_IP_VERSION_OPT = \
constants.IP6_VERSION),
help="Cluster-wide IP version for primary IP")
#: Options provided by all commands
COMMON_OPTS = [DEBUG_OPT]
def _ParseArgs(argv, commands, aliases):
"""Parser for the command line arguments.
......@@ -1104,7 +1107,7 @@ def _ParseArgs(argv, commands, aliases):
cmd = aliases[cmd]
func, args_def, parser_opts, usage, description = commands[cmd]
parser = OptionParser(option_list=parser_opts + [DEBUG_OPT],
parser = OptionParser(option_list=parser_opts + COMMON_OPTS,
description=description,
formatter=TitledHelpFormatter(),
usage="%%prog %s %s" % (cmd, usage))
......
......@@ -6531,7 +6531,6 @@ class LUCreateInstance(LogicalUnit):
("identify_defaults", False, _TBool),
("file_driver", None, _TOr(_TNone, _TElemOf(constants.FILE_DRIVER))),
("file_storage_dir", None, _TMaybeString),
("dry_run", False, _TBool),
]
REQ_BGL = False
......
......@@ -676,6 +676,18 @@ class _WaitForJobChangesHelper(object):
return constants.JOB_NOTCHANGED
def _EncodeOpError(err):
"""Encodes an error which occurred while processing an opcode.
"""
if isinstance(err, errors.GenericError):
to_encode = err
else:
to_encode = errors.OpExecError(str(err))
return errors.EncodeException(to_encode)
class _JobQueueWorker(workerpool.BaseWorker):
"""The actual job workers.
......@@ -764,18 +776,14 @@ class _JobQueueWorker(workerpool.BaseWorker):
try:
logging.debug("Opcode %s/%s failed", idx + 1, count)
op.status = constants.OP_STATUS_ERROR
if isinstance(err, errors.GenericError):
to_encode = err
else:
to_encode = errors.OpExecError(str(err))
op.result = errors.EncodeException(to_encode)
op.result = _EncodeOpError(err)
op.end_timestamp = TimeStampNow()
logging.info("Op %s/%s: Error in opcode %s: %s",
idx + 1, count, op_summary, err)
to_encode = errors.OpExecError("Preceding opcode failed")
job.MarkUnfinishedOps(constants.OP_STATUS_ERROR,
errors.EncodeException(to_encode))
_EncodeOpError(to_encode))
# Consistency check
assert compat.all(i.status == constants.OP_STATUS_SUCCESS
......
......@@ -480,7 +480,6 @@ class OpCreateInstance(OpCode):
"source_handshake",
"source_x509_ca",
"source_instance_name",
"dry_run",
]
......
......@@ -35,11 +35,11 @@ from ganeti import netutils
def FormatParamikoFingerprint(fingerprint):
"""Formats the fingerprint of L{paramiko.PKey.get_fingerprint()}
"""Format paramiko PKey fingerprint.
@type fingerprint: str
@param fingerprint: PKey fingerprint
@return The string hex representation of the fingerprint
@return: The string hex representation of the fingerprint
"""
assert len(fingerprint) % 2 == 0
......
......@@ -220,5 +220,24 @@ class TestWaitForJobChangesHelper(unittest.TestCase):
["status"], None, None, 1.0) is None)
class TestEncodeOpError(unittest.TestCase):
def test(self):
encerr = jqueue._EncodeOpError(errors.LockError("Test 1"))
self.assert_(isinstance(encerr, tuple))
self.assertRaises(errors.LockError, errors.MaybeRaise, encerr)
encerr = jqueue._EncodeOpError(errors.GenericError("Test 2"))
self.assert_(isinstance(encerr, tuple))
self.assertRaises(errors.GenericError, errors.MaybeRaise, encerr)
encerr = jqueue._EncodeOpError(NotImplementedError("Foo"))
self.assert_(isinstance(encerr, tuple))
self.assertRaises(errors.OpExecError, errors.MaybeRaise, encerr)
encerr = jqueue._EncodeOpError("Hello World")
self.assert_(isinstance(encerr, tuple))
self.assertRaises(errors.OpExecError, errors.MaybeRaise, encerr)
if __name__ == "__main__":
testutils.GanetiTestProgram()
......@@ -437,7 +437,7 @@ class MoveDestExecutor(object):
mrt.dest_to_source.release()
@staticmethod
def _CreateInstance(cl, name, snode, pnode, iallocator, instance, expinfo):
def _CreateInstance(cl, name, pnode, snode, iallocator, instance, expinfo):
"""Starts the instance creation in remote import mode.
@type cl: L{rapi.client.GanetiRapiClient}
......
......@@ -217,7 +217,7 @@ def SetupLogging(options):
def LoadPrivateKeys(options):
"""Load the list of available private keys
"""Load the list of available private keys.
It loads the standard ssh key from disk and then tries to connect to
the ssh agent too.
......@@ -284,9 +284,9 @@ def LoginViaKeys(transport, username, keys):
def LoadKnownHosts():
"""Loads the known hosts
"""Load the known hosts.
@return L{paramiko.util.load_host_keys} dict
@return: paramiko.util.load_host_keys dict
"""
homedir = utils.GetHomeDir(constants.GANETI_RUNAS)
......
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