From 5c840c4941d8401ee3c2d15c9a6cfb4f6a074deb Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Tue, 23 May 2017 16:19:30 +0000 Subject: 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 --- os_net_config/__init__.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'os_net_config/__init__.py') 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) -- cgit 1.2.3-korg