Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a health check for SONiC to enable the measurement of its startup time #195

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions images/sonic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ ENV LIBGUESTFS_BACKEND=direct
RUN apt-get update && \
apt-get --no-install-recommends install --yes \
curl \
libpcap0.8 \
iproute2 \
linux-image-cloud-amd64 \
python3 \
python3-guestfs \
python3-scapy \
qemu-system-x86 \
telnet

Expand All @@ -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
19 changes: 19 additions & 0 deletions images/sonic/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand Down Expand Up @@ -168,6 +171,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()

Expand Down Expand Up @@ -218,5 +229,13 @@ def get_default_gateway() -> str:
return socket.inet_ntoa(struct.pack("<L", int(fields[2], 16)))


def is_port_configuration_done(packet):
if packet.haslayer(LLDPDUChassisID):
chassis_id_tlv = packet.getlayer(LLDPDUChassisID)
if chassis_id_tlv.subtype == LLDPDUChassisID.SUBTYPE_MAC_ADDRESS and chassis_id_tlv.id == get_mac_address('eth0'):
return True
return False


if __name__ == '__main__':
main()