From 991c98e560efc02d61d995dce4662d5137d872bd Mon Sep 17 00:00:00 2001 From: mssonicbld <79238446+mssonicbld@users.noreply.github.com> Date: Tue, 10 Jan 2023 02:28:03 +0800 Subject: [PATCH] During build time mask only those feature/services that are disabled excplicitly (#13283) (#13296) What I did: Fix : #13117 How I did: During build time mask only those feature/services that are disabled explicitly. Some of the features ((eg: teamd/bgp/dhcp-relay/mux/etc..)) state is determine run-time so for those feature by default service will be up and running and then later hostcfgd will mask them if needed. So Default behavior will be init_cfg.json.j2 during build time make state as disabled then mask the service init_cfg.json.j2 during build time make state as another jinja2 template render string than do no mask the service init_cfg.json.j2 during build time make state as enabled then do not mask the service How I verify: Manual Verification. Signed-off-by: Abhishek Dosi Signed-off-by: Abhishek Dosi Co-authored-by: abdosi <58047199+abdosi@users.noreply.github.com> --- files/build_scripts/mask_disabled_services.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/files/build_scripts/mask_disabled_services.py b/files/build_scripts/mask_disabled_services.py index 5c1a369580..291b8d7e07 100755 --- a/files/build_scripts/mask_disabled_services.py +++ b/files/build_scripts/mask_disabled_services.py @@ -4,10 +4,20 @@ import json import subprocess INIT_CFG_FILE_PATH = '/etc/sonic/init_cfg.json' +WARM_OR_FAST_BOOT_DATAPLANE_NEEDED_SERVICES = ['database', 'swss', 'syncd', 'teamd', 'bgp'] with open(INIT_CFG_FILE_PATH) as init_cfg_file: init_cfg = json.load(init_cfg_file) if 'FEATURE' in init_cfg: for feature_name, feature_props in init_cfg['FEATURE'].items(): - if 'state' in feature_props and feature_props['state'] != 'enabled' and feature_props['state'] != 'always_enabled': - subprocess.run(['systemctl', 'mask', '{}.service'.format(feature_name)]) + # For warm/fast boot we want to have all crtical dataplane needed service + # to start immediately before hostcfgd can render `state` field unless the `state` field is marked disabled + # explicitly during build time rendering of init_cfg.json + if feature_name in WARM_OR_FAST_BOOT_DATAPLANE_NEEDED_SERVICES: + if 'state' in feature_props and (feature_props['state'] == 'disabled' or feature_props['state'] == 'always_disabled'): + subprocess.run(['systemctl', 'mask', '{}.service'.format(feature_name)]) + # For other services by default mask out the service if not enable explicitly. This service can get enable later on when + # hostcfgd render the state as enable. This should not cause dataplane impact. + else: + if 'state' in feature_props and feature_props['state'] != 'enabled' and feature_props['state'] != 'always_enabled': + subprocess.run(['systemctl', 'mask', '{}.service'.format(feature_name)])