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 47D82A2EFC for ; Mon, 14 Oct 2019 20:45:06 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 417E61C11B; Mon, 14 Oct 2019 20:45:06 +0200 (CEST) Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by dpdk.org (Postfix) with ESMTP id 7ACCE1C11B for ; Mon, 14 Oct 2019 20:45:04 +0200 (CEST) Received: by mail-pl1-f196.google.com with SMTP id f21so8374075plj.10 for ; Mon, 14 Oct 2019 11:45:04 -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=U1sHhQfk1uVkCjNzTINe8aemH0OzkFiGzo2zrkV3oD8=; b=pdE9LBOP9K1U1JYWaE328TZAypYa0IqqDOnKJI6ifd1c5s51lwn/NETtJDH8y9Vjwh WVXzvmUEjk4YCdigOBstdnN9KH3J+2U3bGH/Gys+c3gNT6FPvapoB3iHLWfT3+Qa9wRK q1yPh3NhLZ/Jr7USm8y94IgwngwJI6eNpvWVT8awIdOK2X0jSPdS/KfywqZ0KGhIE9Jn eFWCIWi2dHqIm+ZvLb8e0WBJfgo1udkt4n4B8Xwj6Z19sagyBUSHQxPkS5t+oFR8/0AW pTmA3c0dTjBDAKQ06wVoQTAmMas24Gd364u+eZbLR3wy8mA1n0nJYy+RGuvQ+IUCmOiG rAXQ== 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=U1sHhQfk1uVkCjNzTINe8aemH0OzkFiGzo2zrkV3oD8=; b=LtOPbajYlr+MIAjpTp4K6GXdDt+Ifr4aTA6p711Ash0iNyPC52l8mmUw6YytyyrAe3 D+VEs9rm7hczPYP/4/qlAsg6ZhUG5L4M+f2g55JNTUZ/S+XzJDlNOmHr7mkfYxfoREvS /Khf9ALnHWFNft/vfYY0X6+sMFMl+XI5izFtcjxp7t08VBrJPs0uEaboCLttN6LBMbMt crdgEwNU7bg3Z/ZXYXv3v1dI/bKh+2GCfjTw239xIcCaE88ZT4FT0dExzYvBdsNV4sUN JFlhT42xBtUEC5MXuycicpx/dbvJ77ww8yHT23jvJuVuXVx28YcEOw60rqBKBikGV6j7 YGCw== X-Gm-Message-State: APjAAAXsZYJGVd3vX8IvKR9C62SamozjiY9cNfPAp1cl/KDU9MSMaunw eKapGYByKjGGMJNMhlvzdS4B4xvX51Y= X-Google-Smtp-Source: APXvYqy4Mvx8J4gOuZz/dkIgW8NtbIb3oReqGQTpEih49t1Yyv7AklIhUHeEsnaqqtvDm2rAL/rc/w== X-Received: by 2002:a17:902:a514:: with SMTP id s20mr30989152plq.157.1571078703537; Mon, 14 Oct 2019 11:45:03 -0700 (PDT) Received: from localhost.localdomain ([2400:4050:c8c2:de00:9046:90d6:77b7:3115]) by smtp.gmail.com with ESMTPSA id k15sm19240959pfa.65.2019.10.14.11.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 11:45:02 -0700 (PDT) From: Yasufumi Ogawa To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Tue, 15 Oct 2019 03:44:48 +0900 Message-Id: <20191014184448.26510-3-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191014184448.26510-1-yasufum.o@gmail.com> References: <20191014184448.26510-1-yasufum.o@gmail.com> Subject: [spp] [PATCH 2/2] cli: change to wait spp_primary as optional 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" For SPP CLI, waiting spp_primary launched is useful, but no need if it is already launched. This update is to change the feature as optional. SPP CLI waits primary if `--wait-pri` is given. $ python3 src/spp.py --wait-pri In terms of implementation, behaviour of waiting primary is moved from __init__() to _wait_pri_launched(). Signed-off-by: Yasufumi Ogawa --- src/cli/shell.py | 62 +++++++++++++++++++++++++++++------------------- src/cli/spp.py | 4 +++- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/cli/shell.py b/src/cli/shell.py index 2a28aa3..0de6176 100644 --- a/src/cli/shell.py +++ b/src/cli/shell.py @@ -28,7 +28,7 @@ class Shell(cmd.Cmd, object): WAIT_PRI_INTERVAL = 0.5 # sec WAIT_PRI_TIMEOUT = 20 # sec - def __init__(self, spp_cli_objs, config, use_cache=False): + def __init__(self, spp_cli_objs, config, wait_pri=False, use_cache=False): # Load default config, can be changed via `config` command try: @@ -82,30 +82,8 @@ 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! ({}[sec])'.format(cnt * self.WAIT_PRI_INTERVAL)) + if wait_pri is True: + self._wait_pri_launched() def init_spp_procs(self): """Initialize delegators of SPP processes. @@ -138,6 +116,40 @@ class Shell(cmd.Cmd, object): self.secondaries['pcap'][sec_id] = pcap.SppPcap( self.spp_ctl_cli, sec_id) + def _wait_pri_launched(self): + """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 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 + break + time.sleep(self.WAIT_PRI_INTERVAL) + print('.', end='', flush=True) + cnt += 1 + + t = cnt * self.WAIT_PRI_INTERVAL + if is_pri_ready is True: + print(' OK! ({}[sec])'.format(t)) + else: + print(' Timeout! ({}[sec])'.format(t)) + # Called everytime after running command. `stop` is returned from `do_*` # method and SPP CLI is terminated if it is True. It means that only # `do_bye` and `do_exit` return True. diff --git a/src/cli/spp.py b/src/cli/spp.py index 8cf31eb..991218d 100644 --- a/src/cli/spp.py +++ b/src/cli/spp.py @@ -21,6 +21,8 @@ def main(argv): parser.add_argument('-b', '--bind-addr', action='append', default=['%s:%s' % (api_ipaddr, api_port)], help='bind address, default=127.0.0.1:7777') + parser.add_argument('--wait-pri', action='store_true', + help='Wait for spp_primary is launched') parser.add_argument('--config', type=str, help='Config file path') args = parser.parse_args() @@ -51,7 +53,7 @@ def main(argv): spp_cli_objs.append(spp_ctl_cli) - shell = Shell(spp_cli_objs, args.config) + shell = Shell(spp_cli_objs, args.config, args.wait_pri) shell.cmdloop() shell = None -- 2.17.1