Skip to content

Commit aa971f6

Browse files
authored
Revert "[featured] fix non existing feature start (#234)" (#272)
This reverts commit 29b8be8. Because it blocks submodule update in sonic-buildimage repo. The build and test are verified in a draft PR sonic-net/sonic-buildimage#23027.
1 parent 04e49f8 commit aa971f6

File tree

2 files changed

+6
-60
lines changed

2 files changed

+6
-60
lines changed

scripts/featured

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,11 @@ class FeatureHandler(object):
274274
return True
275275

276276
if enable:
277-
if not self.enable_feature(feature):
278-
return False
277+
self.enable_feature(feature)
279278
syslog.syslog(syslog.LOG_INFO, "Feature {} is enabled and started".format(feature.name))
280279

281280
if disable:
282-
if not self.disable_feature(feature):
283-
return False
281+
self.disable_feature(feature)
284282
syslog.syslog(syslog.LOG_INFO, "Feature {} is stopped and disabled".format(feature.name))
285283

286284
return True
@@ -415,7 +413,7 @@ class FeatureHandler(object):
415413
for feature_name in feature_names:
416414
# Check if it is already enabled, if yes skip the system call
417415
unit_file_state = self.get_systemd_unit_state("{}.{}".format(feature_name, feature_suffixes[-1]))
418-
if unit_file_state == "enabled":
416+
if unit_file_state == "enabled" or not unit_file_state:
419417
continue
420418
cmds = []
421419
for suffix in feature_suffixes:
@@ -435,17 +433,16 @@ class FeatureHandler(object):
435433
syslog.syslog(syslog.LOG_ERR, "Feature '{}.{}' failed to be enabled and started"
436434
.format(feature.name, feature_suffixes[-1]))
437435
self.set_feature_state(feature, self.FEATURE_STATE_FAILED)
438-
return False
436+
return
439437

440438
self.set_feature_state(feature, self.FEATURE_STATE_ENABLED)
441-
return True
442439

443440
def disable_feature(self, feature):
444441
feature_names, feature_suffixes = self.get_multiasic_feature_instances(feature)
445442
for feature_name in feature_names:
446443
# Check if it is already disabled, if yes skip the system call
447444
unit_file_state = self.get_systemd_unit_state("{}.{}".format(feature_name, feature_suffixes[-1]))
448-
if unit_file_state in ("disabled", "masked"):
445+
if unit_file_state in ("disabled", "masked") or not unit_file_state:
449446
continue
450447
cmds = []
451448
for suffix in reversed(feature_suffixes):
@@ -460,10 +457,9 @@ class FeatureHandler(object):
460457
syslog.syslog(syslog.LOG_ERR, "Feature '{}.{}' failed to be stopped and disabled"
461458
.format(feature.name, feature_suffixes[-1]))
462459
self.set_feature_state(feature, self.FEATURE_STATE_FAILED)
463-
return False
460+
return
464461

465462
self.set_feature_state(feature, self.FEATURE_STATE_DISABLED)
466-
return True
467463

468464
def resync_feature_state(self, feature):
469465
current_entry = self._config_db.get_entry('FEATURE', feature.name)

tests/featured/featured_test.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -493,53 +493,3 @@ def test_portinit_timeout(self, mock_syslog, get_runtime):
493493
call(['sudo', 'systemctl', 'enable', 'telemetry.service'], capture_output=True, check=True, text=True),
494494
call(['sudo', 'systemctl', 'start', 'telemetry.service'], capture_output=True, check=True, text=True)]
495495
mocked_subprocess.run.assert_has_calls(expected, any_order=True)
496-
497-
def test_systemctl_command_failure(self, mock_syslog, get_runtime):
498-
"""Test that when systemctl commands fail:
499-
1. The feature state is not cached
500-
2. The feature state is set to FAILED
501-
3. The update_feature_state returns False
502-
"""
503-
mock_db = mock.MagicMock()
504-
mock_feature_state_table = mock.MagicMock()
505-
506-
feature_handler = featured.FeatureHandler(mock_db, mock_feature_state_table, {}, False)
507-
feature_handler.is_delayed_enabled = True
508-
509-
# Create a feature that should be enabled
510-
feature_name = 'test_feature'
511-
feature_cfg = {
512-
'state': 'enabled',
513-
'auto_restart': 'enabled',
514-
'delayed': 'False',
515-
'has_global_scope': 'True',
516-
'has_per_asic_scope': 'False'
517-
}
518-
519-
# Initialize the feature in cached_config using the same pattern as in featured
520-
feature = featured.Feature(feature_name, feature_cfg)
521-
feature_handler._cached_config.setdefault(feature_name, featured.Feature(feature_name, {}))
522-
523-
# Mock subprocess.run and Popen to simulate command failure
524-
with mock.patch('featured.subprocess') as mocked_subprocess:
525-
# Mock Popen for get_systemd_unit_state
526-
popen_mock = mock.Mock()
527-
popen_mock.communicate.return_value = ('enabled', '')
528-
popen_mock.returncode = 1
529-
mocked_subprocess.Popen.return_value = popen_mock
530-
531-
# Mock run_cmd to raise an exception
532-
with mock.patch('featured.run_cmd') as mocked_run_cmd:
533-
mocked_run_cmd.side_effect = Exception("Command failed")
534-
535-
# Try to update feature state
536-
result = feature_handler.update_feature_state(feature)
537-
538-
# Verify the result is False
539-
assert result is False
540-
541-
# Verify the feature state was set to FAILED
542-
mock_feature_state_table.set.assert_called_with('test_feature', [('state', 'failed')])
543-
544-
# Verify the feature state was not enabled in the cache
545-
assert feature_handler._cached_config[feature.name].state != 'enabled'

0 commit comments

Comments
 (0)