From 52f6c7b61899349d5b741220351c1364a4c722df Mon Sep 17 00:00:00 2001 From: Brett Holman Date: Wed, 18 Sep 2024 06:57:42 -0700 Subject: [PATCH] chore: clean up old pickle workaround --- cloudinit/sources/DataSourceEc2.py | 15 ------ tests/unittests/sources/test_ec2.py | 79 ----------------------------- 2 files changed, 94 deletions(-) diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py index 01d6c06b729..bf3b84850ec 100644 --- a/cloudinit/sources/DataSourceEc2.py +++ b/cloudinit/sources/DataSourceEc2.py @@ -508,21 +508,6 @@ def network_config(self): return None result = None - no_network_metadata_on_aws = bool( - "network" not in self.metadata - and self.cloud_name == CloudNames.AWS - ) - if no_network_metadata_on_aws: - LOG.debug( - "Metadata 'network' not present:" - " Refreshing stale metadata from prior to upgrade." - ) - util.log_time( - logfunc=LOG.debug, - msg="Re-crawl of metadata service", - func=self.get_data, - ) - iface = self.distro.fallback_interface net_md = self.metadata.get("network") if isinstance(net_md, dict): diff --git a/tests/unittests/sources/test_ec2.py b/tests/unittests/sources/test_ec2.py index abb010e2870..5cf2c38d543 100644 --- a/tests/unittests/sources/test_ec2.py +++ b/tests/unittests/sources/test_ec2.py @@ -4,7 +4,6 @@ import copy import json import logging -from typing import List from unittest import mock import pytest @@ -612,84 +611,6 @@ def test_network_config_property_is_cached_in_datasource( ds._network_config = {"cached": "data"} assert {"cached": "data"} == ds.network_config - @responses.activate - @mock.patch("cloudinit.net.dhcp.maybe_perform_dhcp_discovery") - def test_network_config_cached_property_refreshed_on_upgrade( - self, m_dhcp, caplog, mocker, tmpdir - ): - """Refresh the network_config Ec2 cache if network key is absent. - - This catches an upgrade issue where obj.pkl contained stale metadata - which lacked newly required network key. - """ - old_metadata = copy.deepcopy(DEFAULT_METADATA) - old_metadata.pop("network") - ds = self._setup_ds( - platform_data=self.valid_platform_data, - sys_cfg={"datasource": {"Ec2": {"strict_id": True}}}, - md={"md": old_metadata}, - mocker=mocker, - tmpdir=tmpdir, - ) - assert True is ds.get_data() - - def _remove_md(resp_list: List) -> None: - for index, url in enumerate(resp_list): - try: - url = url.url - except AttributeError: - # Can be removed when Bionic is EOL - url = url["url"] - if url.startswith( - "http://169.254.169.254/2009-04-04/meta-data/" - ): - del resp_list[index] - - # Workaround https://github.com/getsentry/responses/issues/212 - if hasattr(responses, "_urls"): - # Can be removed when Bionic is EOL - _remove_md(responses._urls) - elif hasattr(responses, "_default_mock") and hasattr( - responses._default_mock, "_urls" - ): - # Can be removed when Bionic is EOL - _remove_md(responses._default_mock._urls) - elif hasattr(responses, "_matches"): - # Can be removed when Focal is EOL - _remove_md(responses._matches) - elif hasattr(responses, "_default_mock") and hasattr( - responses._default_mock, "_matches" - ): - # Can be removed when Focal is EOL - _remove_md(responses._default_mock._matches) - - # Provide new revision of metadata that contains network data - register_mock_metaserver( - "http://169.254.169.254/2009-04-04/meta-data/", - DEFAULT_METADATA, - responses, - ) - mac1 = "06:17:04:d7:26:09" # Defined in DEFAULT_METADATA - get_interface_mac_path = M_PATH_NET + "get_interfaces_by_mac" - ds.distro.fallback_nic = "eth9" - with mock.patch(get_interface_mac_path) as m_get_interfaces_by_mac: - m_get_interfaces_by_mac.return_value = {mac1: "eth9"} - nc = ds.network_config # Will re-crawl network metadata - assert None is not nc - assert "Refreshing stale metadata from prior to upgrade" in caplog.text - expected = { - "version": 2, - "ethernets": { - "eth9": { - "match": {"macaddress": mac1}, - "set-name": "eth9", - "dhcp4": True, - "dhcp6": True, - } - }, - } - assert expected == ds.network_config - @responses.activate def test_ec2_get_instance_id_refreshes_identity_on_upgrade( self, mocker, tmpdir