Skip to content

Commit

Permalink
fmt_pkt: improve scapy-server logging
Browse files Browse the repository at this point in the history
The daemon will now log to scapy.log file.

Log messages include stats on request processing time as well as any
errors that may happen during processing.

If you'd like to see even more logs (e.g. for debugging purposes), just
pass --verbose to scapy-server.

Signed-off-by: Ihar Hrachyshka <ihrachys@redhat.com>
Acked-by: Mark Michelson <mmichels@redhat.com>
Signed-off-by: Mark Michelson <mmichels@redhat.com>
  • Loading branch information
booxter authored and putnopvut committed Dec 4, 2023
1 parent cd3dd36 commit ec88b71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion tests/ovn-macros.at
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,10 @@ fmt_pkt() {
start_scapy_server() {
pidfile=$ovs_base/scapy.pid
ctlfile=$ovs_base/scapy.ctl
"$top_srcdir"/tests/scapy-server.py --pidfile=$pidfile --unixctl=$ctlfile --detach
logfile=$ovs_base/scapy.log

"$top_srcdir"/tests/scapy-server.py \
--pidfile=$pidfile --unixctl=$ctlfile --log-file=$logfile --detach
on_exit "test -e \"$pidfile\" && ovs-appctl -t $ctlfile exit"
}

Expand Down
16 changes: 14 additions & 2 deletions tests/scapy-server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import argparse
import time

import ovs.daemon
import ovs.unixctl
Expand All @@ -24,15 +25,24 @@ def exit(conn, argv, aux):


def process(data):
start_time = time.perf_counter()
vlog.info(f"received payload request: {data}")
try:
data = data.replace('\n', '')
return binascii.hexlify(raw(eval(data))).decode()
except Exception:
except Exception as e:
vlog.exception(f"failed to process payload request: {e}")
return ""
finally:
total_time = (time.perf_counter() - start_time) * 1000
vlog.info(f"took {total_time:.2f}ms to process payload request")


def payload(conn, argv, aux):
conn.reply(process(argv[0]))
try:
conn.reply(process(argv[0]))
except Exception as e:
vlog.exception(f"failed to reply to payload request: {e}")


def main():
Expand All @@ -56,6 +66,8 @@ def main():
ovs.unixctl.command_register("payload", "", 1, 1, payload, None)
ovs.daemon.daemonize_complete()

vlog.info("scapy server ready")

poller = ovs.poller.Poller()
while not exiting:
server.run()
Expand Down

0 comments on commit ec88b71

Please sign in to comment.