-
Notifications
You must be signed in to change notification settings - Fork 1k
[recovery] introduce adaptive recover method #1583
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
Changes from 5 commits
09e1d34
06dcd60
18e52b0
e004bdf
9841c5d
752b755
38fa48b
911eaca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
|
|
||
| from common.utilities import wait, wait_until | ||
| from common.errors import RunAnsibleModuleFail | ||
| from common.platform.device_utils import fanout_switch_port_lookup | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -26,13 +27,58 @@ def reboot_dut(dut, localhost, cmd): | |
| assert False, "Failed to reboot the DUT" | ||
|
|
||
| localhost.wait_for(host=dut.hostname, port=22, state="started", delay=10, timeout=300) | ||
| wait(30, msg="Wait 30 seconds for system to be stable.") | ||
| wait(120, msg="Wait 120 seconds for system to be stable.") | ||
daall marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def recover(dut, localhost, recover_method): | ||
| def __recover_interfaces(dut, fanouthosts, result): | ||
| for port in result['down_ports']: | ||
| logging.info("Restoring port {}".format(port)) | ||
| fanout, fanout_port = fanout_switch_port_lookup(fanouthosts, port) | ||
| if fanout and fanout_port: | ||
| fanout.no_shutdown(fanout_port) | ||
| dut.no_shutdown(port) | ||
| wait(30, msg="Wait 30 seconds for interface(s) to restore.") | ||
|
||
|
|
||
|
|
||
| def __recover_services(dut, result): | ||
| status = result['services_status'] | ||
| services = [ x for x in status if not status[x] ] | ||
| logging.info("Service(s) down: {}".format(services)) | ||
| return 'reboot' if 'database' in services else 'config_reload' | ||
|
|
||
|
|
||
| def adaptive_recover(dut, localhost, fanouthosts, check_results): | ||
| outstanding_action = None | ||
| for result in check_results: | ||
| if result['failed']: | ||
| logging.info("Restoring {}".format(result)) | ||
| if result['check_item'] == 'interfaces': | ||
| __recover_interfaces(dut, fanouthosts, result) | ||
| elif result['check_item'] == 'services': | ||
| action = __recover_services(dut, result) | ||
| # Only allow outstanding_action be overridden when it is | ||
| # None. In case the outstanding_action has already been | ||
| # been set to 'reboot'. | ||
| outstanding_action = action if not outstanding_action | ||
| else: | ||
| outstanding_action = 'reboot' | ||
|
|
||
| if outstanding_action: | ||
| method = constants.RECOVER_METHODS[outstanding_action] | ||
| if method["reboot"]: | ||
| reboot_dut(dut, localhost, constants.RECOVER_METHODS[recover_method]["cmd"]) | ||
| else: | ||
| dut.command(method["cmd"]) | ||
| wait(60, msg="Wait 60 seconds for system to be stable.") | ||
|
|
||
|
|
||
| def recover(dut, localhost, fanouthosts, check_results, recover_method): | ||
| logger.info("Try to recover %s using method %s" % (dut.hostname, recover_method)) | ||
| if constants.RECOVER_METHODS[recover_method]["reboot"]: | ||
| method = constants.RECOVER_METHODS[recover_method] | ||
| if method["adaptive"]: | ||
| adaptive_recover(dut, localhost, fanouthosts, check_results) | ||
| elif method["reboot"]: | ||
| reboot_dut(dut, localhost, constants.RECOVER_METHODS[recover_method]["cmd"]) | ||
| else: | ||
| dut.command(constants.RECOVER_METHODS[recover_method]["cmd"]) | ||
| wait(30, msg="Wait 30 seconds for system to be stable.") | ||
| dut.command(method["cmd"]) | ||
| wait(60, msg="Wait 60 seconds for system to be stable.") | ||
daall marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.