Skip to content

Commit

Permalink
generic_updater: Fix service validator related issues (#1901)
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
renukamanavalan authored Nov 5, 2021
1 parent efbe1f4 commit 095bf54
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
19 changes: 16 additions & 3 deletions generic_config_updater/change_applier.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from swsscommon.swsscommon import ConfigDBConnector
from .gu_common import genericUpdaterLogging


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

print_to_console = False
Expand Down Expand Up @@ -44,6 +44,19 @@ def set_config(config_db, tbl, key, data):
config_db.set_entry(tbl, key, data)


def prune_empty_table(data):
# For JSON Patch empty entries are valid
# With redis, when last key is removed, the table gets removed too.
#
# Hence where required, prune tables with no keys.
#
tables = list(data.keys())
for tbl in tables:
if not data[tbl]:
data.pop(tbl)
return data


class ChangeApplier:

updater_conf = None
Expand Down Expand Up @@ -111,7 +124,7 @@ def _report_mismatch(self, run_data, upd_data):

def apply(self, change):
run_data = self._get_running_config()
upd_data = change.apply(copy.deepcopy(run_data))
upd_data = prune_empty_table(change.apply(copy.deepcopy(run_data)))
upd_keys = defaultdict(dict)

for tbl in sorted(set(run_data.keys()).union(set(upd_data.keys()))):
Expand Down
38 changes: 19 additions & 19 deletions generic_config_updater/generic_updater_config.conf.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
{
"tables": {
"": {
"services_to_validate": [ "system_health" ]
},
"PORT": {
"services_to_validate": [ "port_service" ]
},
"SYSLOG_SERVER":{
"services_to_validate": [ "rsyslog" ]
},
"DHCP_RELAY": {
"services_to_validate": [ "dhcp-relay" ]
},
"DHCP_SERVER": {
"services_to_validate": [ "dhcp-relay" ]
}
},
"README": [
"Validate_commands provides, module & method name as ",
" <module name>.<method name>",
Expand All @@ -41,6 +24,23 @@
"Note: The commands may be called in any order",
""
],
"tables": {
"": {
"services_to_validate": [ "system_health" ]
},
"PORT": {
"services_to_validate": [ "port_service" ]
},
"SYSLOG_SERVER":{
"services_to_validate": [ "rsyslog" ]
},
"DHCP_RELAY": {
"services_to_validate": [ "dhcp-relay" ]
},
"DHCP_SERVER": {
"services_to_validate": [ "dhcp-relay" ]
}
},
"services": {
"system_health": {
"validate_commands": [ ]
Expand All @@ -49,10 +49,10 @@
"validate_commands": [ ]
},
"rsyslog": {
"validate_commands": [ "services_validator.ryslog_validator" ]
"validate_commands": [ "generic_config_updater.services_validator.ryslog_validator" ]
},
"dhcp-relay": {
"validate_commands": [ "services_validator.dhcp_validator" ]
"validate_commands": [ "generic_config_updater.services_validator.dhcp_validator" ]
}
}
}
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'watchdogutil',
],
package_data={
'generic_config_updater': ['generic_updater_config.conf.json'],
'show': ['aliases.ini'],
'sonic_installer': ['aliases.ini'],
'tests': ['acl_input/*',
Expand Down

0 comments on commit 095bf54

Please sign in to comment.