Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[schema] Added regexp pattern for interface mac address
  • Loading branch information
nemesifier committed Mar 24, 2016
1 parent de98ae6 commit 4679282
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 2 additions & 3 deletions netjsonconfig/schema.py
Expand Up @@ -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": {
Expand Down
26 changes: 26 additions & 0 deletions tests/openwrt/test_network.py
Expand Up @@ -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.