Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp, spp@dpdk.org
Subject: [spp] [PATCH] spp-ctl: fix error in parsing replied message
Date: Wed, 16 Jan 2019 15:12:42 +0900	[thread overview]
Message-ID: <20190116061242.7325-1-ogawa.yasufumi@lab.ntt.co.jp> (raw)

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

Spp-ctl expects a response of command from secondary process is JSON
format for checking the result, but it is not a constraint. However,
parsing is failed and terminated if it is not JSON because of
inappropriate error handling. This update is to add a exception handler
of JSONDecodeError and not terminated.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/spp-ctl/spp_ctl.py    |  1 -
 src/spp-ctl/spp_proc.py   | 19 ++++++++++++++-----
 src/spp-ctl/spp_webapi.py | 15 +--------------
 3 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/src/spp-ctl/spp_ctl.py b/src/spp-ctl/spp_ctl.py
index f6c00fb..c4dd4b2 100644
--- a/src/spp-ctl/spp_ctl.py
+++ b/src/spp-ctl/spp_ctl.py
@@ -6,7 +6,6 @@ eventlet.monkey_patch()
 
 import argparse
 import errno
-import json
 import logging
 import socket
 import subprocess
diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
index b9105d0..19a5e53 100644
--- a/src/spp-ctl/spp_proc.py
+++ b/src/spp-ctl/spp_proc.py
@@ -57,12 +57,21 @@ class SppProc(object):
     @staticmethod
     def _decode_reply(data):
         # Remove '\0' in msg from secondary process to avoid error.
-        data = json.loads(data.replace('\0', ''))
+        try:
+            data = json.loads(data.replace('\0', ''))
+
+            if "results" in data.keys():  # msg ffrom spp_vf
+                result = data["results"][0]
+                if result["result"] == "error":
+                    msg = result["error_details"]["message"]
+                    raise bottle.HTTPError(400, "command error: %s" % msg)
+
+            return data
+
+        except json.JSONDecodeError as e:
+            LOG.error("'{}' in JSON decoding.".format(e))
 
-        result = data["results"][0]
-        if result["result"] == "error":
-            msg = result["error_details"]["message"]
-            raise bottle.HTTPError(400, "command error: %s" % msg)
+        LOG.debug("Reply msg is not JSON format '{data}'.".format(**locals()))
         return data
 
     @staticmethod
diff --git a/src/spp-ctl/spp_webapi.py b/src/spp-ctl/spp_webapi.py
index d88d7a9..0fd2f2a 100644
--- a/src/spp-ctl/spp_webapi.py
+++ b/src/spp-ctl/spp_webapi.py
@@ -378,21 +378,8 @@ class V1NFVHandler(BaseHandler):
         self.route('/<sec_id:int>/patches', 'DELETE',
                    callback=self.nfv_patch_del)
 
-    def convert_nfv_info(self, sec_id, data):
-        nfv = {}
-
-        # spp_nfv returns status info in JSON format. 'null' means
-        # that it has no dst port.
-        #   {"status":"idling","ports":[{"src":"phy:0","dst":"null"},...
-
-        try:
-            nfv = json.loads(data)
-        except json.JSONDecodeError as e:
-            print("%s" % e)
-        return nfv
-
     def nfv_get(self, proc):
-        return self.convert_nfv_info(proc.id, proc.get_status())
+        return proc.get_status()
 
     def _validate_nfv_forward(self, body):
         if 'action' not in body:
-- 
2.17.1

                 reply	other threads:[~2019-01-16  6:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190116061242.7325-1-ogawa.yasufumi@lab.ntt.co.jp \
    --to=ogawa.yasufumi@lab.ntt.co.jp \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).