diff options
author | Chris Patterson <cpatterson@microsoft.com> | 2022-01-20 17:31:25 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-20 16:31:25 -0600 |
commit | 109c2bbd9eb9a3b0612098bb010317191c436ad2 (patch) | |
tree | 50d23617d1e43ca800148bc414f2304edae39ca9 /cloudinit | |
parent | 2a08d592f7fbdb64452eb2da14592ae5aec806ea (diff) | |
download | vyos-cloud-init-109c2bbd9eb9a3b0612098bb010317191c436ad2.tar.gz vyos-cloud-init-109c2bbd9eb9a3b0612098bb010317191c436ad2.zip |
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
Diffstat (limited to 'cloudinit')
-rwxr-xr-x | cloudinit/sources/DataSourceAzure.py | 14 |
1 files 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( |