[spp] [PATCH 2/2] spp-ctl: change NfvProc to parse JSON msg
ogawa.yasufumi at lab.ntt.co.jp
ogawa.yasufumi at lab.ntt.co.jp
Tue Jan 15 13:28:00 CET 2019
From: Yasufumi Ogawa <ogawa.yasufumi at 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 at 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
More information about the spp
mailing list