Skip to content

Commit

Permalink
Add refresh facts.
Browse files Browse the repository at this point in the history
  • Loading branch information
pszulczewski committed Dec 19, 2023
1 parent ab81f35 commit 3c5e3ef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pyntc/devices/nxos_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ def _image_booted(self, image_name, **vendor_specifics):
def _wait_for_device_reboot(self, timeout=3600):
start = time.time()
while time.time() - start < timeout:
# Clear cache
self._uptime = None
delattr(self.native, "_facts")

self.refresh()
try: # NXOS stays online, when it installs OS
if self.uptime < 180:
log.debug("Host %s: Device rebooted.", self.host)
Expand All @@ -72,6 +69,11 @@ def _wait_for_device_reboot(self, timeout=3600):
log.error("Host %s: Device timed out while rebooting.", self.host)
raise RebootTimeoutError(hostname=self.hostname, wait_time=timeout)

def refresh(self):
"""Refresh caches on device instance."""
delattr(self.native, "_facts")
super().refresh()

def backup_running_config(self, filename):
"""Backup running configuration.
Expand Down Expand Up @@ -142,6 +144,18 @@ def uptime(self):
log.debug("Host %s: Uptime %s", self.host, self._uptime)
return self._uptime

@property
def uptime_string(self):
"""Get uptime in format dd:hh:mm.
Returns:
str: Uptime of device.
"""
if self._uptime_string is None:
self._uptime_string = self.native.facts.get("uptime_string")

return self._uptime_string

@property
def hostname(self):
"""Get hostname of the device.
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_devices/test_nxos_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ def test_starting_config(self):
expected = self.device.show("show startup-config", raw_text=True)
self.assertEqual(self.device.startup_config, expected)

def test_refresh(self):
self.assertTrue(hasattr(self.device.native, "_facts"))
self.device.refresh()
self.assertIsNone(self.device._uptime)
self.assertFalse(hasattr(self.device.native, "_facts"))


if __name__ == "__main__":
unittest.main()

0 comments on commit 3c5e3ef

Please sign in to comment.