Skip to content

Commit

Permalink
Merge pull request sonic-net#267 from oleksandrivantsiv/bluefield
Browse files Browse the repository at this point in the history
Merge commit 'e66ae597f97c14b8d0fe3bb9e85c545b69081f1a' into bluefield
  • Loading branch information
oleksandrivantsiv authored Oct 30, 2023
2 parents 4dafb18 + ae5f09b commit c06c3c3
Show file tree
Hide file tree
Showing 56 changed files with 2,479 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/azure-pipelines-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:
make $BUILD_OPTIONS ENABLE_ASAN=y target/docker-sonic-vs.gz
mv target/docker-sonic-vs.gz target/docker-sonic-vs-asan.gz
fi
if [ $(K8S_OPTIONS) == 'INCLUDE_KUBERNETES_MASTER=y' ]; then
if [ "$(K8S_OPTIONS)" == 'INCLUDE_KUBERNETES_MASTER=y' ]; then
make $BUILD_OPTIONS $(K8S_OPTIONS) target/sonic-vs.img.gz
mv target/sonic-vs.img.gz target/sonic-vs-k8s.img.gz
fi
Expand Down
3 changes: 3 additions & 0 deletions Makefile.work
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ $(shell \
SONIC_VERSION_CACHE_SOURCE=$(SONIC_VERSION_CACHE_SOURCE) \
DBGOPT='$(DBGOPT)' \
MIRROR_SNAPSHOT=$(MIRROR_SNAPSHOT) \
PIP_HTTP_TIMEOUT=$(PIP_HTTP_TIMEOUT) \
scripts/generate_buildinfo_config.sh)

# Generate the slave Dockerfile, and prepare build info for it
Expand Down Expand Up @@ -572,6 +573,7 @@ SONIC_BUILD_INSTRUCTION := $(MAKE) \
SONIC_VERSION_CONTROL_COMPONENTS=$(SONIC_VERSION_CONTROL_COMPONENTS) \
ONIE_IMAGE_PART_SIZE=$(ONIE_IMAGE_PART_SIZE) \
SONIC_OS_VERSION=$(SONIC_OS_VERSION) \
PIP_HTTP_TIMEOUT=$(PIP_HTTP_TIMEOUT) \
$(SONIC_OVERRIDE_BUILD_VARS)

.PHONY: sonic-slave-build sonic-slave-bash init reset
Expand All @@ -594,6 +596,7 @@ export MIRROR_URLS
export MIRROR_SECURITY_URLS
export MIRROR_SNAPSHOT
export SONIC_VERSION_CONTROL_COMPONENTS
export PIP_HTTP_TIMEOUT

%:: | sonic-build-hooks
ifneq ($(filter y, $(MULTIARCH_QEMU_ENVIRON) $(CROSS_BUILD_ENVIRON)),)
Expand Down
24 changes: 22 additions & 2 deletions build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ TRUSTED_GPG_DIR=$BUILD_TOOL_PATH/trusted.gpg.d
exit 1
}

if [ "$IMAGE_TYPE" = "aboot" ]; then
TARGET_BOOTLOADER="aboot"
fi

## Check if not a last stage of RFS build
if [[ $RFS_SPLIT_LAST_STAGE != y ]]; then

Expand All @@ -68,9 +72,14 @@ if [[ -d $FILESYSTEM_ROOT ]]; then
fi
mkdir -p $FILESYSTEM_ROOT
mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR
mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR/grub
touch $FILESYSTEM_ROOT/$PLATFORM_DIR/firsttime

bootloader_packages=""
if [ "$TARGET_BOOTLOADER" != "aboot" ]; then
mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR/grub
bootloader_packages="grub2-common"
fi

## ensure proc is mounted
sudo mount proc /proc -t proc || true

Expand Down Expand Up @@ -365,7 +374,7 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in
gdisk \
sysfsutils \
squashfs-tools \
grub2-common \
$bootloader_packages \
screen \
hping3 \
tcptraceroute \
Expand Down Expand Up @@ -827,6 +836,17 @@ sudo mkdir -p $FILESYSTEM_ROOT/var/lib/docker
sudo rm -f $FILESYSTEM_ROOT/etc/resolvconf/resolv.conf.d/original
sudo cp files/image_config/resolv-config/resolv.conf.head $FILESYSTEM_ROOT/etc/resolvconf/resolv.conf.d/head

## Optimize filesystem size
if [ "$BUILD_REDUCE_IMAGE_SIZE" = "y" ]; then
sudo scripts/build-optimize-fs-size.py "$FILESYSTEM_ROOT" \
--image-type "$IMAGE_TYPE" \
--hardlinks var/lib/docker \
--hardlinks usr/share/sonic/device \
--remove-docs \
--remove-mans \
--remove-licenses
fi

sudo mksquashfs $FILESYSTEM_ROOT $FILESYSTEM_SQUASHFS -comp zstd -b 1M -e boot -e var/lib/docker -e $PLATFORM_DIR

