From 87f5c2983398c0674787f07d213b3075ccf676c3 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 10 Jun 2009 18:28:51 +0200 Subject: [PATCH] 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: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- lib/backend.py | 16 +++++++--------- lib/cmdlib.py | 17 +++++------------ lib/constants.py | 3 --- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/lib/backend.py b/lib/backend.py index eaf559b8f..3635d49fd 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -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): diff --git a/lib/cmdlib.py b/lib/cmdlib.py index d2eb0fdde..a96087ec8 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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() diff --git a/lib/constants.py b/lib/constants.py index 260b509ef..9fb44ea5e 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -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 -- GitLab