From bbb7b7213562137fd38244a73edc66767c4e289c Mon Sep 17 00:00:00 2001 From: root Date: Wed, 15 Apr 2020 10:30:05 +0000 Subject: [PATCH] Do not raise exception when path already exists Isi sdk will report error when the path to create already exists. This change is to cache the error and not raise an exception. --- src/isilon_hadoop_tools/directories.py | 10 ++++++++-- src/isilon_hadoop_tools/onefs.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/isilon_hadoop_tools/directories.py b/src/isilon_hadoop_tools/directories.py index faeb6c3..831ac1a 100644 --- a/src/isilon_hadoop_tools/directories.py +++ b/src/isilon_hadoop_tools/directories.py @@ -6,9 +6,9 @@ import logging import posixpath +import isilon_hadoop_tools.onefs from isilon_hadoop_tools import IsilonHadoopToolError - __all__ = [ # Exceptions 'DirectoriesError', @@ -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) diff --git a/src/isilon_hadoop_tools/onefs.py b/src/isilon_hadoop_tools/onefs.py index 509d2fa..6018a86 100644 --- a/src/isilon_hadoop_tools/onefs.py +++ b/src/isilon_hadoop_tools/onefs.py @@ -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): @@ -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."""