Skip to content

Commit 04ca8f6

Browse files
authored
Merge branch 'sonic-net:master' into master
2 parents 760ecb5 + fd638d4 commit 04ca8f6

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

scripts/featured

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Feature(object):
7777
self.state = self._get_feature_table_key_render_value(feature_cfg.get('state'), device_config or {}, ['enabled', 'disabled', 'always_enabled', 'always_disabled'])
7878
self.auto_restart = feature_cfg.get('auto_restart', 'disabled')
7979
self.delayed = safe_eval(feature_cfg.get('delayed', 'False'))
80-
self.has_global_scope = safe_eval(feature_cfg.get('has_global_scope', 'True'))
80+
self.has_global_scope = safe_eval(self._get_feature_table_key_render_value(feature_cfg.get('has_global_scope', 'True'), device_config or {}, ['True', 'False']))
8181
self.has_per_asic_scope = safe_eval(self._get_feature_table_key_render_value(feature_cfg.get('has_per_asic_scope', 'False'), device_config or {}, ['True', 'False']))
8282
self.has_per_dpu_scope = safe_eval(feature_cfg.get('has_per_dpu_scope', 'False'))
8383

@@ -198,7 +198,7 @@ class FeatureHandler(object):
198198
# Enable/disable the container service if the feature state was changed from its previous state.
199199
if self._cached_config[feature_name].state != feature.state:
200200
if self.update_feature_state(feature):
201-
self.sync_feature_asic_scope(feature)
201+
self.sync_feature_scope(feature)
202202
self._cached_config[feature_name] = feature
203203
else:
204204
self.resync_feature_state(self._cached_config[feature_name])
@@ -222,7 +222,7 @@ class FeatureHandler(object):
222222
self._cached_config.setdefault(feature_name, feature)
223223
self.update_systemd_config(feature)
224224
self.update_feature_state(feature)
225-
self.sync_feature_asic_scope(feature)
225+
self.sync_feature_scope(feature)
226226
self.resync_feature_state(feature)
227227

228228
def update_feature_state(self, feature):
@@ -270,10 +270,10 @@ class FeatureHandler(object):
270270

271271
return True
272272

