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

op mode: T6498: move uptime helpers to vyos.utils.system #3684

Merged
merged 1 commit into from
Jun 21, 2024

Conversation

dmbaturin
Copy link
Member

Change Summary

Move the functions for getting system uptime and load averages from uptime.py to vyos.utils.system, mainly to be able to call them from the new tech-support script, but that's not all.

There's also a "while we are at it" change that makes the performance of those functions better.

  1. get_uptime_seconds() no longer reads the uptime file twice.
  2. get_load_averages() now reads /proc/loadavg directly instead of spawning uptime as a subprocess.

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

Op mode.

Proposed changes

How to test

run show system uptime should work as before.

Smoketest result

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

Copy link

github-actions bot commented Jun 19, 2024


PR title 'op mode: T6498: move uptime helpers to vyos.utils.system' does not match the required format!. Valid title example: T99999: make IPsec secure

Copy link
Contributor

@jestabro jestabro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor point: pylint complains about '\s' and '\.' if the regex is not a raw string; annoyingly, it can produce a vague warning message when pylint called on an unrelated file:
<unknown>:108: SyntaxWarning: invalid escape sequence '\.'

To make pylint happy:

diff --git a/python/vyos/utils/system.py b/python/vyos/utils/system.py
index dc8c9aa89..b3b1dbb7f 100644
--- a/python/vyos/utils/system.py
+++ b/python/vyos/utils/system.py
@@ -105,7 +105,7 @@ def get_uptime_seconds():
     from vyos.utils.file import read_file
 
     data = read_file("/proc/uptime")
-    seconds = search("([0-9\.]+)\s", data).group(1)
+    seconds = search(r'([0-9\.]+)\s', data).group(1)
     res  = int(float(seconds))
 
     return res

I have encountered this recently and have in a working repo (part of a larger PR):

diff --git a/python/vyos/utils/dict.py b/python/vyos/utils/dict.py
index 062ab9c81..1eb6abcd5 100644
--- a/python/vyos/utils/dict.py
+++ b/python/vyos/utils/dict.py
@@ -34,7 +34,7 @@ def colon_separated_to_dict(data_string, uniquekeys=False):
         otherwise they are always lists of strings.
     """
     import re
-    key_value_re = re.compile('([^:]+)\s*\:\s*(.*)')
+    key_value_re = re.compile(r'([^:]+)\s*\:\s*(.*)')
 
     data_raw = re.split('\n', data_string)

to be able to call them from the new tech-support script
@dmbaturin dmbaturin force-pushed the T6498-uptime-helpers branch from 0115008 to d91fa43 Compare June 21, 2024 16:31
@jestabro jestabro merged commit 569b29e into vyos:current Jun 21, 2024
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants