improved coretk gui alerts to display alert text when selected, fixed merged code for adding a check to cleanup interfaces, updated session.exceptions to use enums directly
This commit is contained in:
parent
c0c23190d1
commit
513eaf2b76
8 changed files with 50 additions and 60 deletions
|
@ -145,7 +145,7 @@ def handle_exception_event(event):
|
|||
"""
|
||||
return core_pb2.ExceptionEvent(
|
||||
node_id=event.node,
|
||||
level=event.level,
|
||||
level=event.level.value,
|
||||
source=event.source,
|
||||
date=event.date,
|
||||
text=event.text,
|
||||
|
|
|
@ -299,7 +299,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
[
|
||||
(ExceptionTlvs.NODE, exception_data.node),
|
||||
(ExceptionTlvs.SESSION, exception_data.session),
|
||||
(ExceptionTlvs.LEVEL, exception_data.level),
|
||||
(ExceptionTlvs.LEVEL, exception_data.level.value),
|
||||
(ExceptionTlvs.SOURCE, exception_data.source),
|
||||
(ExceptionTlvs.DATE, exception_data.date),
|
||||
(ExceptionTlvs.TEXT, exception_data.text),
|
||||
|
|
|
@ -1411,13 +1411,12 @@ class Session:
|
|||
"""
|
||||
Generate and broadcast an exception event.
|
||||
|
||||
:param str level: exception level
|
||||
:param core.emulator.enumerations.ExceptionLevel level: exception level
|
||||
:param str source: source name
|
||||
:param int node_id: node related to exception
|
||||
:param str text: exception message
|
||||
:return: nothing
|
||||
"""
|
||||
|
||||
exception_data = ExceptionData(
|
||||
node=node_id,
|
||||
session=str(self.id),
|
||||
|
@ -1426,7 +1425,6 @@ class Session:
|
|||
date=time.ctime(),
|
||||
text=text,
|
||||
)
|
||||
|
||||
self.broadcast_exception(exception_data)
|
||||
|
||||
def instantiate(self):
|
||||
|
|
|
@ -167,7 +167,7 @@ class CoreClient:
|
|||
elif event.HasField("config_event"):
|
||||
logging.info("config event: %s", event)
|
||||
elif event.HasField("exception_event"):
|
||||
self.handle_exception_event(event.exception_event)
|
||||
self.handle_exception_event(event)
|
||||
else:
|
||||
logging.info("unhandled event: %s", event)
|
||||
|
||||
|
@ -204,7 +204,7 @@ class CoreClient:
|
|||
|
||||
def handle_throughputs(self, event):
|
||||
if event.session_id != self.session_id:
|
||||
logging.warn(
|
||||
logging.warning(
|
||||
"ignoring throughput event session(%s) current(%s)",
|
||||
event.session_id,
|
||||
self.session_id,
|
||||
|
|
|
@ -4,9 +4,7 @@ check engine light
|
|||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
from grpc import RpcError
|
||||
|
||||
from core.api.grpc import core_pb2
|
||||
from core.api.grpc.core_pb2 import ExceptionLevel
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.themes import PADX, PADY
|
||||
from core.gui.widgets import CodeText
|
||||
|
@ -18,6 +16,7 @@ class AlertsDialog(Dialog):
|
|||
self.app = app
|
||||
self.tree = None
|
||||
self.codetext = None
|
||||
self.alarm_map = {}
|
||||
self.draw()
|
||||
|
||||
def draw(self):
|
||||
|
@ -48,25 +47,31 @@ class AlertsDialog(Dialog):
|
|||
self.tree.bind("<<TreeviewSelect>>", self.click_select)
|
||||
|
||||
for alarm in self.app.statusbar.core_alarms:
|
||||
level = self.get_level(alarm.level)
|
||||
self.tree.insert(
|
||||
exception = alarm.exception_event
|
||||
level_name = ExceptionLevel.Enum.Name(exception.level)
|
||||
insert_id = self.tree.insert(
|
||||
"",
|
||||
tk.END,
|
||||
text=str(alarm.date),
|
||||
text=exception.date,
|
||||
values=(
|
||||
alarm.date,
|
||||
level + " (%s)" % alarm.level,
|
||||
exception.date,
|
||||
level_name,
|
||||
alarm.session_id,
|
||||
alarm.node_id,
|
||||
alarm.source,
|
||||
exception.node_id,
|
||||
exception.source,
|
||||
),
|
||||
tags=(level,),
|
||||
tags=(level_name,),
|
||||
)
|
||||
self.alarm_map[insert_id] = alarm
|
||||
|
||||
self.tree.tag_configure("ERROR", background="#ff6666")
|
||||
self.tree.tag_configure("FATAL", background="#d9d9d9")
|
||||
self.tree.tag_configure("WARNING", background="#ffff99")
|
||||
self.tree.tag_configure("NOTICE", background="#85e085")
|
||||
error_name = ExceptionLevel.Enum.Name(ExceptionLevel.ERROR)
|
||||
self.tree.tag_configure(error_name, background="#ff6666")
|
||||
fatal_name = ExceptionLevel.Enum.Name(ExceptionLevel.FATAL)
|
||||
self.tree.tag_configure(fatal_name, background="#d9d9d9")
|
||||
warning_name = ExceptionLevel.Enum.Name(ExceptionLevel.WARNING)
|
||||
self.tree.tag_configure(warning_name, background="#ffff99")
|
||||
notice_name = ExceptionLevel.Enum.Name(ExceptionLevel.NOTICE)
|
||||
self.tree.tag_configure(notice_name, background="#85e085")
|
||||
|
||||
yscrollbar = ttk.Scrollbar(frame, orient="vertical", command=self.tree.yview)
|
||||
yscrollbar.grid(row=0, column=1, sticky="ns")
|
||||
|
@ -105,40 +110,13 @@ class AlertsDialog(Dialog):
|
|||
dialog = DaemonLog(self, self.app)
|
||||
dialog.show()
|
||||
|
||||
def get_level(self, level):
|
||||
if level == core_pb2.ExceptionLevel.ERROR:
|
||||
return "ERROR"
|
||||
if level == core_pb2.ExceptionLevel.FATAL:
|
||||
return "FATAL"
|
||||
if level == core_pb2.ExceptionLevel.WARNING:
|
||||
return "WARNING"
|
||||
if level == core_pb2.ExceptionLevel.NOTICE:
|
||||
return "NOTICE"
|
||||
|
||||
def click_select(self, event):
|
||||
current = self.tree.selection()
|
||||
values = self.tree.item(current)["values"]
|
||||
time = values[0]
|
||||
level = values[1]
|
||||
session_id = values[2]
|
||||
node_id = values[3]
|
||||
source = values[4]
|
||||
text = "DATE: %s\nLEVEL: %s\nNODE: %s (%s)\nSESSION: %s\nSOURCE: %s\n\n" % (
|
||||
time,
|
||||
level,
|
||||
node_id,
|
||||
self.app.core.canvas_nodes[node_id].core_node.name,
|
||||
session_id,
|
||||
source,
|
||||
)
|
||||
try:
|
||||
sid = self.app.core.session_id
|
||||
self.app.core.client.get_node(sid, node_id)
|
||||
text = text + "node created"
|
||||
except RpcError:
|
||||
text = text + "node not created"
|
||||
current = self.tree.selection()[0]
|
||||
alarm = self.alarm_map[current]
|
||||
self.codetext.text.config(state=tk.NORMAL)
|
||||
self.codetext.text.delete("1.0", "end")
|
||||
self.codetext.text.insert("1.0", text)
|
||||
self.codetext.text.insert("1.0", alarm.exception_event.text)
|
||||
self.codetext.text.config(state=tk.DISABLED)
|
||||
|
||||
|
||||
class DaemonLog(Dialog):
|
||||
|
|
|
@ -127,7 +127,8 @@ class LinuxNetClient:
|
|||
:return: nothing
|
||||
"""
|
||||
self.run(
|
||||
f"[ -e /sys/class/net/{device} ] && {IP_BIN} -6 address flush dev {device} || true"
|
||||
f"[ -e /sys/class/net/{device} ] && {IP_BIN} -6 address flush dev {device} || true",
|
||||
shell=True,
|
||||
)
|
||||
|
||||
def device_mac(self, device, mac):
|
||||
|
|
|
@ -14,7 +14,7 @@ import time
|
|||
from core import utils
|
||||
from core.constants import which
|
||||
from core.emulator.data import FileData
|
||||
from core.emulator.enumerations import MessageFlags, RegisterTlvs
|
||||
from core.emulator.enumerations import ExceptionLevels, MessageFlags, RegisterTlvs
|
||||
from core.errors import CoreCommandError
|
||||
|
||||
|
||||
|
@ -628,7 +628,13 @@ class CoreServices:
|
|||
for args in service.shutdown:
|
||||
try:
|
||||
node.cmd(args)
|
||||
except CoreCommandError:
|
||||
except CoreCommandError as e:
|
||||
self.session.exception(
|
||||
ExceptionLevels.ERROR,
|
||||
"services",
|
||||
node.id,
|
||||
f"error stopping service {service.name}: {e.stderr}",
|
||||
)
|
||||
logging.exception("error running stop command %s", args)
|
||||
status = -1
|
||||
return status
|
||||
|
|
|
@ -1101,19 +1101,26 @@ class TestGrpc:
|
|||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
queue = Queue()
|
||||
exception_level = ExceptionLevels.FATAL
|
||||
source = "test"
|
||||
node_id = None
|
||||
text = "exception message"
|
||||
|
||||
def handle_event(event_data):
|
||||
assert event_data.session_id == session.id
|
||||
assert event_data.HasField("exception_event")
|
||||
exception_event = event_data.exception_event
|
||||
assert exception_event.level == exception_level.value
|
||||
assert exception_event.node_id == 0
|
||||
assert exception_event.source == source
|
||||
assert exception_event.text == text
|
||||
queue.put(event_data)
|
||||
|
||||
# then
|
||||
with client.context_connect():
|
||||
client.events(session.id, handle_event)
|
||||
time.sleep(0.1)
|
||||
session.exception(
|
||||
ExceptionLevels.FATAL.value, "test", None, "exception message"
|
||||
)
|
||||
session.exception(exception_level, source, node_id, text)
|
||||
|
||||
# then
|
||||
queue.get(timeout=5)
|
||||
|
|
Loading…
Reference in a new issue