From e12ec97ea9ade42246fd3389985af9f08f1e953b Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Thu, 5 Mar 2015 09:36:54 -0800 Subject: [PATCH] Make try block shorter for _make_password_file The yield statement should not be inside the try block since it will be used as a 'with' statement. When an exception is raised inside the with block it gets caught and was raising a PasswordFileFailedToCreate exception. It is not required to set the mkstemp() file as R/W only by the user as this is what mkstemp() does. Change-Id: Id4b0aaabd6bc493874232c6445340787b7ca3ae6 --- ironic/drivers/modules/ipmitool.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ironic/drivers/modules/ipmitool.py b/ironic/drivers/modules/ipmitool.py index 64b71282a2..d5fbcafcc2 100644 --- a/ironic/drivers/modules/ipmitool.py +++ b/ironic/drivers/modules/ipmitool.py @@ -32,7 +32,6 @@ DRIVER. import contextlib import os import re -import stat import tempfile import time @@ -185,15 +184,15 @@ def _make_password_file(password): """ try: fd, path = tempfile.mkstemp() - os.fchmod(fd, stat.S_IRUSR | stat.S_IWUSR) with os.fdopen(fd, "w") as f: f.write(str(password)) - - yield path - utils.delete_if_exists(path) except Exception as exc: utils.delete_if_exists(path) raise exception.PasswordFileFailedToCreate(error=exc) + try: + yield path + finally: + utils.delete_if_exists(path) def _parse_driver_info(node):