Skip to content
Merged
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
11 changes: 9 additions & 2 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,15 @@ def _get_sonic_services():


def _get_delayed_sonic_services():
out = clicommon.run_command("systemctl list-dependencies --plain sonic-delayed.target | sed '1d'", return_cmd=True)
return (unit.strip().rstrip('.timer') for unit in out.splitlines())
rc1 = clicommon.run_command("systemctl list-dependencies --plain sonic-delayed.target | sed '1d'", return_cmd=True)
rc2 = clicommon.run_command("systemctl is-enabled {}".format(rc1.replace("\n", " ")), return_cmd=True)
timer = [line.strip() for line in rc1.splitlines()]
state = [line.strip() for line in rc2.splitlines()]
services = []
for unit in timer:
if state[timer.index(unit)] == "enabled":
services.append(unit.rstrip(".timer"))
return services


def _reset_failed_services():
Expand Down
4 changes: 3 additions & 1 deletion tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def mock_run_command_side_effect(*args, **kwargs):
return 'snmp.timer'
elif command == "systemctl list-dependencies --plain sonic.target | sed '1d'":
return 'swss'
elif command == "systemctl is-enabled snmp.timer":
return 'enabled'
else:
return ''

Expand Down Expand Up @@ -164,7 +166,7 @@ def test_load_minigraph(self, get_cmd_module, setup_single_broadcom_asic):
mock_run_command.assert_any_call('systemctl reset-failed swss')
# Verify "systemctl reset-failed" is called for services under sonic-delayed.target
mock_run_command.assert_any_call('systemctl reset-failed snmp')
assert mock_run_command.call_count == 10
assert mock_run_command.call_count == 11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgsudharsan what this hard coded number stands for? should we count it in a better way than just a number?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the logic is testing for number of calls to clicommon.run_command which is internal implementation. There is no way of knowing it in test script (even in the code). If tomorrow an additional command gets added this needs to be changed again. I agree this is not a deterministic method but its an existing code and I am not sure of the motivation.
For e.g below are the calls internally invoked.
sudo systemctl stop sonic.target --job-mode replace-irreversibly
/usr/local/bin/sonic-cfggen -H -m --write-to-db
config qos reload --no-dynamic-buffer
pfcwd start_default
systemctl list-dependencies --plain sonic.target | sed '1d'
systemctl list-dependencies --plain sonic-delayed.target | sed '1d'
systemctl is-enabled snmp.timer
systemctl reset-failed swss
systemctl reset-failed snmp
sudo systemctl restart sonic.target
sudo monit reload


def test_load_minigraph_with_port_config_bad_format(self, get_cmd_module, setup_single_broadcom_asic):
with mock.patch(
Expand Down