Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): Fix expected log for ipv6-only ephemeral network #4641

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 34 additions & 40 deletions cloudinit/net/ephemeral.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,49 +371,43 @@ def __enter__(self):
# no ephemeral network requested, but this object still needs to
# function as a context manager
return self
try:
exceptions = []
ephemeral_obtained = False
if self.ipv4:
try:
self.stack.enter_context(
EphemeralDHCPv4(
self.distro,
self.interface,
)
exceptions = []
ephemeral_obtained = False
if self.ipv4:
try:
self.stack.enter_context(
EphemeralDHCPv4(
self.distro,
self.interface,
)
ephemeral_obtained = True
except (ProcessExecutionError, NoDHCPLeaseError) as e:
LOG.info("Failed to bring up %s for ipv4.", self)
exceptions.append(e)

if self.ipv6:
try:
self.stack.enter_context(
EphemeralIPv6Network(
self.distro,
self.interface,
)
)
ephemeral_obtained = True
except (ProcessExecutionError, NoDHCPLeaseError) as e:
LOG.info("Failed to bring up %s for ipv4.", self)
exceptions.append(e)

if self.ipv6:
try:
self.stack.enter_context(
EphemeralIPv6Network(
self.distro,
self.interface,
)
ephemeral_obtained = True
except ProcessExecutionError as e:
LOG.info("Failed to bring up %s for ipv6.", self)
exceptions.append(e)
if not ephemeral_obtained:
# Ephemeral network setup failed in linkup for both ipv4 and
# ipv6. Raise only the first exception found.
LOG.error(
"Failed to bring up EphemeralIPNetwork. "
"Datasource setup cannot continue"
)
raise exceptions[0]
except NoDHCPLeaseError as e:
if self.ipv6:
# ipv6 dualstack might succeed when dhcp4 fails, so catch
# NoDHCPLeaseError unless only v4 is used
self.state_msg = "using link-local ipv6"
else:
raise e
ephemeral_obtained = True
if exceptions or not self.ipv4:
self.state_msg = "using link-local ipv6"
except ProcessExecutionError as e:
LOG.info("Failed to bring up %s for ipv6.", self)
exceptions.append(e)
if not ephemeral_obtained:
# Ephemeral network setup failed in linkup for both ipv4 and
# ipv6. Raise only the first exception found.
LOG.error(
"Failed to bring up EphemeralIPNetwork. "
"Datasource setup cannot continue"
)
raise exceptions[0]
return self

def __exit__(self, *_args):
Expand Down
Loading