From 7268003a9e548dbf5cd0cc6e07b68420099db7ef Mon Sep 17 00:00:00 2001 From: Chad Smith Date: Mon, 22 Apr 2024 20:56:02 -0600 Subject: [PATCH] tests: validate netplan API YAML instead of strict content (#5195) Netplan API is used on Mantic and later which prevents cloud-init from writing a header comment in /etc/netplan/50-cloud-init.yaml. Only compare the loaded YAML dict of networking config instead of the full content of the file before and after upgrade to assert the equality of network config. --- tests/integration_tests/test_networking.py | 5 ++++- tests/integration_tests/test_upgrade.py | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/integration_tests/test_networking.py b/tests/integration_tests/test_networking.py index 3a53b8da6c0..6e93f2f4054 100644 --- a/tests/integration_tests/test_networking.py +++ b/tests/integration_tests/test_networking.py @@ -198,7 +198,10 @@ def test_netplan_rendering( } with session_cloud.launch(launch_kwargs=launch_kwargs) as client: result = client.execute("cat /etc/netplan/50-cloud-init.yaml") - assert result.stdout.startswith(EXPECTED_NETPLAN_HEADER) + if CURRENT_RELEASE < MANTIC: + assert result.stdout.startswith(EXPECTED_NETPLAN_HEADER) + else: + assert EXPECTED_NETPLAN_HEADER not in result.stdout assert expected == yaml.safe_load(result.stdout) diff --git a/tests/integration_tests/test_upgrade.py b/tests/integration_tests/test_upgrade.py index e0d5b3219e5..45685a9c683 100644 --- a/tests/integration_tests/test_upgrade.py +++ b/tests/integration_tests/test_upgrade.py @@ -12,6 +12,7 @@ CURRENT_RELEASE, FOCAL, IS_UBUNTU, + MANTIC, NOBLE, ) from tests.integration_tests.util import verify_clean_log @@ -154,7 +155,17 @@ def test_clean_boot_of_upgraded_package(session_cloud: IntegrationCloud): values.pop("dhcp6") assert yaml.dump(pre_network) == yaml.dump(post_network) else: - assert pre_network == post_network + if CURRENT_RELEASE < MANTIC: + # Assert the full content is preserved including header comment + # since cloud-init writes the file directly and does not use + # netplan API to write 50-cloud-init.yaml. + assert pre_network == post_network + else: + # Mantic and later Netplan API is used and doesn't allow + # cloud-init to write header comments in network config + assert yaml.safe_load(pre_network) == yaml.safe_load( + post_network + ) # Calculate and log all the boot numbers pre_analyze_totals = [