Check for fields that are of the wrong type. Fix bug in ip_interface() validator thanks to this unittest

This commit is contained in:
Pim van Pelt
2022-03-13 20:20:14 +00:00
parent 0f03d6cbaa
commit 2ca7cc3f11
3 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,18 @@
test:
description: "A bunch of schema fields with the wrong type"
errors:
expected:
- "yamale: .* is not a "
count: 9
---
interfaces:
GigabitEthernet1/0/0:
description: 1234
lcp: True
mac: "0001.0203.0405"
addresses: [ 1234, "hello world", 192.0.2.1, 2001:db8::1 ]
sub-interfaces:
100:
description: [ "a", "list" ]
encapsulation:
dot1q: "hello world"

View File

@ -33,6 +33,8 @@ class IPInterfaceWithPrefixLength(Validator):
network = ipaddress.ip_interface(value)
except:
return False
if not isinstance(value, str):
return False
if not '/' in value:
return False
e = value.split('/')