You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2013/11/01 16:28:15 UTC

[04/15] git commit: AMBARI-3655. Resource Management. Link: handle exceptional cases (Andrew Onischuk via dlysnichenko)

AMBARI-3655. Resource Management. Link: handle exceptional cases (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/451222fe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/451222fe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/451222fe

Branch: refs/heads/trunk
Commit: 451222fea021938ff950956eefcd312b8fb39fa0
Parents: a02af69
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Fri Nov 1 17:10:20 2013 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Fri Nov 1 17:10:20 2013 +0200

----------------------------------------------------------------------
 .../python/resource_management/providers/system.py    | 14 +++++++++++---
 .../src/main/python/resource_management/shell.py      |  4 ++--
 2 files changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/451222fe/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 5c27fbe..d4ff90c 100644
--- a/ambari-agent/src/main/python/resource_management/providers/system.py
+++ b/ambari-agent/src/main/python/resource_management/providers/system.py
@@ -163,14 +163,22 @@ class LinkProvider(Provider):
       if not os.path.islink(path):
         raise Fail(
           "%s trying to create a symlink with the same name as an existing file or directory" % self)
-      self.log.info("%s replacing old symlink to %s" % (self, oldpath))
+      self.log.info("%s replacing old symlink to %s" % (self.resource, oldpath))
       os.unlink(path)
-
+      
     if self.resource.hard:
+      if not os.path.exists(self.resource.to):
+        raise Fail("Failed to apply %s, linking to nonexistent location %s" % (self.resource, self.resource.to))
+      if os.path.isdir(self.resource.to):
+        raise Fail("Failed to apply %s, cannot create hard link to a directory (%s)" % (self.resource, self.resource.to))
+      
       self.log.info("Creating hard %s" % self.resource)
       os.link(self.resource.to, path)
       self.resource.updated()
     else:
+      if not os.path.exists(self.resource.to):
+        self.log.info("Warning: linking to nonexistent location %s", self.resource.to)
+        
       self.log.info("Creating symbolic %s" % self.resource)
       os.symlink(self.resource.to, path)
       self.resource.updated()
@@ -206,7 +214,7 @@ class ExecuteProvider(Provider):
     self.log.info("Executing %s" % self.resource)
     
     if self.resource.path != []:
-      self.resource.environment['PATH'] = ":".join(self.resource.path) 
+      self.resource.environment['PATH'] = os.pathsep.join(self.resource.path) 
     
     for i in range (0, self.resource.tries):
       try:

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/451222fe/ambari-agent/src/main/python/resource_management/shell.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/shell.py b/ambari-agent/src/main/python/resource_management/shell.py
index 13bb8a0..0ebba09 100644
--- a/ambari-agent/src/main/python/resource_management/shell.py
+++ b/ambari-agent/src/main/python/resource_management/shell.py
@@ -32,8 +32,8 @@ def _call(command, logoutput=False, throw_on_failure=True,
                           cwd=cwd, env=env, shell=shell,
                           preexec_fn=preexec_fn)
   
-  out = proc.communicate()[0] if not proc.stdout.closed  else ""
-  code = proc.wait()
+  out = proc.communicate()[0]
+  code = proc.returncode
   
   if logoutput and out and out!="":
     log.info(out)