diff --git a/files/build_templates/init_cfg.json.j2 b/files/build_templates/init_cfg.json.j2 index b51aaf2f0c14..12ce54a7e940 100644 --- a/files/build_templates/init_cfg.json.j2 +++ b/files/build_templates/init_cfg.json.j2 @@ -38,7 +38,7 @@ ("syncd", "enabled", false, "enabled"), ("teamd", "enabled", false, "enabled")] %} {% do features.append(("dhcp_relay", "{% if not (DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] is not in ['ToRRouter', 'EPMS', 'MgmtTsToR', 'MgmtToRRouter']) %}enabled{% else %}disabled{% endif %}", false, "enabled")) %} -{%- if sonic_asic_platform == "vs" %}{% do features.append(("gbsyncd", "enabled", false, "enabled")) %}{% endif %} +{% if sonic_asic_platform == "vs" %}{% do features.append(("gbsyncd", "enabled", false, "enabled")) %}{% else %}{% do features.append("gbsyncd", "{% if gbsyncd_supported_platform == True %}enabled{% else %}always_disabled{% endif %}", false, "enabled") }{% endif %} {%- if include_iccpd == "y" %}{% do features.append(("iccpd", "disabled", false, "enabled")) %}{% endif %} {%- if include_mgmt_framework == "y" %}{% do features.append(("mgmt-framework", "enabled", true, "enabled")) %}{% endif %} {%- if include_mux == "y" %}{% do features.append(("mux", "{% if 'subtype' in DEVICE_METADATA['localhost'] and DEVICE_METADATA['localhost']['subtype'] == 'DualToR' %}enabled{% else %}always_disabled{% endif %}", false, "enabled")) %}{% endif %} diff --git a/src/sonic-host-services/scripts/hostcfgd b/src/sonic-host-services/scripts/hostcfgd index 7f8f4be0b2e7..3914da056568 100755 --- a/src/sonic-host-services/scripts/hostcfgd +++ b/src/sonic-host-services/scripts/hostcfgd @@ -120,7 +120,7 @@ def get_pid(procname): class Feature(object): """ Represents a feature configuration from CONFIG_DB data. """ - def __init__(self, feature_name, feature_cfg, device_config=None): + def __init__(self, feature_name, feature_cfg, feature_state_params=None): """ Initialize Feature object based on CONFIG_DB data. Args: @@ -130,13 +130,13 @@ class Feature(object): """ self.name = feature_name - self.state = self._get_target_state(feature_cfg.get('state'), device_config or {}) + self.state = self._get_target_state(feature_cfg.get('state'), feature_state_params or {}) self.auto_restart = feature_cfg.get('auto_restart', 'disabled') self.has_timer = safe_eval(feature_cfg.get('has_timer', 'False')) self.has_global_scope = safe_eval(feature_cfg.get('has_global_scope', 'True')) self.has_per_asic_scope = safe_eval(feature_cfg.get('has_per_asic_scope', 'False')) - def _get_target_state(self, state_configuration, device_config): + def _get_target_state(self, state_configuration, feature_state_params): """ Returns the target state for the feature by rendering the state field as J2 template. Args: @@ -150,7 +150,7 @@ class Feature(object): return None template = jinja2.Template(state_configuration) - target_state = template.render(device_config) + target_state = template.render(feature_state_params) if target_state not in ('enabled', 'disabled', 'always_enabled', 'always_disabled'): raise ValueError('Invalid state rendered for feature {}: {}'.format(self.name, target_state)) return target_state @@ -181,6 +181,10 @@ class FeatureHandler(object): self._device_config = device_config self._cached_config = {} self.is_multi_npu = device_info.is_multi_npu() + self.feature_state_params = { + "device_config": device_config, + "gbsyncd_supported_platform": device_info.is_gbsyncd_platform() + } def handle(self, feature_name, op, feature_cfg): if not feature_cfg: @@ -189,7 +193,7 @@ class FeatureHandler(object): self._feature_state_table._del(feature_name) return - feature = Feature(feature_name, feature_cfg, self._device_config) + feature = Feature(feature_name, feature_cfg, self.feature_state_params) self._cached_config.setdefault(feature_name, Feature(feature_name, {})) # Change auto-restart configuration first. @@ -1230,7 +1234,7 @@ class HostConfigDaemon: self.config_db.subscribe('VLAN_SUB_INTERFACE', make_callback(self.vlan_sub_intf_handler)) self.config_db.subscribe('PORTCHANNEL_INTERFACE', make_callback(self.portchannel_intf_handler)) self.config_db.subscribe('INTERFACE', make_callback(self.phy_intf_handler)) - + syslog.syslog(syslog.LOG_INFO, "Waiting for systemctl to finish initialization") self.wait_till_system_init_done() @@ -1251,4 +1255,3 @@ def main(): if __name__ == "__main__": main() - diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index d57e08b3b5cb..72e5fd800180 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -631,3 +631,12 @@ def is_fast_reboot_enabled(): fb_system_state = stdout.rstrip('\n') return fb_system_state + +def is_gbsyncd_platform(): + platform = get_platform() + if platform is None: + return False + gbsyncd_ini_file = "/usr/share/sonic/device/{}/gbsyncd.ini".format(platform) + if os.path.exists(gbsyncd_ini_file): + return True + return False \ No newline at end of file