Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generic_updater: Fix service validator related issues #1901

Merged
merged 16 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

@qiluo-msft qiluo-msft Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generic_config_updater.conf

Regarding the filename, generic_config_updater.conf.json seems make more sense. It is confusing to see ..config.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