* [spp] [PATCH] controller: avoid launch with duplicated IDs
@ 2019-07-25 11:26 yasufum.o
0 siblings, 0 replies; only message in thread
From: yasufum.o @ 2019-07-25 11:26 UTC (permalink / raw)
To: spp, ferruh.yigit, yasufum.o
From: Yasufumi Ogawa <yasufum.o@gmail.com>
If secondary processes are launched with the same ID, it should be
uncontrollable. To avoid such a situation, this patch adds checking
secondary ID for `pri; launch` command.
Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
src/controller/commands/pri.py | 23 ++++++++++++++++++++---
src/controller/spp_common.py | 6 +++++-
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/controller/commands/pri.py b/src/controller/commands/pri.py
index eaf3d09..5ad0539 100644
--- a/src/controller/commands/pri.py
+++ b/src/controller/commands/pri.py
@@ -347,18 +347,27 @@ class SppPrimary(object):
elif len(tokens) == 4 and tokens[1] == 'launch':
if 'max_secondary' in cli_config.keys():
- max_secondary = int(cli_config['max_secondary']['val'])
+ max_secondary = int(
+ cli_config['max_secondary']['val'])
if tokens[2] in spp_common.SEC_TYPES:
+ used_ids = spp_common.used_sec_ids
candidates = [
- str(i+1) for i in range(max_secondary)]
+ str(i+1) for i in range(max_secondary)
+ if str(i+1) not in used_ids]
else:
logger.error(
'Error: max_secondary is not defined in config')
candidates = []
elif len(tokens) == 5 and tokens[1] == 'launch':
- candidates = self._setup_launch_opts(tokens, cli_config)
+ # Do not show candidate if given sec ID is already used.
+ # 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:
+ candidates = self._setup_launch_opts(
+ tokens, cli_config)
if not text:
completions = candidates
@@ -517,6 +526,12 @@ class SppPrimary(object):
else:
opts['app']['--client-id'] = sec_id
+ # Check if sec ID is already used.
+ if sec_id in spp_common.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.
@@ -529,6 +544,8 @@ class SppPrimary(object):
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/controller/spp_common.py b/src/controller/spp_common.py
index 6bf8b1f..5ddca46 100644
--- a/src/controller/spp_common.py
+++ b/src/controller/spp_common.py
@@ -5,14 +5,18 @@
import logging
import os
+# Type definitions.
PORT_TYPES = ['phy', 'ring', 'vhost', 'pcap', 'nullpmd']
-
SEC_TYPES = ['nfv', 'vf', 'mirror', 'pcap']
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-07-25 11:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-25 11:26 [spp] [PATCH] controller: avoid launch with duplicated IDs 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).