Skip to content

Commit

Permalink
[202211][config reload]Config Reload Enhancement (#15334)
Browse files Browse the repository at this point in the history
Backporting #13969

Why I did it
Implementing code changes for sonic-net/SONiC#1203

Work item tracking
Microsoft ADO (number only):
How I did it
Removed the timers and delayed target since the delayed services would start based on event driven approach.
Cleared port table during config reload and cold reboot scenario.
Modified yang model, init_cfg.json to change has_timer to delayed

How to verify it
Added UT to verify
  • Loading branch information
dgsudharsan committed Jun 12, 2023
1 parent 3e2211b commit 78977dd
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 153 deletions.
6 changes: 3 additions & 3 deletions files/build_templates/init_cfg.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
{%- if include_macsec == "y" %}{% do features.append(("macsec", "{% if 'type' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['type'] == 'SpineRouter' and DEVICE_RUNTIME_METADATA['MACSEC_SUPPORTED'] %}enabled{% else %}disabled{% endif %}", false, "enabled")) %}{% endif %}
{%- if include_system_telemetry == "y" %}{% do features.append(("telemetry", "enabled", true, "enabled")) %}{% endif %}
"FEATURE": {
{# has_timer field if set, will start the feature systemd .timer unit instead of .service unit #}
{%- for feature, state, has_timer, autorestart in features %}
{# delayed field if set, will start the feature systemd .timer unit instead of .service unit #}
{%- for feature, state, delayed, autorestart in features %}
"{{feature}}": {
"state": "{{state}}",
"has_timer" : {{has_timer | lower()}},
"delayed" : {{delayed | lower()}},
"has_global_scope": {% if feature + '.service' in installer_services.split(' ') %}true{% else %}false{% endif %},
{%- if feature in ["lldp"] %}
"has_per_asic_scope": {% raw %}"{% if not DEVICE_RUNTIME_METADATA['ETHERNET_PORTS_PRESENT'] or ('CHASSIS_METADATA' in DEVICE_RUNTIME_METADATA and DEVICE_RUNTIME_METADATA['CHASSIS_METADATA']['module_type'] in ['supervisor']) %}False{% else %}True{% endif %}"{% endraw %},
Expand Down
11 changes: 0 additions & 11 deletions files/build_templates/mgmt-framework.timer

This file was deleted.

12 changes: 0 additions & 12 deletions files/build_templates/per_namespace/lldp.timer.j2

This file was deleted.

12 changes: 0 additions & 12 deletions files/build_templates/pmon.timer

This file was deleted.

2 changes: 1 addition & 1 deletion files/build_templates/snmp.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Description=SNMP container
Requires=updategraph.service
Requisite=swss.service
After=updategraph.service swss.service syncd.service
After=updategraph.service swss.service syncd.service interfaces-config.service
BindsTo=sonic.target
After=sonic.target
Before=ntp-config.service
Expand Down
12 changes: 0 additions & 12 deletions files/build_templates/snmp.timer

This file was deleted.

5 changes: 0 additions & 5 deletions files/build_templates/sonic-delayed.target

This file was deleted.

34 changes: 0 additions & 34 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -852,19 +852,6 @@ if [ -f {{service}} ]; then
echo "{{service}}" | sudo tee -a $GENERATED_SERVICE_FILE
fi
{% endfor %}
{% for timer in installer_timers.split(' ') -%}
if [ -f {{timer}} ]; then
sudo cp {{timer}} $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM

{% if "@" in timer %}
MULTI_INSTANCE="{{timer}}"
SINGLE_INSTANCE=${MULTI_INSTANCE/"@"}
sudo cp $SINGLE_INSTANCE $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
{% endif %}

echo "{{timer}}" | sudo tee -a $GENERATED_SERVICE_FILE
fi
{% endfor %}
if [ -f iccpd.service ]; then
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl disable iccpd.service
fi
Expand Down Expand Up @@ -898,30 +885,9 @@ sudo LANG=C cp $SCRIPTS_DIR/write_standby.py $FILESYSTEM_ROOT/usr/local/bin/writ
# Copy mark_dhcp_packet script
sudo LANG=C cp $SCRIPTS_DIR/mark_dhcp_packet.py $FILESYSTEM_ROOT/usr/local/bin/mark_dhcp_packet.py

# Copy systemd timer configuration
# It implements delayed start of services
sudo cp $BUILD_TEMPLATES/snmp.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
echo "snmp.timer" | sudo tee -a $GENERATED_SERVICE_FILE

{% if include_system_telemetry == 'y' %}
sudo cp $BUILD_TEMPLATES/telemetry.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
echo "telemetry.timer" | sudo tee -a $GENERATED_SERVICE_FILE
{% endif %}

{% if include_mgmt_framework == 'y' %}
sudo cp $BUILD_TEMPLATES/mgmt-framework.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
echo "mgmt-framework.timer" | sudo tee -a $GENERATED_SERVICE_FILE
{% endif %}

sudo cp $BUILD_TEMPLATES/pmon.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
echo "pmon.timer" | sudo tee -a $GENERATED_SERVICE_FILE

sudo cp $BUILD_TEMPLATES/sonic.target $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable sonic.target

sudo cp $BUILD_TEMPLATES/sonic-delayed.target $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable sonic-delayed.target

sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get purge -y python3-dev
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get purge -y build-essential libssl-dev swig
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get purge -y libcairo2-dev libdbus-1-dev libgirepository1.0-dev libsystemd-dev pkg-config
Expand Down
11 changes: 0 additions & 11 deletions files/build_templates/telemetry.timer

This file was deleted.

2 changes: 2 additions & 0 deletions files/scripts/swss.sh
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ stop() {
if [[ x"$WARM_BOOT" != x"true" ]] && [[ x"$FAST_BOOT" != x"true" ]]; then
/usr/bin/${SERVICE}.sh stop $DEV
debug "Stopped ${SERVICE}$DEV service..."
$SONIC_DB_CLI APPL_DB DEL PORT_TABLE:PortInitDone
debug "Cleared PortInitDone from APPL_DB..."
else
debug "Killing Docker swss..."
/usr/bin/docker kill swss &> /dev/null || debug "Docker swss is not running ($?) ..."
Expand Down
31 changes: 0 additions & 31 deletions slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1312,14 +1312,6 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
$(eval $(docker:-dbg.gz=.gz)_GLOBAL = yes)
)
fi
if [ -f files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 ]; then
j2 files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer

# Set the flag GLOBAL_TIMER for all the global system-wide dockers timers.
$(if $(shell ls files/build_templates/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 2>/dev/null),\
$(eval $(docker:-dbg.gz=.gz)_GLOBAL_TIMER = yes)
)
fi
# Any service template, inside instance directory, will be used to generate .service and @.service file.
if [ -f files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then
export multi_instance="true"
Expand All @@ -1330,16 +1322,6 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
export multi_instance="false"
j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service
fi
# Any timer template, inside instance directory, will be used to generate .timer and @.timer file.
if [ -f files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 ]; then
export multi_instance="true"
j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME)@.timer
$(if $(shell ls files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 2>/dev/null),\
$(eval $(docker:-dbg.gz=.gz)_TEMPLATE_TIMER = yes)
)
export multi_instance="false"
j2 files/build_templates/per_namespace/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer.j2 > $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).timer
fi
# Any service template, inside share_image directory, will be used to generate -chassis.service file.
# TODO: need better way to name the image-shared service
if [ -f files/build_templates/share_image/$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).service.j2 ]; then
Expand Down Expand Up @@ -1376,20 +1358,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
$(eval SERVICES += "$(addsuffix -chassis.service, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")
)
)
# Marks template timers with an "@" according to systemd convention
# If the $($docker)_TEMPLATE_TIMER) variable is set, the timer will be treated as a template
# If the $($docker)_GLOBAL_TIMER) and $($docker)_TEMPLATE_TIMER) variables are set the timer will be added both as a global and template timer.
$(foreach docker, $($*_DOCKERS),\
$(if $($(docker:-dbg.gz=.gz)_TEMPLATE_TIMER),\
$(if $($(docker:-dbg.gz=.gz)_GLOBAL_TIMER),\
$(eval TIMERS += "$(addsuffix .timer, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")\
)\
$(eval TIMERS += "$(addsuffix @.timer, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))"),\
$(eval TIMERS += "$(addsuffix .timer, $($(docker:-dbg.gz=.gz)_CONTAINER_NAME))")
)
)
export installer_services="$(SERVICES)"
export installer_timers="$(TIMERS)"

export installer_extra_files="$(foreach docker, $($*_DOCKERS), $(foreach file, $($(docker:-dbg.gz=.gz)_BASE_IMAGE_FILES), $($(docker:-dbg.gz=.gz)_PATH)/base_image_files/$(file)))"

Expand Down
14 changes: 7 additions & 7 deletions src/sonic-yang-models/tests/files/sample_config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@
"auto_restart": "enabled",
"has_global_scope": "False",
"has_per_asic_scope": "True",
"has_timer": "False",
"delayed": "False",
"high_mem_alert": "disabled",
"state": "enabled",
"set_owner": "local",
Expand All @@ -1560,7 +1560,7 @@
"auto_restart": "always_enabled",
"has_global_scope": "true",
"has_per_asic_scope": "true",
"has_timer": "false",
"delayed": "false",
"high_mem_alert": "disabled",
"state": "always_enabled",
"set_owner": "local",
Expand All @@ -1571,7 +1571,7 @@
"auto_restart": "enabled",
"has_global_scope": "true",
"has_per_asic_scope": "false",
"has_timer": "true",
"delayed": "true",
"high_mem_alert": "disabled",
"state": "enabled",
"set_owner": "kube",
Expand All @@ -1582,7 +1582,7 @@
"auto_restart": "enabled",
"has_global_scope": "false",
"has_per_asic_scope": "true",
"has_timer": "false",
"delayed": "false",
"high_mem_alert": "disabled",
"state": "enabled",
"set_owner": "local",
Expand All @@ -1593,7 +1593,7 @@
"auto_restart": "enabled",
"has_global_scope": "false",
"has_per_asic_scope": "true",
"has_timer": "false",
"delayed": "false",
"high_mem_alert": "disabled",
"state": "enabled",
"set_owner": "local",
Expand All @@ -1604,7 +1604,7 @@
"auto_restart": "enabled",
"has_global_scope": "false",
"has_per_asic_scope": "{% if not DEVICE_RUNTIME_METADATA['ETHERNET_PORTS_PRESENT'] or ('CHASSIS_METADATA' in DEVICE_RUNTIME_METADATA and DEVICE_RUNTIME_METADATA['CHASSIS_METADATA']['module_type'] in ['supervisor']) %}False{% else %}True{% endif %}",
"has_timer": "false",
"delayed": "false",
"high_mem_alert": "disabled",
"state": "enabled",
"set_owner": "kube",
Expand All @@ -1615,7 +1615,7 @@
"auto_restart": "enabled",
"has_global_scope": "false",
"has_per_asic_scope": "true",
"has_timer": "false",
"delayed": "false",
"high_mem_alert": "disabled",
"state": "{% if not (DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] != 'ToRRouter') %}enabled{% else %}disabled{% endif %}",
"set_owner": "kube",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "database",
"state": "always_enabled",
"auto_restart": "always_enabled",
"has_timer": "False",
"delayed": "False",
"has_global_scope": "True",
"has_per_asic_scope": "True",
"set_owner": "local",
Expand All @@ -18,7 +18,7 @@
"name": "swss",
"state": "always_enabled",
"auto_restart": "always_enabled",
"has_timer": "false",
"delayed": "false",
"has_global_scope": "false",
"has_per_asic_scope": "true",
"set_owner": "local",
Expand All @@ -29,7 +29,7 @@
"name": "syncd",
"state": "always_enabled",
"auto_restart": "always_enabled",
"has_timer": "false",
"delayed": "false",
"has_global_scope": "false",
"has_per_asic_scope": "true",
"set_owner": "local",
Expand All @@ -40,7 +40,7 @@
"name": "snmp",
"state": "enabled",
"auto_restart": "enabled",
"has_timer": "false",
"delayed": "false",
"has_global_scope": "true",
"has_per_asic_scope": "false",
"set_owner": "kube",
Expand All @@ -51,7 +51,7 @@
"name": "lldp",
"state": "disabled",
"auto_restart": "disabled",
"has_timer": "false",
"delayed": "false",
"has_global_scope": "false",
"has_per_asic_scope": "{% if not DEVICE_RUNTIME_METADATA['ETHERNET_PORTS_PRESENT'] or ('CHASSIS_METADATA' in DEVICE_RUNTIME_METADATA and DEVICE_RUNTIME_METADATA['CHASSIS_METADATA']['module_type'] in ['supervisor']) %}False{% else %}True{% endif %}",
"set_owner": "kube",
Expand All @@ -62,7 +62,7 @@
"name": "dhcp_relay",
"state": "{% if not (DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] != 'ToRRouter') %}enabled{% else %}disabled{% endif %}",
"auto_restart": "disabled",
"has_timer": "false",
"delayed": "false",
"has_global_scope": "false",
"has_per_asic_scope": "true",
"set_owner": "kube",
Expand All @@ -81,7 +81,7 @@
"name": "lldp",
"state": "disabled",
"auto_restart": "disabled",
"has_timer": "false",
"delayed": "false",
"has_global_scope": "false",
"has_per_asic_scope": "{% if not DEVICE_RUNTIME_METADATA['ETHERNET_PORTS_PRESENT'] or ('CHASSIS_METADATA' in DEVICE_RUNTIME_METADATA and DEVICE_RUNTIME_METADATA['CHASSIS_METADATA']['module_type'] in ['supervisor']) %}False{% else %}True{% endif %}",
"set_owner": "invalid",
Expand All @@ -100,7 +100,7 @@
"name": "lldp",
"state": "disabled",
"auto_restart": "disabled",
"has_timer": "false",
"delayed": "false",
"has_global_scope": "false",
"has_per_asic_scope": "{% if not DEVICE_RUNTIME_METADATA['ETHERNET_PORTS_PRESENT'] or ('CHASSIS_METADATA' in DEVICE_RUNTIME_METADATA and DEVICE_RUNTIME_METADATA['CHASSIS_METADATA']['module_type'] in ['supervisor']) %}False{% else %}True{% endif %}",
"check_up_status": "false",
Expand All @@ -119,7 +119,7 @@
"name": "database",
"state": "always_enabled",
"auto_restart": "always_enabled",
"has_timer": "FALSE",
"delayed": "FALSE",
"has_global_scope": "TRUE",
"has_per_asic_scope": "TRUE",
"check_up_status": "FALSE",
Expand Down
6 changes: 3 additions & 3 deletions src/sonic-yang-models/yang-models/sonic-feature.yang
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ module sonic-feature{
default "enabled";
}

leaf has_timer {
description "This configuration identicates if there is
timer associated to this feature";
leaf delayed {
description "This configuration identicates if the feature needs to be delayed until
system initialization";
type stypes:boolean_type;
default "false";
}
Expand Down

0 comments on commit 78977dd

Please sign in to comment.