aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2018-07-31 07:38:02 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-07-31 07:38:02 +0000
commita84480299427f5380d6518069371de47346672c6 (patch)
tree8e07ee1c57f32dcb16f312525b3bcadac105b9d8
parent0258ce3bc5713339cf0cf3d7e711cbd8d276f74f (diff)
parent43c189b709b49b9b0b3b5d9dedd40872e2dff4cb (diff)
Merge "Change assert statement to raise in common/utils"
-rw-r--r--yardstick/common/exceptions.py4
-rw-r--r--yardstick/common/utils.py8
-rw-r--r--yardstick/tests/unit/common/test_utils.py8
3 files changed, 18 insertions, 2 deletions
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
diff --git a/yardstick/tests/unit/common/test_utils.py b/yardstick/tests/unit/common/test_utils.py
index 7c58a8243..b634ff4b4 100644
--- a/yardstick/tests/unit/common/test_utils.py
+++ b/yardstick/tests/unit/common/test_utils.py
@@ -196,6 +196,14 @@ class TestMacAddressToHex(ut_base.BaseUnitTestCase):
self.assertEqual(utils.mac_address_to_hex_list("ea:3e:e1:9a:99:e8"),
['0xea', '0x3e', '0xe1', '0x9a', '0x99', '0xe8'])
+ def test_mac_address_to_hex_list_too_short_mac(self):
+ with self.assertRaises(exceptions.InvalidMacAddress):
+ utils.mac_address_to_hex_list("ea:3e:e1:9a")
+
+ def test_mac_address_to_hex_list_no_int_mac(self):
+ with self.assertRaises(exceptions.InvalidMacAddress):
+ utils.mac_address_to_hex_list("invalid_mac")
+
class TranslateToStrTestCase(ut_base.BaseUnitTestCase):