aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config/__init__.py
diff options
context:
space:
mode:
authorBen Nemec <bnemec@redhat.com>2017-05-23 16:19:30 +0000
committerBen Nemec <bnemec@redhat.com>2017-05-30 20:17:21 +0000
commit5c840c4941d8401ee3c2d15c9a6cfb4f6a074deb (patch)
tree38ccfcc98076fafbb10dccf6fd1674057074e9ba /os_net_config/__init__.py
parente7e81ac01122dd1b7711116d583a69fb655e0bca (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/__init__.py')
-rw-r--r--os_net_config/__init__.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/os_net_config/__init__.py b/os_net_config/__init__.py
index cb56059..609d5dc 100644
--- a/os_net_config/__init__.py
+++ b/os_net_config/__init__.py
@@ -30,6 +30,10 @@ class NotImplemented(Exception):
pass
+class ConfigurationError(Exception):
+ pass
+
+
class NetConfig(object):
"""Common network config methods class."""
@@ -37,6 +41,7 @@ class NetConfig(object):
self.noop = noop
self.log_prefix = "NOOP: " if noop else ""
self.root_dir = root_dir
+ self.errors = []
def add_object(self, obj):
"""Convenience method to add any type of object to the network config.
@@ -249,8 +254,20 @@ class NetConfig(object):
self.execute(msg, '/sbin/ifdown', interface, check_exit_code=False)
def ifup(self, interface, iftype='interface'):
+ """Run 'ifup' on the specified interface
+
+ If a failure occurs when bringing up the interface it will be saved
+ to self.errors for later handling. This allows callers to continue
+ trying to bring up interfaces even if one fails.
+
+ :param interface: The name of the interface to be started.
+ :param iftype: The type of the interface.
+ """
msg = 'running ifup on %s: %s' % (iftype, interface)
- self.execute(msg, '/sbin/ifup', interface)
+ try:
+ self.execute(msg, '/sbin/ifup', interface)
+ except processutils.ProcessExecutionError as e:
+ self.errors.append(e)
def ifrename(self, oldname, newname):
msg = 'renaming %s to %s: ' % (oldname, newname)