Skip to content

Commit

Permalink
tests: validate netplan API YAML instead of strict content (#5195)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
blackboxsw authored Apr 23, 2024
1 parent 31039d0 commit 7268003
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tests/integration_tests/test_networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
13 changes: 12 additions & 1 deletion tests/integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
CURRENT_RELEASE,
FOCAL,
IS_UBUNTU,
MANTIC,
NOBLE,
)
from tests.integration_tests.util import verify_clean_log
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit 7268003

Please sign in to comment.