Public bug reported: 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 https://github.com/canonical/cloud- init/commit/217ef6ba6c52788f4363b998b6da08863fea5cd9 (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-<cloud>, 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") ** Affects: cloud-init Importance: High Status: Triaged ** Tags: bitesize ** Changed in: cloud-init Status: New => Triaged ** Changed in: cloud-init Importance: Undecided => High ** Tags added: bitesize -- You received this bug notification because you are a member of Yahoo! Engineering Team, which is subscribed to cloud-init. https://bugs.launchpad.net/bugs/1998998 Title: azure: /run/cloud-init/cloud-id broken symlink across reboot. Status in cloud-init: Triaged Bug description: 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 https://github.com/canonical/cloud- init/commit/217ef6ba6c52788f4363b998b6da08863fea5cd9 (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-<cloud>, 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") To manage notifications about this bug go to: https://bugs.launchpad.net/cloud-init/+bug/1998998/+subscriptions -- Mailing list: https://launchpad.net/~yahoo-eng-team Post to : yahoo-eng-team@lists.launchpad.net Unsubscribe : https://launchpad.net/~yahoo-eng-team More help : https://help.launchpad.net/ListHelp