Skip to content

Commit

Permalink
Revert "Remove syslog service validator in GCU (#2991)" (#3015)
Browse files Browse the repository at this point in the history
This reverts commit 6ba6ddf.
  • Loading branch information
wen587 authored and StormLiangMS committed Oct 25, 2023
1 parent ab7f03e commit 569beb1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions generic_config_updater/gcu_services_validator.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"PORT": {
"services_to_validate": [ "port_service" ]
},
"SYSLOG_SERVER":{
"services_to_validate": [ "rsyslog" ]
},
"DHCP_RELAY": {
"services_to_validate": [ "dhcp-relay" ]
},
Expand All @@ -57,6 +60,9 @@
"port_service": {
"validate_commands": [ ]
},
"rsyslog": {
"validate_commands": [ "generic_config_updater.services_validator.rsyslog_validator" ]
},
"dhcp-relay": {
"validate_commands": [ "generic_config_updater.services_validator.dhcp_validator" ]
},
Expand Down
8 changes: 8 additions & 0 deletions generic_config_updater/services_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ def _service_restart(svc_name):
return rc == 0


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


def dhcp_validator(old_config, upd_config, keys):
return _service_restart("dhcp_relay")

Expand Down
18 changes: 17 additions & 1 deletion tests/generic_config_updater/service_validator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections import defaultdict
from unittest.mock import patch

from generic_config_updater.services_validator import vlan_validator, caclmgrd_validator, vlanintf_validator
from generic_config_updater.services_validator import vlan_validator, rsyslog_validator, caclmgrd_validator, vlanintf_validator
import generic_config_updater.gu_common


Expand Down Expand Up @@ -142,6 +142,16 @@ 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_vlanintf_data = [
{ "old": {}, "upd": {}, "cmd": "" },
{
Expand Down Expand Up @@ -201,6 +211,12 @@ def test_change_apply_os_system(self, mock_os_sys):

# Test failure case
#
os_system_calls = test_rsyslog_fail
os_system_call_index = 0

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

os_system_calls = []
os_system_call_index = 0
for entry in test_vlanintf_data:
Expand Down

0 comments on commit 569beb1

Please sign in to comment.