Soft Patch Panel
 help / color / mirror / Atom feed
From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH] spp-ctl: add updating for no existing sec procs
Date: Mon, 24 Jun 2019 19:45:22 +0900	[thread overview]
Message-ID: <20190624104522.25087-1-yasufum.o@gmail.com> (raw)

From: Yasufumi Ogawa <yasufum.o@gmail.com>

If secondary process is died, spp-ctl cannot find the event and does
not update list of secondary processes. As the result, spp-ctl returns
an invalid message for inquiring status.

This update is to add a method _update_proc() for updating the list run
before making the result message. In the method, spp-ctl tries to
retrieve status of all processes and remove entries of the list if it
is failed.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/spp-ctl/spp_ctl.py | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/src/spp-ctl/spp_ctl.py b/src/spp-ctl/spp_ctl.py
index ce1a2e2..93b87dd 100644
--- a/src/spp-ctl/spp_ctl.py
+++ b/src/spp-ctl/spp_ctl.py
@@ -118,13 +118,17 @@ class Controller(object):
 
     @staticmethod
     def _send_command(conn, command):
-        conn.sendall(command.encode())
-        data = conn.recv(MSG_SIZE)
-        if data and len(data) == MSG_SIZE:
-            # could not receive data at once. recieve remining data.
-            data += self._continue_recv(conn)
-        if data:
-            data = data.decode()
+        data = None
+        try:
+            conn.sendall(command.encode())
+            data = conn.recv(MSG_SIZE)
+            if data and len(data) == MSG_SIZE:
+                # could not receive data at once. recieve remining data.
+                data += self._continue_recv(conn)
+            if data:
+                data = data.decode()
+        except Exception as e:
+            LOG.info("Error: {}".format(e))
         return data
 
     def _get_proc(self, conn):
@@ -137,9 +141,26 @@ class Controller(object):
             if sec_id is not None:
                 return proc(sec_id, conn)
 
+    def _update_procs(self):
+        """Remove no existing processes from `self.procs`."""
+        removed_ids = []
+        for idx, proc in self.procs.items():
+            if proc.id != spp_proc.ID_PRIMARY:
+                try:
+                    # Check the process can be accessed. If not, go
+                    # to except block.
+                    proc.get_status()
+                except Exception as e:
+                    LOG.error(e)
+                    removed_ids.append(idx)
+        for idx in removed_ids:
+            LOG.info("Remove no existing {}:{}.".format(
+                self.procs[idx].type, self.procs[idx].id))
+            del self.procs[idx]
+
     def get_processes(self):
         procs = []
-        LOG.info('get_proesses: {}'.format(self.procs.values()))
+        self._update_procs()
         for proc in self.procs.values():
             p = {"type": proc.type}
             if proc.id != spp_proc.ID_PRIMARY:
-- 
2.17.1


                 reply	other threads:[~2019-06-24 10:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20190624104522.25087-1-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
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).