summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-07-04 19:35:20 -0500
committerJohn Estabrook <jestabro@vyos.io>2024-07-04 19:48:48 -0500
commitbd42f131ea2ceec2c591303ea69b7d3a36e41a7c (patch)
tree0c40f78ee866c5987e7cc8e9b963ca8d66f9ba2b
parentc3bf4b80cd25dc8e64826b6d2f7ad0b3d1ae06c0 (diff)
downloadvyos-1x-bd42f131ea2ceec2c591303ea69b7d3a36e41a7c.tar.gz
vyos-1x-bd42f131ea2ceec2c591303ea69b7d3a36e41a7c.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.
-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.
"""