vici: Evaluate Python streamed command results, and raise CommandException
authorMartin Willi <martin@revosec.ch>
Mon, 9 Mar 2015 11:16:10 +0000 (12:16 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 18 Mar 2015 12:59:14 +0000 (13:59 +0100)
src/libcharon/plugins/vici/python/vici/session.py

index da79ecd..9f4dc5f 100644 (file)
@@ -295,7 +295,7 @@ class SessionHandler(object):
                 break
 
         if response.response_type == Packet.CMD_RESPONSE:
-            Message.deserialize(response.payload)
+            command_response = Message.deserialize(response.payload)
         else:
             raise SessionException(
                 "Unexpected response type {type}, "
@@ -316,3 +316,12 @@ class SessionHandler(object):
                     confirm=Packet.EVENT_CONFIRM,
                 )
             )
+
+        # evaluate command result, if any
+        if "success" in command_response:
+            if command_response["success"] != "yes":
+                raise CommandException(
+                    "Command failed: {errmsg}".format(
+                        errmsg=command_response["errmsg"]
+                    )
+                )