← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1987005] [NEW] ipv6_ready referenced before assignment

 

Public bug reported:

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)

** Affects: cloud-init
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to cloud-init.
https://bugs.launchpad.net/bugs/1987005

Title:
  ipv6_ready referenced before assignment

Status in cloud-init:
  New

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)

To manage notifications about this bug go to:
https://bugs.launchpad.net/cloud-init/+bug/1987005/+subscriptions



Follow ups