From 69ee8a3650c7b3a8dd46d530439c109068ad17d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Fl=C3=B8tten?= Date: Thu, 30 Oct 2025 18:09:47 +0100 Subject: [PATCH 1/3] Add version info to settings --- changelog.d/2082.added.md | 1 + pyproject.toml | 2 ++ python/nav/django/settings.py | 12 ++++++++++++ 3 files changed, 15 insertions(+) create mode 100644 changelog.d/2082.added.md diff --git a/changelog.d/2082.added.md b/changelog.d/2082.added.md new file mode 100644 index 0000000000..dea6bfa71b --- /dev/null +++ b/changelog.d/2082.added.md @@ -0,0 +1 @@ +Add OS version and NAV version to exception debug view \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 003b426b0e..ec2ba3071f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,8 @@ dependencies = [ "pyjwt>=2.6.0", + "distro", + # The following modules are really sub-requirements of Twisted, not of # NAV directly. They may be optional from Twisted's point of view, # but they are required for parts of the Twisted library that NAV uses: diff --git a/python/nav/django/settings.py b/python/nav/django/settings.py index 618ce5937f..0dcae12d58 100644 --- a/python/nav/django/settings.py +++ b/python/nav/django/settings.py @@ -17,11 +17,14 @@ """Django configuration wrapper around the NAV configuration files""" +import distro +import platform import os import sys import copy import warnings + from django.utils.log import DEFAULT_LOGGING from nav.config import NAV_CONFIG, getconfig, find_config_dir @@ -315,3 +318,12 @@ 'JWT_ISSUERS': _issuers_setting, 'JWT_AUTH_HEADER_PREFIX': 'Bearer', } + +# Add NAV and OS-versions so they are added to exception views. +NAV_VERSION = nav.buildconf.VERSION +if platform.system() == "Linux": + OS_VERSION = f"{distro.name(pretty=True)} {distro.version()}" +elif platform.system() == "Darwin": + OS_VERSION = f"macOS {platform.mac_ver()[0]}" +else: + OS_VERSION = f"{platform.system()} {platform.release()} ({platform.version()})" From 147f14c3446f963dcf4c1cc638a8e968c4ec3748 Mon Sep 17 00:00:00 2001 From: aleksfl Date: Thu, 4 Dec 2025 11:04:45 +0100 Subject: [PATCH 2/3] Update python/nav/django/settings.py Co-authored-by: Johanna England --- python/nav/django/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/nav/django/settings.py b/python/nav/django/settings.py index 0dcae12d58..5dbd341ab4 100644 --- a/python/nav/django/settings.py +++ b/python/nav/django/settings.py @@ -322,7 +322,7 @@ # Add NAV and OS-versions so they are added to exception views. NAV_VERSION = nav.buildconf.VERSION if platform.system() == "Linux": - OS_VERSION = f"{distro.name(pretty=True)} {distro.version()}" + OS_VERSION = distro.name(pretty=True) elif platform.system() == "Darwin": OS_VERSION = f"macOS {platform.mac_ver()[0]}" else: From ddcd7fc52e72fb12f6544067c97dd31b2049f66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Fl=C3=B8tten?= Date: Thu, 4 Dec 2025 11:26:01 +0100 Subject: [PATCH 3/3] Add test for versions --- python/nav/django/settings.py | 2 +- tests/unittests/django/settings_test.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/unittests/django/settings_test.py diff --git a/python/nav/django/settings.py b/python/nav/django/settings.py index 5dbd341ab4..9a0f2e59d3 100644 --- a/python/nav/django/settings.py +++ b/python/nav/django/settings.py @@ -322,7 +322,7 @@ # Add NAV and OS-versions so they are added to exception views. NAV_VERSION = nav.buildconf.VERSION if platform.system() == "Linux": - OS_VERSION = distro.name(pretty=True) + OS_VERSION = f"Linux {distro.name(pretty=True)}" elif platform.system() == "Darwin": OS_VERSION = f"macOS {platform.mac_ver()[0]}" else: diff --git a/tests/unittests/django/settings_test.py b/tests/unittests/django/settings_test.py new file mode 100644 index 0000000000..410b83e330 --- /dev/null +++ b/tests/unittests/django/settings_test.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +from nav.django.settings import NAV_VERSION, OS_VERSION + + +def test_valid_nav_version(): + """ + Test that NAV_VERSION is set to something containing a '.', + which is assumed to be a valid version. + """ + assert "." in NAV_VERSION + + +def test_valid_os_version(): + """Test that OS_VERSION contains a supported OS""" + os_list = ["windows", "macos", "linux", "freebsd"] + assert any(os in OS_VERSION.lower() for os in os_list)