## Reduce /boot permission
Expand Down
21 changes: 19 additions & 2 deletions dockers/docker-dhcp-server/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM docker-config-engine-bullseye-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}}

ARG docker_container_name
ARG image_version
RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf

## Make apt-get non-interactive
ENV DEBIAN_FRONTEND=noninteractive
Expand All @@ -13,6 +14,7 @@ ENV IMAGE_VERSION=$image_version
RUN apt-get update && \
apt-get install -f -y \
tcpdump \
python3-dev \
# For kea build environment
automake \
libtool \
Expand Down Expand Up @@ -47,7 +49,9 @@ RUN echo "/usr/local/lib/kea/hooks" > /etc/ld.so.conf.d/kea.conf && \
RUN cd /usr/local/sbin && rm -f kea-admin kea-ctrl-agent kea-dhcp-ddns kea-dhcp6 keactrl
# Remove hook lib we don't need
RUN cd /usr/local/lib/kea/hooks && rm -f libdhcp_bootp.so libdhcp_flex_option.so libdhcp_stat_cmds.so
# RUN pip3 install psutil
RUN pip3 install psutil
# TODO issue on remote rsyslog server in non-host container
RUN rm -f /etc/supervisor/conf.d/containercfgd.conf

{% if docker_dhcp_server_debs.strip() -%}
# Copy locally-built Debian package dependencies
Expand All @@ -57,23 +61,36 @@ RUN cd /usr/local/lib/kea/hooks && rm -f libdhcp_bootp.so libdhcp_flex_option.so
{{ install_debian_packages(docker_dhcp_server_debs.split(' ')) }}
{%- endif %}

{% if docker_dhcp_server_whls.strip() %}
# Copy locally-built Python wheel dependencies
{{ copy_files("python-wheels/", docker_dhcp_server_whls.split(' '), "/python-wheels/") }}

# Install locally-built Python wheel dependencies
{{ install_python_wheels(docker_dhcp_server_whls.split(' ')) }}
{% endif %}

# Remove build stuff we don't need
RUN apt-get remove -y devscripts \
automake \
libtool \
pkg-config \
build-essential \
python3-dev \
ccache

RUN apt-get clean -y && \
apt-get autoclean -y && \
apt-get autoremove -y && \
rm -rf /debs

