-
Notifications
You must be signed in to change notification settings - Fork 656
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_config_updater: Filename changed & VLAN validator added #1919
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7863b59
ChangeApplier and unit test code.
renukamanavalan 84f493b
minor update
renukamanavalan dd337eb
fix unused import
renukamanavalan 6e0bba0
Added service validation
renukamanavalan cabcf23
Take off added code for logging
renukamanavalan a075606
Merge remote-tracking branch 'upstream/master' into updater
renukamanavalan bd7781c
fix merge
renukamanavalan f839e53
change applier & test updated for service validation
renukamanavalan beb1ea7
removed unused import
renukamanavalan fe25d2e
Added two service validators
renukamanavalan fec8f8f
move global to class; No logical code changes
renukamanavalan 7d90266
A fix in file path
renukamanavalan 91f8f7e
Merge remote-tracking branch 'upstream/master' into updater
renukamanavalan 6cd9dd8
1) Copy generic_updater_config.conf.json as part of install
renukamanavalan 5a9434b
Merge remote-tracking branch 'upstream/master' into updater
renukamanavalan 30feec2
Prune only empty tables
renukamanavalan 8cd17fd
file rename
renukamanavalan 7533ed1
Merge remote-tracking branch 'upstream/master' into updater
renukamanavalan 9abb300
1) Drop print to stdout from change_applier
renukamanavalan a41052b
No logical code changes; Name changes only, per review comments
renukamanavalan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,41 @@ | |
|
||
logger = genericUpdaterLogging.get_logger(title="Service Validator") | ||
|
||
print_to_console = False | ||
|
||
def set_verbose(verbose=False): | ||
global print_to_console, logger | ||
|
||
print_to_console = verbose | ||
if verbose: | ||
logger.set_min_log_priority_debug() | ||
else: | ||
logger.set_min_log_priority_notice() | ||
|
||
|
||
def _service_restart(svc_name): | ||
os.system(f"systemctl restart {svc_name}") | ||
logger.log_notice(f"Restarted {svc_name}") | ||
rc = os.system(f"systemctl restart {svc_name}") | ||
logger.log(logger.LOG_PRIORITY_NOTICE, | ||
f"Restarted {svc_name}", print_to_console) | ||
return rc == 0 | ||
|
||
|
||
def ryslog_validator(old_config, upd_config, keys): | ||
_service_restart("rsyslog-config") | ||
def rsyslog_validator(old_config, upd_config, keys): | ||
return _service_restart("rsyslog-config") | ||
|
||
|
||
def dhcp_validator(old_config, upd_config, keys): | ||
_service_restart("dhcp_relay") | ||
return _service_restart("dhcp_relay") | ||
|
||
|
||
def vlan_validator(old_config, upd_config, keys): | ||
old_vlan = old_config.get("VLAN", {}) | ||
upd_vlan = upd_config.get("VLAN", {}) | ||
|
||
for key in set(old_vlan.keys()).union(set(upd_vlan.keys())): | ||
if (old_vlan.get(key, {}).get("dhcp_servers", []) != | ||
upd_vlan.get(key, {}).get("dhcp_servers", [])): | ||
return _service_restart("dhcp_relay") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NICE! We just restart dhcp at the first occurrence of mismatch between dhcp_servers in old vs updated. |
||
# No update to DHCP servers. | ||
return True | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import copy | ||
import json | ||
import jsondiff | ||
import os | ||
import unittest | ||
from collections import defaultdict | ||
from unittest.mock import patch | ||
|
||
from generic_config_updater.services_validator import vlan_validator | ||
import generic_config_updater.gu_common | ||
|
||
|
||
# Mimics os.system call | ||
# | ||
os_system_expected_cmd = "" | ||
msg = "" | ||
|
||
def os_system_cfggen(cmd): | ||
assert cmd == os_system_expected_cmd, msg | ||
return 0 | ||
|
||
|
||
test_data = [ | ||
{ "old": {}, "upd": {}, "cmd": "" }, | ||
{ | ||
"old": { "VLAN": { "XXX": { "dhcp_servers": [ "10.10.10.10" ] } } }, | ||
"upd": { "VLAN": { "XXX": { "dhcp_servers": [ "10.10.10.10" ] } } }, | ||
"cmd": "" | ||
}, | ||
{ | ||
"old": { "VLAN": { "XXX": { "dhcp_servers": [ "10.10.10.10" ] } } }, | ||
"upd": { "VLAN": { "XXX": { "dhcp_servers": [ "10.10.10.11" ] } } }, | ||
"cmd": "systemctl restart dhcp_relay" | ||
}, | ||
{ | ||
"old": { "VLAN": { "XXX": { "dhcp_servers": [ "10.10.10.10" ] } } }, | ||
"upd": { "VLAN": { | ||
"XXX": { "dhcp_servers": [ "10.10.10.10" ] }, | ||
"YYY": { "dhcp_servers": [ ] } } }, | ||
"cmd": "" | ||
}, | ||
{ | ||
"old": { "VLAN": { "XXX": { "dhcp_servers": [ "10.10.10.10" ] } } }, | ||
"upd": { "VLAN": { | ||
"XXX": { "dhcp_servers": [ "10.10.10.10" ] }, | ||
"YYY": { "dhcp_servers": [ "10.12.12.1" ] } } }, | ||
"cmd": "systemctl restart dhcp_relay" | ||
}, | ||
{ | ||
"old": { "VLAN": { "XXX": { "dhcp_servers": [ "10.10.10.10" ] } } }, | ||
"upd": {}, | ||
"cmd": "systemctl restart dhcp_relay" | ||
} | ||
] | ||
|
||
class TestServiceValidator(unittest.TestCase): | ||
|
||
@patch("generic_config_updater.change_applier.os.system") | ||
def test_change_apply(self, mock_os_sys): | ||
global os_system_expected_cmd | ||
|
||
mock_os_sys.side_effect = os_system_cfggen | ||
|
||
i = 0 | ||
for entry in test_data: | ||
os_system_expected_cmd = entry["cmd"] | ||
msg = "case failed: {}".format(str(entry)) | ||
|
||
vlan_validator(entry["old"], entry["upd"], None) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the design doc https://github.com/Azure/SONiC/blob/master/doc/config-generic-update-rollback/Json_Change_Application_Design.md#3212-metadata. It fits better as
restart-command
thanservices_to_validate
#ClosedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not blindly restart.
For example, in case of VLAN table update, we call vlan_validator, which may or may not restart dhcp_sevice.
Again a validator, could potentially restart more than one and possibly none too, as in vlan case.
So I prefer this name validator, which is table specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the intelligence of restarting dhcp_service for vlan-service. However, the validator is design as read-only operations for the purpose of validation, including validating services are completely restarted and healthy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get your last comments. But Design doc updated.