Soft Patch Panel
 help / color / Atom feed
From: Yasufumi Ogawa <yasufum.o@gmail.com>
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 4/7] cli: fix error in asking ports if no pri forwarder
Date: Thu, 16 Jan 2020 21:02:32 +0900
Message-ID: <20200116120235.31550-5-yasufum.o@gmail.com> (raw)
In-Reply-To: <20200116120235.31550-1-yasufum.o@gmail.com>

SPP CLI retrieves status of spp_primary not only for `status` command
but also others, such as `add` or `del`, to check the result of the
commands. For the commands other than `status`, SPP CLI is terminated
if it retrieves the status and forwarder thread is not running because
SPP CLI expects to receive the status including 'forwarder' attribute,
but does not exist.

This update is to fix the issue. SPP CLI tells you that forwarder thread
is not running for the cases.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/cli/commands/pri.py | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/src/cli/commands/pri.py b/src/cli/commands/pri.py
index 1443e9e..f7d86bb 100644
--- a/src/cli/commands/pri.py
+++ b/src/cli/commands/pri.py
@@ -263,6 +263,7 @@ class SppPrimary(object):
                 pass
             else:
                 print('Error: unknown response for get_ports.')
+            return None
 
     def _get_patches(self):
         """Get all of patched ports as a list of dicts.
@@ -285,6 +286,7 @@ class SppPrimary(object):
                 pass
             else:
                 print('Error: unknown response for get_patches.')
+            return None
 
     def _get_ports_and_patches(self):
         """Get all of ports and patches at once.
@@ -309,7 +311,8 @@ class SppPrimary(object):
             elif res.status_code in error_codes:
                 pass
             else:
-                print('Error: unknown response 3.')
+                print('Error: unknown response.')
+            return None, None
 
     def _get_patched_ports(self):
         """Get all of patched ports as a list.
@@ -619,8 +622,16 @@ class SppPrimary(object):
         if len(sub_tokens) < 3:
             tmp_ary = []
 
+            # Update to current status
             self.ports, self.patches = self._get_ports_and_patches()
 
+            if self.ports is None:
+                self.ports, self.patches = [], []
+                return []
+            elif self.patches is None:
+                self.ports, self.patches = [], []
+                return []
+
             # Patched ports should not be included in the candidate of del.
             patched_ports = self._get_patched_ports()
 
@@ -635,7 +646,7 @@ class SppPrimary(object):
                         else:
                             tmp_ary.append(kw)
 
-            # Physical port cannot be removed.
+            # Exclude phy ports which cannot be deleted.
             for p in tmp_ary:
                 if not p.startswith('phy:'):
                     res.append(p)
@@ -653,6 +664,13 @@ class SppPrimary(object):
 
             self.ports, self.patches = self._get_ports_and_patches()
 
+            if self.ports is None:
+                self.ports, self.patches = [], []
+                return []
+            elif self.patches is None:
+                self.ports, self.patches = [], []
+                return []
+
             # Get patched ports of src and dst to be used for completion.
             src_ports = []
             dst_ports = []
@@ -735,8 +753,6 @@ class SppPrimary(object):
         elif params[0] in self.ports:
             print("'%s' is already added." % params[0])
         else:
-            self.ports = self._get_ports()
-
             req_params = {'action': 'add', 'port': params[0]}
 
             res = self.spp_ctl_cli.put('primary/ports', req_params)
@@ -749,6 +765,11 @@ class SppPrimary(object):
                 else:
                     print('Error: unknown response for add.')
 
+            self.ports = self._get_ports()  # update to current status
+            if self.ports is None:
+                print('Cannot retrieve ports from spp_primary')
+                self.ports = []
+
     def _run_del(self, params):
         """Run `del` command."""
 
@@ -757,8 +778,6 @@ class SppPrimary(object):
         elif 'phy:' in params[0]:
             print("Cannot delete phy port '%s'." % params[0])
         else:
-            self.patches = self._get_patches()
-
             # Patched ports should not be deleted.
             patched_ports = self._get_patched_ports()
 
@@ -776,6 +795,11 @@ class SppPrimary(object):
                     else:
                         print('Error: unknown response for del.')
 
+            self.patches = self._get_patches()  # update to current status
+            if self.patches is None:
+                print('Cannot retrieve patches from spp_primary')
+                self.patches = []
+
     def _run_forward_or_stop(self, cmd):
         """Run `forward` or `stop` command."""
 
-- 
2.17.1


  parent reply index

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16 12:02 [spp] [PATCH 0/7] Update for fixing errors for CLI Yasufumi Ogawa
2020-01-16 12:02 ` [spp] [PATCH 1/7] shared: revise vdev prefixs of pcap and nullpmd Yasufumi Ogawa
2020-01-16 12:02 ` [spp] [PATCH 2/7] shared: fix wrong port_type in parsing dev name Yasufumi Ogawa
2020-01-16 12:02 ` [spp] [PATCH 3/7] cli: add filter for running pri commands Yasufumi Ogawa
2020-01-16 12:02 ` Yasufumi Ogawa [this message]
2020-01-16 12:02 ` [spp] [PATCH 5/7] cli: fix terminated if spp_primary is not running Yasufumi Ogawa
2020-01-16 12:02 ` [spp] [PATCH 6/7] cli: move logfile to under project log dir Yasufumi Ogawa
2020-01-16 12:02 ` [spp] [PATCH 7/7] cli: fix parsing forward and stop commands Yasufumi Ogawa

Reply instructions:

You may reply publically 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=20200116120235.31550-5-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --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

Soft Patch Panel

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/spp/0 spp/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 spp spp/ http://inbox.dpdk.org/spp \
		spp@dpdk.org
	public-inbox-index spp


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.spp


AGPL code for this site: git clone https://public-inbox.org/ public-inbox