Pass errors from cmd.run to state

Change-Id: Ic8d23c5ae9b3a7a710c36acf7ada8c1ca9ea436d
diff --git a/_modules/helm.py b/_modules/helm.py
index f6d7088..e140087 100644
--- a/_modules/helm.py
+++ b/_modules/helm.py
@@ -5,6 +5,16 @@
 HELM_HOME = '/srv/helm/home'
 LOG = logging.getLogger(__name__)
 
+def ok_or_output(cmd, prefix=None):
+    ret = __salt__['cmd.run_all'](**cmd)
+    if ret['retcode'] == 0:
+        return None
+    msg = "Stdout:\n{0[stdout]}\nStderr:\n{0[stderr]}".format(ret)
+    if prefix:
+        msg = prefix + ':\n' + msg
+    return msg
+
+
 def _helm_cmd(*args):
     return {
         'cmd': ('helm',) + args,
@@ -28,12 +38,12 @@
     if values is not None:
         cmd['stdin'] = yaml.serialize(values, default_flow_style=False)
     LOG.debug('Creating release with args: %s', cmd)
-    return __salt__['cmd.retcode'](**cmd) == 0
+    return ok_or_output(cmd, 'Failed to create release "{}"'.format(name))
 
 
 def release_delete(name):
     cmd = _helm_cmd('delete', '--purge', name)
-    return __salt__['cmd.retcode'](**cmd) == 0
+    return ok_or_output(cmd, 'Failed to delete release "{}"'.format(name))
 
 
 def release_upgrade(name, namespace, chart_name, version=None, values=None):
@@ -47,7 +57,7 @@
     if values is not None:
         cmd['stdin'] = yaml.serialize(values, default_flow_style=False)
     LOG.debug('Upgrading release with args: %s', cmd)
-    return __salt__['cmd.retcode'](**cmd) == 0
+    return ok_or_output(cmd, 'Failed to upgrade release "{}"'.format(name))
 
 
 def get_values(name):
diff --git a/_states/helm_release.py b/_states/helm_release.py
index b3b4fac..2177bcd 100644
--- a/_states/helm_release.py
+++ b/_states/helm_release.py
@@ -16,10 +16,10 @@
 def present(name, chart_name, namespace, version=None, values=None):
     exists =  __salt__['helm.release_exists'](name, namespace)
     if not exists:
-        result = __salt__['helm.release_create'](
+        err = __salt__['helm.release_create'](
             name, namespace, chart_name, version, values)
-        if not result:
-            return failure(name, 'Failed to create release "{}"'.format(name))
+        if err:
+            return failure(name, err)
         return {
             'name': name,
             'changes': {name: 'CREATED'},
@@ -28,10 +28,10 @@
         }
 
     old_values = __salt__['helm.get_values'](name)
-    result = __salt__['helm.release_upgrade'](
+    err = __salt__['helm.release_upgrade'](
         name, namespace, chart_name, version, values)
-    if not result:
-        return failure(name, 'Failed to create release "{}"'.format(name))
+    if err:
+        return failure(name, err)
 
     new_values = __salt__['helm.get_values'](name)
     if new_values == old_values:
@@ -63,9 +63,9 @@
             'result': True,
             'comment': 'Release "{}" doesn\'t exist'.format(name),
         }
-    result = __salt__['helm.release_delete'](name)
-    if not result:
-        return failure(name, 'Failed to delete release "{}"'.format(name))
+    err = __salt__['helm.release_delete'](name)
+    if err:
+        return failure(name, err)
     return {
         'name': name,
         'changes': {name: 'DELETED'},