diff --git a/cloudinit/net/ephemeral.py b/cloudinit/net/ephemeral.py index 3b5f9b96a2ef..fd54fc1d9f8f 100644 --- a/cloudinit/net/ephemeral.py +++ b/cloudinit/net/ephemeral.py @@ -107,9 +107,8 @@ def __enter__(self): elif self.router: self._bringup_router() except subp.ProcessExecutionError: - LOG.error( - "Error bringing up EphemeralIPv4Network. " - "Datasource setup cannot continue" + LOG.warn( + "Error bringing up EphemeralIPv4Network." ) self.__exit__(None, None, None) raise @@ -233,13 +232,20 @@ def __enter__(self): https://www.kernel.org/doc/html/latest/networking/ipv6.html """ - if net.read_sys_net(self.interface, "operstate") != "up": - self.distro.net_ops.link_up(self.interface) + try: + if net.read_sys_net(self.interface, "operstate") != "up": + self.distro.net_ops.link_up(self.interface) + except subp.ProcessExecutionError: + LOG.warn( + "Error bringing up EphemeralIPv6Network." + ) + raise def __exit__(self, *_args): """No need to set the link to down state""" + class EphemeralDHCPv4: def __init__( self, @@ -370,14 +376,35 @@ def __enter__(self): # ipv6 dualstack might succeed when dhcp4 fails # therefore catch exception unless only v4 is used try: + exceptions = [] + ephemeral_obtained = False if self.ipv4: - self.stack.enter_context( - EphemeralDHCPv4(self.distro, self.interface) - ) + try: + self.stack.enter_context( + EphemeralDHCPv4(self.distro, self.interface) + ) + ephemeral_obtained = True + except subp.ProcessExecutionError as e: + exceptions.append(e) + if self.ipv6: - self.stack.enter_context( - EphemeralIPv6Network(self.distro, self.interface) + try: + self.stack.enter_context( + EphemeralIPv6Network(self.distro, self.interface) + ) + ephemeral_obtained = True + except subp.ProcessExecutionError as e: + exceptions.append(e) + + if not ephemeral_obtained: + # raise only the first exception found + # is there a way to merge / represent that both failed? + LOG.error( + "Error bringing up EphemeralIPNetwork. " + "Datasource setup cannot continue" ) + raise exceptions[0] + # v6 link local might be usable # caller may want to log network state except NoDHCPLeaseError as e: