ipv6_ready referenced before assignment

Bug #1987005 reported by Jerry Cheng
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
High
Andrew Kutz

Bug Description

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)

Revision history for this message
Andrew Kutz (akutz) wrote :
Changed in cloud-init:
assignee: nobody → Andrew Kutz (akutz)
Revision history for this message
Chad Smith (chad.smith) wrote :

Thanks Andrew for the upstream commit here.
https://github.com/canonical/cloud-init/commit/9f0efc474ea430c75cd0abec3e2da719d4934346

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.

Changed in cloud-init:
status: New → Fix Committed
importance: Undecided → High
James Falcon (falcojr)
Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.