canonical / cloud-init

Official upstream for the cloud-init: cloud instance initialization

Home Page:https://cloud-init.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting data from <class 'cloudinit.sources.DataSourceGCE.DataSourceGCELocal'> failed

valentindavid opened this issue · comments

Bug report

cloud-init 24.1.1-0ubuntu1 fails to get data from GCE on Ubuntu Core 24

Steps to reproduce the problem

Environment details

  • Cloud-init version: 24.1.1-0ubuntu1
  • Operating System Distribution: Ubuntu Core 24
  • Cloud provider, platform or installer type: GCE

cloud-init logs

2024-03-21 14:51:33,426 - util.py[DEBUG]: Cloud-init v. 24.1.1-0ubuntu1 running 'init-local' at Thu, 21 Mar 2024 14:51:33 +0000. Up 22.75 seconds.
2024-03-21 14:51:33,426 - main.py[INFO]: PID [1] started cloud-init.
2024-03-21 14:51:33,427 - main.py[DEBUG]: No kernel command line url found.
2024-03-21 14:51:33,427 - main.py[DEBUG]: Closing stdin.
2024-03-21 14:51:33,431 - util.py[DEBUG]: Writing to /var/log/cloud-init.log - ab: [640] 0 bytes
2024-03-21 14:51:33,432 - util.py[DEBUG]: Changing the ownership of /var/log/cloud-init.log to 108:4
2024-03-21 14:51:33,433 - util.py[DEBUG]: Writing to /var/lib/cloud/data/python-version - wb: [644] 4 bytes
2024-03-21 14:51:33,433 - util.py[DEBUG]: Attempting to remove /var/lib/cloud/instance/boot-finished
2024-03-21 14:51:33,433 - handlers.py[DEBUG]: start: init-local/check-cache: attempting to read from cache [check]
2024-03-21 14:51:33,433 - util.py[DEBUG]: Reading from /var/lib/cloud/instance/obj.pkl (quiet=False)
2024-03-21 14:51:33,434 - stages.py[DEBUG]: no cache found
2024-03-21 14:51:33,434 - handlers.py[DEBUG]: finish: init-local/check-cache: SUCCESS: no cache found
2024-03-21 14:51:33,434 - util.py[DEBUG]: Attempting to remove /var/lib/cloud/instance
2024-03-21 14:51:33,437 - stages.py[DEBUG]: Using distro class <class 'cloudinit.distros.ubuntu.Distro'>
2024-03-21 14:51:33,437 - sources[DEBUG]: Looking for data source in: ['GCE', 'None'], via packages ['', 'cloudinit.sources'] that matches dependencies ['FILESYSTEM']
2024-03-21 14:51:33,515 - sources[DEBUG]: Searching for local data source in: ['DataSourceGCELocal']
2024-03-21 14:51:33,515 - handlers.py[DEBUG]: start: init-local/search-GCELocal: searching for local data from DataSourceGCELocal
2024-03-21 14:51:33,515 - sources[DEBUG]: Seeing if we can get any data from <class 'cloudinit.sources.DataSourceGCE.DataSourceGCELocal'>
2024-03-21 14:51:33,515 - sources[DEBUG]: Update datasource metadata and network config due to events: boot-new-instance
2024-03-21 14:51:33,516 - sources[DEBUG]: Detected platform: DataSourceGCELocal. Checking for active instance data
2024-03-21 14:51:33,516 - util.py[DEBUG]: Reading from /sys/class/net/ens4/name_assign_type (quiet=False)
2024-03-21 14:51:33,516 - util.py[DEBUG]: Read 2 bytes from /sys/class/net/ens4/name_assign_type
2024-03-21 14:51:33,516 - util.py[DEBUG]: Reading from /sys/class/net/ens4/address (quiet=False)
2024-03-21 14:51:33,516 - util.py[DEBUG]: Read 18 bytes from /sys/class/net/ens4/address
2024-03-21 14:51:33,516 - util.py[DEBUG]: Reading from /sys/class/net/ens4/device/device (quiet=False)
2024-03-21 14:51:33,516 - util.py[DEBUG]: Read 7 bytes from /sys/class/net/ens4/device/device
2024-03-21 14:51:33,516 - util.py[DEBUG]: Reading from /sys/class/net/lo/address (quiet=False)
2024-03-21 14:51:33,516 - util.py[DEBUG]: Read 18 bytes from /sys/class/net/lo/address
2024-03-21 14:51:33,516 - util.py[DEBUG]: Reading from /sys/class/net/lo/device/device (quiet=False)
2024-03-21 14:51:33,516 - util.py[DEBUG]: Reading from /sys/class/net/ens4/carrier (quiet=False)
2024-03-21 14:51:33,517 - net[DEBUG]: Interface has no carrier: ens4
2024-03-21 14:51:33,517 - util.py[DEBUG]: Reading from /sys/class/net/ens4/dormant (quiet=False)
2024-03-21 14:51:33,517 - util.py[DEBUG]: Reading from /sys/class/net/ens4/operstate (quiet=False)
2024-03-21 14:51:33,517 - util.py[DEBUG]: Read 5 bytes from /sys/class/net/ens4/operstate
2024-03-21 14:51:33,517 - DataSourceGCE.py[DEBUG]: Looking for the primary NIC in: ['ens4']
2024-03-21 14:51:33,517 - distros[DEBUG]: Using configured dhcp client priority list: ['dhcpcd', 'dhclient', 'udhcpc']
2024-03-21 14:51:33,518 - distros[DEBUG]: DHCP client not found: dhcpcd
2024-03-21 14:51:33,518 - distros[DEBUG]: DHCP client not found: dhclient
2024-03-21 14:51:33,519 - distros[DEBUG]: DHCP client not found: udhcpc
2024-03-21 14:51:33,519 - util.py[DEBUG]: Reading from /sys/class/net/ens4/name_assign_type (quiet=False)
2024-03-21 14:51:33,519 - util.py[DEBUG]: Read 2 bytes from /sys/class/net/ens4/name_assign_type
2024-03-21 14:51:33,519 - util.py[DEBUG]: Reading from /sys/class/net/ens4/address (quiet=False)
2024-03-21 14:51:33,519 - util.py[DEBUG]: Read 18 bytes from /sys/class/net/ens4/address
2024-03-21 14:51:33,519 - util.py[DEBUG]: Reading from /sys/class/net/ens4/device/device (quiet=False)
2024-03-21 14:51:33,520 - util.py[DEBUG]: Read 7 bytes from /sys/class/net/ens4/device/device
2024-03-21 14:51:33,520 - util.py[DEBUG]: Reading from /sys/class/net/lo/address (quiet=False)
2024-03-21 14:51:33,520 - util.py[DEBUG]: Read 18 bytes from /sys/class/net/lo/address
2024-03-21 14:51:33,520 - util.py[DEBUG]: Reading from /sys/class/net/lo/device/device (quiet=False)
2024-03-21 14:51:33,520 - util.py[DEBUG]: Reading from /sys/class/net/ens4/carrier (quiet=False)
2024-03-21 14:51:33,520 - net[DEBUG]: Interface has no carrier: ens4
2024-03-21 14:51:33,520 - util.py[DEBUG]: Reading from /sys/class/net/ens4/dormant (quiet=False)
2024-03-21 14:51:33,520 - util.py[DEBUG]: Reading from /sys/class/net/ens4/operstate (quiet=False)
2024-03-21 14:51:33,520 - util.py[DEBUG]: Read 5 bytes from /sys/class/net/ens4/operstate
2024-03-21 14:51:33,520 - handlers.py[DEBUG]: finish: init-local/search-GCELocal: FAIL: no local data found from DataSourceGCELocal
2024-03-21 14:51:33,520 - util.py[WARNING]: Getting data from <class 'cloudinit.sources.DataSourceGCE.DataSourceGCELocal'> failed
2024-03-21 14:51:33,521 - util.py[DEBUG]: Getting data from <class 'cloudinit.sources.DataSourceGCE.DataSourceGCELocal'> failed
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/sources/__init__.py", line 1028, in find_source
    if s.update_metadata_if_supported(
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/sources/__init__.py", line 914, in update_metadata_if_supported
    result = self.get_data()
             ^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/sources/__init__.py", line 460, in get_data
    return_value = self._check_and_get_data()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/sources/__init__.py", line 392, in _check_and_get_data
    return self._get_data()
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceGCE.py", line 145, in _get_data
    if not ret["success"]:
           ^^^
UnboundLocalError: cannot access local variable 'ret' where it is not associated with a value

The logs continue, but I suppose it is not really relevant.

Thank you @valentindavid for the bug report here and making cloud-init better.

I'm unfamiliar with the internals of ubuntu core 24 environment. Do you have recommendations for a dhcp client (if any) in core 24 that cloud-init could leverage to expedite boot times by bringing up networking on the primary NIC in order to consume instance metadata from Google's IMDS. I can see that core looks to have recently removed dhcpcd-base. Is there an alternative dhcp client that we expect to exist in the core 24 image?

Regardless of the DHCP client situation in core24. I think we can minimally ensure cloud-init better handles that particular traceback when no viable DHCP clients are present and skip any init-local detection for any DataSource which tires to setup ephemeral networking when no viable dhcp clients are present. This should allow cloud-init to at least fall back to whatever system networking config Core24 provides, which will allow cloud-init to discover GCE in the init-network boot stage after system networking is brought up.

I'll mark this bug as incomplete as we look to further discussion and or recommendations on whether cloud-init should be able to leverage a different DHCP client in core images for early boot (init-local timeframe) datasource discovery.

cloud-init 24.1.1-0ubuntu1 fails to get data from GCE on Ubuntu Core 24

As @blackboxsw already pointed out, Ubuntu Core 24 fails to provide a required dependency to cloud-init. See my comment on that PR for more context.

We could certainly improve the debugging logs a bit here, but right now I think this is "not a cloud-init bug".