Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH] cli: fix used sec ID is not updated
@ 2019-08-06  9:41 yasufum.o
  0 siblings, 0 replies; only message in thread
From: yasufum.o @ 2019-08-06  9:41 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

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

Shared variable `spp_common.used_sec_ids` was introduced to avoid
that two secondary processes are launched with duplicated sec IDs.
However, it is not updated if secondary process is terminated, and
its ID cannot be used again although the ID is released actually.

To fix the issue, change to get used sec IDs everytime it is referred
and remove nouse `spp_common.used_sec_ids`.

Fixes: 6da5038472d9 ("controller: avoid launch with duplicated IDs")

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/cli/commands/pri.py | 18 ++++++++++--------
 src/cli/spp_common.py   |  3 ---
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/cli/commands/pri.py b/src/cli/commands/pri.py
index 5ad0539..01a2522 100644
--- a/src/cli/commands/pri.py
+++ b/src/cli/commands/pri.py
@@ -351,10 +351,11 @@ class SppPrimary(object):
                             cli_config['max_secondary']['val'])
 
                     if tokens[2] in spp_common.SEC_TYPES:
-                        used_ids = spp_common.used_sec_ids
+                        used_sec_ids = [str(i) for i in self._get_sec_ids()]
                         candidates = [
                                 str(i+1) for i in range(max_secondary)
-                                if str(i+1) not in used_ids]
+                                if str(i+1) not in used_sec_ids]
+                        logger.debug(candidates)
                 else:
                     logger.error(
                             'Error: max_secondary is not defined in config')
@@ -365,7 +366,8 @@ class SppPrimary(object):
                 # Sec ID is contained as the third entry in tokens. Here is an
                 # example of tokens.
                 #   ['pri;', 'launch', 'nfv', '1', '']
-                if tokens[3] not in spp_common.used_sec_ids:
+                used_sec_ids = [str(i) for i in self._get_sec_ids()]
+                if tokens[3] not in used_sec_ids:
                     candidates = self._setup_launch_opts(
                             tokens, cli_config)
 
@@ -527,25 +529,25 @@ class SppPrimary(object):
                 opts['app']['--client-id'] = sec_id
 
         # Check if sec ID is already used.
-        if sec_id in spp_common.used_sec_ids:
+        used_sec_ids = [str(i) for i in self._get_sec_ids()]
+        if sec_id in used_sec_ids:
             print('Secondary ID {sid} is already used!'.format(
                 sid=sec_id))
             return None
 
         logger.debug('launch, {}'.format(opts))
 
-        # Send request for launch secondary.
+        # Send request for launching secondary.
         res = self.spp_ctl_cli.put('primary/launch', opts)
         if res is not None:
             error_codes = self.spp_ctl_cli.rest_common_error_codes
             if res.status_code == 204:
-                # Wait for launch secondary as best effort
+                # Wait for launching secondary as best effort
                 time.sleep(wait_time)
 
                 print('Send request to launch {ptype}:{sid}.'.format(
                     ptype=proc_type, sid=sec_id))
-                # Add used ID to avoid to launch with duplicated ID.
-                spp_common.used_sec_ids.append(sec_id)
+
             elif res.status_code in error_codes:
                 pass
             else:
diff --git a/src/cli/spp_common.py b/src/cli/spp_common.py
index 5ddca46..b717fb0 100644
--- a/src/cli/spp_common.py
+++ b/src/cli/spp_common.py
@@ -14,9 +14,6 @@ LOGFILE = 'spp_cli.log'  # name of logfile under `/src/controller/log/`
 # Current server under management of SPP CLI.
 cur_server_addr = None
 
-# Entry of used secondary IDs to avoid to launch duplicated ID.
-used_sec_ids = []
-
 # Setup logger object
 logger = logging.getLogger(__name__)
 # handler = logging.StreamHandler()
-- 
2.17.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-06  9:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-06  9:41 [spp] [PATCH] cli: fix used sec ID is not updated yasufum.o

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).