Skip to content

In DataSourceCloudStack the primary_nic is not Always Assigned a Value but it may Always be Read #6838

@bryanfraschetti

Description

@bryanfraschetti

Bug report

When using a NetworkManager backend on Ubuntu in CloudStack a strange situation can arise where there is no primary_nic and we try to obtain a DHCP lease. Most likely this is because Ubuntu's service ordering currently doesn't block on NetworkManager-wait-online.service and so the interfaces have not yet been brought up. Attempting to obtain a DHCP lease on the undefined nic essentially becomes a no-op and works fine. However, the error below is thrown when attempting to log the situation. Something in the boot process has probably gone wrong for the nic to be unassigned but given that the traceback is just occuring on the log statement rather than anything else it may be clearer to set a default value of None for primary_nic so that the logs will show "Unable to obtain a DHCP lease on None" rather than throwing an error.

2026-03-31 17:50:51,633 - log_util.py[DEBUG]: Getting data from <class 'cloudinit.sources.DataSourceCloudStack.DataSourceCloudStack'> failed
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/net/dhcp.py", line 864, in get_newest_lease
    subp.subp(
  File "/usr/lib/python3/dist-packages/cloudinit/subp.py", line 291, in subp
    raise ProcessExecutionError(
cloudinit.subp.ProcessExecutionError: Unexpected error while running command.
Command: ['dhcpcd', '--dumplease', '--ipv4only', 'ens3']
Exit code: 1
Reason: -
Stdout:
Stderr: dhcpcd is not running

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudStack.py", line 214, in _get_data
    vr_addr = get_vr_address(self.distro)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudStack.py", line 342, in get_vr_address
    latest_lease = distro.dhcp_client.get_newest_lease(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/net/dhcp.py", line 882, in get_newest_lease
    raise NoDHCPLeaseError from error
cloudinit.net.dhcp.NoDHCPLeaseError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/sources/__init__.py", line 1091, in find_source
    if s.update_metadata_if_supported(
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/sources/__init__.py", line 959, in update_metadata_if_supported
    result = self.get_data()
             ^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/performance.py", line 103, in decorator
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/sources/__init__.py", line 505, in get_data
    return_value = self._check_and_get_data()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/sources/__init__.py", line 436, in _check_and_get_data
    return self._get_data()
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudStack.py", line 229, in _get_data
    LOG.warning("Unable to obtain a DHCP lease on %s", primary_nic)
                                                       ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'primary_nic' where it is not associated with a value

Steps to reproduce the problem

Boot an Ubuntu Noble VM that uses NetworkManager in a CloudStack environment

Environment details

  • Cloud-init version: 25.3-0ubuntu1~24.04 and also the daily PPA: 100.0.1-daily-202603021632-a2209a9e1~ubuntu24.04.1
  • Operating System Distribution: Ubuntu Noble
  • Cloud provider, platform or installer type: CloudStack

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working correctly

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions