Skip to content

Commit fc34ccf

Browse files
authored
Merge pull request #16 from stfc/fix-hypervisor-uptime-less-than-day
Handle uptime days is 1
2 parents 5d65e72 + 3687ef5 commit fc34ccf

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

openstackquery/time_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ def extract_uptime(uptime_string: str) -> Optional[float]:
6969
if match:
7070
uptime_string = match.group(1)
7171
days = 0
72-
if "days" in uptime_string:
73-
days_part, time_part = uptime_string.split(" days, ")
72+
time_part = uptime_string
73+
if "day" in uptime_string:
74+
days_part, time_part = uptime_string.split(
75+
" day" + ("s" if "days" in uptime_string else "") + ", "
76+
)
7477
days += int(days_part)
75-
else:
76-
time_part = uptime_string
7778

7879
hours, minutes = map(int, time_part.split(":"))
7980
days += hours / 24 + minutes / 1440

tests/test_time_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,13 @@ def test_extract_uptime_less_than_day():
112112
res = TimeUtils.extract_uptime(mock_string)
113113

114114
assert res == 0.25
115+
116+
117+
def test_extract_uptime_is_one_day():
118+
"""
119+
Test extraction when less than a day uptime
120+
"""
121+
mock_string = "17:13:49 up 1 day, 7:03, 0 users, load average: 0.00, 0.01, 0.00"
122+
res = TimeUtils.extract_uptime(mock_string)
123+
124+
assert res == 1.29

0 commit comments

Comments
 (0)