AMBARI-3654. Directory: allow to ignore_failures, check exceptional cases, support recursive deleting (Andrew Onischuk via dlysnichenko)
Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/a02af69f Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/a02af69f Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/a02af69f Branch: refs/heads/trunk Commit: a02af69f9b7c77ad7aa9c4fc689ed1ea7d38d02b Parents: 99ac88e Author: Lisnichenko Dmitro <[email protected]> Authored: Fri Nov 1 17:08:31 2013 +0200 Committer: Lisnichenko Dmitro <[email protected]> Committed: Fri Nov 1 17:08:31 2013 +0200 ---------------------------------------------------------------------- .../src/main/python/resource_management/environment.py | 8 +++++++- .../main/python/resource_management/providers/system.py | 12 +++++++++--- .../main/python/resource_management/resources/system.py | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a02af69f/ambari-agent/src/main/python/resource_management/environment.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/resource_management/environment.py b/ambari-agent/src/main/python/resource_management/environment.py index 30bb728..c1f84c5 100644 --- a/ambari-agent/src/main/python/resource_management/environment.py +++ b/ambari-agent/src/main/python/resource_management/environment.py @@ -118,7 +118,13 @@ class Environment(object): continue for action in resource.action: - self.run_action(resource, action) + if not resource.ignore_failures: + self.run_action(resource, action) + else: + try: + self.run_action(resource, action) + except Exception: + pass # Run delayed actions while self.delayed_actions: http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a02af69f/ambari-agent/src/main/python/resource_management/providers/system.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/resource_management/providers/system.py b/ambari-agent/src/main/python/resource_management/providers/system.py index d366942..5c27fbe 100644 --- a/ambari-agent/src/main/python/resource_management/providers/system.py +++ b/ambari-agent/src/main/python/resource_management/providers/system.py @@ -4,6 +4,7 @@ import grp import os import pwd import time +import shutil from resource_management import shell from resource_management.base import Fail from resource_management.providers import Provider @@ -132,6 +133,9 @@ class DirectoryProvider(Provider): else: os.mkdir(path, self.resource.mode or 0755) self.resource.updated() + + if not os.path.isdir(path): + raise Fail("Applying %s failed, file %s already exists" % (self.resource, path)) if _ensure_metadata(path, self.resource.owner, self.resource.group, mode=self.resource.mode, log=self.log): @@ -140,9 +144,11 @@ class DirectoryProvider(Provider): def action_delete(self): path = self.resource.path if os.path.exists(path): - self.log.info("Removing directory %s" % self.resource) - os.rmdir(path) - # TODO: recursive + if not os.path.isdir(path): + raise Fail("Applying %s failed, %s is not a directory" % (self.resource, path)) + + self.log.info("Removing directory %s and all its content" % self.resource) + shutil.rmtree(path) self.resource.updated() http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a02af69f/ambari-agent/src/main/python/resource_management/resources/system.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/resource_management/resources/system.py b/ambari-agent/src/main/python/resource_management/resources/system.py index 7765102..e53a569 100644 --- a/ambari-agent/src/main/python/resource_management/resources/system.py +++ b/ambari-agent/src/main/python/resource_management/resources/system.py @@ -23,7 +23,7 @@ class Directory(Resource): mode = ResourceArgument() owner = ResourceArgument() group = ResourceArgument() - recursive = BooleanArgument(default=False) + recursive = BooleanArgument(default=False) # this work for 'create', 'delete' is anyway recursive actions = Resource.actions + ["create", "delete"]
