Page MenuHomeVyOS Platform

cloud-init cannot clean up previously downloaded instance data
Open, HighPublicBUG

Description

When cloud-init runs in the update ISO, it becomes apparent that there's a logic error: it assumes that the instance data is a single file, when in reality it's now a directory.

2024-12-05 18:23:06,198 - util.py[DEBUG]: Attempting to remove /opt/vyatta/etc/config/cloud/instance
2024-12-05 18:23:06,198 - util.py[WARNING]: failed stage init-local
2024-12-05 18:23:06,198 - util.py[DEBUG]: failed stage init-local
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 761, in status_wrapper
    ret = functor(name, args)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 384, in main_init
    init.fetch(existing=existing)
  File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 432, in fetch
    return self._get_data_source(existing=existing)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 319, in _get_data_source
    util.del_file(self.paths.instance_link)
  File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 1900, in del_file
    raise e
  File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 1897, in del_file
    os.unlink(path)
IsADirectoryError: [Errno 21] Is a directory: '/opt/vyatta/etc/config/cloud/instance'

Since it's only happens when cloud-init's work was already done during the initial deployment, this issue has no effect on the system operation.

Details

Version
1.4.1
Is it a breaking change?
Perfectly compatible
Issue type
Bug (incorrect behavior)

Event Timeline

natali-rs1985 changed the task status from Open to In progress.Jun 13 2025, 3:00 PM
natali-rs1985 claimed this task.
natali-rs1985 changed the task status from In progress to Open.Jun 16 2025, 2:11 PM
natali-rs1985 removed natali-rs1985 as the assignee of this task.
natali-rs1985 subscribed.

I checked the current public vyos-cloud-init branches and the issue still appears to be present: cloudinit/stages.py calls util.del_file(self.paths.instance_link), while util.del_file() uses os.unlink(), so a stale real directory at that path still raises IsADirectoryError.

I plan to keep the fix narrowly scoped: preserve the existing file/symlink behavior, but handle the real-directory case before datasource discovery continues. I will add focused unit coverage for the stale directory case.

Please assign this task to me if that scope is acceptable.

Hi @hybridops could you add a PR and maintainers will take a look on proposed fix.
Thanks