-
Notifications
You must be signed in to change notification settings - Fork 908
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug(schema): write network-config if instance dir present (#4635)
Only write /var/lib/cloud/instance/network-config.json once datasource is detected. The /var/lib/clound/instance symlink is created by Init.instancify after datasource detection is complete. Move creation of /var/lib/cloud/instance/network-config.json into it's own method _write_network_config_json. It will be called by any call to apply_network_config. apply_network_config is called in both Local and Network stages. In Local stage, apply_network_config is used to either: - render the final network config of datasource detected in Local - in absence of Local datasource, render basic fallback DHCP on primary NIC to allow network to come up before detecting a Network datasource For Network datasources, they will not have been discovered or instancify'd in Local boot stage, so apply_network_config cannot yet persist network-config.json. Defer creation of network-config.json for Network datasources until until the link /var/lib/cloud/instance exists and apply_network_config is called in Network stage to render final network config. Fixes GH-4630
- Loading branch information
1 parent
cd35cad
commit ac72b28
Showing
6 changed files
with
165 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
"""DataSourceNone integration tests on LXD.""" | ||
import json | ||
|
||
from pycloudlib.lxd.instance import LXDInstance | ||
|
||
from tests.integration_tests.decorators import retry | ||
from tests.integration_tests.instances import IntegrationInstance | ||
from tests.integration_tests.util import verify_clean_log | ||
|
||
DS_NONE_BASE_CFG = """\ | ||
datasource_list: [None] | ||
datasource: | ||
None: | ||
metadata: | ||
instance-id: my-iid-uuid | ||
userdata_raw: | | ||
#cloud-config | ||
runcmd: | ||
- touch /var/tmp/success-with-datasource-none | ||
""" | ||
|
||
|
||
@retry(tries=30, delay=1) | ||
def wait_for_cloud_init_status_file(instance: LXDInstance): | ||
"""Wait for a non-empty status.json indicating cloud-init has started. | ||
We don't wait for cloud-init to complete in this scenario as the failure | ||
path on some images leaves us with cloud-init status blocking | ||
indefinitely in the "running" state. | ||
""" | ||
status_file = instance.read_from_file("/run/cloud-init/status.json") | ||
assert len(status_file) | ||
|
||
|
||
def test_datasource_none_discovery(client: IntegrationInstance): | ||
"""Integration test for #4635. | ||
Test that DataSourceNone detection (used by live installers) doesn't | ||
generate errors or warnings. | ||
""" | ||
log = client.read_from_file("/var/log/cloud-init.log") | ||
verify_clean_log(log) | ||
# Limit datasource detection to DataSourceNone. | ||
client.write_to_file( | ||
"/etc/cloud/cloud.cfg.d/99-force-dsnone.cfg", DS_NONE_BASE_CFG | ||
) | ||
if client.settings.PLATFORM in ["lxd_container"]: | ||
# DataSourceNone provides no network_config. | ||
# To avoid changing network config from platform desired net cfg | ||
# to fallback config, copy out the rendered network config | ||
# to /etc/cloud/cloud.cfg.d/99-orig-net.cfg so it is | ||
# setup by the DataSourceNone case as well. | ||
# Otherwise (LXD specifically) we'll have network torn down due | ||
# to virtual NICs present which results in not network being | ||
# brought up when we emit fallback config which attempts to | ||
# match on PermanentMACAddress. LP:#2022947 | ||
client.execute( | ||
"cp /etc/netplan/50-cloud-init.yaml" | ||
" /etc/cloud/cloud.cfg.d/99-orig-net.cfg" | ||
) | ||
client.execute("cloud-init clean --logs --reboot") | ||
wait_for_cloud_init_status_file(client) | ||
status = json.loads(client.execute("cloud-init status --format=json")) | ||
assert [] == status["errors"] | ||
expected_warnings = set( | ||
[ | ||
"Used fallback datasource", | ||
"Running ['netplan', 'apply'] resulted in stderr output: Cannot" | ||
" call Open vSwitch: ovsdb-server.service is not running.\nFailed" | ||
" to connect system bus: No such file or directory\nFalling back" | ||
" to a hard restart of systemd-networkd.service\n", | ||
] | ||
) | ||
unexpected_warnings = [] | ||
unexpected_warnings = set( | ||
status["recoverable_errors"].get("WARNING", []) | ||
).difference(expected_warnings) | ||
if unexpected_warnings: | ||
raise AssertionError( | ||
f"Unexpected recoverable errors: {list(unexpected_warnings)}" | ||
) | ||
client.execute("cloud-init status --wait") | ||
log = client.read_from_file("/var/log/cloud-init.log") | ||
verify_clean_log(log) | ||
assert client.execute("test -f /var/tmp/success-with-datasource-none").ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters