From 109c2bbd9eb9a3b0612098bb010317191c436ad2 Mon Sep 17 00:00:00 2001 From: Chris Patterson Date: Thu, 20 Jan 2022 17:31:25 -0500 Subject: sources/azure: always initialize _ephemeral_dhcp_ctx on unpickle (#1199) Avoid requirement of getattr() and ensure _ephemeral_dhcp_ctx isn't persisted in the cache. Signed-off-by: Chris Patterson cpatterson@microsoft.com --- cloudinit/sources/DataSourceAzure.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index 9577355c..81ab88a9 100755 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -299,6 +299,8 @@ class DataSourceAzure(sources.DataSource): def _unpickle(self, ci_pkl_version: int) -> None: super()._unpickle(ci_pkl_version) + + self._ephemeral_dhcp_ctx = None if not hasattr(self, "iso_dev"): self.iso_dev = None @@ -514,9 +516,11 @@ class DataSourceAzure(sources.DataSource): if perform_reprovision or perform_reprovision_after_nic_attach: LOG.info("Reporting ready to Azure after getting ReprovisionData") - use_cached_ephemeral = self.distro.networking.is_up( - self.fallback_interface - ) and getattr(self, "_ephemeral_dhcp_ctx", None) + use_cached_ephemeral = ( + self.distro.networking.is_up(self.fallback_interface) + and self._ephemeral_dhcp_ctx + and self._ephemeral_dhcp_ctx.lease + ) if use_cached_ephemeral: self._report_ready(lease=self._ephemeral_dhcp_ctx.lease) self._ephemeral_dhcp_ctx.clean_network() # Teardown ephemeral @@ -1322,8 +1326,8 @@ class DataSourceAzure(sources.DataSource): try: if ( self.distro.networking.is_up(self.fallback_interface) - and getattr(self, "_ephemeral_dhcp_ctx", None) - and getattr(self._ephemeral_dhcp_ctx, "lease", None) + and self._ephemeral_dhcp_ctx + and self._ephemeral_dhcp_ctx.lease and unknown_245_key in self._ephemeral_dhcp_ctx.lease ): report_diagnostic_event( -- cgit v1.2.3