Skip to content

Commit 5f290f5

Browse files
chore: Add feature flag for manual network waiting (canonical#5977)
Controls the behavior added in e30549e for easier downstream patching
1 parent 6226277 commit 5f290f5

File tree

7 files changed

+46
-22
lines changed

7 files changed

+46
-22
lines changed

cloudinit/cmd/main.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import yaml
2222
from typing import Optional, Tuple, Callable, Union
2323

24-
from cloudinit import netinfo
24+
from cloudinit import features, netinfo
2525
from cloudinit import signal_handler
2626
from cloudinit import sources
2727
from cloudinit import socket
@@ -486,7 +486,9 @@ def main_init(name, args):
486486
mode = sources.DSMODE_LOCAL if args.local else sources.DSMODE_NETWORK
487487

488488
if mode == sources.DSMODE_NETWORK:
489-
if not os.path.exists(init.paths.get_runpath(".skip-network")):
489+
if features.MANUAL_NETWORK_WAIT and not os.path.exists(
490+
init.paths.get_runpath(".skip-network")
491+
):
490492
LOG.debug("Will wait for network connectivity before continuing")
491493
init.distro.wait_for_network()
492494
existing = "trust"
@@ -560,20 +562,21 @@ def main_init(name, args):
560562
init.apply_network_config(bring_up=bring_up_interfaces)
561563

562564
if mode == sources.DSMODE_LOCAL:
563-
should_wait, reason = _should_wait_on_network(init.datasource)
564-
if should_wait:
565-
LOG.debug(
566-
"Network connectivity determined necessary for "
567-
"cloud-init's network stage. Reason: %s",
568-
reason,
569-
)
570-
else:
571-
LOG.debug(
572-
"Network connectivity determined unnecessary for "
573-
"cloud-init's network stage. Reason: %s",
574-
reason,
575-
)
576-
util.write_file(init.paths.get_runpath(".skip-network"), "")
565+
if features.MANUAL_NETWORK_WAIT:
566+
should_wait, reason = _should_wait_on_network(init.datasource)
567+
if should_wait:
568+
LOG.debug(
569+
"Network connectivity determined necessary for "
570+
"cloud-init's network stage. Reason: %s",
571+
reason,
572+
)
573+
else:
574+
LOG.debug(
575+
"Network connectivity determined unnecessary for "
576+
"cloud-init's network stage. Reason: %s",
577+
reason,
578+
)
579+
util.write_file(init.paths.get_runpath(".skip-network"), "")
577580

578581
if init.datasource.dsmode != mode:
579582
LOG.debug(

cloudinit/features.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@
8787
to write /etc/apt/sources.list directly.
8888
"""
8989

90+
MANUAL_NETWORK_WAIT = True
91+
"""
92+
On Ubuntu systems, cloud-init-network.service will start immediately after
93+
cloud-init-local.service and manually wait for network online when necessary.
94+
If False, rely on systemd ordering to ensure network is available before
95+
starting cloud-init-network.service.
96+
97+
Note that in addition to this flag, downstream patches are also likely needed
98+
to modify the systemd unit files.
99+
"""
100+
90101
DEPRECATION_INFO_BOUNDARY = "devel"
91102
"""
92103
DEPRECATION_INFO_BOUNDARY is used by distros to configure at which upstream

tests/integration_tests/datasources/test_nocloud.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from pycloudlib.lxd.instance import LXDInstance
77

8-
from cloudinit import lifecycle
8+
from cloudinit import features, lifecycle
99
from cloudinit.subp import subp
1010
from tests.integration_tests.instances import IntegrationInstance
1111
from tests.integration_tests.integration_settings import PLATFORM
@@ -100,7 +100,10 @@ def test_nocloud_seedfrom_vendordata(client: IntegrationInstance):
100100
client.restart()
101101
assert client.execute("cloud-init status").ok
102102
assert "seeded_vendordata_test_file" in client.execute("ls /var/tmp")
103-
assert network_wait_logged(client.execute("cat /var/log/cloud-init.log"))
103+
assert (
104+
network_wait_logged(client.execute("cat /var/log/cloud-init.log"))
105+
== features.MANUAL_NETWORK_WAIT
106+
)
104107

105108

106109
SMBIOS_USERDATA = """\

tests/integration_tests/modules/test_boothook.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55

6+
from cloudinit import features
67
from tests.integration_tests.instances import IntegrationInstance
78
from tests.integration_tests.util import (
89
network_wait_logged,
@@ -55,6 +56,9 @@ def test_boothook_waits_for_network(
5556
):
5657
"""Test boothook handling waits for network before running."""
5758
client = class_client
58-
assert network_wait_logged(
59-
client.read_from_file("/var/log/cloud-init.log")
59+
assert (
60+
network_wait_logged(
61+
client.read_from_file("/var/log/cloud-init.log")
62+
)
63+
== features.MANUAL_NETWORK_WAIT
6064
)

tests/unittests/cmd/test_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import pytest
1111

12-
from cloudinit import safeyaml, util
12+
from cloudinit import features, safeyaml, util
1313
from cloudinit.cmd import main
1414
from cloudinit.util import ensure_dir, load_text_file, write_file
1515

@@ -363,7 +363,7 @@ def test_distro_wait_for_network(
363363
skip_log_setup=False,
364364
)
365365
main.main_init("init", cmdargs)
366-
if expected_add_wait:
366+
if features.MANUAL_NETWORK_WAIT and expected_add_wait:
367367
m_nm.assert_called_once()
368368
m_subp.assert_called_with(
369369
["systemctl", "start", "systemd-networkd-wait-online.service"]

tests/unittests/test_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ def test_shellscript(self, init_tmp, tmpdir, caplog):
516516
"DEPRECATION_INFO_BOUNDARY": "devel",
517517
"NOCLOUD_SEED_URL_APPEND_FORWARD_SLASH": False,
518518
"APT_DEB822_SOURCE_LIST_FILE": True,
519+
"MANUAL_NETWORK_WAIT": True,
519520
},
520521
"system_info": {
521522
"default_user": {"name": "ubuntu"},

tests/unittests/test_features.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_feature_without_override(self):
2222
DEPRECATION_INFO_BOUNDARY="devel",
2323
NOCLOUD_SEED_URL_APPEND_FORWARD_SLASH=False,
2424
APT_DEB822_SOURCE_LIST_FILE=True,
25+
MANUAL_NETWORK_WAIT=False,
2526
):
2627
assert {
2728
"ERROR_ON_USER_DATA_FAILURE": True,
@@ -31,4 +32,5 @@ def test_feature_without_override(self):
3132
"NOCLOUD_SEED_URL_APPEND_FORWARD_SLASH": False,
3233
"APT_DEB822_SOURCE_LIST_FILE": True,
3334
"DEPRECATION_INFO_BOUNDARY": "devel",
35+
"MANUAL_NETWORK_WAIT": False,
3436
} == features.get_features()

0 commit comments

Comments
 (0)