Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions cloudinit/sources/DataSourceOracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,6 @@ def _add_network_config_from_opc_imds(self, set_primary: bool = False):
)
continue
name = interfaces_by_mac[mac_address]
if is_ipv6_only:
network = ipaddress.ip_network(
vnic_dict["ipv6Addresses"][0],
)
else:
network = ipaddress.ip_network(vnic_dict["subnetCidrBlock"])

if is_primary:
if is_ipv6_only:
subnets = [{"type": "dhcp6"}]
Expand All @@ -394,6 +387,9 @@ def _add_network_config_from_opc_imds(self, set_primary: bool = False):
else:
subnets = []
if vnic_dict.get("privateIp"):
network = ipaddress.ip_network(
vnic_dict["subnetCidrBlock"]
)
subnets.append(
{
"type": "static",
Expand All @@ -404,6 +400,9 @@ def _add_network_config_from_opc_imds(self, set_primary: bool = False):
}
)
if vnic_dict.get("ipv6Addresses"):
network = ipaddress.ip_network(
vnic_dict["ipv6SubnetCidrBlock"]
)
subnets.append(
{
"type": "static",
Expand Down
31 changes: 30 additions & 1 deletion tests/unittests/sources/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,40 @@ def test_imds_nic_setup_v1_ipv6_only(self, set_primary, oracle_ds):
assert 9000 == secondary_cfg["mtu"]
assert 1 == len(secondary_cfg["subnets"])
assert (
"2603:c020:400d:5d7e:aacc:8e5f:3b1b:3a4a/128"
"2603:c020:400d:5d7e:aacc:8e5f:3b1b:3a4a/64"
== secondary_cfg["subnets"][0]["address"]
)
assert "static" == secondary_cfg["subnets"][0]["type"]

def test_imds_dual_stack_secondary_uses_ipv6_prefix(self, oracle_ds):
oracle_ds._vnics_data = json.loads(
OPC_VM_DUAL_STACK_SECONDARY_VNIC_RESPONSE
)
oracle_ds._network_config = {
"version": 1,
"config": [{"primary": "nic"}],
}
with mock.patch(
f"{DS_PATH}.get_interfaces_by_mac",
return_value={
"02:00:17:0d:6b:be": "ens3",
"02:00:17:18:f6:ff": "ens4",
},
):
oracle_ds._add_network_config_from_opc_imds(set_primary=False)

nic_cfg = oracle_ds.network_config["config"]
secondary_cfg = nic_cfg[1]
assert 2 == len(secondary_cfg["subnets"])
assert (
"10.0.0.183/24"
== secondary_cfg["subnets"][0]["address"]
)
assert (
"2603:c020:400d:5dbb:e94a:a85d:26e3:e0d4/64"
== secondary_cfg["subnets"][1]["address"]
)

@pytest.mark.parametrize("error_add_network", [None, Exception])
@pytest.mark.parametrize(
"configure_secondary_nics",
Expand Down