diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-06-18 12:50:07 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-06-18 12:50:07 -0400 |
commit | 6b0bb7b68c86ce8d0297cb1b2d2ee8eaa5427369 (patch) | |
tree | c5f0310a1a42eedd3ae8bbb6e6a17e671c5e7b26 /cloudinit/execute.py | |
parent | 09d34f80736f336b9c556e930a8b910c8c9a341c (diff) | |
download | vyos-cloud-init-6b0bb7b68c86ce8d0297cb1b2d2ee8eaa5427369.tar.gz vyos-cloud-init-6b0bb7b68c86ce8d0297cb1b2d2ee8eaa5427369.zip |
improve the cloud-init-run-module code a bit, fix LP:#568139
568139 was fixed because the test for "always" was using "is"
instead of "=="
LP: #568139
Diffstat (limited to 'cloudinit/execute.py')
-rw-r--r-- | cloudinit/execute.py | 21 |
1 files changed, 10 insertions, 11 deletions
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 )) |