From dda6740789f80649a1628653146ba4369bbed00a Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Thu, 5 Mar 2026 20:59:12 +0000 Subject: template: T8347: for netifaces set "pylint: disable = no-name-in-module" As the python netifaces module is written in C - we can not inspect any import line as the linter does not see it. Disable the warnings here. --- python/vyos/template.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/vyos/template.py b/python/vyos/template.py index 596f9e8c5..2a783bc74 100755 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -274,9 +274,9 @@ def netmask_from_ipv4(address): Example: - 172.18.201.10 -> 255.255.255.128 """ - from netifaces import interfaces - from netifaces import ifaddresses - from netifaces import AF_INET + from netifaces import interfaces # pylint: disable = no-name-in-module + from netifaces import ifaddresses # pylint: disable = no-name-in-module + from socket import AF_INET for interface in interfaces(): tmp = ifaddresses(interface) if AF_INET in tmp: -- cgit v1.2.3 From a7457202b82fed4c06cb45a463b1e015addd9a06 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Thu, 5 Mar 2026 21:01:03 +0000 Subject: configverify: T8347: fix use of undefined variable for CA certs --- python/vyos/configverify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py index cc4419913..995c4ee83 100644 --- a/python/vyos/configverify.py +++ b/python/vyos/configverify.py @@ -501,7 +501,7 @@ def verify_pki_ca_certificate(config: dict, ca_name: str): pki_cert = config['pki']['ca'][ca_name] if 'certificate' not in pki_cert: - raise ConfigError(f'PEM CA certificate for "{cert_name}" missing in configuration!') + raise ConfigError(f'PEM CA certificate for "{ca_name}" missing in configuration!') def verify_pki_dh_parameters(config: dict, dh_name: str, min_key_size: int=0): """ -- cgit v1.2.3 From 2d73f1e8195a2f5edffcf95a4741885cfcd0bf6c Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Thu, 5 Mar 2026 21:02:50 +0000 Subject: remote: T8347: avoid Python requests module dynamic alias for urllib3 This happens because requests.packages.urllib3 is essentially a dynamic alias that requests creates at runtime. Because it's dynamically generated, pylint's static analysis cannot find it, which triggers the import error. Avoid dynamic import by importing PoolManager directly from urllib3. --- python/vyos/remote.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/vyos/remote.py b/python/vyos/remote.py index b73f486c0..d4efac0d9 100644 --- a/python/vyos/remote.py +++ b/python/vyos/remote.py @@ -35,7 +35,7 @@ from paramiko import MissingHostKeyPolicy from requests import Session from requests.adapters import HTTPAdapter -from requests.packages.urllib3 import PoolManager +from urllib3 import PoolManager from vyos.progressbar import Progressbar from vyos.utils.io import ask_yes_no -- cgit v1.2.3 From 838cf65b1c181b7b4f00ae712166065bad0fbf54 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Thu, 5 Mar 2026 21:05:36 +0000 Subject: remote: T8347: fix variable assignment for try/except block Pylint is pointing out that because sftp.put(location, path) is located inside a finally block, it is guaranteed to execute regardless of whether the try block succeeds or fails. If an exception other than an IOError is raised inside the try block, "except IOError" block gets skipped, Python then jumps straight to the finally block. When it executes the finally block, it attempts to read the variable path, but path was never assigned! This triggers UnboundLocalError, local variable 'path' referenced before assignment. --- python/vyos/remote.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'python') diff --git a/python/vyos/remote.py b/python/vyos/remote.py index d4efac0d9..417f9d42c 100644 --- a/python/vyos/remote.py +++ b/python/vyos/remote.py @@ -220,23 +220,21 @@ class SshC: def upload(self, location: str): with self._establish() as ssh, ssh.open_sftp() as sftp: + # A file exists at this destination. We're simply going to clobber it. + # This is our default fallback + path = self.path try: # If the remote path is a directory, use the original filename. if stat.S_ISDIR(sftp.stat(self.path).st_mode): path = os.path.join(self.path, os.path.basename(location)) - # A file exists at this destination. We're simply going to clobber it. - else: - path = self.path - # This path doesn't point at any existing file. We can freely use this filename. except IOError: - path = self.path - finally: - if self.progressbar: - with Progressbar() as p: - sftp.put(location, path, callback=p.progress) - else: - sftp.put(location, path) + pass + if self.progressbar: + with Progressbar() as p: + sftp.put(location, path, callback=p.progress) + else: + sftp.put(location, path) class HttpC: def __init__(self, -- cgit v1.2.3 From 8e9e278750ee52a0d7e057c0666555b03880ced0 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Thu, 5 Mar 2026 21:09:05 +0000 Subject: vyos.debug: T8347: fix UnboundLocalError in try/finally statement Pylint warns about mask being used before assignment because mask is created inside the try block. While os.umask() itself is highly unlikely to fail, Python can raise asynchronous exceptions like KeyboardInterrupt or MemoryError at any given moment. If one of those exceptions occurs precisely after the try: statement but before "mask = os.umask(0o111)" completes, Python calls finally with "os.umask(mask)" causing UnboundLocalError. --- python/vyos/debug.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'python') diff --git a/python/vyos/debug.py b/python/vyos/debug.py index 5b6e8172e..1a6924ef5 100644 --- a/python/vyos/debug.py +++ b/python/vyos/debug.py @@ -38,13 +38,12 @@ def message(message, flag='', destination=sys.stdout): if not logfile: return enable + mask = os.umask(0o111) try: # at boot the file is created as root:vyattacfg # at runtime the file is created as user:vyattacfg # but the helper scripts are not run as this so it # need the default permission to be 666 (an not 660) - mask = os.umask(0o111) - with open(logfile, 'a') as f: f.write(_timed(_format('log', message))) finally: -- cgit v1.2.3