summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-07-04 19:35:20 -0500
committerJohn Estabrook <jestabro@vyos.io>2024-09-11 12:07:48 -0500
commiteaa9c82670fa5ee90835266e6f7a24f81c49d17e (patch)
tree6bc77cf4ddd59c8c8fe3da76b0dacfa715eb8243
parent6bc1aff55e29dba2367839379fbd3863498ba757 (diff)
downloadvyos-1x-eaa9c82670fa5ee90835266e6f7a24f81c49d17e.tar.gz
vyos-1x-eaa9c82670fa5ee90835266e6f7a24f81c49d17e.zip
migration: T6007: add missing check for None in utility function
An empty component version string will trigger a full migration, however, the case of component_version is None was missed in a utility function. Fix comment formatting. (cherry picked from commit bd42f131ea2ceec2c591303ea69b7d3a36e41a7c)
-rw-r--r--python/vyos/component_version.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/python/vyos/component_version.py b/python/vyos/component_version.py
index 0c305e5e0..94215531d 100644
--- a/python/vyos/component_version.py
+++ b/python/vyos/component_version.py
@@ -129,6 +129,7 @@ def component_from_string(string: str) -> dict:
return {k: int(v) for k, v in re.findall(r'([\w,-]+)@(\d+)', string)}
def version_info_from_file(config_file) -> VersionInfo:
+ """Return config file component and release version info."""
version_info = VersionInfo()
try:
with open(config_file) as f:
@@ -166,9 +167,7 @@ def version_info_from_file(config_file) -> VersionInfo:
return version_info
def version_info_from_system() -> VersionInfo:
- """
- Return system component versions.
- """
+ """Return system component and release version info."""
d = component_version()
sort_d = dict(sorted(d.items(), key=lambda x: x[0]))
version_info = VersionInfo(
@@ -180,20 +179,18 @@ def version_info_from_system() -> VersionInfo:
return version_info
def version_info_copy(v: VersionInfo) -> VersionInfo:
- """
- Make a copy of dataclass.
- """
+ """Make a copy of dataclass."""
return replace(v)
def version_info_prune_component(x: VersionInfo, y: VersionInfo) -> VersionInfo:
- """
- In place pruning of component keys of x not in y.
- """
+ """In place pruning of component keys of x not in y."""
+ if x.component is None or y.component is None:
+ return
x.component = { k: v for k,v in x.component.items() if k in y.component }
def add_system_version(config_str: str = None, out_file: str = None):
- """
- Wrap config string with system version and write to out_file.
+ """Wrap config string with system version and write to out_file.
+
For convenience, calling with no argument will write system version
string to stdout, for use in bash scripts.
"""