Permalink
Browse files

[schema] Added regexp pattern for interface mac address

  • Loading branch information...
nemesisdesign committed Mar 24, 2016
1 parent de98ae6 commit 4679282c17f86cd446c84c066a719200e22c1244
Showing with 28 additions and 3 deletions.
  1. +2 −3 netjsonconfig/schema.py
  2. +26 −0 tests/openwrt/test_network.py
@@ -141,9 +141,8 @@
},
"mac": {
"type": "string",
"title": "mac address",
"minLength": 17,
"maxLength": 17,
"title": "override mac-address",
"pattern": "^(([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})|)$", # can be empty
"propertyOrder": 2,
},
"mtu": {
@@ -848,3 +848,29 @@ def test_empty_dns(self):
option proto 'none'
""")
self.assertEqual(o.render(), expected)
def test_mac_address_format(self):
o = OpenWrt({
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
"mac": "00:11:22:33:44:55"
}
]
})
o.validate()
# too short
o.config['interfaces'][0]['mac'] = '00:11:22:33:44'
with self.assertRaises(ValidationError):
o.validate()
# valid
o.config['interfaces'][0]['mac'] = '00-11-22-33-44-55'
o.validate()
# should not be valid
o.config['interfaces'][0]['mac'] = '00:11:22:33:44:ZY'
with self.assertRaises(ValidationError):
o.validate()
# empty is valid (will be ignored)
o.config['interfaces'][0]['mac'] = ''
o.validate()

0 comments on commit 4679282

Please sign in to comment.