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 BE92BA0352 for ; Thu, 16 Jan 2020 13:02:47 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B521B1C2AB; Thu, 16 Jan 2020 13:02:47 +0100 (CET) Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by dpdk.org (Postfix) with ESMTP id 762211C2AB for ; Thu, 16 Jan 2020 13:02:46 +0100 (CET) Received: by mail-pf1-f178.google.com with SMTP id i23so10131119pfo.2 for ; Thu, 16 Jan 2020 04:02:46 -0800 (PST) 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=82fIzyb5Pvu2EQN7Fi84EW0AZwfAyGxJEyBWAwtH59E=; b=Lf3A+Q0OS79v8ZN5U5pnn+pHnwzPJIYApwJ9yzuzfBz2Prit9+FG/Q6WZpmi6grM+1 0ZjYl+DkIlygBY07jN1+gTx1JA30om/WyFCem0lYGhPi0bULsPrWRuKVzuk+e7Dczliq Y1VJB8YOHeM3jc8sIaOnctseKIniGKcwDpaZqfOwgsCMODJtraeZBDzNhUGxKGMjeQcr /jANrDdi7sA3nD2vezzumiwtaDxFOUkAz2QOxglwB9ljZwXs4y3TNVwMBxz6CMuza11E Uo5ULLsb8W8Lg3sXrX/J856evls+4sdgKWp4UKPTi6OxHFhzbrwVO9JyXDSMPM+y7ykX ix4Q== 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=82fIzyb5Pvu2EQN7Fi84EW0AZwfAyGxJEyBWAwtH59E=; b=J33ohm1f0pwvd0v8WrqP9XGGOWjMB8aPZmTozB2YhQQr4Qq4/RPYVq0/nhcVwAe2kh 8awbm4Ym+DLmXDVVDhsQMoV7w719EMKFiXdwPgkoJWYBHPHc0CiFqPV0VqTHROimJJqo Om8ckNgxsjttgr25SUYJJHoZJKwAqnCT4CG2D5vMPRK3TejKIfP+elX6DjioGRIAqxTr ZxNNDSwmg5p5KTynUmkq6tEcm+IMj9VYsk6T26Df4M/4MzZAh4hxqQPPn/DfIKnpb1JC D9S7NtKObauz1zdx9w8sIsK+FQSQrGTaHW6c/goibCzFjG9C8JLD/r+ntF8s0f1ddSz4 BDsw== X-Gm-Message-State: APjAAAWinbZnfhs/ooKWw5HrANANsrkPPQE6Fd82ZztvT7dUIqFkt7FK C0zmJgWZv3UnYVs5pT+DuVdOOcU3 X-Google-Smtp-Source: APXvYqwNJ/9LwSFQ5Vx7uStLVnVy92GE268/hhWoiPSTFOJm7P2ymXXsJ6rPZZaig/SCH4GwHgZBqw== X-Received: by 2002:aa7:87cf:: with SMTP id i15mr36925064pfo.114.1579176165547; Thu, 16 Jan 2020 04:02:45 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c8c2:de00:98b6:858d:e282:492e]) by smtp.gmail.com with ESMTPSA id u7sm25392890pfh.128.2020.01.16.04.02.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2020 04:02:45 -0800 (PST) From: Yasufumi Ogawa To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Thu, 16 Jan 2020 21:02:31 +0900 Message-Id: <20200116120235.31550-4-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200116120235.31550-1-yasufum.o@gmail.com> References: <20200116120235.31550-1-yasufum.o@gmail.com> Subject: [spp] [PATCH 3/7] cli: add filter for running pri commands 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_primary, some of methods such as _run_add(), _run_del() or so, should not be executed if forwarder thread is not running. This update is to add util function for checking the forwarder is running, and refuse required operation if the forwarder is not running. Signed-off-by: Yasufumi Ogawa --- src/cli/commands/pri.py | 59 ++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/src/cli/commands/pri.py b/src/cli/commands/pri.py index 9212897..1443e9e 100644 --- a/src/cli/commands/pri.py +++ b/src/cli/commands/pri.py @@ -46,6 +46,20 @@ class SppPrimary(object): temp = temp + "{vhost_cli}" self.launch_template = temp + def _do_if_forwarder_exists(self, status, func, params): + """Execute command of func if forwarder thread is existing. + + Params status is a json object, func is a method of this class such + as _run_add() or _run_del() or so, and params is a set of given + parameters. + """ + + # It includes `forwarder` if spp_primary runs a forwarder thread. + if 'forwarder' in status: + func(params) + else: + print('No forwarder is running.') + def run(self, cmd, cli_config): """Called from do_pri() to Send command to primary process.""" @@ -60,11 +74,15 @@ class SppPrimary(object): # use short name common_err_codes = self.spp_ctl_cli.rest_common_error_codes + # Get status here for inspecting if forwarder exists. Do not run + # command such as `add` or `del` if forwarder does not exist. + res = self.spp_ctl_cli.get('primary/status') + status = res.json() + if subcmd == 'status': - res = self.spp_ctl_cli.get('primary/status') if res is not None: if res.status_code == 200: - self.print_status(res.json()) + self.print_status(status) elif res.status_code in common_err_codes: # Print default error message pass @@ -72,16 +90,17 @@ class SppPrimary(object): print('Error: unknown response from status.') elif subcmd == 'add': - self._run_add(params) + self._do_if_forwarder_exists(status, self._run_add, params) elif subcmd == 'del': - self._run_del(params) + self._do_if_forwarder_exists(status, self._run_del, params) elif subcmd == 'forward' or cmd == 'stop': - self._run_forward_or_stop(cmd) + self._do_if_forwarder_exists(status, + self._run_forward_or_stop, params) elif subcmd == 'patch': - self._run_patch(params) + self._do_if_forwarder_exists(status, self._run_patch, params) elif subcmd == 'launch': wait_time = float(cli_config['sec_wait_launch']['val']) @@ -217,8 +236,10 @@ class SppPrimary(object): temp = '{s6}{rid:2} {rx:10} {tx:10} {rx_d:10} {tx_d:10}' for rports in json_obj['ring_ports']: print(temp.format(s6=sep*6, - rid=rports['id'], rx=rports['rx'], tx=rports['tx'], - rx_d=rports['rx_drop'], tx_d=rports['tx_drop'])) + rid=rports['id'], + rx=rports['rx'], tx=rports['tx'], + rx_d=rports['rx_drop'], + tx_d=rports['tx_drop'])) except KeyError as e: logger.error('{} is not defined!'.format(e)) @@ -233,7 +254,11 @@ class SppPrimary(object): if res is not None: error_codes = self.spp_ctl_cli.rest_common_error_codes if res.status_code == 200: - return res.json()['forwarder']['ports'] + if 'forwarder' in res.json(): + return res.json()['forwarder']['ports'] + else: + # Do nothing if there is no forwarder + pass elif res.status_code in error_codes: pass else: @@ -251,7 +276,11 @@ class SppPrimary(object): if res is not None: error_codes = self.spp_ctl_cli.rest_common_error_codes if res.status_code == 200: - return res.json()['forwarder']['patches'] + if 'forwarder' in res.json(): + return res.json()['forwarder']['patches'] + else: + # Do nothing if there is no forwarder + pass elif res.status_code in error_codes: pass else: @@ -270,9 +299,13 @@ class SppPrimary(object): if res is not None: error_codes = self.spp_ctl_cli.rest_common_error_codes if res.status_code == 200: - ports = res.json()['forwarder']['ports'] - patches = res.json()['forwarder']['patches'] - return ports, patches + if 'forwarder' in res.json(): + ports = res.json()['forwarder']['ports'] + patches = res.json()['forwarder']['patches'] + return ports, patches + else: + # Do nothing if there is no forwarder + pass elif res.status_code in error_codes: pass else: -- 2.17.1