Skip to content

Commit

Permalink
integration tests source uri check
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealFalcon committed Oct 17, 2024
1 parent 2dfb920 commit 45d48ac
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cloudinit/cmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ def _should_wait_via_user_data(
# These all have the potential to require network access, so we should wait
if "write_files" in parsed_yaml:
for item in parsed_yaml["write_files"]:
source_uri = item.get("source", {}).get("uri", "")
source_dict = item.get("source") or {}
source_uri = source_dict.get("uri", "")
if source_uri and not (source_uri.startswith(("/", "file:"))):
return True, "write_files with source uri found"
return False, "write_files without source uri found"
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/datasources/test_nocloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
override_kernel_command_line,
verify_clean_boot,
verify_clean_log,
wait_online_called,
network_wait_logged,
)

VENDOR_DATA = """\
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_nocloud_seedfrom_vendordata(client: IntegrationInstance):
client.restart()
assert client.execute("cloud-init status").ok
assert "seeded_vendordata_test_file" in client.execute("ls /var/tmp")
assert wait_online_called(client.execute("cat /var/log/cloud-init.log"))
assert network_wait_logged(client.execute("cat /var/log/cloud-init.log"))


SMBIOS_USERDATA = """\
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/modules/test_boothook.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from tests.integration_tests.instances import IntegrationInstance
from tests.integration_tests.util import (
network_wait_logged,
verify_clean_boot,
verify_clean_log,
wait_online_called,
)

USER_DATA = """\
Expand Down Expand Up @@ -55,6 +55,6 @@ def test_boothook_waits_for_network(
):
"""Test boothook handling waits for network before running."""
client = class_client
assert wait_online_called(
assert network_wait_logged(
client.read_from_file("/var/log/cloud-init.log")
)
4 changes: 2 additions & 2 deletions tests/integration_tests/modules/test_combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
get_feature_flag_value,
get_inactive_modules,
lxd_has_nocloud,
network_wait_logged,
verify_clean_boot,
verify_ordered_items_in_text,
wait_online_called,
)

USER_DATA = """\
Expand Down Expand Up @@ -558,7 +558,7 @@ def test_unicode(self, class_client: IntegrationInstance):
@pytest.mark.skipif(not IS_UBUNTU, reason="Ubuntu-only behavior")
def test_networkd_wait_online(self, class_client: IntegrationInstance):
client = class_client
assert not wait_online_called(
assert not network_wait_logged(
client.read_from_file("/var/log/cloud-init.log")
)

Expand Down
7 changes: 5 additions & 2 deletions tests/integration_tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,5 +634,8 @@ def push_and_enable_systemd_unit(
client.execute(f"systemctl enable {unit_name}", use_sudo=True)


def wait_online_called(log: str) -> bool:
return "Running command ['/lib/systemd/systemd-networkd-wait-online" in log
def network_wait_logged(log: str) -> bool:
return (
"Running command "
"['systemctl', 'start', 'systemd-networkd-wait-online.service']"
) in log

0 comments on commit 45d48ac

Please sign in to comment.