Skip to content

Commit

Permalink
Do not raise exception when path already exists
Browse files Browse the repository at this point in the history
Isi sdk will report error when the path to create already exists.
This change is to cache the error and not raise an exception.
  • Loading branch information
root authored and shirleylxie committed Apr 16, 2020
1 parent 7abfe85 commit bbb7b72
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/isilon_hadoop_tools/directories.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import logging
import posixpath

import isilon_hadoop_tools.onefs
from isilon_hadoop_tools import IsilonHadoopToolError


__all__ = [
# Exceptions
'DirectoriesError',
Expand Down Expand Up @@ -62,7 +62,13 @@ def create_directories(self, directories, setup=None, mkdir=None, chmod=None, ch
for directory in directories:
path = posixpath.join(zone_hdfs, directory.path.lstrip(posixpath.sep))
LOGGER.info("mkdir '%s%s'", zone_root, path)
(mkdir or self.onefs.mkdir)(path, directory.mode, zone=self.onefs_zone)
try:
(mkdir or self.onefs.mkdir)(path, directory.mode, zone=self.onefs_zone)
except isilon_hadoop_tools.onefs.APIError as exc:
if exc.dir_path_already_exists_error():
LOGGER.warning("%s%s already exists. ", zone_root, path)
else:
raise
LOGGER.info("chmod '%o' '%s%s'", directory.mode, zone_root, path)
(chmod or self.onefs.chmod)(path, directory.mode, zone=self.onefs_zone)
LOGGER.info("chown '%s:%s' '%s%s'", directory.owner, directory.group, zone_root, path)
Expand Down
10 changes: 10 additions & 0 deletions src/isilon_hadoop_tools/onefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ class APIError(_BaseAPIError):
user_not_found_error_format = "Failed to find user for 'USER:{0}': No such user"
user_unresolvable_error_format = "Could not resolve user {0}"
zone_not_found_error_format = 'Access Zone "{0}" not found.'
dir_path_already_exists_error_format = \
'Unable to create directory as requested -- container already exists'
# pylint: enable=invalid-name

def __str__(self):
Expand Down Expand Up @@ -459,6 +461,14 @@ def zone_not_found_error(self, zone_name):
)
)

def dir_path_already_exists_error(self):
"""Returns True if the exception contains a directory path already exist error."""
return any(
self.filtered_errors(
lambda error: error['message'] == self.dir_path_already_exists_error_format,
)
)


class MissingLicenseError(OneFSError):
"""This Exception is raised when a license that is expected to exist cannot be found."""
Expand Down

0 comments on commit bbb7b72

Please sign in to comment.