From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7CA8DA3160 for ; Sat, 12 Oct 2019 11:59:33 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6280C1EA8D; Sat, 12 Oct 2019 11:59:33 +0200 (CEST) Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by dpdk.org (Postfix) with ESMTP id 749CE1EAA6 for ; Sat, 12 Oct 2019 11:59:31 +0200 (CEST) Received: by mail-pf1-f180.google.com with SMTP id 205so7556485pfw.2 for ; Sat, 12 Oct 2019 02:59:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=gs6E8ZACar8+nk39Rldki/0rHT4SvM60rXTnamz7I0c=; b=jbXs0cyZKhuX2EsnA3WE8FTfCC5e+iYmKcqQ5iNB7tW64a1z7I/RF+RAmGOFjWQKAC TRq8wsP2Ul4Zi0ERZds+sTqnVP7RRxot+RByRfSPJgX/JPvT/dtVyC1bOhhGfC8LgWFz NMcZ5ZTmU9+ykZ2/mb6EBW7lQiT3rNe9vAzV4lRfYVfDecvE5h2DCl3oCbZCqmDFrN7u WXZGLP6WAeQjiJjd6ZwwRzTfhV4R5uXv4gLtvRYhCpN/P/t7Yq4ydtVQSzlvRzTuIPRw RcXU3TGQ/yhpaY83k7UsIungEmoTptZ+6OmlbWPRQea+0kt/b+Zlzz5vuFuUF9N+b+RC FLew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=gs6E8ZACar8+nk39Rldki/0rHT4SvM60rXTnamz7I0c=; b=sHQm+Zn38USFElABP1kbEENLgp5or1YcEtEpr2UjYFO0w5DNlhln5ylZoKi1dG45t4 aeSMQTYIxj4NN0bzi69r/ljlT8INjD2eossZrNKo/g7F97tGS7hMGQDU/Ls7BnYsH4Fo 0QQnQOx3mgFqqozcHHtU26dYsvYS/r8AuTsNDWl2tCKUSmg6rshExsg8PWmHIC/iYDPq 7X5c1RCV9va+7l49F6TCGZyyq1gX2v8ay9JNdmLq4yiEzcYGqfEC4t2qmTnQoKBAG+m/ U4sJo1f4FAI+rIZmYTAp274uk127lkX9KwT6/c0SksDdsREXIg0+iTGrT+YSU+8O/EJY ZTeg== X-Gm-Message-State: APjAAAX4z4huicyX3L0Y5gTbMKThYz1xZhjkNCZziTMyI7NpWDBcCT8c 4Ze7ZpM14dXVcoOyd1K/wRtk9CKOce4= X-Google-Smtp-Source: APXvYqyKfoOGWtCn7QTtkm9naYggD8mrFf0w0vvbIUdRnknZc/yTPSjdY9k/vecfNjZh8leLOfhMLg== X-Received: by 2002:a63:540c:: with SMTP id i12mr22215892pgb.322.1570874370260; Sat, 12 Oct 2019 02:59:30 -0700 (PDT) Received: from localhost.localdomain ([2400:4050:c8c2:de00:315b:e060:85ee:9247]) by smtp.gmail.com with ESMTPSA id 6sm10143191pgl.40.2019.10.12.02.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Oct 2019 02:59:29 -0700 (PDT) From: Yasufumi Ogawa To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Sat, 12 Oct 2019 18:59:24 +0900 Message-Id: <20191012095924.30592-2-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191012095924.30592-1-yasufum.o@gmail.com> References: <20191012095924.30592-1-yasufum.o@gmail.com> Subject: [spp] [PATCH 1/1] cli: wait for spp_primary is launched 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: , Errors-To: spp-bounces@dpdk.org Sender: "spp" This update is to add checking if spp_primary is ready for use. Interval time and timeout for checking are defined in Shell class as following. WAIT_PRI_INTERVAL = 0.5 # sec WAIT_PRI_TIMEOUT = 20 # sec This update is also including refactor for each of `print` method to use `format` method. Signed-off-by: Yasufumi Ogawa --- src/cli/shell.py | 55 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/src/cli/shell.py b/src/cli/shell.py index 925c231..7fda64d 100644 --- a/src/cli/shell.py +++ b/src/cli/shell.py @@ -18,12 +18,16 @@ from .shell_lib import common from . import spp_common from .spp_common import logger import subprocess +import time import yaml class Shell(cmd.Cmd, object): """SPP command prompt.""" + WAIT_PRI_INTERVAL = 0.5 # sec + WAIT_PRI_TIMEOUT = 20 # sec + def __init__(self, spp_cli_objs, config, use_cache=False): # Load default config, can be changed via `config` command @@ -78,6 +82,31 @@ class Shell(cmd.Cmd, object): common.set_current_server_addr( self.spp_ctl_cli.ip_addr, self.spp_ctl_cli.port) + # Wait for launching spp_primary. + print('Waiting for spp_primary is ready .', end='', flush=True) + wait_cnt = self.WAIT_PRI_TIMEOUT / self.WAIT_PRI_INTERVAL + cnt = 0 + is_pri_ready = False + while(is_pri_ready is False) and (cnt < wait_cnt): + res = self.spp_ctl_cli.get('processes') + if res is not None: + if res.status_code == 200: + pri_obj = None + try: + proc_objs = res.json() + for proc_obj in proc_objs: + if proc_obj['type'] == 'primary': + pri_obj = proc_obj + except KeyError as e: + print('Error: {} is not defined!'.format(e)) + + if pri_obj is not None: + is_pri_ready = True + time.sleep(self.WAIT_PRI_INTERVAL) + print('.', end='', flush=True) + cnt += 1 + print(' OK!') + def init_spp_procs(self): """Initialize delegators of SPP processes. @@ -129,7 +158,7 @@ class Shell(cmd.Cmd, object): """ if common.is_comment_line(line): - print("%s" % line.strip()) + print("{}".format(line.strip())) else: super(Shell, self).default(line) @@ -146,7 +175,7 @@ class Shell(cmd.Cmd, object): """Display information about connected clients.""" print('- spp-ctl:') - print(' - address: %s:%s' % (self.spp_ctl_cli.ip_addr, + print(' - address: {}:{}'.format(self.spp_ctl_cli.ip_addr, self.spp_ctl_cli.port)) res = self.spp_ctl_cli.get('processes') if res is not None: @@ -177,8 +206,8 @@ class Shell(cmd.Cmd, object): cnt = 1 for pt in ['nfv', 'vf', 'mirror', 'pcap']: for obj in sec_obj[pt]: - print(' %d: %s:%s' % - (cnt, obj['type'], obj['client-id'])) + print(' {}: {}:{}'.format( + cnt, obj['type'], obj['client-id'])) cnt += 1 except KeyError as e: print('Error: {} is not defined!'.format(e)) @@ -312,7 +341,7 @@ class Shell(cmd.Cmd, object): if self._is_sec_registered('nfv', int(cmds[0])): self.secondaries['nfv'][int(cmds[0])].run(cmds[1]) else: - print('Invalid command: %s' % tmparg) + print('Invalid command: {}'.format(tmparg)) def help_nfv(self): """Print help message of nfv command.""" @@ -373,7 +402,7 @@ class Shell(cmd.Cmd, object): if self._is_sec_registered('vf', int(cmds[0])): self.secondaries['vf'][int(cmds[0])].run(cmds[1]) else: - print('Invalid command: %s' % tmparg) + print('Invalid command: {}'.format(tmparg)) def help_vf(self): """Print help message of vf command.""" @@ -430,7 +459,7 @@ class Shell(cmd.Cmd, object): if self._is_sec_registered('mirror', int(cmds[0])): self.secondaries['mirror'][int(cmds[0])].run(cmds[1]) else: - print('Invalid command: %s' % tmparg) + print('Invalid command: {}'.format(tmparg)) def help_mirror(self): """Print help message of mirror command.""" @@ -839,7 +868,7 @@ class Shell(cmd.Cmd, object): print("No subgraph.") else: for label, subg in self.spp_topo.subgraphs.items(): - print('label: %s\tsubgraph: "%s"' % (label, subg)) + print('label: {}\tsubgraph: "{}"'.format(label, subg)) else: # add or del tokens = args_cleaned.split(' ') # Add subgraph @@ -853,18 +882,18 @@ class Shell(cmd.Cmd, object): # TODO(yasufum) add validation for subgraph self.spp_topo.subgraphs[label] = subg - print("Add subgraph '%s'" % label) + print("Add subgraph '{}'".format(label)) else: - print("Invalid syntax '%s'!" % args_cleaned) + print("Invalid syntax '{}'!".format(args_cleaned)) # Delete subgraph elif ((tokens[0] == 'del') or (tokens[0] == 'delete') or (tokens[0] == 'remove')): del(self.spp_topo.subgraphs[tokens[1]]) - print("Delete subgraph '%s'" % tokens[1]) + print("Delete subgraph '{}'".format(tokens[1])) else: - print("Ivalid subcommand '%s'!" % tokens[0]) + print("Ivalid subcommand '{}'!".format(tokens[0])) def help_topo_subgraph(self): """Print help message of topo_subgraph command.""" @@ -919,7 +948,7 @@ class Shell(cmd.Cmd, object): do_cmd = '%s.%s' % (mod_name, method_name) exec('Shell.%s = %s' % (method_name, do_cmd)) - print("Module '%s' loaded." % mod_name) + print("Module '{}' loaded.".format(mod_name)) def help_load_cmd(self): """Print help message of load_cmd command.""" -- 2.17.1