-
Notifications
You must be signed in to change notification settings - Fork 52
Fixed Arista EOS reboots not being detected when waiting for the device to reload #407
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 @@ | ||
| Fixed Arista EOS reboots not being detected when waiting for the device to reload. |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
|
|
||
| EOS_SUPPORTED_HASHING_ALGORITHMS = {"md5", "sha1", "sha256", "sha512"} # Subset of HASHING_ALGORITHMS for EOS verify | ||
| EOS_SUPPORTED_SCHEMES = {"http", "https", "scp", "ftp", "sftp", "tftp"} | ||
| DEFAULT_REBOOT_TIMEOUT = 3600 # seconds (1 hour) to wait for a device to come back after a reboot | ||
| BASIC_FACTS_KM = {"model": "modelName", "os_version": "internalVersion", "serial_number": "serialNumber"} | ||
| INTERFACES_KM = { | ||
| "speed": "bandwidth", | ||
|
|
@@ -177,15 +178,40 @@ def _uptime_to_string(self, uptime): | |
|
|
||
| return f"{days:02d}:{hours:02d}:{mins:02d}:{seconds:02d}" | ||
|
|
||
| def _wait_for_device_reboot(self, timeout=3600): | ||
| def _wait_for_device_reboot(self, original_boot_time, timeout=DEFAULT_REBOOT_TIMEOUT): | ||
| """Block until the device reboots, detected by its boot time advancing past original_boot_time. | ||
|
|
||
| Args: | ||
| original_boot_time (float): Device boot time (epoch seconds) captured before the reboot. | ||
| timeout (int): Max seconds to poll for the device to return. Defaults to 3600. | ||
|
|
||
| Raises: | ||
| ValueError: When original_boot_time is None (no pre-reboot boot time was captured). | ||
| RebootTimeoutError: When the device does not report a later boot time within timeout. | ||
| """ | ||
| if original_boot_time is None: | ||
| raise ValueError("original_boot_time is required to detect a reboot; capture it before issuing the reload.") | ||
|
|
||
| start = time.time() | ||
| while time.time() - start < timeout: | ||
| try: | ||
| self.show("show hostname") | ||
| log.debug("Host %s: Device rebooted.", self.host) | ||
| return | ||
| except: # noqa E722 # nosec # pylint: disable=bare-except | ||
| time.sleep(10) | ||
| current_boot_time = self.boot_time | ||
| if current_boot_time > original_boot_time: | ||
| log.info( | ||
| "Host %s: Device rebooted (boot time %s > pre-reboot %s).", | ||
| self.host, | ||
| current_boot_time, | ||
| original_boot_time, | ||
| ) | ||
| return | ||
| log.debug( | ||
| "Host %s: Reachable but boot time unchanged (%s); still waiting.", | ||
| self.host, | ||
| current_boot_time, | ||
| ) | ||
| except Exception as exc: # pylint: disable=broad-exception-caught | ||
| log.debug("Host %s: Reboot probe failed (%s); will retry.", self.host, exc) | ||
| time.sleep(10) | ||
|
|
||
| log.error("Host %s: Device timed out while rebooting.", self.host) | ||
| raise RebootTimeoutError(hostname=self.hostname, wait_time=timeout) | ||
|
|
@@ -263,6 +289,15 @@ def enable(self): | |
|
|
||
| log.debug("Host %s: Device enabled", self.host) | ||
|
|
||
| @property | ||
| def boot_time(self): | ||
| """Get the epoch timestamp (seconds) of the device's last boot, read live from ``show version``. | ||
|
|
||
| Returns: | ||
| (float): Epoch seconds when the device last booted, per ``bootupTimestamp``. | ||
| """ | ||
| return self.show("show version")["bootupTimestamp"] | ||
|
|
||
| @property | ||
| def uptime(self): | ||
| """ | ||
|
|
@@ -729,14 +764,13 @@ def install_os(self, image_name, reboot=True, **vendor_specifics): | |
| Returns: | ||
| (bool): True if device OS is succesfully installed. | ||
| """ | ||
| timeout = vendor_specifics.get("timeout", 3600) | ||
| timeout = vendor_specifics.get("timeout", DEFAULT_REBOOT_TIMEOUT) | ||
| if not self._image_booted(image_name): | ||
| self.set_boot_options(image_name, **vendor_specifics) | ||
| if not reboot: | ||
| log.info("Host %s: OS image %s boot options set. Reboot the device to apply", self.host, image_name) | ||
| return True | ||
| self.reboot() | ||
| self._wait_for_device_reboot(timeout=timeout) | ||
|
Contributor
Author
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. This was already in reboot() So as long as we pass in the timeout and wait_for_reload=True we can remove the call here. |
||
| self.reboot(wait_for_reload=True, timeout=timeout) | ||
| if not self._image_booted(image_name): | ||
| log.error("Host %s: OS install error for image %s", self.host, image_name) | ||
| raise OSInstallError(hostname=self.hostname, desired_boot=image_name) | ||
|
|
@@ -770,12 +804,14 @@ def open(self): | |
|
|
||
| log.debug("Host %s: Connection to controller was opened successfully.", self.host) | ||
|
|
||
| def reboot(self, wait_for_reload=False, **kwargs): | ||
| def reboot(self, wait_for_reload=False, timeout=DEFAULT_REBOOT_TIMEOUT, **kwargs): | ||
| """ | ||
| Reload the controller or controller pair. | ||
|
|
||
| Args: | ||
| wait_for_reload (bool): Whether or not reboot method should also run _wait_for_device_reboot(). Defaults to False. | ||
| wait_for_reload (bool): When True, block until the device reboots (detected via | ||
| the pre-reboot boot time capture) before returning. Defaults to False. | ||
| timeout (int): Max seconds to poll for the device to return when wait_for_reload is True. Defaults to 3600. | ||
| kwargs (dict): Additional keyword arguments, such as confirm. | ||
|
|
||
| Raises: | ||
|
|
@@ -790,10 +826,11 @@ def reboot(self, wait_for_reload=False, **kwargs): | |
| if kwargs.get("confirm"): | ||
| log.warning("Passing 'confirm' to reboot method is deprecated.") | ||
|
|
||
| original_boot_time = self.boot_time if wait_for_reload else None | ||
| self.show("reload now") | ||
| log.info("Host %s: Device rebooted.", self.host) | ||
| if wait_for_reload: | ||
| self._wait_for_device_reboot() | ||
| self._wait_for_device_reboot(original_boot_time, timeout=timeout) | ||
|
|
||
| def rollback(self, rollback_to): | ||
| """Rollback device configuration. | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
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.
Using boot time instead of uptime here for the case where a devices has a uptime of 30 sec upgrades then takes a few min such that the uptime is greater then 30 sec when the api is ready which will result in a timeout.