diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index 1d02d1d84ca..d168df674d0 100644 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -357,6 +357,9 @@ def _unpickle(self, ci_pkl_version: int) -> None: self._ephemeral_dhcp_ctx = None self._iso_dev = None self._wireserver_endpoint = DEFAULT_WIRESERVER_ENDPOINT + self._reported_ready_marker_file = os.path.join( + self.paths.cloud_dir, "data", "reported_ready" + ) def __str__(self): root = sources.DataSource.__str__(self) diff --git a/tests/data/old_pickles/focal-azure-20.1-10-g71af48df-0ubuntu5.pkl b/tests/data/old_pickles/focal-azure-20.1-10-g71af48df-0ubuntu5.pkl new file mode 100644 index 00000000000..7f6000c7708 Binary files /dev/null and b/tests/data/old_pickles/focal-azure-20.1-10-g71af48df-0ubuntu5.pkl differ diff --git a/tests/integration_tests/test_upgrade.py b/tests/integration_tests/test_upgrade.py index b13d4703dd8..5ef82e88828 100644 --- a/tests/integration_tests/test_upgrade.py +++ b/tests/integration_tests/test_upgrade.py @@ -95,7 +95,12 @@ def test_clean_boot_of_upgraded_package(session_cloud: IntegrationCloud): # have broken across re-constitution of a cached datasource. Some # platforms invalidate their datasource cache on reboot, so we run # it here to ensure we get a dirty run. - assert instance.execute("cloud-init init").ok + assert instance.execute( + "cloud-init init --local; " + "cloud-init init; " + "cloud-init modules --mode=config; " + "cloud-init modules --mode=final" + ).ok # Reboot instance.execute("hostname something-else") @@ -185,4 +190,6 @@ def test_subsequent_boot_of_upgraded_package(session_cloud: IntegrationCloud): source, take_snapshot=False, clean=False ) instance.restart() + log = instance.read_from_file("/var/log/cloud-init.log") + verify_clean_log(log) assert instance.execute("cloud-init status --wait --long").ok diff --git a/tests/integration_tests/util.py b/tests/integration_tests/util.py index 7eec3a4a408..f955e94ec11 100644 --- a/tests/integration_tests/util.py +++ b/tests/integration_tests/util.py @@ -47,6 +47,12 @@ def verify_clean_log(log: str, ignore_deprecations: bool = True): ) log = "\n".join(log_lines) + error_logs = re.findall("ERROR.*", log) + if error_logs: + raise AssertionError( + "Found unexpected errors: %s" % "\n".join(error_logs) + ) + warning_count = log.count("WARN") expected_warnings = 0 traceback_count = log.count("Traceback") diff --git a/tests/unittests/test_upgrade.py b/tests/unittests/test_upgrade.py index ed3c7efb464..218915ed63a 100644 --- a/tests/unittests/test_upgrade.py +++ b/tests/unittests/test_upgrade.py @@ -1,7 +1,5 @@ # Copyright (C) 2020 Canonical Ltd. # -# Author: Daniel Watkins -# # This file is part of cloud-init. See LICENSE file for license information. """Upgrade testing for cloud-init. @@ -19,8 +17,15 @@ import pytest from cloudinit.sources import pkl_load +from cloudinit.sources.DataSourceAzure import DataSourceAzure +from cloudinit.sources.DataSourceNoCloud import DataSourceNoCloud from tests.unittests.helpers import resourceLocation +DSNAME_TO_CLASS = { + "Azure": DataSourceAzure, + "NoCloud": DataSourceNoCloud, +} + class TestUpgrade: @pytest.fixture( @@ -36,6 +41,25 @@ def previous_obj_pkl(self, request): """ return pkl_load(str(request.param)) + def test_pkl_load_defines_all_init_side_effect_attributes( + self, previous_obj_pkl + ): + """Any attrs as side-effects of __init__ exist in unpickled obj.""" + ds_class = DSNAME_TO_CLASS[previous_obj_pkl.dsname] + sys_cfg = previous_obj_pkl.sys_cfg + distro = previous_obj_pkl.distro + paths = previous_obj_pkl.paths + ds = ds_class(sys_cfg, distro, paths) + if ds.dsname == "NoCloud" and previous_obj_pkl.__dict__: + expected = ( + set({"seed_dirs"}), # LP: #1568150 handled with getattr checks + set(), + ) + else: + expected = (set(),) + missing_attrs = ds.__dict__.keys() - previous_obj_pkl.__dict__.keys() + assert missing_attrs in expected + def test_networking_set_on_distro(self, previous_obj_pkl): """We always expect to have ``.networking`` on ``Distro`` objects.""" assert previous_obj_pkl.distro.networking is not None