From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from tama50.ecl.ntt.co.jp (tama50.ecl.ntt.co.jp [129.60.39.147]) by dpdk.org (Postfix) with ESMTP id A603620BD for ; Thu, 21 Feb 2019 04:29:58 +0100 (CET) Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x1L3Tv5r024335; Thu, 21 Feb 2019 12:29:57 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 3B341EA7A24; Thu, 21 Feb 2019 12:29:57 +0900 (JST) Received: from localhost.localdomain (lobster.nslab.ecl.ntt.co.jp [129.60.13.95]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 2D58BEA793B; Thu, 21 Feb 2019 12:29:57 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp Date: Thu, 21 Feb 2019 12:27:38 +0900 Message-Id: <1550719659-14226-2-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550719659-14226-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> References: <1550719659-14226-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-TM-AS-MML: disable Subject: [spp] [PATCH 1/2] controller: fix bug terminated if no sec ID found X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Feb 2019 03:29:59 -0000 From: Yasufumi Ogawa SPP CLI is terminated if sec ID of process is not exist. For instance, it is failed and terminated if you run `nfv 1; status` without launching nfv 1. This update is to add `_is_sec_registered()` to check sec process is launched before. Signed-off-by: Yasufumi Ogawa --- src/controller/shell.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/controller/shell.py b/src/controller/shell.py index 43ef991..2568523 100644 --- a/src/controller/shell.py +++ b/src/controller/shell.py @@ -214,11 +214,26 @@ class Shell(cmd.Cmd, object): res = re.sub(r'\s?;\s?', ";", tmparg) return res + def _is_sec_registered(self, ptype, sid): + """Check secondary process is registered. + + Return True if registered, or print error and return False if not. + """ + + if sid in self.secondaries[ptype]: + return True + else: + print('"{ptype} {sid}" does not exist.'.format( + ptype=ptype, sid=sid)) + return False + def precmd(self, line): """Called before running a command It is called for checking a contents of command line. """ + if self.use_cache is False: + self.init_spp_procs() if self.recorded_file: if not ( @@ -341,7 +356,8 @@ class Shell(cmd.Cmd, object): if len(cmds) < 2: print("Required an ID and ';' before the command.") elif str.isdigit(cmds[0]): - self.secondaries['nfv'][int(cmds[0])].run(cmds[1]) + if self._is_sec_registered('nfv', int(cmds[0])): + self.secondaries['nfv'][int(cmds[0])].run(cmds[1]) else: print('Invalid command: %s' % tmparg) @@ -440,7 +456,9 @@ class Shell(cmd.Cmd, object): if len(cmds) < 2: print("Required an ID and ';' before the command.") elif str.isdigit(cmds[0]): - self.secondaries['vf'][int(cmds[0])].run(cmds[1]) + + if self._is_sec_registered('vf', int(cmds[0])): + self.secondaries['vf'][int(cmds[0])].run(cmds[1]) else: print('Invalid command: %s' % tmparg) @@ -518,7 +536,8 @@ class Shell(cmd.Cmd, object): if len(cmds) < 2: print("Required an ID and ';' before the command.") elif str.isdigit(cmds[0]): - self.secondaries['mirror'][int(cmds[0])].run(cmds[1]) + if self._is_sec_registered('mirror', int(cmds[0])): + self.secondaries['mirror'][int(cmds[0])].run(cmds[1]) else: print('Invalid command: %s' % tmparg) @@ -585,7 +604,8 @@ class Shell(cmd.Cmd, object): if len(cmds) < 2: print("Required an ID and ';' before the command.") elif str.isdigit(cmds[0]): - self.secondaries['pcap'][int(cmds[0])].run(cmds[1]) + if self._is_sec_registered('pcap', int(cmds[0])): + self.secondaries['pcap'][int(cmds[0])].run(cmds[1]) else: print('Invalid command: {}'.format(tmparg)) -- 2.17.1