Implement validation for optional VLANs in BaseDevice

- Added a check in the BaseDevice class to raise a ValueError if the 'vlans' section is declared in the template but not present in the raw data returned by TTP.
- This enhancement improves data integrity by ensuring that optional groups are properly validated before processing.
This commit is contained in:
IluaAir
2026-02-24 22:28:36 +03:00
parent 753268a381
commit 3fdff33e2e

View File

@@ -78,6 +78,11 @@ class BaseDevice(ABC):
}
if "vlans" in self._declared_sections:
if "vlans" not in self.raw:
raise ValueError(
f"{self.__class__.__name__}: template '{self.template}' declares optional group "
f"'vlans', but TTP did not return it."
)
vlans_data = self.vlans() or []
result["vlans"] = [Vlans(**item) for item in vlans_data]
return result