Skip to content

Commit 67e1c3d

Browse files
authored
Update GCU rsyslog validator (#3012)
What I did In the privous PR #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
1 parent 253b797 commit 67e1c3d

File tree

2 files changed

+50
-19
lines changed

2 files changed

+50
-19
lines changed

generic_config_updater/services_validator.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@ def _service_restart(svc_name):
4949

5050

5151
def rsyslog_validator(old_config, upd_config, keys):
52-
rc = os.system("/usr/bin/rsyslog-config.sh")
53-
if rc != 0:
54-
return _service_restart("rsyslog")
55-
else:
56-
return True
52+
old_syslog = old_config.get("SYSLOG_SERVER", {})
53+
upd_syslog = upd_config.get("SYSLOG_SERVER", {})
54+
55+
if old_syslog != upd_syslog:
56+
os.system("systemctl reset-failed rsyslog-config rsyslog")
57+
rc = os.system("systemctl restart rsyslog-config")
58+
if rc != 0:
59+
return False
60+
return True
5761

5862

5963
def dhcp_validator(old_config, upd_config, keys):

tests/generic_config_updater/service_validator_test.py

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,39 @@ def mock_time_sleep_call(sleep_time):
142142
},
143143
]
144144

145-
test_rsyslog_fail = [
146-
# Fail the calls, to get the entire fail path calls invoked
147-
#
148-
{ "cmd": "/usr/bin/rsyslog-config.sh", "rc": 1 }, # config update; fails
149-
{ "cmd": "systemctl restart rsyslog", "rc": 1 }, # rsyslog restart; fails
150-
{ "cmd": "systemctl reset-failed rsyslog", "rc": 1 }, # reset; failure here just logs
151-
{ "cmd": "systemctl restart rsyslog", "rc": 1 }, # restart again; fails
152-
{ "cmd": "systemctl restart rsyslog", "rc": 1 }, # restart again; fails
145+
146+
test_rsyslog_data = [
147+
{ "old": {}, "upd": {}, "cmd": "" },
148+
{
149+
"old": { "SYSLOG_SERVER": {
150+
"10.13.14.17": {},
151+
"2001:aa:aa::aa": {} } },
152+
"upd": { "SYSLOG_SERVER": {
153+
"10.13.14.17": {},
154+
"2001:aa:aa::aa": {} } },
155+
"cmd": ""
156+
},
157+
{
158+
"old": { "SYSLOG_SERVER": {
159+
"10.13.14.17": {} } },
160+
"upd": { "SYSLOG_SERVER": {
161+
"10.13.14.18": {} } },
162+
"cmd": "systemctl reset-failed rsyslog-config rsyslog,systemctl restart rsyslog-config"
163+
},
164+
{
165+
"old": { "SYSLOG_SERVER": {
166+
"10.13.14.17": {} } },
167+
"upd": { "SYSLOG_SERVER": {
168+
"10.13.14.17": {},
169+
"2001:aa:aa::aa": {} } },
170+
"cmd": "systemctl reset-failed rsyslog-config rsyslog,systemctl restart rsyslog-config"
171+
},
172+
{
173+
"old": { "SYSLOG_SERVER": {
174+
"10.13.14.17": {} } },
175+
"upd": {},
176+
"cmd": "systemctl reset-failed rsyslog-config rsyslog,systemctl restart rsyslog-config"
177+
}
153178
]
154179

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

210235

211-
212-
# Test failure case
213-
#
214-
os_system_calls = test_rsyslog_fail
236+
os_system_calls = []
215237
os_system_call_index = 0
238+
for entry in test_rsyslog_data:
239+
if entry["cmd"]:
240+
for c in entry["cmd"].split(","):
241+
os_system_calls.append({"cmd": c, "rc": 0})
242+
msg = "case failed: {}".format(str(entry))
243+
244+
rsyslog_validator(entry["old"], entry["upd"], None)
216245

217-
rc = rsyslog_validator("", "", "")
218-
assert not rc, "rsyslog_validator expected to fail"
219246

220247
os_system_calls = []
221248
os_system_call_index = 0

0 commit comments

Comments
 (0)