cloud-init icon indicating copy to clipboard operation
cloud-init copied to clipboard

Scaleway datasource tries to access missing keys in metadata

Open ffeldhaus opened this issue 2 weeks ago • 1 comments

Bug report

Inside cloudinit/sources/DataSourceScaleway.py metadata keys are accessed which may not exist. This leads to failures of the datasource.

Problematic cases:

This can be fixed by using self.metadata.get with a default instead of directly accessing the key.

Steps to reproduce the problem

Deploy a scaleway baremetal server with cloud-init and with the default configuration (e.g. no private network).

Environment details

  • Cloud-init version: 25.1.4
  • Operating System Distribution: Ubuntu 24.04.1
  • Cloud provider, platform or installer type: Scaleway

cloud-init logs

2025-12-07 13:27:45,294 - main.py[ERROR]: failed stage init
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 931, in status_wrapper
    ret = functor(name, args)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 561, in main_init
    init.apply_network_config(bring_up=bring_up_interfaces)
  File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 1059, in apply_network_config
    netcfg, src = self._find_networking_config()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 993, in _find_networking_config
    if self.datasource and hasattr(self.datasource, "network_config"):
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceScaleway.py", line 324, in network_config
    if self.metadata["private_ip"] is None:
       ~~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'private_ip'

ffeldhaus avatar Dec 07 '25 14:12 ffeldhaus

Thank you for filing this bug and improving cloud-init on various platforms. I agree with your suggested approach using .get() to avoid KeyError issues in this case. If you would like to propose a pull request with such a fix and a unittest in tests/unittests/sources/test_scaleway.py we will help you get that fix merged.

blackboxsw avatar Dec 08 '25 16:12 blackboxsw

This issue is resolved by https://github.com/canonical/cloud-init/pull/6617 which refactors Scaleway datasource to avoid attempting to process private_ip in metadata.

blackboxsw avatar Dec 17 '25 17:12 blackboxsw