Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: ferruh.yigit@intel.com, spp@dpdk.org, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 2/2] spp-ctl: change NfvProc to parse JSON msg
Date: Tue, 15 Jan 2019 21:28:00 +0900	[thread overview]
Message-ID: <1547555280-11736-3-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1547555280-11736-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>

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

This update is to change parsing client ID of spp_nfv from plain text to
JSON as same as other secondary processes.

Parsing JSON message from secondary process is failed if it includes
null characters '\0\0\0...'. This update also includes removing them
from the message to avoid error in `json.load()` method.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/spp-ctl/spp_proc.py | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
index 282fea8..b9105d0 100644
--- a/src/spp-ctl/spp_proc.py
+++ b/src/spp-ctl/spp_proc.py
@@ -56,7 +56,9 @@ class SppProc(object):
 
     @staticmethod
     def _decode_reply(data):
-        data = json.loads(data)
+        # Remove '\0' in msg from secondary process to avoid error.
+        data = json.loads(data.replace('\0', ''))
+
         result = data["results"][0]
         if result["result"] == "error":
             msg = result["error_details"]["message"]
@@ -69,7 +71,8 @@ class SppProc(object):
             data = SppProc._decode_reply(data)
             if data["process_type"] == proc_type:
                 return data["client_id"]
-        except:
+        except Exception as e:
+            LOG.error(e)
             return None
 
 
@@ -160,16 +163,9 @@ class NfvProc(SppProc):
     def __init__(self, id, conn):
         super(NfvProc, self).__init__(TYPE_NFV, id, conn)
 
-    @staticmethod
-    def _decode_reply(data):
-        return data.strip('\0')
-
     @staticmethod
     def _decode_client_id(data):
-        try:
-            return int(NfvProc._decode_reply(data))
-        except:
-            return None
+        return SppProc._decode_client_id_common(data, TYPE_NFV)
 
     @exec_command
     def get_status(self):
-- 
2.17.1

      parent reply	other threads:[~2019-01-15 12:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-15 12:27 [spp] [PATCH 0/2] Change response of _get_client_id in spp_nfv ogawa.yasufumi
2019-01-15 12:27 ` [spp] [PATCH 1/2] spp_nfv: change _get_client_id to return JSON msg ogawa.yasufumi
2019-01-15 12:28 ` ogawa.yasufumi [this message]

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=1547555280-11736-3-git-send-email-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).