Skip to content
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

vyos.utils: T6244: add whitespace after time unit in uptime (backport #3336) #3343

Merged
merged 3 commits into from
Apr 22, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Apr 22, 2024

Change Summary

We only supported calculating seconds to weeks but not seconds to years. This has been added.

In addition when handling optional separators rather build up a list and join

This PR thus changes the result of "show system uptime" 2w4d22h54m9s to a more human readable string 2w 4d 22h 54m 9s.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

Related PR(s)

Component(s) name

vyos.utils

Proposed changes

How to test

#!/usr/bin/env python3
from vyos.utils.convert import seconds_to_human

minute = 60
hour = minute * 60
day = hour * 24
week = day * 7
year = day * 365.25

for separator in ['', ' ', '-', '/']:
  print(f'----- Using separator "{separator}" -----')
  print(seconds_to_human(10, separator))
  print(seconds_to_human(5* minute, separator))
  print(seconds_to_human(3* hour, separator))
  print(seconds_to_human(4* day, separator))
  print(seconds_to_human(7 * week, separator))
  print(seconds_to_human(10 * year, separator))
  print(seconds_to_human(5*year + 4*week + 3*day + 2*hour + minute + 5, separator))
  print()

yields:

cpo@LR1.wue3:~$ ./foo.py
----- Using separator "" -----
10s
5m
3h
4d
7w
10y
5y4w3d2h1m5s

----- Using separator " " -----
10s
5m
3h
4d
7w
10y
5y 4w 3d 2h 1m 5s

----- Using separator "-" -----
10s
5m
3h
4d
7w
10y
5y-4w-3d-2h-1m-5s

----- Using separator "/" -----
10s
5m
3h
4d
7w
10y
5y/4w/3d/2h/1m/5s
cpo@LR1.wue3:~$ show system uptime
Uptime: 4d 19h 8m 51s

Load averages:
1  minute:   0.0%
5  minutes:  0.0%
15 minutes:  0.0%

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • I have run the components SMOKETESTS if applicable
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

This is an automatic backport of pull request #3336 done by [Mergify](https://mergify.com).

c-po added 3 commits April 22, 2024 16:15
When handling optional separators rather build up a list and join the list
with the requested delimiter to form the resulting human readable time string.

(cherry picked from commit 6e9cd88)
We only supported calculating seconds to weeks but not seconds to years. This
has been added.

Testcase:
from vyos.utils.convert import seconds_to_human

minute = 60
hour = minute * 60
day = hour * 24
week = day * 7
year = day * 365.25

for separator in ['', ' ', '-', '/']:
  print(f'----- Using separator "{separator}" -----')
  print(seconds_to_human(10, separator))
  print(seconds_to_human(5* minute, separator))
  print(seconds_to_human(3* hour, separator))
  print(seconds_to_human(4* day, separator))
  print(seconds_to_human(7 * week, separator))
  print(seconds_to_human(10 * year, separator))
  print(seconds_to_human(5*year + 4*week + 3*day + 2*hour + minute + 5, separator))
  print()

cpo@LR1.wue3:~$ ./foo.py
----- Using separator "" -----
10s
5m
3h
4d
7w
10y
5y4w3d2h1m5s

----- Using separator " " -----
10s
5m
3h
4d
7w
10y
5y 4w 3d 2h 1m 5s

----- Using separator "-" -----
10s
5m
3h
4d
7w
10y
5y-4w-3d-2h-1m-5s

----- Using separator "/" -----
10s
5m
3h
4d
7w
10y
5y/4w/3d/2h/1m/5s

(cherry picked from commit 8d8f313)
@vyosbot vyosbot requested a review from a team April 22, 2024 16:15
@github-actions github-actions bot added the sagitta VyOS 1.4 LTS label Apr 22, 2024
@vyosbot vyosbot requested review from dmbaturin, sarthurdev, zdc, jestabro, sever-sever and c-po and removed request for a team April 22, 2024 16:15
@c-po c-po merged commit 626321a into sagitta Apr 22, 2024
5 checks passed
@mergify mergify bot deleted the mergify/bp/sagitta/pr-3336 branch April 22, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sagitta VyOS 1.4 LTS
Development

Successfully merging this pull request may close these issues.

2 participants