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

add gbsyncd to feature table on supported platforms #10834

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion files/build_templates/init_cfg.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
17 changes: 10 additions & 7 deletions src/sonic-host-services/scripts/hostcfgd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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()
Expand All @@ -1251,4 +1255,3 @@ def main():

if __name__ == "__main__":
main()

9 changes: 9 additions & 0 deletions src/sonic-py-common/sonic_py_common/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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