Skip to content

Commit

Permalink
Ensure system_cfg read before ds net config on Oracle (SC-720) (canon…
Browse files Browse the repository at this point in the history
…ical#1174)

In 2c52e6e, the order of
reading network config was changed for Oracle due to initramfs
needing to take lower precedence than the datasource. However,
this also bumped system_cfg to a lower precedence than ds, which
means that any network configuration specified in /etc/cloud will not
be applied. system_cfg should instead be moved above ds so network
configuration in /etc/cloud takes precedence.

LP: #1956788
  • Loading branch information
TheRealFalcon authored Jan 15, 2022
1 parent 73b1bb1 commit b306633
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cloudinit/sources/DataSourceOracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ class DataSourceOracle(sources.DataSource):
vendordata_pure = None
network_config_sources = (
sources.NetworkConfigSource.cmdline,
sources.NetworkConfigSource.system_cfg,
sources.NetworkConfigSource.ds,
sources.NetworkConfigSource.initramfs,
sources.NetworkConfigSource.system_cfg,
)

_network_config = sources.UNSET
Expand Down
27 changes: 27 additions & 0 deletions tests/integration_tests/network/test_net_config_load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Test loading the network config"""
import pytest

from tests.integration_tests.instances import IntegrationInstance


def _customize_envionment(client: IntegrationInstance):
# Insert our "disable_network_config" file here
client.write_to_file(
"/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg",
"network: {config: disabled}\n",
)
client.execute("cloud-init clean --logs")
client.restart()


def test_network_disabled_via_etc_cloud(client: IntegrationInstance):
"""Test that network can be disabled via config file in /etc/cloud"""
if client.settings.CLOUD_INIT_SOURCE == "IN_PLACE":
pytest.skip(
"IN_PLACE not supported as we mount /etc/cloud contents into the "
"container"
)
_customize_envionment(client)

log = client.read_from_file("/var/log/cloud-init.log")
assert "network config is disabled by system_cfg" in log
8 changes: 5 additions & 3 deletions tests/unittests/sources/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,12 +920,14 @@ def test_secondary_nic_failure_isnt_blocking(
assert network_config == m_read_initramfs_config.return_value
assert "Failed to parse secondary network configuration" in caplog.text

def test_ds_network_cfg_preferred_over_initramfs(self, _m):
"""Ensure that DS net config is preferred over initramfs config"""
def test_ds_network_cfg_order(self, _m):
"""Ensure that DS net config is preferred over initramfs config
but less than system config."""
config_sources = oracle.DataSourceOracle.network_config_sources
system_idx = config_sources.index(NetworkConfigSource.system_cfg)
ds_idx = config_sources.index(NetworkConfigSource.ds)
initramfs_idx = config_sources.index(NetworkConfigSource.initramfs)
assert ds_idx < initramfs_idx
assert system_idx < ds_idx < initramfs_idx


# vi: ts=4 expandtab

0 comments on commit b306633

Please sign in to comment.