Use method delete_if_exists from oslo.utils

oslo.utils provides same method[1] in module fileutils,
and just use it.

TrivialFix

[1]9981276fe6/oslo_utils/fileutils.py (L49-L60)

Change-Id: Ic83cfa28f96f97af17f19eda950fc6709ce12760
This commit is contained in:
ChangBo Guo(gcb) 2016-09-29 13:53:20 +08:00
parent c445c19285
commit 8279341149
2 changed files with 3 additions and 15 deletions

View File

@ -135,18 +135,6 @@ def random_alnum(size=32):
return ''.join(random.choice(characters) for _ in range(size))
def delete_if_exists(pathname):
"""delete a file, but ignore file not found error."""
try:
os.unlink(pathname)
except OSError as e:
if e.errno == errno.ENOENT:
return
else:
raise
def is_valid_boolstr(val):
"""Check if the provided string is a valid bool string or not."""
boolstrs = ('true', 'false', 'yes', 'no', 'y', 'n', '1', '0')

View File

@ -29,11 +29,11 @@ import time
from ironic_lib import utils as ironic_utils
from oslo_log import log as logging
from oslo_service import loopingcall
from oslo_utils import fileutils
from oslo_utils import netutils
from ironic.common import exception
from ironic.common.i18n import _, _LE, _LW
from ironic.common import utils
from ironic.conf import CONF
@ -117,13 +117,13 @@ def make_persistent_password_file(path, password):
"""Writes a file containing a password until deleted."""
try:
utils.delete_if_exists(path)
fileutils.delete_if_exists(path)
with open(path, 'wb') as file:
os.chmod(path, 0o600)
file.write(password.encode())
return path
except Exception as e:
utils.delete_if_exists(path)
fileutils.delete_if_exists(path)
raise exception.PasswordFileFailedToCreate(error=e)