Merge "Treat device with no MAC address as not ready"
This commit is contained in:
commit
0ee22a997e
@ -1062,8 +1062,12 @@ def ensure_device_is_ready(device_name, namespace=None):
|
||||
dev = IPDevice(device_name, namespace=namespace)
|
||||
dev.set_log_fail_as_error(False)
|
||||
try:
|
||||
# Ensure the device is up, even if it is already up. If the device
|
||||
# doesn't exist, a RuntimeError will be raised.
|
||||
# Ensure the device has a MAC address and is up, even if it is already
|
||||
# up. If the device doesn't exist, a RuntimeError will be raised.
|
||||
if not dev.link.address:
|
||||
LOG.error("Device %s cannot be used as it has no MAC "
|
||||
"address", device_name)
|
||||
return False
|
||||
dev.link.set_up()
|
||||
except RuntimeError:
|
||||
return False
|
||||
|
@ -1343,6 +1343,12 @@ class TestDeviceExists(base.BaseTestCase):
|
||||
ip_lib_mock.link.set_up.side_effect = RuntimeError
|
||||
self.assertFalse(ip_lib.ensure_device_is_ready("eth0"))
|
||||
|
||||
def test_ensure_device_is_ready_no_link_address(self):
|
||||
with mock.patch.object(ip_lib.IPDevice, '_execute') as _execute:
|
||||
# Use lo, it has no MAC address
|
||||
_execute.return_value = LINK_SAMPLE[0]
|
||||
self.assertFalse(ip_lib.ensure_device_is_ready("lo"))
|
||||
|
||||
|
||||
class TestGetRoutingTable(base.BaseTestCase):
|
||||
ip_db_interfaces = {
|
||||
|
Loading…
Reference in New Issue
Block a user