From ec1189e4734ed9c1c39bab0175877bf011a32df0 Mon Sep 17 00:00:00 2001 From: Bharat Kumar Kobagana Date: Thu, 20 Nov 2014 17:09:38 +0530 Subject: [PATCH] Defining the variable "tmp" before try block In file "image_utils.py", "tmp" variable initialized in try block. So, if any exception occurred in the try block, then "tmp" would not be assigned with any value. Because of this finally block will raise an exception like "local variable tmp tried to use before the assignment". This patch resolves that issue by defining "tmp" variable before try block. Change-Id: I9d8c8eaaeba0a7aab7ebfc791b9ddd967f324184 Closes-Bug: #1394548 --- cinder/image/image_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cinder/image/image_utils.py b/cinder/image/image_utils.py index 3d280a3ca..d1dea63a0 100644 --- a/cinder/image/image_utils.py +++ b/cinder/image/image_utils.py @@ -389,11 +389,13 @@ def rename_file(src, dst): @contextlib.contextmanager def temporary_file(*args, **kwargs): + tmp = None try: tmp = create_temporary_file(*args, **kwargs) yield tmp finally: - fileutils.delete_if_exists(tmp) + if tmp: + fileutils.delete_if_exists(tmp) def temporary_dir(): -- 2.45.2