Skip to content

Commit

Permalink
Update GCU rsyslog validator (sonic-net#3012)
Browse files Browse the repository at this point in the history
What I did
In the privous PR sonic-net#2991, we removed the rsyslog validator because the background daemon can now react(reset-failed & restart) the rsyslog service when the configuration changes.

However, this change introduced an issue found in nightly tests. The problem is that there is a chance that the rsyslog service is not refreshed promptly after modification.

We have two potential solutions: we can either modify the sonic-mgmt syslog test to wait more time for the completion of the rsyslog update or reintroduce the syslog validator with enhancements. As the update for rsyslog happens after the completion of the GCU apply-patch, I choose to modify in GCU to ensure that it accurately reflects the completion of the rsyslog change when the apply-patch process is finished.

Now the behavior in this pull request aligns with the SONiC CLI when updating rsyslog settings.

How I did it
Add back and update GCU rsyslog validator and align it with syslog CLI.

How to verify it
Unit test and E2E test
  • Loading branch information
wen587 authored Nov 13, 2023
1 parent 253b797 commit 67e1c3d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
14 changes: 9 additions & 5 deletions generic_config_updater/services_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ def _service_restart(svc_name):


def rsyslog_validator(old_config, upd_config, keys):
rc = os.system("/usr/bin/rsyslog-config.sh")
if rc != 0:
return _service_restart("rsyslog")
else:
return True
old_syslog = old_config.get("SYSLOG_SERVER", {})
upd_syslog = upd_config.get("SYSLOG_SERVER", {})

if old_syslog != upd_syslog:
os.system("systemctl reset-failed rsyslog-config rsyslog")
rc = os.system("systemctl restart rsyslog-config")
if rc != 0:
return False
return True


def dhcp_validator(old_config, upd_config, keys):
Expand Down
55 changes: 41 additions & 14 deletions tests/generic_config_updater/service_validator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,39 @@ def mock_time_sleep_call(sleep_time):
},
]

test_rsyslog_fail = [
# Fail the calls, to get the entire fail path calls invoked
#
{ "cmd": "/usr/bin/rsyslog-config.sh", "rc": 1 }, # config update; fails
{ "cmd": "systemctl restart rsyslog", "rc": 1 }, # rsyslog restart; fails
{ "cmd": "systemctl reset-failed rsyslog", "rc": 1 }, # reset; failure here just logs
{ "cmd": "systemctl restart rsyslog", "rc": 1 }, # restart again; fails
{ "cmd": "systemctl restart rsyslog", "rc": 1 }, # restart again; fails

test_rsyslog_data = [
{ "old": {}, "upd": {}, "cmd": "" },
{
"old": { "SYSLOG_SERVER": {
"10.13.14.17": {},
"2001:aa:aa::aa": {} } },
"upd": { "SYSLOG_SERVER": {
"10.13.14.17": {},
"2001:aa:aa::aa": {} } },
"cmd": ""
},
{
"old": { "SYSLOG_SERVER": {
"10.13.14.17": {} } },
"upd": { "SYSLOG_SERVER": {
"10.13.14.18": {} } },
"cmd": "systemctl reset-failed rsyslog-config rsyslog,systemctl restart rsyslog-config"
},
{
"old": { "SYSLOG_SERVER": {
"10.13.14.17": {} } },
"upd": { "SYSLOG_SERVER": {
"10.13.14.17": {},
"2001:aa:aa::aa": {} } },
"cmd": "systemctl reset-failed rsyslog-config rsyslog,systemctl restart rsyslog-config"
},
{
"old": { "SYSLOG_SERVER": {
"10.13.14.17": {} } },
"upd": {},
"cmd": "systemctl reset-failed rsyslog-config rsyslog,systemctl restart rsyslog-config"
}
]

test_vlanintf_data = [
Expand Down Expand Up @@ -208,14 +233,16 @@ def test_change_apply_os_system(self, mock_os_sys):
vlan_validator(entry["old"], entry["upd"], None)



# Test failure case
#
os_system_calls = test_rsyslog_fail
os_system_calls = []
os_system_call_index = 0
for entry in test_rsyslog_data:
if entry["cmd"]:
for c in entry["cmd"].split(","):
os_system_calls.append({"cmd": c, "rc": 0})
msg = "case failed: {}".format(str(entry))

rsyslog_validator(entry["old"], entry["upd"], None)

rc = rsyslog_validator("", "", "")
assert not rc, "rsyslog_validator expected to fail"

os_system_calls = []
os_system_call_index = 0
Expand Down

0 comments on commit 67e1c3d

Please sign in to comment.