COPY ["docker_init.sh", "/usr/bin/"]
COPY ["docker_init.sh", "start.sh", "/usr/bin/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
COPY ["port-name-alias-map.txt.j2", "rsyslog/rsyslog.conf.j2", "kea-dhcp4.conf.j2", "/usr/share/sonic/templates/"]
COPY ["critical_processes", "/etc/supervisor/"]
COPY ["lease_update.sh", "/etc/kea/"]
COPY ["kea-dhcp4-init.conf", "/etc/kea/kea-dhcp4.conf"]
COPY ["cli", "/cli/"]
COPY ["rsyslog/default.conf", "/etc/rsyslog.d"]

ENTRYPOINT ["/usr/bin/docker_init.sh"]
1 change: 1 addition & 0 deletions dockers/docker-dhcp-server/critical_processes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
group:dhcp-server-ipv4
16 changes: 16 additions & 0 deletions dockers/docker-dhcp-server/docker_init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env bash


# Generate supervisord config file
mkdir -p /etc/supervisor/conf.d/
# Generate kea folder
mkdir -p /etc/kea/
udp_server_ip=$(ip -j -4 addr list lo scope host | jq -r -M '.[0].addr_info[0].local')
hostname=$(hostname)
# Generate the following files from templates:
# port-to-alias name map
sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 \
-a "{\"udp_server_ip\": \"$udp_server_ip\", \"hostname\": \"$hostname\"}" \
> /etc/rsyslog.conf
sonic-cfggen -d -t /usr/share/sonic/templates/port-name-alias-map.txt.j2,/tmp/port-name-alias-map.txt

# Make the script that waits for all interfaces to come up executable
chmod +x /etc/kea/lease_update.sh /usr/bin/start.sh
# The docker container should start this script as PID 1, so now that supervisord is
# properly configured, we exec /usr/local/bin/supervisord so that it runs as PID 1 for the
# duration of the container's lifetime
Expand Down
40 changes: 40 additions & 0 deletions dockers/docker-dhcp-server/kea-dhcp4-init.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"Dhcp4": {
"hooks-libraries": [
{
"library": "/usr/local/lib/kea/hooks/libdhcp_run_script.so",
"parameters": {
"name": "/etc/kea/lease_update.sh",
"sync": false
}
}
],
"interfaces-config": {
"interfaces": ["eth0"]
},
"control-socket": {
"socket-type": "unix",
"socket-name": "/run/kea/kea4-ctrl-socket"
},
"lease-database": {
"type": "memfile",
"persist": true,
"name": "/tmp/kea-lease.csv",
"lfc-interval": 3600
},
"subnet4": [],
"loggers": [
{
"name": "kea-dhcp4",
"output_options": [
{
"output": "/tmp/kea-dhcp.log",
"pattern": "%-5p %m\n"
}
],
"severity": "INFO",
"debuglevel": 0
}
]
}
}
87 changes: 87 additions & 0 deletions dockers/docker-dhcp-server/kea-dhcp4.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{%- set default_lease_time = 900 -%}
{
"Dhcp4": {
"hooks-libraries": [
{
"library": "/usr/local/lib/kea/hooks/libdhcp_run_script.so",
"parameters": {
"name": "{{ lease_update_script_path }}",
"sync": false
}
}
],
"interfaces-config": {
"interfaces": [
"eth0"
]
},
"control-socket": {
"socket-type": "unix",
"socket-name": "/run/kea/kea4-ctrl-socket"
},
"lease-database": {
"type": "memfile",
"persist": true,
"name": "{{ lease_path }}",
"lfc-interval": 3600
},
"subnet4": [
{%- set add_subnet_preceding_comma = { 'flag': False } %}
{%- for subnet_info in subnets %}
{%- if add_subnet_preceding_comma.flag -%},{%- endif -%}
{%- set _dummy = add_subnet_preceding_comma.update({'flag': True}) %}
{
"subnet": "{{ subnet_info["subnet"] }}",
"pools": [
{%- set add_pool_preceding_comma = { 'flag': False } %}
{%- for pool in subnet_info["pools"] %}
{%- if add_pool_preceding_comma.flag -%},{%- endif -%}
{%- set _dummy = add_pool_preceding_comma.update({'flag': True}) %}
{
"pool": "{{ pool["range"] }}",
"client-class": "{{ pool["client_class"] }}"
}
{%- endfor%}
],
"option-data": [
{
"name": "routers",
"data": "{{ subnet_info["gateway"] if "gateway" in subnet_info else subnet_info["server_id"] }}"
},
{
"name": "dhcp-server-identifier",
"data": "{{ subnet_info["server_id"] }}"
}
],
"valid-lifetime": {{ subnet_info["lease_time"] if "lease_time" in subnet_info else default_lease_time }},
"reservations": []
}
{%- endfor %}
],
"loggers": [
{
"name": "kea-dhcp4",
"output_options": [
{
"output": "/var/log/kea-dhcp.log",
"pattern": "%-5p %m\n"
}
],
"severity": "INFO",
"debuglevel": 0
}
]{%- if client_classes -%},
"client-classes": [
{%- set add_preceding_comma = { 'flag': False } %}
{%- for class in client_classes %}
{%- if add_preceding_comma.flag -%},{%- endif -%}
{%- set _dummy = add_preceding_comma.update({'flag': True}) %}
{
"name": "{{ class["name"] }}",
"test": "{{ class["condition"] }}"
}
{%- endfor %}
]
{%- endif %}
}
}
12 changes: 12 additions & 0 deletions dockers/docker-dhcp-server/lease_update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# This script would run once kea-dhcp4 lease change (defined in kea-dhcp4.conf),
# it is to find running process dhcpservd.py, and send SIGUSR1 signal to this
# process to inform it to update lease table in state_db (defined in dhcpservd.py)

pid=`ps aux | grep 'dhcpservd' | grep -nv 'grep' | awk '{print $2}'`
if [ -z "$pid" ]; then
logger -p daemon.error Cannot find running dhcpservd.py.
else
# Send SIGUSR1 signal to dhcpservd.py
kill -s 10 ${pid}
fi
5 changes: 5 additions & 0 deletions dockers/docker-dhcp-server/port-name-alias-map.txt.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{# Generate port name-alias map for isc-dhcp-relay to parse. Each line contains one #}
{# name-alias pair of the form "<name> <alias>" #}
{% for port, config in PORT.items() %}
{{- port }} {% if "alias" in config %}{{ config["alias"] }}{% else %}{{ port }}{% endif %} {{- "\n" -}}
{% endfor -%}
27 changes: 27 additions & 0 deletions dockers/docker-dhcp-server/rsyslog/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# First some standard log files. Log by facility.
#

# Log all facilities to /var/log/syslog except cron, auth
# and authpriv. They are noisy - log them to their own files
*.*;cron,auth,authpriv.none -/var/log/syslog
auth,authpriv.* /var/log/auth.log
cron.* /var/log/cron.log

#
# Emergencies are sent to everybody logged in.
#
*.emerg :omusrmsg:*

# The named pipe /dev/xconsole is for the `xconsole' utility. To use it,
# you must invoke `xconsole' with the `-file' option:
#
# $ xconsole -file /dev/xconsole [...]
#
# NOTE: adjust the list below, or you'll go crazy if you have a reasonably
# busy site..
#
#daemon.*;mail.*;\
# news.err;\
# *.=debug;*.=info;\
# *.=notice;*.=warn |/dev/xconsole
Loading

0 comments on commit c06c3c3

Please sign in to comment.