telemetry: error message handling part2 41/35841/6
authorViliam Luc <vluc@cisco.com>
Thu, 31 Mar 2022 09:01:25 +0000 (11:01 +0200)
committerPeter Mikus <pmikus@cisco.com>
Mon, 4 Apr 2022 11:46:00 +0000 (11:46 +0000)
Signed-off-by: Viliam Luc <vluc@cisco.com>
Change-Id: I4d8de4e6ccff25c0c1dcf66c192c56710939bf7d

resources/tools/telemetry/bundle_bpf.py
resources/tools/telemetry/constants.py
resources/tools/telemetry/executor.py
resources/tools/telemetry/parser.py

index 655152c..b9baeab 100644 (file)
@@ -17,6 +17,7 @@ from logging import getLogger
 import sys
 
 from bcc import BPF
+from .constants import Constants
 
 
 class BundleBpf:
@@ -67,8 +68,8 @@ class BundleBpf:
                     sample_period=duration
                 )
         except AttributeError:
-            getLogger(__name__).error(u"Cannot attach BPF events!")
-            sys.exit(1)
+            getLogger("console_stderr").error(u"Could not attach BPF events!")
+            sys.exit(Constants.err_linux_attach)
 
     def detach(self):
         """
@@ -81,8 +82,8 @@ class BundleBpf:
                     ev_config=event[u"name"]
                 )
         except AttributeError:
-            getLogger(__name__).error(u"Cannot dettach BPF events!")
-            sys.exit(1)
+            getLogger("console_stderr").error(u"Could not detach BPF events!")
+            sys.exit(Constants.err_linux_detach)
 
     def fetch_data(self):
         """
index fda558b..4b47a39 100644 (file)
@@ -26,6 +26,12 @@ class Constants:
     # Failed when processing data
     err_telemetry_process = 1
 
+    # Failed to read YAML file
+    err_telemetry_yaml = 2
+
+    # Error executing bundle
+    err_telemetry_bundle = 3
+
     # Could not connect to VPP
     err_vpp_connect = 11
 
@@ -35,3 +41,9 @@ class Constants:
     # Failed when executing command
     err_vpp_execute = 13
 
+    # Could not attach BPF events
+    err_linux_attach = 51
+
+    # Could not detach BPF events
+    err_linux_detach = 52
+
index 75db4b6..4d335c1 100644 (file)
@@ -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,6 +20,7 @@ import sys
 
 from .parser import Parser
 from .serializer import Serializer
+from .constants import Constants
 
 
 class Executor:
@@ -103,5 +104,5 @@ class ExecutorError(Exception):
         """
         super().__init__()
         self.message = message
-        getLogger(__name__).error(message)
-        sys.exit(1)
+        getLogger("console_stderr").error(message)
+        sys.exit(Constants.err_telemetry_bundle)
index c6cc167..1570a4f 100644 (file)
@@ -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:
@@ -18,6 +18,7 @@ from pathlib import Path
 import sys
 
 from yaml import safe_load, YAMLError
+from .constants import Constants
 
 
 class Parser:
@@ -103,5 +104,5 @@ class ParserError(Exception):
         """
         super().__init__()
         self.message = message
-        getLogger(__name__).error(self.message)
-        sys.exit(1)
+        getLogger("console_stderr").error(self.message)
+        sys.exit(Constants.err_telemetry_yaml)