[modules] don't ignore errors in create and configure
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 04 Mar 2016 12:29:42 +0100
changeset 76 49a436f14557
parent 75 6bd9ee482905
child 77 62d8dbe7c966
[modules] don't ignore errors in create and configure Try to avoid reporting success when something didn't work.
_modules/cubicweb.py
--- a/_modules/cubicweb.py	Fri Mar 04 12:27:32 2016 +0100
+++ b/_modules/cubicweb.py	Fri Mar 04 12:29:42 2016 +0100
@@ -23,7 +23,7 @@
 except ImportError:
     # legacy  < 2015.8
     from salt.utils import strip_proto
-from salt.exceptions import CommandNotFoundError
+from salt.exceptions import CommandNotFoundError, CommandExecutionError
 
 log = logging.getLogger(__name__)
 
@@ -216,9 +216,11 @@
         cubes = ",".join(cubes)
     cmd = ('cubicweb-ctl create --automatic --no-db-create --config={0} '
            '{1} {2}').format(install_type, cubes, name)
-    result1 = __salt__['cmd.run'](cmd)
-    log.debug('creation: {0}: {1} => {2!r}'.format(name, cubes, result1))
-
+    ret = __salt__['cmd.run_all'](cmd)
+    log.debug('creation: {0}: {1} => {2!r}'.format(name, cubes, ret['stdout']))
+    if ret['retcode']:
+        raise CommandExecutionError(ret['stderr'])
+    result1 = ret['stdout']
     result2 = configure(name, **kwargs)
     return result1 + result2
 
@@ -264,10 +266,12 @@
     if dbcfg:
         cmd += ' --db={0}'.format(','.join(dbcfg))
     cmd += ' {0}'.format(name)
-    result = __salt__['cmd.run'](cmd)
+    result = __salt__['cmd.run_all'](cmd)
     log.debug('configure {0}: {1!r}'.format(name, cmd))
-    log.debug('==> {0!r}'.format(result))
-    return result
+    log.debug('==> {0!r}'.format(result['stdout']))
+    if result['retcode']:
+        raise CommandExecutionError(result['stderr'])
+    return result['stdout']
 
 def initialize(name, drop=False):
     '''Initialize the database for an instance