diff options
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/__init__.py | 6 | ||||
-rw-r--r-- | cloudinit/execute.py | 21 |
2 files changed, 13 insertions, 14 deletions
diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py index 04beca1e..624b8ee8 100644 --- a/cloudinit/__init__.py +++ b/cloudinit/__init__.py @@ -277,7 +277,7 @@ class CloudInit: return("%s/%s.%s" % (semdir,name,freqtok)) def sem_has_run(self,name,freq): - if freq is "always": return False + if freq == "always": return False semfile = self.sem_getpath(name,freq) if os.path.exists(semfile): return True @@ -293,7 +293,7 @@ class CloudInit: if e.errno != errno.EEXIST: raise e - if os.path.exists(semfile) and freq is not "always": + if os.path.exists(semfile) and freq != "always": return False # race condition @@ -325,7 +325,7 @@ class CloudInit: return try: if not self.sem_acquire(semname,freq): - raise Exception("Failed to acquire lock on %s\n" % semname) + raise Exception("Failed to acquire lock on %s" % semname) func(*args) except: diff --git a/cloudinit/execute.py b/cloudinit/execute.py index eb7b568c..17c3ad69 100644 --- a/cloudinit/execute.py +++ b/cloudinit/execute.py @@ -15,16 +15,15 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -def run(list,cfg): +def run(args,cfg,log): import subprocess - retcode = subprocess.call(list) - - if retcode == 0: + import traceback + try: + subprocess.check_call(args) return - - if retcode < 0: - str="Cmd terminated by signal %s\n" % -retcode - else: - str="Cmd returned %s\n" % retcode - str+=' '.join(list) - raise Exception(str) + except subprocess.CalledProcessError as e: + log.debug(traceback.format_exc(e)) + raise Exception("Cmd returned %s: %s" % ( e.returncode, args )) + except OSError as e: + log.debug(traceback.format_exc(e)) + raise Exception("Cmd failed to execute: %s" % ( args )) |