Scan for MAC through all devices in macvtap agent

The first device the agent happens to pick could be something
without a MAC address like a 6in6 interface. This was causing
the agent to fail to start if it was unlucky enough to pick
that address.

This patch just adjusts the logic to keep iterating through
the list until we find a MAC.

Change-Id: Iba9c7c3cb200e74a78ea885e8d9323de64c2c663
Closes-Bug: #1801030
This commit is contained in:
Brian Haley 2018-11-01 15:48:18 -04:00
parent 4a4fa0db7f
commit a58a527494
2 changed files with 18 additions and 7 deletions

View File

@ -112,13 +112,13 @@ class MacvtapManager(amb.CommonAgentManagerBase):
def get_agent_id(self):
devices = ip_lib.IPWrapper().get_devices(True)
if devices:
mac = ip_lib.get_device_mac(devices[0].name)
return 'macvtap%s' % mac.replace(":", "")
else:
LOG.error("Unable to obtain MAC address for unique ID. "
"Agent terminated!")
sys.exit(1)
for device in devices:
mac = ip_lib.get_device_mac(device.name)
if mac:
return 'macvtap%s' % mac.replace(":", "")
LOG.error("Unable to obtain MAC address for unique ID. "
"Agent terminated!")
sys.exit(1)
def get_devices_modified_timestamps(self, devices):
# TODO(kevinbenton): this should be implemented to detect

View File

@ -146,6 +146,17 @@ class TestMacvtapManager(base.BaseTestCase):
self.mgr.get_agent_id()
mock_exit.assert_called_once_with(1)
def test_get_agent_id_no_mac(self):
mock_devices = [ip_lib.IPDevice('macvtap0'),
ip_lib.IPDevice('macvtap1')]
with mock.patch.object(ip_lib.IPWrapper, 'get_devices',
return_value=mock_devices),\
mock.patch.object(ip_lib, 'get_device_mac',
side_effect=[None, 'foo:bar:1']) as mock_gdm:
self.assertEqual('macvtapfoobar1', self.mgr.get_agent_id())
mock_gdm.assert_has_calls([mock.call('macvtap0'),
mock.call('macvtap1')])
def test_get_extension_driver_type(self):
self.assertEqual('macvtap', self.mgr.get_extension_driver_type())