273-
def sync_feature_asic_scope(self, feature_config):
274-
"""Updates the has_per_asic_scope field in the FEATURE|* tables as the field
273+
def sync_feature_scope(self, feature_config):
274+
"""Updates the has_global_scope or has_per_asic_scope field in the FEATURE|* tables as the field
275275
might have to be rendered based on DEVICE_METADATA table or Device Running configuration.
276-
Disable the ASIC instance service unit file it the render value is False and update config
276+
Disable the Global/ASIC instance service unit file it the render value is False and update config
277277
278278
Args:
279279
feature: An object represents a feature's configuration in `FEATURE`
@@ -284,12 +284,11 @@ class FeatureHandler(object):
284284
"""
285285
feature_names, feature_suffixes = self.get_multiasic_feature_instances(feature_config, True)
286286
for feature_name in feature_names:
287-
if '@' not in feature_name:
288-
continue
289287
unit_file_state = self.get_systemd_unit_state("{}.{}".format(feature_name, feature_suffixes[-1]))
290288
if not unit_file_state:
291289
continue
292-
if unit_file_state != "disabled" and not feature_config.has_per_asic_scope:
290+
if unit_file_state != "disabled" and \
291+
((not feature_config.has_per_asic_scope and '@' in feature_name) or (not feature_config.has_global_scope and '@' not in feature_name)):
293292
cmds = []
294293
for suffix in reversed(feature_suffixes):
295294
cmds.append(["sudo", "systemctl", "stop", "{}.{}".format(feature_name, suffix)])
@@ -305,10 +304,12 @@ class FeatureHandler(object):
305304
self.set_feature_state(feature_config, self.FEATURE_STATE_FAILED)
306305
return
307306
self._config_db.mod_entry(FEATURE_TBL, feature_config.name, {'has_per_asic_scope': str(feature_config.has_per_asic_scope)})
307+
self._config_db.mod_entry(FEATURE_TBL, feature_config.name, {'has_global_scope': str(feature_config.has_global_scope)})
308308

309309
# sync has_per_asic_scope to CONFIG_DB in namespaces in multi-asic platform
310310
for ns, db in self.ns_cfg_db.items():
311311
db.mod_entry(FEATURE_TBL, feature_config.name, {'has_per_asic_scope': str(feature_config.has_per_asic_scope)})
312+
db.mod_entry(FEATURE_TBL, feature_config.name, {'has_global_scope': str(feature_config.has_global_scope)})
312313

313314
def update_systemd_config(self, feature_config):
314315
"""Updates `Restart=` field in feature's systemd configuration file
@@ -364,7 +365,7 @@ class FeatureHandler(object):
364365
def get_multiasic_feature_instances(self, feature, all_instance=False):
365366
# Create feature name suffix depending feature is running in host or namespace or in both
366367
feature_names = (
367-
([feature.name] if feature.has_global_scope or not self.is_multi_npu else []) +
368+
([feature.name] if feature.has_global_scope or all_instance or not self.is_multi_npu else []) +
368369
([(feature.name + '@' + str(asic_inst)) for asic_inst in range(device_info.get_num_npus())
369370
if self.is_multi_npu and (all_instance or feature.has_per_asic_scope)]) +
370371
([(feature.name + '@' + device_info.DPU_NAME_PREFIX + str(dpu_inst)) for dpu_inst in range(self.num_dpus)

tests/featured/featured_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def test_feature_config_parsing_defaults(self):
262262

263263
@mock.patch('featured.FeatureHandler.update_systemd_config', mock.MagicMock())
264264
@mock.patch('featured.FeatureHandler.update_feature_state', mock.MagicMock())
265-
@mock.patch('featured.FeatureHandler.sync_feature_asic_scope', mock.MagicMock())
265+
@mock.patch('featured.FeatureHandler.sync_feature_scope', mock.MagicMock())
266266
def test_feature_resync(self):
267267
mock_db = mock.MagicMock()
268268
mock_db.get_entry = mock.MagicMock()

tests/featured/test_vectors.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@
10831083
"lldp": {
10841084
"state": "enabled",
10851085
"delayed": "False",
1086-
"has_global_scope": "True",
1086+
"has_global_scope": "{% if ('CHASSIS_METADATA' in DEVICE_RUNTIME_METADATA and DEVICE_RUNTIME_METADATA['CHASSIS_METADATA']['module_type'] in ['linecard']) %}False{% else %}True{% endif %}",
10871087
"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 %}",
10881088
"auto_restart": "enabled",
10891089
"high_mem_alert": "disabled"
@@ -1118,7 +1118,7 @@
11181118
},
11191119
"lldp": {
11201120
"auto_restart": "enabled",
1121-
"has_global_scope": "True",
1121+
"has_global_scope": "False",
11221122
"has_per_asic_scope": "True",
11231123
"delayed": "False",
11241124
"high_mem_alert": "disabled",
@@ -1147,9 +1147,9 @@
11471147
call(['sudo', 'systemctl', 'unmask', '[email protected]']),
11481148
call(['sudo', 'systemctl', 'enable', '[email protected]']),
11491149
call(['sudo', 'systemctl', 'start', '[email protected]']),
1150-
call(['sudo', 'systemctl', 'unmask', 'lldp.service']),
1151-
call(['sudo', 'systemctl', 'enable', 'lldp.service']),
1152-
call(['sudo', 'systemctl', 'start', 'lldp.service']),
1150+
call(['sudo', 'systemctl', 'mask', 'lldp.service']),
1151+
call(['sudo', 'systemctl', 'disable', 'lldp.service']),
1152+
call(['sudo', 'systemctl', 'stop', 'lldp.service']),
11531153
call(['sudo', 'systemctl', 'unmask', '[email protected]']),
11541154
call(['sudo', 'systemctl', 'enable', '[email protected]']),
11551155
call(['sudo', 'systemctl', 'start', '[email protected]']),

0 commit comments

Comments
 (0)