Fix random_mac_generator to make proper EUI64s
The initial implementation of random_mac_generator created MAC addresses that were one octet too long - the MAC addresses would have seven octets instead of the proper EUI64-standard six. This resolved testing issues in the consuming patch in Neutron (see the change referenced in the Needed-By line). A test is added that replicates the conditions of the failure. In the failed tests, the base mac '12:34:56:78' was instead parsed so it became '12:34:56:7:8'; when the code went to add 2 octets to the result, there were too many octets to form a valid EUI64 MAC address. Implements: blueprint speed-up-neutron-bulk-creation Needed-By: https://review.openstack.org/584061 Change-Id: I9a2c40709db9204c7686500deac9ee8e8471b1bc
This commit is contained in:
parent
a8751fb404
commit
0ecceacb3e
neutron_lib
@ -77,6 +77,14 @@ class TestRandomMacGenerator(base.BaseTestCase):
|
||||
self.assertEqual(['aa:bb:00:a2:a2:a2'], list(generator))
|
||||
mock_rnd.assert_called_with(8)
|
||||
|
||||
@mock.patch.object(random, 'getrandbits', return_value=0xa2)
|
||||
def test_short_supplied_mac(self, mock_rnd):
|
||||
mac_base = '12:34:56:78'
|
||||
mac = mac_base.split(':')
|
||||
generator = itertools.islice(net.random_mac_generator(mac), 1)
|
||||
self.assertEqual(['12:34:56:78:a2:a2'], list(generator))
|
||||
mock_rnd.assert_called_with(8)
|
||||
|
||||
|
||||
class TestPortDeviceOwner(base.BaseTestCase):
|
||||
|
||||
|
@ -56,7 +56,7 @@ def random_mac_generator(base_mac):
|
||||
fixed = list(base_mac[0:3])
|
||||
to_generate = 3
|
||||
if base_mac[3] != '00':
|
||||
fixed += base_mac[3]
|
||||
fixed = list(base_mac[0:4])
|
||||
to_generate = 2
|
||||
beginning = ':'.join(fixed) + ':'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user