From 43c189b709b49b9b0b3b5d9dedd40872e2dff4cb Mon Sep 17 00:00:00 2001 From: Miikka Koistinen Date: Mon, 30 Jul 2018 16:01:14 +0300 Subject: Change assert statement to raise in common/utils This modification utilises a custom exception to be raised if an invalid mac address is passed to the function "mac_address_to_hex_list". JIRA: YARDSTICK-966 Change-Id: Ic2940276f500e9710c54963a445a137e73bd6b25 Signed-off-by: Miikka Koistinen --- yardstick/common/exceptions.py | 4 ++++ yardstick/common/utils.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'yardstick/common') diff --git a/yardstick/common/exceptions.py b/yardstick/common/exceptions.py index a559ab4bc..48f15c059 100644 --- a/yardstick/common/exceptions.py +++ b/yardstick/common/exceptions.py @@ -404,3 +404,7 @@ class AclMissingActionArguments(YardstickException): class AclUnknownActionTemplate(YardstickException): message = 'No ACL CLI template found for "%(action_name)s" action' + + +class InvalidMacAddress(YardstickException): + message = 'Mac address "%(mac_address)s" is invalid' diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py index c74dd675e..6c5389cd0 100644 --- a/yardstick/common/utils.py +++ b/yardstick/common/utils.py @@ -282,8 +282,12 @@ def get_free_port(ip): def mac_address_to_hex_list(mac): - octets = ["0x{:02x}".format(int(elem, 16)) for elem in mac.split(':')] - assert len(octets) == 6 and all(len(octet) == 4 for octet in octets) + try: + octets = ["0x{:02x}".format(int(elem, 16)) for elem in mac.split(':')] + except ValueError: + raise exceptions.InvalidMacAddress(mac_address=mac) + if len(octets) != 6 or all(len(octet) != 4 for octet in octets): + raise exceptions.InvalidMacAddress(mac_address=mac) return octets -- cgit 1.2.3-korg