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

ipv6_ready referenced before assignment #4011

Closed
ubuntu-server-builder opened this issue May 12, 2023 · 2 comments
Closed

ipv6_ready referenced before assignment #4011

ubuntu-server-builder opened this issue May 12, 2023 · 2 comments
Labels
launchpad Migrated from Launchpad priority Fix soon

Comments

@ubuntu-server-builder
Copy link
Collaborator

This bug was originally filed in Launchpad as LP: #1987005

Launchpad details
affected_projects = []
assignee = akutz
assignee_name = Andrew Kutz
date_closed = 2022-12-12T13:57:23.063028+00:00
date_created = 2022-08-18T22:32:29.336307+00:00
date_fix_committed = 2022-08-22T19:09:12.247013+00:00
date_fix_released = 2022-12-12T13:57:23.063028+00:00
id = 1987005
importance = high
is_complete = True
lp_url = https://bugs.launchpad.net/cloud-init/+bug/1987005
milestone = None
owner = jerrychengca
owner_name = Jerry Cheng
private = False
status = fix_released
submitter = jerrychengca
submitter_name = Jerry Cheng
tags = []
duplicates = []

Launchpad user Jerry Cheng(jerrychengca) wrote on 2022-08-18T22:32:29.336307+00:00

cloud-init crashes due to reference ipv6_ready before assignment.
cloud-init version: 22.2.2-1.ph3

traceback in cloudinit/sources/DataSourceVMware.py:

[2022-08-15 17:38:14] 2022-08-15 17:38:14,682 - util.py[WARNING]: failed stage init

[2022-08-15 17:38:14] failed run of stage init

[2022-08-15 17:38:14] ------------------------------------------------------------

[2022-08-15 17:38:14] Traceback (most recent call last):

[2022-08-15 17:38:14] File "/usr/lib/python3.7/site-packages/cloudinit/cmd/main.py", line 740, in status_wrapper

[2022-08-15 17:38:14] ret = functor(name, args)

[2022-08-15 17:38:14] File "/usr/lib/python3.7/site-packages/cloudinit/cmd/main.py", line 429, in main_init

[2022-08-15 17:38:14] init.setup_datasource()

[2022-08-15 17:38:14] File "/usr/lib/python3.7/site-packages/cloudinit/stages.py", line 468, in setup_datasource

[2022-08-15 17:38:14] self.datasource.setup(is_new_instance=self.is_new_instance())

[2022-08-15 17:38:14] File "/usr/lib/python3.7/site-packages/cloudinit/sources/DataSourceVMware.py", line 340, in setup

[2022-08-15 17:38:14] host_info = wait_on_network(self.metadata)

[2022-08-15 17:38:14] File "/usr/lib/python3.7/site-packages/cloudinit/sources/DataSourceVMware.py", line 963, in wait_on_network

[2022-08-15 17:38:14] ipv6_ready,

[2022-08-15 17:38:14] UnboundLocalError: local variable 'ipv6_ready' referenced before assignment

There is an issue in the source code: under certain conditions, ipv6_ready may be referenced in LOG.debug() before assignment if wait_on_ipv6 = false. The same issue may also happen for ipv4_ready if wait_on_ipv4 = false.

host_info = None

while host_info is None:

    # This loop + sleep results in two logs every second while waiting

    # for either ipv4 or ipv6 up. Do we really need to log each iteration

    # or can we log once and log on successful exit?

    host_info = get_host_info()



    network = host_info.get("network") or {}

    interfaces = network.get("interfaces") or {}

    by_ipv4 = interfaces.get("by-ipv4") or {}

    by_ipv6 = interfaces.get("by-ipv6") or {}



    if wait_on_ipv4:

        ipv4_ready = len(by_ipv4) > 0 if by_ipv4 else False

        if not ipv4_ready:

            host_info = None



    if wait_on_ipv6:

        ipv6_ready = len(by_ipv6) > 0 if by_ipv6 else False

        if not ipv6_ready:

            host_info = None



    if host_info is None:

        LOG.debug(

            "waiting on network: wait4=%s, ready4=%s, wait6=%s, ready6=%s",

            wait_on_ipv4,

            ipv4_ready,

            wait_on_ipv6,

            ipv6_ready,

        )

        time.sleep(1)
@ubuntu-server-builder ubuntu-server-builder added launchpad Migrated from Launchpad priority Fix soon labels May 12, 2023
@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user Andrew Kutz(akutz) wrote on 2022-08-19T13:55:22.598106+00:00

Opened PR to fix the issue -- #1674

@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user Chad Smith(chad.smith) wrote on 2022-08-22T19:11:17.429794+00:00

Thanks Andrew for the upstream commit here.
9f0efc4

This will be in cloud-init the next cloud-init SRU of 22.3-X which should also make it into Ubuntu Bionic, Focal and Jammy in the next 2 weeks.

I realize this doesn't help Photon OS, but wanted to provide a reference in case this hits Ubuntu consumers too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
launchpad Migrated from Launchpad priority Fix soon
Projects
None yet
Development

No branches or pull requests

1 participant