diff options
-rw-r--r-- | os_net_config/objects.py | 2 | ||||
-rw-r--r-- | os_net_config/tests/test_objects.py | 6 | ||||
-rw-r--r-- | os_net_config/utils.py | 4 |
3 files changed, 10 insertions, 2 deletions
diff --git a/os_net_config/objects.py b/os_net_config/objects.py index 2db7cf5..2958f84 100644 --- a/os_net_config/objects.py +++ b/os_net_config/objects.py @@ -100,6 +100,8 @@ def _numbered_nics(nic_mapping=None): _NUMBERED_NICS[nic_alias] = nic_mapped logger.info("%s mapped to: %s" % (nic_alias, nic_mapped)) + if not _NUMBERED_NICS: + logger.warning('No active nics found.') return _NUMBERED_NICS diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py index a7b4230..3367df0 100644 --- a/os_net_config/tests/test_objects.py +++ b/os_net_config/tests/test_objects.py @@ -603,3 +603,9 @@ class TestNumberedNicsMapping(base.TestCase): mapping = {'nic1': '12:34:56:de:f0:12', 'nic2': '12:34:56:78:9a:bc'} expected = {'nic1': 'em2', 'nic2': 'em1'} self.assertEqual(expected, objects._numbered_nics(nic_mapping=mapping)) + + def test_numbered_nics_no_active(self): + self._stub_active_nics([]) + expected = {} + # This only emits a warning, so it should still work + self.assertEqual(expected, objects._numbered_nics()) diff --git a/os_net_config/utils.py b/os_net_config/utils.py index da7ab11..4e25d30 100644 --- a/os_net_config/utils.py +++ b/os_net_config/utils.py @@ -60,13 +60,13 @@ def _is_active_nic(interface_name): operstate = None with open(_SYS_CLASS_NET + '/%s/operstate' % interface_name, 'r') as f: - operstate = f.read().rstrip() + operstate = f.read().rstrip().lower() address = None with open(_SYS_CLASS_NET + '/%s/address' % interface_name, 'r') as f: address = f.read().rstrip() - if has_device_dir and operstate == 'UP' and address: + if has_device_dir and operstate == 'up' and address: return True else: return False |