From 6a13bd7e89566b76f6c7daf09160f697c2af4df1 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sat, 28 Mar 2020 15:02:38 +0000 Subject: ifconfig: T2057: correctly provide the reason why a MAC could not be set --- python/vyos/validate.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/vyos/validate.py b/python/vyos/validate.py index 48a18642b..0e6d34e7e 100644 --- a/python/vyos/validate.py +++ b/python/vyos/validate.py @@ -204,11 +204,19 @@ def assert_mtu(mtu, min=68, max=9000): def assert_mac(m): - octets = [int(i, 16) for i in m.split(':')] + split = m.split(':') + size = len(split) # a mac address consits out of 6 octets - if len(octets) != 6: - raise ValueError(f'wrong number of MAC octets: {octets}') + if size != 6: + raise ValueError(f'wrong number of MAC octets ({size}): {m}') + + octets = [] + try: + for octet in split: + octets.append(int(octet, 16)) + except ValueError: + raise ValueError(f'invalid hex number "{octet}" in : {m}') # validate against the first mac address byte if it's a multicast # address -- cgit v1.2.3