Skip to content

Commit 095bf54

Browse files
generic_updater: Fix service validator related issues (sonic-net#1901)
1) Copy generic_updater_config.conf.json as part of install 2) Read conf file from install dir 3) Drop empty keys & tables upon jsonpatch.JsonPatch.apply to be in sync with redis update 4) Prefix service_validator module path with "generic_updater"
1 parent efbe1f4 commit 095bf54

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

generic_config_updater/change_applier.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from swsscommon.swsscommon import ConfigDBConnector
99
from .gu_common import genericUpdaterLogging
1010

11-
12-
UPDATER_CONF_FILE = "/etc/sonic/generic_config_updater.conf"
11+
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
12+
UPDATER_CONF_FILE = f"{SCRIPT_DIR}/generic_updater_config.conf.json"
1313
logger = genericUpdaterLogging.get_logger(title="Change Applier")
1414

1515
print_to_console = False
@@ -44,6 +44,19 @@ def set_config(config_db, tbl, key, data):
4444
config_db.set_entry(tbl, key, data)
4545

4646

47+
def prune_empty_table(data):
48+
# For JSON Patch empty entries are valid
49+
# With redis, when last key is removed, the table gets removed too.
50+
#
51+
# Hence where required, prune tables with no keys.
52+
#
53+
tables = list(data.keys())
54+
for tbl in tables:
55+
if not data[tbl]:
56+
data.pop(tbl)
57+
return data
58+
59+
4760
class ChangeApplier:
4861

4962
updater_conf = None
@@ -111,7 +124,7 @@ def _report_mismatch(self, run_data, upd_data):
111124

112125
def apply(self, change):
113126
run_data = self._get_running_config()
114-
upd_data = change.apply(copy.deepcopy(run_data))
127+
upd_data = prune_empty_table(change.apply(copy.deepcopy(run_data)))
115128
upd_keys = defaultdict(dict)
116129

117130
for tbl in sorted(set(run_data.keys()).union(set(upd_data.keys()))):

generic_config_updater/generic_updater_config.conf.json

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
11
{
2-
"tables": {
3-
"": {
4-
"services_to_validate": [ "system_health" ]
5-
},
6-
"PORT": {
7-
"services_to_validate": [ "port_service" ]
8-
},
9-
"SYSLOG_SERVER":{
10-
"services_to_validate": [ "rsyslog" ]
11-
},
12-
"DHCP_RELAY": {
13-
"services_to_validate": [ "dhcp-relay" ]
14-
},
15-
"DHCP_SERVER": {
16-
"services_to_validate": [ "dhcp-relay" ]
17-
}
18-
},
192
"README": [
203
"Validate_commands provides, module & method name as ",
214
" <module name>.<method name>",
@@ -41,6 +24,23 @@
4124
"Note: The commands may be called in any order",
4225
""
4326
],
27+
"tables": {
28+
"": {
29+
"services_to_validate": [ "system_health" ]
30+
},
31+
"PORT": {
32+
"services_to_validate": [ "port_service" ]
33+
},
34+
"SYSLOG_SERVER":{
35+
"services_to_validate": [ "rsyslog" ]
36+
},
37+
"DHCP_RELAY": {
38+
"services_to_validate": [ "dhcp-relay" ]
39+
},
40+
"DHCP_SERVER": {
41+
"services_to_validate": [ "dhcp-relay" ]
42+
}
43+
},
4444
"services": {
4545
"system_health": {
4646
"validate_commands": [ ]
@@ -49,10 +49,10 @@
4949
"validate_commands": [ ]
5050
},
5151
"rsyslog": {
52-
"validate_commands": [ "services_validator.ryslog_validator" ]
52+
"validate_commands": [ "generic_config_updater.services_validator.ryslog_validator" ]
5353
},
5454
"dhcp-relay": {
55-
"validate_commands": [ "services_validator.dhcp_validator" ]
55+
"validate_commands": [ "generic_config_updater.services_validator.dhcp_validator" ]
5656
}
5757
}
5858
}

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
'watchdogutil',
5959
],
6060
package_data={
61+
'generic_config_updater': ['generic_updater_config.conf.json'],
6162
'show': ['aliases.ini'],
6263
'sonic_installer': ['aliases.ini'],
6364
'tests': ['acl_input/*',

0 commit comments

Comments
 (0)