Commit 87f5c298 authored by Iustin Pop's avatar Iustin Pop
Browse files

Convert iallocator_runner rpc to new result style



This patch converts this rpc into the new style. Since the function
already had some error handling, we remove this custom error reporting
and replace it with our (new-style) result type. This allows significant
cleaning up of this code.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 3fb4f740
......@@ -2605,17 +2605,15 @@ class IAllocatorRunner(object):
@param idata: the allocator input data
@rtype: tuple
@return: four element tuple of:
- run status (one of the IARUN_ constants)
- stdout
- stderr
- fail reason (as from L{utils.RunResult})
@return: two element tuple of:
- status
- either error message or stdout of allocator (for success)
"""
alloc_script = utils.FindFile(name, constants.IALLOCATOR_SEARCH_PATH,
os.path.isfile)
if alloc_script is None:
return (constants.IARUN_NOTFOUND, None, None, None)
_Fail("iallocator module '%s' not found in the search path", name)
fd, fin_name = tempfile.mkstemp(prefix="ganeti-iallocator.")
try:
......@@ -2623,12 +2621,12 @@ class IAllocatorRunner(object):
os.close(fd)
result = utils.RunCmd([alloc_script, fin_name])
if result.failed:
return (constants.IARUN_FAILURE, result.stdout, result.stderr,
result.fail_reason)
_Fail("iallocator module '%s' failed: %s, output '%s'",
name, result.fail_reason, result.output)
finally:
os.unlink(fin_name)
return (constants.IARUN_SUCCESS, result.stdout, result.stderr, None)
return True, result.stdout
class DevCacheManager(object):
......
......@@ -7123,19 +7123,12 @@ class IAllocator(object):
data = self.in_text
result = call_fn(self.lu.cfg.GetMasterNode(), name, self.in_text)
result.Raise()
if not isinstance(result.data, (list, tuple)) or len(result.data) != 4:
raise errors.OpExecError("Invalid result from master iallocator runner")
rcode, stdout, stderr, fail = result.data
msg = result.RemoteFailMsg()
if msg:
raise errors.OpExecError("Failure while running the iallocator"
" script: %s" % msg)
if rcode == constants.IARUN_NOTFOUND:
raise errors.OpExecError("Can't find allocator '%s'" % name)
elif rcode == constants.IARUN_FAILURE:
raise errors.OpExecError("Instance allocator call failed: %s,"
" output: %s" % (fail, stdout+stderr))
self.out_text = stdout
self.out_text = result.payload
if validate:
self._ValidateResult()
......
......@@ -440,9 +440,6 @@ IALLOCATOR_DIR_OUT = "out"
IALLOCATOR_MODE_ALLOC = "allocate"
IALLOCATOR_MODE_RELOC = "relocate"
IALLOCATOR_SEARCH_PATH = _autoconf.IALLOCATOR_SEARCH_PATH
IARUN_NOTFOUND = 1
IARUN_FAILURE = 2
IARUN_SUCCESS = 3
# Job queue
JOB_QUEUE_VERSION = 1
......
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