Skip to content

Commit 6c169ae

Browse files
committed
DNM
1 parent 902e85d commit 6c169ae

19 files changed

+290
-13
lines changed

.ansible-lint

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exclude_paths:
2020
- roles/kustomize_deploy/molecule/flexible_loop/files/networking-environment-definition.yml # Generated
2121
- roles/kustomize_deploy/molecule/flexible_loop/prepare.yml # import_playbook
2222
- roles/*/molecule/*/side_effect.yml # syntax-check[empty-playbook] https://github.com/ansible/molecule/issues/3617
23+
- roles/ci_multus/molecule/*/nads_output.yml # internal-error due to "---" characters
2324
strict: true
2425
quiet: false
2526
verbosity: 1

molecule-ci-framework.git

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
diff --git a/roles/ci_multus/molecule/default/verify_crc.yml b/roles/ci_multus/molecule/default/verify_crc.yml
2+
index 79d9587a..5c3133e4 100644
3+
--- a/roles/ci_multus/molecule/default/verify_crc.yml
4+
+++ b/roles/ci_multus/molecule/default/verify_crc.yml
5+
@@ -40,20 +40,27 @@
6+
path: "nads_output.yml"
7+
register: _ci_multus_expected
8+
9+
- - name: Set _ci_multus_expected variable
10+
+ - name: Store expected spec
11+
ansible.builtin.set_fact:
12+
- _ci_multus_expected: >-
13+
+ _ci_multus_expected_spec: >-
14+
{{
15+
- _ci_multus_expected.content |
16+
+ _ci_multus_expected[0].content |
17+
b64decode |
18+
- from_yaml_all
19+
+ from_yaml_all |
20+
+ map(attribute='spec.config')
21+
+ }}
22+
+ - name: Store output spec
23+
+ ansible.builtin.set_fact:
24+
+ _ci_multus_out_spec: >-
25+
+ {{
26+
+ _ci_multus_molecule_nads_out.resources |
27+
+ map(attribute='spec.config')
28+
}}
29+
30+
- name: Assert expected Network Attachment Definitions content with the expected
31+
ansible.builtin.assert:
32+
- that:
33+
- - _ci_multus_molecule_nads_out == _ci_multus_expected
34+
- quiet: true
35+
+ that: _ci_multus_out_spec == _ci_multus_expected_spec
36+
+ quiet: false
37+
38+
- name: Create a test pod to attach a network
39+
kubernetes.core.k8s:
40+
diff --git a/roles/ci_multus/molecule/resources/verify.yml b/roles/ci_multus/molecule/resources/verify.yml
41+
index f5d0cd5b..b046876e 100644
42+
--- a/roles/ci_multus/molecule/resources/verify.yml
43+
+++ b/roles/ci_multus/molecule/resources/verify.yml
44+
@@ -53,6 +53,13 @@
45+
b64decode |
46+
from_yaml_all
47+
}}
48+
+ - name: Store output spec
49+
+ ansible.builtin.set_fact:
50+
+ _ci_multus_out_spec: >-
51+
+ {{
52+
+ _ci_multus_nad.resources |
53+
+ map(attribute='spec.config')
54+
+ }}
55+
56+
- name: Assert expected number of Network Attachment Definitions are created
57+
ansible.builtin.assert:

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/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Creates additional networks in a OCP cluster using NetworkAttachmentDefinition
1010
* `cifmw_ci_multus_namespace`: (String) The namespace where OCP resources will be installed. Defaults to `openstack`.
1111
* `cifmw_ci_multus_ocp_hostname`: (String) The OCP inventory hostname. Used to gather network information specific to those nodes, mostly the interfaces. Defaults to `crc`.
1212
* `cifmw_ci_multus_cniversion`: (String) The CNI specification version used when creating the resource. Defaults to `0.3.1`.
13-
* `cifmw_ci_multus_default_nad_type`: (String) Default NAD type used when not specified by the network configuration. Defaults to `macvlan`.
13+
* `cifmw_ci_multus_default_nad_type`: (String) Default NAD type used when not specified by the network configuration. Defaults to `macvlan`. You can select the type of each NAD by "type"
1414
* `cifmw_ci_multus_default_nad_ipam_type`: (String) Default NAD IPAM type to be used when not specified by the network configuration. Defaults to `whereabouts`.
1515
* `cifmw_ci_multus_default_nad_ipam_type_ip_version``: (String) Default IP version to use in IPAM config. Defaults to `v4`.
1616
* `cifmw_ci_multus_dryrun`: (Bool) When enabled, tasks that require an OCP environment are skipped. Defaults to `false`.
@@ -36,6 +36,7 @@ cifmw_ci_multus_net_info_patch_1:
3636
ipv4_ranges:
3737
- start: 192.168.122.30
3838
end: 192.168.122.70
39+
type: bridge
3940
```
4041
4142
## Limitations
@@ -70,6 +71,7 @@ cifmw_ci_multus_net_info_patch_1:
7071
ipv4_ranges:
7172
- start: 192.168.122.30
7273
end: 192.168.122.70
74+
type: macvlan
7375
ansible.builtin.include_role:
7476
name: "ci_multus"
7577
```

roles/ci_multus/molecule/default/molecule.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ provisioner:
2626
ipv4_ranges:
2727
- start: 192.168.122.30
2828
end: 192.168.122.70
29+
type: macvlan
2930

3031
cifmw_path: "{{ ansible_user_dir }}/.crc/bin:{{ ansible_user_dir }}/.crc/bin/oc:{{ ansible_user_dir }}/bin:{{ ansible_env.PATH }}"
3132
cifmw_openshift_kubeconfig: "{{ ansible_user_dir }}/.crc/machines/crc/kubeconfig"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
apiVersion: k8s.cni.cncf.io/v1
3+
kind: NetworkAttachmentDefinition
4+
metadata:
5+
labels:
6+
osp/net: default
7+
name: default
8+
namespace: openstack
9+
spec:
10+
config: |
11+
{
12+
"cniVersion": "0.3.1",
13+
"name": "default",
14+
"type": "bridge",
15+
"bridge": "eth1",
16+
"ipam": {
17+
"type": "whereabouts",
18+
"range": "192.168.122.0/24",
19+
"range_start": "192.168.122.30",
20+
"range_end": "192.168.122.70"
21+
}
22+
}
23+
---
24+
apiVersion: k8s.cni.cncf.io/v1
25+
kind: NetworkAttachmentDefinition
26+
metadata:
27+
labels:
28+
osp/net: patchnetwork
29+
name: patchnetwork
30+
namespace: openstack
31+
spec:
32+
config: |
33+
{
34+
"cniVersion": "0.3.1",
35+
"name": "patchnetwork",
36+
"type": "macvlan",
37+
"master": "eth2",
38+
"ipam": {
39+
"type": "whereabouts",
40+
"range": "192.168.122.0/24",
41+
"range_start": "192.168.122.30",
42+
"range_end": "192.168.122.70"
43+
}
44+
}

roles/ci_multus/molecule/default/verify_crc.yml

+27
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,33 @@
3535
(_ci_multus_molecule_nads_out is failed) or
3636
(_ci_multus_molecule_nads_out.resources | length == 0)
3737
38+
- name: Fetch file content
39+
ansible.builtin.slurp:
40+
path: "nads_output.yml"
41+
register: _ci_multus_expected
42+
43+
- name: Store expected spec
44+
ansible.builtin.set_fact:
45+
_ci_multus_expected_spec: >-
46+
{{
47+
_ci_multus_expected[0].content |
48+
b64decode |
49+
from_yaml_all |
50+
map(attribute='spec.config')
51+
}}
52+
- name: Store output spec
53+
ansible.builtin.set_fact:
54+
_ci_multus_out_spec: >-
55+
{{
56+
_ci_multus_molecule_nads_out.resources |
57+
map(attribute='spec.config')
58+
}}
59+
60+
- name: Assert expected Network Attachment Definitions content with the expected
61+
ansible.builtin.assert:
62+
that: _ci_multus_out_spec == _ci_multus_expected_spec
63+
quiet: false
64+
3865
- name: Create a test pod to attach a network
3966
kubernetes.core.k8s:
4067
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"

roles/ci_multus/molecule/local/molecule.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ provisioner:
2626
ipv4_ranges:
2727
- start: 192.168.122.30
2828
end: 192.168.122.70
29+
type: macvlan
2930

3031
prerun: false
3132
scenario:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
apiVersion: k8s.cni.cncf.io/v1
3+
kind: NetworkAttachmentDefinition
4+
metadata:
5+
labels:
6+
osp/net: default
7+
name: default
8+
namespace: openstack
9+
spec:
10+
config: |
11+
{
12+
"cniVersion": "0.3.1",
13+
"name": "default",
14+
"type": "bridge",
15+
"bridge": "eth1",
16+
"ipam": {
17+
"type": "whereabouts",
18+
"range": "192.168.122.0/24",
19+
"range_start": "192.168.122.30",
20+
"range_end": "192.168.122.70"
21+
}
22+
}
23+
---
24+
apiVersion: k8s.cni.cncf.io/v1
25+
kind: NetworkAttachmentDefinition
26+
metadata:
27+
labels:
28+
osp/net: patchnetwork
29+
name: patchnetwork
30+
namespace: openstack
31+
spec:
32+
config: |
33+
{
34+
"cniVersion": "0.3.1",
35+
"name": "patchnetwork",
36+
"type": "macvlan",
37+
"master": "eth2",
38+
"ipam": {
39+
"type": "whereabouts",
40+
"range": "192.168.122.0/24",
41+
"range_start": "192.168.122.30",
42+
"range_end": "192.168.122.70"
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
apiVersion: k8s.cni.cncf.io/v1
3+
kind: NetworkAttachmentDefinition
4+
metadata:
5+
labels:
6+
osp/net: default
7+
name: default
8+
namespace: openstack
9+
spec:
10+
config: |
11+
{
12+
"cniVersion": "0.3.1",
13+
"name": "default",
14+
"type": "bridge",
15+
"bridge": "eth1",
16+
"ipam": {
17+
"type": "whereabouts",
18+
"range": "192.168.122.0/24",
19+
"range_start": "192.168.122.30",
20+
"range_end": "192.168.122.70"
21+
}
22+
}

roles/ci_multus/molecule/resources/vars/shared_vars.yml

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ cifmw_networking_env_definition:
3232
ipv4_ranges:
3333
- start: 192.168.122.30
3434
end: 192.168.122.70
35+
type: bridge
3536
deny_network:
3637
gw_v4: 192.168.122.1
3738
network_name: deny_network
@@ -41,6 +42,7 @@ cifmw_networking_env_definition:
4142
ipv4_ranges:
4243
- start: 192.168.122.30
4344
end: 192.168.122.70
45+
type: bridge
4446
not_allowed_network:
4547
gw_v4: 192.168.122.1
4648
network_name: not_allowed_network
@@ -50,6 +52,7 @@ cifmw_networking_env_definition:
5052
ipv4_ranges:
5153
- start: 192.168.122.30
5254
end: 192.168.122.70
55+
type: bridge
5356
no_multus_network:
5457
gw_v4: 192.168.122.1
5558
network_name: patchnetwork

0 commit comments

Comments
 (0)