Commit 5cbc9c34 authored by Andrea Sgambelluri's avatar Andrea Sgambelluri
Browse files

Fix monitoring unit-test ImportError from oc_driver.templates package

Porting the P2MP optical work added a module-level import in
OpenConfigServicer.py pulling in drivers.oc_driver.templates.VPN.transponder.
Importing that submodule executes templates/__init__.py, which unconditionally
imports lxml, jinja2, and paramiko. The monitoring component's CI test image
copies src/device/ source (so its tests can import DeviceService) but only
installs monitoring/requirements.in, not device/requirements.in, so none of
those packages are present there -- breaking test collection with
ModuleNotFoundError: No module named 'lxml'.

Fixed by moving the import into DeleteConfig(), its only call site, so merely
importing DeviceService/OpenConfigServicer no longer drags in those
dependencies.
parent d7509173
Loading
Loading
Loading
Loading
+4 −1
Changes for src/device/service/OpenConfigServicer.py: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ from .driver_api.DriverInstanceCache import DriverInstanceCache, get_driver
from .monitoring.MonitoringLoops import MonitoringLoops
from .Tools import extract_resources, clear_frequency_tracking
from .Tools import check_no_endpoints
from .drivers.oc_driver.templates.VPN.transponder import clear_frequency_tracking_transponder

LOGGER = logging.getLogger(__name__)

@@ -181,6 +180,10 @@ class OpenConfigServicer(DeviceServiceServicer):

            resources, conditions = extract_resources(config=config, device=device)
            clear_frequency_tracking()
            # Imported lazily: the oc_driver.templates package pulls in lxml/jinja2/paramiko
            # at import time, which aren't installed in components (e.g. monitoring) that
            # only import DeviceService for type access and never actually call DeleteConfig.
            from .drivers.oc_driver.templates.VPN.transponder import clear_frequency_tracking_transponder
            clear_frequency_tracking_transponder()

            driver : _Driver = get_driver(self.driver_instance_cache, device)