Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure: /run/cloud-init/cloud-id broken symlink across reboot. #4051

Closed
ubuntu-server-builder opened this issue May 12, 2023 · 1 comment
Closed
Labels
good first issue launchpad Migrated from Launchpad priority Fix soon

Comments

@ubuntu-server-builder
Copy link
Collaborator

This bug was originally filed in Launchpad as LP: #1998998

Launchpad details
affected_projects = []
assignee = None
assignee_name = None
date_closed = 2023-02-22T16:52:32.106568+00:00
date_created = 2022-12-07T04:37:33.678461+00:00
date_fix_committed = 2023-02-22T16:52:32.106568+00:00
date_fix_released = 2023-02-22T16:52:32.106568+00:00
id = 1998998
importance = high
is_complete = True
lp_url = https://bugs.launchpad.net/cloud-init/+bug/1998998
milestone = None
owner = chad.smith
owner_name = Chad Smith
private = False
status = fix_released
submitter = chad.smith
submitter_name = Chad Smith
tags = ['bitesize']
duplicates = []

Launchpad user Chad Smith(chad.smith) wrote on 2022-12-07T04:37:33.678461+00:00

cloud-init 22.4.2

On Azure, datasource details change across reboot cloud-init incorrectly removes /run/cloud-init/cloud-id-azure symlink.

2022-12-07 04:14:17,920 - util.py[DEBUG]: Creating symbolic link from '/run/cloud-init/cloud-id' => '/run/cloud-init/cloud-id-azure'
2022-12-07 04:14:17,920 - util.py[DEBUG]: Attempting to remove /run/cloud-init/cloud-id-azure

FRESH LAUNCH

ubuntu@test-focal:$ ls -l /run/cloud-init/cloud-id
lrwxrwxrwx 1 root root 30 Dec 7 04:10 /run/cloud-init/cloud-id -> /run/cloud-init/cloud-id-azure
ubuntu@test-focal:
$ grep cloud-id /var/log/cloud-init.log
2022-12-07 04:10:34,734 - util.py[DEBUG]: Writing to /run/cloud-init/cloud-id-azure - wb: [644] 6 bytes
2022-12-07 04:10:34,735 - util.py[DEBUG]: Creating symbolic link from '/run/cloud-init/cloud-id' => '/run/cloud-init/cloud-id-azure'

ACROSS REBOOT

ubuntu@test-focal:~$ ls -l /run/cloud-init/cloud-id
lrwxrwxrwx 1 root root 30 Dec 7 04:14 /run/cloud-init/cloud-id -> /run/cloud-init/cloud-id-azure

2022-12-07 04:14:17,920 - util.py[DEBUG]: Writing to /run/cloud-init/cloud-id-azure - wb: [644] 6 bytes
2022-12-07 04:14:17,920 - util.py[DEBUG]: Creating symbolic link from '/run/cloud-init/cloud-id' => '/run/cloud-init/cloud-id-azure'
2022-12-07 04:14:17,920 - util.py[DEBUG]: Attempting to remove /run/cloud-init/cloud-id-azure

It looks like the symlink cleanup logic introduced in 217ef6b (which was released in cloud-init v. 21.4) doesn't do a proper comparison of previous-datasource to current datasource

Debug logs added to https://github.com/canonical/cloud-init/blob/main/cloudinit/sources/__init__.py#L443 shows that we are comparing the incorrect source file /root/cloud-init/cloud-id versus actually comparing the cloud-specific symlink name /run/cloud-init/cloud-id-, resulting in a removal of the cloud-specific link name across reboot.

2022-12-07 04:25:58,162 - init.py[WARNING]: previous_cloud_id_file /run/cloud-init/cloud-id-azure != cloud_id_file /run/cloud-init/cloud-id

Likely all we need is a correction in logic like the following:
diff --git a/cloudinit/sources/init.py b/cloudinit/sources/init.py
index 85e094ac5..3fb08ead2 100644
--- a/cloudinit/sources/init.py
+++ b/cloudinit/sources/init.py
@@ -439,8 +439,9 @@ class DataSource(CloudInitPickleMixin, metaclass=abc.ABCMeta):
prev_cloud_id_file = os.path.realpath(cloud_id_file)
else:
prev_cloud_id_file = cloud_id_file

  •    util.sym_link(f"{cloud_id_file}-{cloud_id}", cloud_id_file, force=True)
    
  •    if prev_cloud_id_file != cloud_id_file:
    
  •    new_cloud_id_file = f"{cloud_id_file}-{cloud_id}"
    
  •    util.sym_link(new_cloud_id_file, cloud_id_file, force=True)
    
  •    if prev_cloud_id_file != new_cloud_id_file:
           util.del_file(prev_cloud_id_file)
       write_json(json_sensitive_file, processed_data, mode=0o600)
       json_file = self.paths.get_runpath("instance_data")
    
@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user Alberto Contreras(aciba) wrote on 2023-02-22T16:52:33.051720+00:00

This bug is believed to be fixed in cloud-init in version 23.1. If this is still a problem for you, please make a comment and set the state back to New

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue launchpad Migrated from Launchpad priority Fix soon
Projects
None yet
Development

No branches or pull requests

1 participant