X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Ftools%2Ftelemetry%2Fbundle_vpp.py;h=315360f63bf904ddf19a6457106ecdf2415e94f0;hb=refs%2Fchanges%2F09%2F35709%2F13;hp=01526fe83f4327bd56d812b7dfa8baa600ade54e;hpb=d255d2545ee6cdc871bc35314fad72c3c48b225b;p=csit.git diff --git a/resources/tools/telemetry/bundle_vpp.py b/resources/tools/telemetry/bundle_vpp.py index 01526fe83f..315360f63b 100644 --- a/resources/tools/telemetry/bundle_vpp.py +++ b/resources/tools/telemetry/bundle_vpp.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2022 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -20,7 +20,7 @@ import struct import sys from vpp_papi.vpp_papi import VPPApiClient as vpp_class - +from .constants import Constants M_RUN_THREAD = ( r"Thread\s" @@ -209,8 +209,8 @@ class BundleVpp: try: self.obj.connect(name=u"telemetry") except (ConnectionRefusedError, OSError): - getLogger(__name__).error(u"Cannot connect to VPP!") - sys.exit(1) + getLogger("console_stderr").error(u"Could not connect to VPP!") + sys.exit(Constants.err_vpp_connect) for command in self.code.splitlines(): api_name = u"cli_inband" @@ -223,7 +223,11 @@ class BundleVpp: """ Detach from VPP. """ - self.obj.disconnect() + try: + self.obj.disconnect() + except (ConnectionRefusedError, OSError): + getLogger("console_stderr").error(u"Could not disconnect from VPP!") + sys.exit(Constants.err_vpp_disconnect) def fetch_data(self): """ @@ -234,8 +238,12 @@ class BundleVpp: papi_fn = getattr(self.obj.api, command[u"api_name"]) getLogger(__name__).info(command[u"api_args"][u"cmd"]) replies = papi_fn(**command[u"api_args"]) - except (AttributeError, IOError, struct.error) as err: - raise AssertionError(err) + except (AssertionError, AttributeError, IOError, struct.error): + getLogger("console_stderr").error( + f"Failed when executing command: " + f"{command['api_args']['cmd']}" + ) + sys.exit(Constants.err_vpp_execute) if not isinstance(replies, list): replies = [replies] @@ -253,27 +261,27 @@ class BundleVpp: Post process command reply. """ for command in zip(self.api_command_list, self.api_replies_list): - self_fn = command[0][u"api_args"][u"cmd"] + self_fn = command[0][u"api_args"][u"cmd"].replace(u" ", u"_") + self_method_list = [meth for meth in dir(self) + if callable(getattr(self, meth)) and + meth.startswith('__') is False] + if self_fn not in self_method_list: + continue try: - self_fn = getattr(self, self_fn.replace(u" ", u"_")) + self_fn = getattr(self, self_fn) self_fn(command[1].reply) except AttributeError: pass + except (KeyError, ValueError, TypeError) as e: + getLogger("console_stderr").error( + f"Failed when processing data. Error message {e}" + ) + sys.exit(Constants.err_telemetry_process) def show_interface(self, reply): """ Parse the show interface output. - Output format: - { - "name": "rx_packets", - "labels": { - "name": "tap0", - "index": "0", - }, - "value": "31", - }, - :param reply: API reply. :type reply: str """ @@ -302,19 +310,6 @@ class BundleVpp: """ Parse the show runtime output. - Output format: - { - "name": "clocks", - "labels": { - "name": "virtio-input", - "state": "polling", - "thread_name": "vpp_wk_1", - "thread_id": "2", - "thread_lcore": "3", - }, - "value": "3.17e2", - }, - :param reply: API reply. :type reply: str """ @@ -347,19 +342,6 @@ class BundleVpp: """ Parse the show node conuter output. - Output format: - { - "name": "node_counters", - "labels": { - "name": "dpdk-input", - "reason": "no_error", - "severity": "error", - "thread_name": "vpp_wk_1", - "thread_id": "2", - }, - "value": "1", - }, - :param reply: API reply. :type reply: str """ @@ -391,19 +373,6 @@ class BundleVpp: """ Parse the permon output. - Output format: - { - "name": "clocks", - "labels": { - "name": "virtio-input", - "state": "polling", - "thread_name": "vpp_wk_1", - "thread_id": "2", - "thread_lcore": "3", - }, - "value": "3.17e2", - }, - :param reply: API reply. :type reply: str """ @@ -480,15 +449,6 @@ class BundleVpp: """ Parse the version output. - Output format: - { - "name": "version", - "labels": { - "version": "v21.06-rc0~596-g1ca6c65e5~b1065", - }, - "value": 1.0, - }, - :param reply: API reply. :type reply: str """ @@ -499,7 +459,7 @@ class BundleVpp: item[u"name"] = metric labels[u"version"] = version item[u"labels"] = labels - item[u"value"] = 1.0 + item[u"value"] = {} self.serializer.serialize( metric=metric, labels=labels, item=item )