diff options
author | 2017-05-23 16:19:30 +0000 | |
---|---|---|
committer | 2017-05-30 20:17:21 +0000 | |
commit | 5c840c4941d8401ee3c2d15c9a6cfb4f6a074deb (patch) | |
tree | 38ccfcc98076fafbb10dccf6fd1674057074e9ba /os_net_config/tests/test_impl_ifcfg.py | |
parent | e7e81ac01122dd1b7711116d583a69fb655e0bca (diff) |
Continue bringing up interfaces even if one fails
Currently os-net-config exits immediately if an interface fails to
come up. This causes problems when we call it with a failsafe
configuration because it can result in working interfaces not
being configured if there are also non-functional interfaces, which
can leave a system unreachable over the network even though it may
have a working connection.
This change stores errors and handles them after all interfaces have
been processed to allow os-net-config to do what it can even with an
invalid configuration. If any failures are detected it will still
cause os-net-config to report failure at the end.
Change-Id: I3bc75e217d0b7c5ae62900f4253ad57ee3720685
Closes-Bug: 1692725
Diffstat (limited to 'os_net_config/tests/test_impl_ifcfg.py')
-rw-r--r-- | os_net_config/tests/test_impl_ifcfg.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py index 9ff2bd6..e400c94 100644 --- a/os_net_config/tests/test_impl_ifcfg.py +++ b/os_net_config/tests/test_impl_ifcfg.py @@ -19,6 +19,7 @@ import tempfile from oslo_concurrency import processutils +import os_net_config from os_net_config import impl_ifcfg from os_net_config import NetConfig from os_net_config import objects @@ -1231,3 +1232,33 @@ class TestIfcfgNetConfigApply(base.TestCase): self.provider.add_interface(interface) self.provider.apply() self.assertNotIn('Restart openvswitch', execute_strings) + + def _failed_execute(*args, **kwargs): + if kwargs.get('check_exit_code', True): + raise processutils.ProcessExecutionError('Test stderr', + 'Test stdout', + str(kwargs)) + + def test_interface_failure(self): + self.stubs.Set(processutils, 'execute', self._failed_execute) + v4_addr = objects.Address('192.168.1.2/24') + interface = objects.Interface('em1', addresses=[v4_addr]) + self.provider.add_interface(interface) + + self.assertRaises(os_net_config.ConfigurationError, + self.provider.apply) + self.assertEqual(1, len(self.provider.errors)) + + def test_interface_failure_multiple(self): + self.stubs.Set(processutils, 'execute', self._failed_execute) + v4_addr = objects.Address('192.168.1.2/24') + interface = objects.Interface('em1', addresses=[v4_addr]) + v4_addr2 = objects.Address('192.168.2.2/24') + interface2 = objects.Interface('em2', addresses=[v4_addr2]) + self.provider.add_interface(interface) + self.provider.add_interface(interface2) + + self.assertRaises(os_net_config.ConfigurationError, + self.provider.apply) + # Even though the first one failed, we should have attempted both + self.assertEqual(2, len(self.provider.errors)) |