Merge "Use method delete_if_exists from oslo.utils"
This commit is contained in:
commit
e6e7d4a523
@ -135,18 +135,6 @@ def random_alnum(size=32):
|
|||||||
return ''.join(random.choice(characters) for _ in range(size))
|
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):
|
def is_valid_boolstr(val):
|
||||||
"""Check if the provided string is a valid bool string or not."""
|
"""Check if the provided string is a valid bool string or not."""
|
||||||
boolstrs = ('true', 'false', 'yes', 'no', 'y', 'n', '1', '0')
|
boolstrs = ('true', 'false', 'yes', 'no', 'y', 'n', '1', '0')
|
||||||
|
@ -29,11 +29,11 @@ import time
|
|||||||
from ironic_lib import utils as ironic_utils
|
from ironic_lib import utils as ironic_utils
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_service import loopingcall
|
from oslo_service import loopingcall
|
||||||
|
from oslo_utils import fileutils
|
||||||
from oslo_utils import netutils
|
from oslo_utils import netutils
|
||||||
|
|
||||||
from ironic.common import exception
|
from ironic.common import exception
|
||||||
from ironic.common.i18n import _, _LE, _LW
|
from ironic.common.i18n import _, _LE, _LW
|
||||||
from ironic.common import utils
|
|
||||||
from ironic.conf import CONF
|
from ironic.conf import CONF
|
||||||
|
|
||||||
|
|
||||||
@ -117,13 +117,13 @@ def make_persistent_password_file(path, password):
|
|||||||
"""Writes a file containing a password until deleted."""
|
"""Writes a file containing a password until deleted."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
utils.delete_if_exists(path)
|
fileutils.delete_if_exists(path)
|
||||||
with open(path, 'wb') as file:
|
with open(path, 'wb') as file:
|
||||||
os.chmod(path, 0o600)
|
os.chmod(path, 0o600)
|
||||||
file.write(password.encode())
|
file.write(password.encode())
|
||||||
return path
|
return path
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
utils.delete_if_exists(path)
|
fileutils.delete_if_exists(path)
|
||||||
raise exception.PasswordFileFailedToCreate(error=e)
|
raise exception.PasswordFileFailedToCreate(error=e)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user