From 29e43e45de8259f26e9a49bd07e543772a71fcd2 Mon Sep 17 00:00:00 2001 From: Constantinos Venetsanopoulos <cven@grnet.gr> Date: Thu, 20 Sep 2012 18:29:13 +0300 Subject: [PATCH] Do not show logfile on ExtStorage's attach error During attach the logfile is `None'. If the attach script fails and we try to Tailfile() its logfile, TailFile breaks with: TypeError: coercing to Unicode: need string or buffer, NoneType found Thus, we don't show the logfile, if ExtStorage's attach script fails. Just throw the appropriate error. Signed-off-by: Constantinos Venetsanopoulos <cven@grnet.gr> --- lib/bdev.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/bdev.py b/lib/bdev.py index 40c75c31b..f3e5fc155 100644 --- a/lib/bdev.py +++ b/lib/bdev.py @@ -2821,7 +2821,7 @@ def _ExtStorageAction(action, unique_id, ext_params, size=None, grow=None): create_env = _ExtStorageEnvironment(unique_id, ext_params, size, grow) # Do not use log file for action `attach' as we need - # to get the outpout from RunResult + # to get the output from RunResult # TODO: find a way to have a log file for attach too logfile = None if action is not constants.ES_ACTION_ATTACH: @@ -2839,11 +2839,18 @@ def _ExtStorageAction(action, unique_id, ext_params, size=None, grow=None): " error: %s, logfile: %s, output: %s", action, result.cmd, result.fail_reason, logfile, result.output) - lines = [utils.SafeEncode(val) - for val in utils.TailFile(logfile, lines=20)] - _ThrowError("External storage's %s script failed (%s), last" - " lines in the log file:\n%s", - action, result.fail_reason, "\n".join(lines)) + + # If logfile is 'None' (during attach), it breaks TailFile + # TODO: have a log file for attach too + if action is not constants.ES_ACTION_ATTACH: + lines = [utils.SafeEncode(val) + for val in utils.TailFile(logfile, lines=20)] + _ThrowError("External storage's %s script failed (%s), last" + " lines in the log file:\n%s", + action, result.fail_reason, "\n".join(lines)) + else: + _ThrowError("External storage's %s script failed (%s)", + action, result.fail_reason) if action == constants.ES_ACTION_ATTACH: return result.stdout -- GitLab