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:
@@ -78,6 +78,11 @@ class BaseDevice(ABC):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if "vlans" in self._declared_sections:
|
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 []
|
vlans_data = self.vlans() or []
|
||||||
result["vlans"] = [Vlans(**item) for item in vlans_data]
|
result["vlans"] = [Vlans(**item) for item in vlans_data]
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user