diff options
author | John Estabrook <jestabro@sentrium.io> | 2020-01-13 11:57:52 -0600 |
---|---|---|
committer | John Estabrook <jestabro@sentrium.io> | 2020-01-14 08:36:25 -0600 |
commit | 29e438755c8bd2b9598a2016a3c42891f0cbfa1d (patch) | |
tree | 28d43916f6194826b7913cfde105418c3c08c9f8 /python/vyos | |
parent | 0ecc2c26f7ac939e4e23c14f5027ac7592c25761 (diff) | |
download | vyos-1x-29e438755c8bd2b9598a2016a3c42891f0cbfa1d.tar.gz vyos-1x-29e438755c8bd2b9598a2016a3c42891f0cbfa1d.zip |
T1950: Add support for reading component versions from JSON file
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/defaults.py | 2 | ||||
-rw-r--r-- | python/vyos/systemversions.py | 28 |
2 files changed, 28 insertions, 2 deletions
diff --git a/python/vyos/defaults.py b/python/vyos/defaults.py index dedb929b4..a2ad142bc 100644 --- a/python/vyos/defaults.py +++ b/python/vyos/defaults.py @@ -29,6 +29,8 @@ cfg_vintage = 'vyatta' commit_lock = '/opt/vyatta/config/.lock' +version_file = '/usr/share/vyos/component-versions.json' + https_data = { 'listen_addresses' : { '*': ['_'] } } diff --git a/python/vyos/systemversions.py b/python/vyos/systemversions.py index 9b3f4f413..5c4deca29 100644 --- a/python/vyos/systemversions.py +++ b/python/vyos/systemversions.py @@ -16,12 +16,15 @@ import os import re import sys +import json + import vyos.defaults def get_system_versions(): """ - Get component versions from running system; critical failure if - unable to read migration directory. + Get component versions from running system: read vyatta directory + structure for versions, then read vyos JSON file. It is a critical + error if either migration directory or JSON file is unreadable. """ system_versions = {} @@ -36,4 +39,25 @@ def get_system_versions(): pair = info.split('@') system_versions[pair[0]] = int(pair[1]) + version_dict = {} + path = vyos.defaults.version_file + + if os.path.isfile(path): + with open(path, 'r') as f: + try: + version_dict = json.load(f) + except ValueError as err: + print(f"\nValue error in {path}: {err}") + sys.exit(1) + + for k, v in version_dict.items(): + if not isinstance(v, int): + print(f"\nType error in {path}; expecting Dict[str, int]") + sys.exit(1) + existing = system_versions.get(k) + if existing is None: + system_versions[k] = v + elif v > existing: + system_versions[k] = v + return system_versions |