From 75dd7ac48572e1f1fcfa89167f05f51cfc0050ee Mon Sep 17 00:00:00 2001 From: James Falcon Date: Thu, 2 Sep 2021 13:11:41 -0500 Subject: [PATCH 1/2] Set Azure to only update metadata on BOOT_NEW_INSTANCE In #834, we refactored the handling of events for fetching new metadata. Previously, in Azure's __init__, the BOOT event was added to the update_events, so it was assumed that Azure required the standard BOOT behavior, which is to apply metadata twice every boot: once during local-init, then again during standard init phase. https://github.com/canonical/cloud-init/blob/21.2/cloudinit/sources/DataSourceAzure.py#L356 However, this line was effectively meaningless. After the metadata was fetched in local-init, it was then pickled out to disk. Because "update_events" was a class variable, the EventType.BOOT was not persisted into the pickle. When the pickle was then unpickled in the init phase, metadata did not get re-fetched because EventType.BOOT was not present, so Azure is effectely only BOOT_NEW_INSTANCE. Fetching metadata twice during boot causes some issue for pre-provisioning on Azure because updating metadata during re-provisioning will cause cloud-init to poll for reprovisiondata again in DataSourceAzure, which will infinitely return 404(reprovisiondata is deleted from IMDS after health signal was sent by cloud-init during init-local). This makes cloud-init stuck in 'init' --- cloudinit/sources/DataSourceAzure.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index caffa944f3d..bfcb7253f37 100755 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -339,13 +339,6 @@ def temporary_hostname(temp_hostname, cfg, hostname_command='hostname'): class DataSourceAzure(sources.DataSource): dsname = 'Azure' - # Regenerate network config new_instance boot and every boot - default_update_events = {EventScope.NETWORK: { - EventType.BOOT_NEW_INSTANCE, - EventType.BOOT, - EventType.BOOT_LEGACY - }} - _negotiated = False _metadata_imds = sources.UNSET _ci_pkl_version = 1 From 843eb94b209a3a5a21cd9da50e5808fafa57966c Mon Sep 17 00:00:00 2001 From: James Falcon Date: Thu, 2 Sep 2021 16:24:19 -0500 Subject: [PATCH 2/2] flake8 --- cloudinit/sources/DataSourceAzure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index bfcb7253f37..3fb564c8dde 100755 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -22,7 +22,7 @@ from cloudinit import dmi from cloudinit import log as logging from cloudinit import net -from cloudinit.event import EventScope, EventType +from cloudinit.event import EventType from cloudinit.net import device_driver from cloudinit.net.dhcp import EphemeralDHCPv4 from cloudinit import sources