Skip to content

Commit

Permalink
Return uptime as float
Browse files Browse the repository at this point in the history
The base napalm model expects uptime to be a float.
  • Loading branch information
inetAnt committed Feb 7, 2024
1 parent c4e16ae commit 6d2b144
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion napalm_servertech_pro2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def convert_uptime(uptime):
)
if not m:
raise ValueError("uptime string was not recognized: regex did not match")
return (
return float(
int(m.group("days")) * 86400
+ int(m.group("hours")) * 3600
+ int(m.group("minutes")) * 60
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

def test_convert_uptime():
uptime = "11 days 4 hours 8 minutes 6 seconds"
assert utils.convert_uptime(uptime) == 965286
assert utils.convert_uptime(uptime) == 965286.0

uptime = "133 days 1 hour 12 minutes 15 seconds"
assert isinstance(utils.convert_uptime(uptime), int)
assert isinstance(utils.convert_uptime(uptime), float)

uptime = "0 days 0 hours 0 minutes 1 second"
assert utils.convert_uptime(uptime) == 1
assert utils.convert_uptime(uptime) == 1.0

with pytest.raises(ValueError):
utils.convert_uptime("hello")
Expand Down

0 comments on commit 6d2b144

Please sign in to comment.