* [spp] [PATCH 1/2] spp_nfv: change _get_client_id to return JSON msg
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 ` ogawa.yasufumi
2019-01-15 12:28 ` [spp] [PATCH 2/2] spp-ctl: change NfvProc to parse " ogawa.yasufumi
1 sibling, 0 replies; 3+ messages in thread
From: ogawa.yasufumi @ 2019-01-15 12:27 UTC (permalink / raw)
To: ferruh.yigit, spp, ogawa.yasufumi
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Spp_nfv returns its client ID as plain text. This update is to change
the format to JSON as same as other secondary processes.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/nfv/commands.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/nfv/commands.h b/src/nfv/commands.h
index 54e0f21..7dbe25b 100644
--- a/src/nfv/commands.h
+++ b/src/nfv/commands.h
@@ -6,6 +6,7 @@
#ifndef _NFV_COMMANDS_H_
#define _NFV_COMMANDS_H_
+#include "shared/common.h"
#include "shared/secondary/add_port.h"
#include "shared/secondary/utils.h"
@@ -180,7 +181,10 @@ parse_command(char *str)
} else if (!strcmp(token_list[0], "_get_client_id")) {
memset(str, '\0', MSG_SIZE);
- sprintf(str, "%d", client_id);
+ sprintf(str, "{%s:%s,%s:%d,%s:%s}",
+ "\"results\"", "[{\"result\":\"success\"}]",
+ "\"client_id\"", client_id,
+ "\"process_type\"", "\"nfv\"");
} else if (!strcmp(token_list[0], "_set_client_id")) {
int id;
--
2.17.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [spp] [PATCH 2/2] spp-ctl: change NfvProc to parse JSON msg
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
1 sibling, 0 replies; 3+ messages in thread
From: ogawa.yasufumi @ 2019-01-15 12:28 UTC (permalink / raw)
To: ferruh.yigit, spp, ogawa.yasufumi
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
^ permalink raw reply [flat|nested] 3+ messages in thread