From 7e9609e565c3e9c7e9987a1e6852101b71b81bbf Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Tue, 29 Oct 2024 22:32:59 +0100 Subject: [PATCH] Implement a health check for SONiC to enable the measurement of its startup time --- images/sonic/Dockerfile | 4 ++++ images/sonic/launch.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/images/sonic/Dockerfile b/images/sonic/Dockerfile index 6cbd4c4..a53c8d9 100644 --- a/images/sonic/Dockerfile +++ b/images/sonic/Dockerfile @@ -5,10 +5,12 @@ ENV LIBGUESTFS_BACKEND=direct RUN apt-get update && \ apt-get --no-install-recommends install --yes \ curl \ + libpcap0.8 \ linux-image-cloud-amd64 \ net-tools \ python3 \ python3-guestfs \ + python3-scapy \ qemu-system-x86 \ telnet @@ -18,3 +20,5 @@ COPY --from=ghcr.io/metal-stack/mini-lab-sonic:base /frr-pythontools.deb /frr-py ENTRYPOINT ["/launch.py"] COPY config_db.json mirror_tap_to_eth.sh launch.py / + +HEALTHCHECK --start-period=10s --interval=5s --retries=20 CMD test -f /healthy diff --git a/images/sonic/launch.py b/images/sonic/launch.py index 1f3af01..fe59c8b 100755 --- a/images/sonic/launch.py +++ b/images/sonic/launch.py @@ -13,6 +13,9 @@ import guestfs from guestfs import GuestFS +from scapy.all import sniff +from scapy.contrib.lldp import LLDPDU, LLDPDUChassisID + BASE_IMG = '/sonic-vs.img' @@ -165,6 +168,14 @@ def main(): logger.info('Start QEMU') vm.start() + # SONiC will start sending LLDP packets after PortConfigDone is set in APPL database + logger.info('Wait until port configuration is done') + sniff(iface="eth0", filter="ether proto 0x88cc", stop_filter=is_port_configuration_done, store=0) + + logger.info('Port configuration is done') + with open('/healthy', 'w'): + pass + logger.info('Wait until QEMU is terminated') vm.wait() @@ -215,5 +226,13 @@ def get_default_gateway() -> str: return socket.inet_ntoa(struct.pack("