Skip to content

Commit af1c269

Browse files
committed
DNM
1 parent 902e85d commit af1c269

8 files changed

+56
-13
lines changed

plugins/module_utils/net_map/networking_definition.py

+25
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,7 @@ class SubnetBasedNetworkToolDefinition:
10441044
__FIELD_ROUTES = "routes"
10451045
__FIELD_ROUTES_IPV4 = "routes-v4"
10461046
__FIELD_ROUTES_IPV6 = "routes-v6"
1047+
__FIELD_TYPE = "type"
10471048

10481049
def __init__(
10491050
self,
@@ -1067,6 +1068,7 @@ def __init__(
10671068
self.__ipv6_ranges: typing.List[HostNetworkRange] = []
10681069
self.__ipv4_routes: typing.List[HostNetworkRoute] = []
10691070
self.__ipv6_routes: typing.List[HostNetworkRoute] = []
1071+
self.__type: typing.Optional[str] = None
10701072

10711073
self.__parse_raw(raw_config)
10721074

@@ -1092,6 +1094,13 @@ def __parse_raw(self, raw_definition: typing.Dict[str, typing.Any]):
10921094
alone_field=self.__FIELD_ROUTES,
10931095
)
10941096

1097+
_validate_fields_one_of(
1098+
[
1099+
self.__FIELD_TYPE,
1100+
],
1101+
raw_definition,
1102+
parent_name=self.__object_name,
1103+
)
10951104
self.__parse_raw_range_field(raw_definition, self.__FIELD_RANGES)
10961105
self.__parse_raw_range_field(
10971106
raw_definition, self.__FIELD_RANGES_IPV4, ip_version=4
@@ -1107,6 +1116,7 @@ def __parse_raw(self, raw_definition: typing.Dict[str, typing.Any]):
11071116
self.__parse_raw_route_field(
11081117
raw_definition, self.__FIELD_ROUTES_IPV6, ip_version=6
11091118
)
1119+
self.__parse_raw_type_field(raw_definition, self.__FIELD_TYPE)
11101120

11111121
def __parse_raw_range_field(
11121122
self,
@@ -1190,6 +1200,21 @@ def __parse_raw_route_field(
11901200
if ipv6_route:
11911201
self.__ipv6_routes.append(ipv6_route)
11921202

1203+
@property
1204+
def type(self) -> str:
1205+
"""The type of the tool for multus."""
1206+
return self.__type
1207+
1208+
def __parse_raw_type_field(self, raw_definition, field_name: str):
1209+
if field_name in raw_definition:
1210+
type = _validate_parse_field_type(
1211+
field_name,
1212+
raw_definition,
1213+
str,
1214+
parent_name=self.__object_name,
1215+
)
1216+
self.__type = type
1217+
11931218

11941219
class MultusNetworkDefinition(SubnetBasedNetworkToolDefinition):
11951220
"""Parses and holds Multus configuration for a given network."""

plugins/module_utils/net_map/networking_env_definitions.py

+2
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,15 @@ class MappedMultusNetworkConfig:
136136
ipv6_ranges: IPv6 ranges assigned to Multus.
137137
ipv4_routes: IPv4 routes assigned to Multus.
138138
ipv6_routes: IPv6 routes assigned to Multus.
139+
multus_type: The type of the multus network.
139140
140141
"""
141142

142143
ipv4_ranges: typing.List[MappedIpv4NetworkRange]
143144
ipv6_ranges: typing.List[MappedIpv6NetworkRange]
144145
ipv4_routes: typing.List[MappedIpv4NetworkRoute]
145146
ipv6_routes: typing.List[MappedIpv6NetworkRoute]
147+
multus_type: typing.Optional[str] = None
146148

147149

148150
@dataclasses.dataclass(frozen=True)

plugins/module_utils/net_map/networking_mapper.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -678,12 +678,15 @@ def __build_network_tool_common(
678678
for ip_route in tool_net_def.routes_ipv6
679679
],
680680
]
681+
multus_type = []
682+
if tool_type.__name__ == "MappedMultusNetworkConfig":
683+
multus_type.append(tool_net_def.type)
681684

682685
if any(
683686
route_field in tool_type.__dataclass_fields__
684687
for route_field in ["ipv4_routes", "ipv6_routes"]
685688
):
686-
args_list = args_list + route_args_list
689+
args_list = args_list + route_args_list + multus_type
687690
return tool_type(*args_list)
688691

689692

roles/ci_multus/templates/nad.yml.j2

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{% for network_name, network_details in _cifmw_ci_multus_net_info.items() %}
2+
{% if 'multus_type' in network_details.tools.multus %}
3+
{% set multus_type = network_details.tools.multus.multus_type %}
4+
{% else %}
5+
{% set multus_type = cifmw_ci_multus_default_nad_type %}
6+
{% endif %}
7+
28
---
39
apiVersion: k8s.cni.cncf.io/v1
410
kind: NetworkAttachmentDefinition
@@ -12,13 +18,12 @@ spec:
1218
{
1319
"cniVersion": "{{ cifmw_ci_multus_cniversion }}",
1420
"name": "{{ network_name }}",
15-
{% if cifmw_ci_multus_default_nad_type == "macvlan" %}
16-
"type": "macvlan",
17-
"master": "{{ network_details.interface_name }}",
21+
"type": "{{ multus_type }}",
22+
{% if multus_type == "macvlan" %}
23+
"master": "{{ network_name }}",
1824
{% endif %}
19-
{% if cifmw_ci_multus_default_nad_type == "bridge" %}
20-
"type": "bridge",
21-
"bridge": "{{ network_details.interface_name }}",
25+
{% if multus_type == "bridge" %}
26+
"bridge": "{{ network_name }}",
2227
{% endif %}
2328
"ipam": {
2429
"type": "{{ cifmw_ci_multus_default_nad_ipam_type }}",

tests/unit/module_utils/test_files/networking-definition-valid-all-tools-full-map-out.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
],
2929
"ipv6_ranges": [],
3030
"ipv4_routes": [],
31-
"ipv6_routes": []
31+
"ipv6_routes": [],
32+
"multus_type": "macvlan"
3233
},
3334
"netconfig": {
3435
"ipv4_ranges": [
@@ -88,7 +89,8 @@
8889
"gateway": "192.168.122.1"
8990
}
9091
],
91-
"ipv6_routes": []
92+
"ipv6_routes": [],
93+
"multus_type": "bridge"
9294
},
9395
"netconfig": {
9496
"ipv4_ranges": [

tests/unit/module_utils/test_files/networking-definition-valid-all-tools-networks-out.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
],
2828
"ipv6_ranges": [],
2929
"ipv4_routes": [],
30-
"ipv6_routes": []
30+
"ipv6_routes": [],
31+
"multus_type": "macvlan"
3132
},
3233
"netconfig": {
3334
"ipv4_ranges": [
@@ -87,7 +88,8 @@
8788
"gateway": "192.168.122.1"
8889
}
8990
],
90-
"ipv6_routes": []
91+
"ipv6_routes": [],
92+
"multus_type": "bridge"
9193
},
9294
"netconfig": {
9395
"ipv4_ranges": [

tests/unit/module_utils/test_files/networking-definition-valid-all-tools-partial-map-out.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
],
2929
"ipv6_ranges": [],
3030
"ipv4_routes": [],
31-
"ipv6_routes": []
31+
"ipv6_routes": [],
32+
"multus_type": "macvlan"
3233
},
3334
"netconfig": {
3435
"ipv4_ranges": [
@@ -88,7 +89,8 @@
8889
"gateway": "192.168.122.1"
8990
}
9091
],
91-
"ipv6_routes": []
92+
"ipv6_routes": [],
93+
"multus_type": "bridge"
9294
},
9395
"netconfig": {
9496
"ipv4_ranges": [

tests/unit/module_utils/test_files/networking-definition-valid-all-tools.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ networks:
44
mtu: 1500
55
tools:
66
multus:
7+
type: macvlan
78
ranges:
89
- start: 30
910
end: 39
@@ -26,6 +27,7 @@ networks:
2627
ranges:
2728
- start: 30
2829
end: 39
30+
type: bridge
2931
routes:
3032
- destination: "192.168.121.0/24"
3133
gateway: "192.168.122.1"

0 commit comments

Comments
 (0)