Skip to content

Commit

Permalink
ephemeral: Handle link up failure for both ipv4 and ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
holmanb committed Oct 24, 2023
1 parent 70af625 commit 3b109b0
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions cloudinit/net/ephemeral.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 3b109b0

Please sign in to comment.