Skip to content

Commit 5c02344

Browse files
[ci_multus] Refactor role
The ci_multus role was created but unused, this patch refreshes it as we will begin to use it in the new job to test Ironic.
1 parent b78ad95 commit 5c02344

File tree

22 files changed

+702
-318
lines changed

22 files changed

+702
-318
lines changed

.ansible-lint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ exclude_paths:
1919
- roles/reproducer/files/cifmw-bootstrap.yml # invalid due to calls to "lookup('file')"
2020
- roles/kustomize_deploy/molecule/flexible_loop/files/networking-environment-definition.yml # Generated
2121
- roles/kustomize_deploy/molecule/flexible_loop/prepare.yml # import_playbook
22+
- roles/*/molecule/*/side_effect.yml # syntax-check[empty-playbook] https://github.com/ansible/molecule/issues/3617
2223
strict: true
2324
quiet: false
2425
verbosity: 1

roles/ci_multus/README.md

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,90 @@
11
# ci_multus
2-
Creates additional networks in a OCP cluster using NetworkAttachmentDefinition (NAD) resources.
2+
3+
Creates additional networks in a OCP cluster using NetworkAttachmentDefinition
4+
(NAD) resources.
35

46
## Parameters
7+
58
* `cifmw_ci_multus_basedir`: (String) Base directory. Defaults to `cifmw_basedir` which defaults to `~/ci-framework-data`.
69
* `cifmw_ci_multus_manifests_dir`: (String) Directory in where OCP manifests will be placed. Defaults to `"{{ cifmw_manifests | default(cifmw_ci_multus_basedir ~ '/artifacts/manifests') }}"`.
7-
* `cifmw_ci_multus_namespace`: (String) The namespace where OCP resources will be installed. Defaults to `ci-multus`.
10+
* `cifmw_ci_multus_namespace`: (String) The namespace where OCP resources will be installed. Defaults to `openstack`.
811
* `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`.
912
* `cifmw_ci_multus_cniversion`: (String) The CNI specification version used when creating the resource. Defaults to `0.3.1`.
1013
* `cifmw_ci_multus_default_nad_type`: (String) Default NAD type used when not specified by the network configuration. Defaults to `macvlan`.
1114
* `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`.
12-
* `cifmw_ci_multus_nad_list`: (List) List of NAD configuration to be created in destination OCP cluster. When not provided, `ci_multus` will build a list based on known cifmw variables (`cifmw_network_layout`, `crc_ci_bootstrap_networks_out`).Defaults to `[]`.
13-
* `cifmw_ci_multus_nad_extra_list`: (List) Additional list of NAD configuration to be created in destination OCP cluster. Defaults to `[]`.
15+
* `cifmw_ci_multus_default_nad_ipam_type_ip_version``: (String) Default IP version to use in IPAM config. Defaults to `v4`.
16+
* `cifmw_ci_multus_dryrun`: (Bool) When enabled, tasks that require an OCP environment are skipped. Defaults to `false`.
17+
* `cifmw_ci_multus_allow_list`: (List) Adding network names to this list allows you to define what networks will be rendered into the NAD manifest. Defaults to `[]`.
18+
* `cifmw_ci_multus_deny_list`: (List) Adding network names to this list allows you to define what networks should be skipped from being rendered into the NAD manifest. Defaults to `[]`.
19+
20+
By default the `ci_multus` role reads the `cifmw_networking_env_definition` variable to generate NetworkAttachmentDefinition manifests for networks who have the Multus tool defined.
1421

15-
## NAD configuration layout
16-
The user can provide a list of NAD configuration as follow:
22+
In addition to that, you can also pass any number of "patch" variables using `cifmw_ci_multus_net_info_patch` that allow you to extend the config used to render the NetworkAttachmentDefinition manifests.
23+
For a working example, please see `cifmw_ci_multus_net_info_patch_1` in molecule/local/molecule.yml
24+
25+
## cifmw_ci_multus_net_info_patch example
1726

1827
```YAML
19-
cifmw_ci_multus_nad_list:
20-
- name: storage
21-
iface: enps6s0.21
22-
type: macvlan
23-
ipam:
24-
type: whereabouts
25-
range: 172.18.0.0/24
26-
range_start: 172.18.0.30
27-
range_end: 172.18.0.70
28-
- name: bgpnet1
29-
iface: bgpiface
30-
type: interface
31-
ipam:
32-
type: whereabouts
33-
range: 100.65.4.0/30
34-
range_start: 100.65.4.1
35-
range_end: 100.65.4.2
28+
cifmw_ci_multus_net_info_patch_1:
29+
patchnetwork:
30+
gw_v4: 192.168.122.1
31+
network_name: patchnetwork
32+
network_v4: 192.168.122.0/24
33+
interface_name: eth2
34+
tools:
35+
multus:
36+
ipv4_ranges:
37+
- start: 192.168.122.30
38+
end: 192.168.122.70
3639
```
37-
`cifmw_ci_multus_nad_list` can be passed directly, but if not given it will default, by that order, to the following:
38-
1. The content of the `cifmw_network_layout` variable.
39-
2. The content of the `crc_ci_bootstrap_networks_out` variable.
40-
3. The content of the `crc_ci_bootstrap_networks_out` variable loaded from `/etc/ci/env`.
41-
42-
If an additional NAD configuration needs to be configured, in addition to the content build from cifmw variables, the `cifmw_ci_multus_nad_extra_list` can be specified.
4340
4441
## Limitations
42+
4543
* Not all NetworkAttachmentDefinition types and parameters are supported by this role.
4644
* Not all IPAM configurations are supported by this role.
4745
* When consuming network info from CI variables, the user must provide the OCP host, using `cifmw_ci_multus_ocp_hostname` parameter, since the role doesn't perform a Node discovery on the OCP node.
4846

4947
## Examples
50-
### 1 - Use of `cifmw_ci_multus_nad_list`:
48+
49+
### 1 - Default use case consuming cifmw_networking_env_definition
50+
5151
```YAML
5252
- name: Configure additional networks using multus
53-
vars:
54-
cifmw_ci_multus_nad_list:
55-
- name: storage
56-
iface: enps6s0.21
57-
type: macvlan
58-
ipam:
59-
type: whereabouts
60-
range: 172.18.0.0/24
61-
range_start: 172.18.0.30
62-
range_end: 172.18.0.70
6353
ansible.builtin.include_role:
6454
name: "ci_multus"
6555
```
66-
### 2 - Content from `cifmw_network_layout`:
56+
57+
### 2 - Using patch:
58+
6759
```YAML
6860
- name: Configure additional networks using multus
6961
vars:
70-
cifmw_network_layout:
71-
networks:
72-
default:
73-
iface: enps6s0
74-
mtu: 1500
75-
range: 192.168.122.0/24
62+
cifmw_ci_multus_net_info_patch_1:
63+
patchnetwork:
64+
gw_v4: 192.168.122.1
65+
network_name: patchnetwork
66+
network_v4: 192.168.122.0/24
67+
interface_name: eth2
68+
tools:
7669
multus:
77-
range: 192.168.122.30-192.168.122.70
70+
ipv4_ranges:
71+
- start: 192.168.122.30
72+
end: 192.168.122.70
73+
ansible.builtin.include_role:
74+
name: "ci_multus"
75+
```
76+
77+
### 2 - Using allow and deny list:
78+
79+
```YAML
80+
- name: Configure additional networks using multus
81+
vars:
82+
cifmw_ci_multus_allow_list:
83+
- default
84+
- awesomenet
85+
- maybenet
86+
cifmw_ci_multus_deny_list:
87+
- maybenet
7888
ansible.builtin.include_role:
7989
name: "ci_multus"
8090
```

roles/ci_multus/defaults/main.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020

2121
cifmw_ci_multus_basedir: "{{ cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}"
2222
cifmw_ci_multus_manifests_dir: "{{ cifmw_manifests | default(cifmw_ci_multus_basedir ~ '/artifacts/manifests') }}/ci_multus"
23-
cifmw_ci_multus_namespace: "ci-multus"
23+
cifmw_ci_multus_namespace: "openstack"
2424
cifmw_ci_multus_ocp_hostname: "crc"
2525
cifmw_ci_multus_cniversion: "0.3.1"
2626
cifmw_ci_multus_default_nad_type: "macvlan"
2727
cifmw_ci_multus_default_nad_ipam_type: "whereabouts"
28+
cifmw_ci_multus_default_nad_ipam_type_ip_version: "v4"
2829
# Input configuration for ci_multus role
29-
cifmw_ci_multus_nad_list: []
30-
cifmw_ci_multus_nad_extra_list: []
30+
cifmw_ci_multus_dryrun: false
31+
cifmw_ci_multus_allow_list: []
32+
cifmw_ci_multus_deny_list: []

roles/ci_multus/molecule/default/converge.yml

Lines changed: 13 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
1616

17-
1817
- name: Converge
1918
hosts: all
2019
gather_facts: true
21-
vars:
22-
cifmw_path: "{{ ansible_user_dir }}/.crc/bin:{{ ansible_user_dir }}/.crc/bin/oc:{{ ansible_user_dir }}/bin:{{ ansible_env.PATH }}"
23-
cifmw_openshift_kubeconfig: "{{ ansible_user_dir }}/.crc/machines/crc/kubeconfig"
24-
testpod_name: "pod-testnad"
2520
tasks:
2621
- name: Add crc hostname with it's IP to /etc/hosts
2722
become: true
@@ -41,161 +36,21 @@
4136
delegate_to: crc
4237
delegate_facts: true
4338

44-
- name: Prepare the network var for the role
39+
- name: Load shared variables
40+
ansible.builtin.include_vars:
41+
file: ../resources/vars/shared_vars.yml
42+
43+
- name: Override interface name in cifmw_networking_env_definition
44+
vars:
45+
_cifmw_networking_env_definition_patch:
46+
instances:
47+
crc:
48+
networks:
49+
default:
50+
interface_name: "{{ hostvars.crc.ansible_default_ipv4.interface }}"
4551
ansible.builtin.set_fact:
46-
crc_ci_bootstrap_networks_out:
47-
networks:
48-
default:
49-
iface: "{{ hostvars.crc.ansible_default_ipv4.interface }}"
50-
mtu: 1500
51-
range: 192.168.122.0/24
52-
multus:
53-
range: 192.168.122.30-192.168.122.70
54-
cifmw_ci_multus_nad_extra_list:
55-
- name: bgpnet1
56-
iface: bgpnet1_iface
57-
type: interface
58-
ipam:
59-
type: whereabouts
60-
range: 100.65.4.0/30
61-
range_start: 100.65.4.1
62-
range_end: 100.65.4.2
52+
cifmw_networking_env_definition: "{{ cifmw_networking_env_definition | combine(_cifmw_networking_env_definition_patch, recursive=True) }}"
6353

6454
- name: Call ci_multus role
6555
ansible.builtin.include_role:
6656
name: "ci_multus"
67-
68-
# Verify the run
69-
- name: Fetch files stat results
70-
ansible.builtin.stat:
71-
path: >-
72-
{{
73-
[
74-
ansible_user_dir,
75-
'ci-framework-data',
76-
'artifacts',
77-
item
78-
] | ansible.builtin.path_join
79-
}}
80-
register: _ci_multus_molecule_stat_out
81-
loop:
82-
- manifests/ci_multus/ci_multus_nads.yml
83-
84-
- name: Assert that all expected files exist
85-
ansible.builtin.assert:
86-
that: >-
87-
_ci_multus_molecule_stat_out.results |
88-
map(attribute="stat.exists") |
89-
select("equalto", true) |
90-
length == (_ci_multus_molecule_stat_out.results | length)
91-
92-
- name: Fetch all files content
93-
ansible.builtin.slurp:
94-
path: "{{ item }}"
95-
register: _ci_multus_molecule_slurp_out
96-
loop: >-
97-
{{
98-
_ci_multus_molecule_stat_out.results |
99-
map(attribute="stat.path")
100-
}}
101-
102-
- name: Assert that all files contains proper YAML data
103-
ansible.builtin.assert:
104-
that: "item.content | b64decode | from_yaml_all | length > 0"
105-
loop: "{{ _ci_multus_molecule_slurp_out.results }}"
106-
loop_control:
107-
label: "{{ item.source }}"
108-
109-
- name: Check if NADs were created
110-
kubernetes.core.k8s_info:
111-
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
112-
namespace: "{{ cifmw_ci_multus_namespace }}"
113-
api_version: k8s.cni.cncf.io/v1
114-
kind: NetworkAttachmentDefinition
115-
register: _ci_multus_molecule_nads_out
116-
failed_when: >-
117-
(_ci_multus_molecule_nads_out is not defined) or
118-
(_ci_multus_molecule_nads_out is failed) or
119-
(_ci_multus_molecule_nads_out.resources | length == 0)
120-
121-
- name: Create a test pod to attach a network
122-
kubernetes.core.k8s:
123-
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
124-
namespace: "{{ cifmw_ci_multus_namespace }}"
125-
state: present
126-
definition:
127-
api_version: v1
128-
kind: Pod
129-
metadata:
130-
name: "{{ testpod_name }}"
131-
annotations:
132-
k8s.v1.cni.cncf.io/networks: default
133-
spec:
134-
containers:
135-
- name: testnad
136-
image: quay.rdoproject.org/openstack-k8s-operators/alpine:latest
137-
imagePullPolicy: Always
138-
command:
139-
- "/bin/ash"
140-
- "-c"
141-
- "trap : TERM INT; sleep infinity & wait"
142-
wait: true
143-
wait_sleep: 10
144-
wait_timeout: 300
145-
wait_condition:
146-
type: Ready
147-
status: "True"
148-
register: _ci_multus_molecule_test_pod_out
149-
150-
- name: Assert that test pod has the additional network
151-
ansible.builtin.assert:
152-
that:
153-
- _ci_multus_molecule_test_pod_out.result.metadata.annotations[
154-
'k8s.v1.cni.cncf.io/networks'] == "default"
155-
156-
- name: Delete test pod
157-
kubernetes.core.k8s:
158-
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
159-
api_key: "{{ cifmw_openshift_token | default(omit)}}"
160-
context: "{{ cifmw_openshift_context | default(omit)}}"
161-
namespace: "{{ cifmw_ci_multus_namespace }}"
162-
state: absent
163-
api_version: v1
164-
kind: Pod
165-
name: "{{ testpod_name }}"
166-
167-
- name: Call cleanup
168-
ansible.builtin.import_role:
169-
name: ci_multus
170-
tasks_from: cleanup.yml
171-
172-
- name: Check if NADs were deleted
173-
kubernetes.core.k8s_info:
174-
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
175-
namespace: "{{ cifmw_ci_multus_namespace }}"
176-
api_version: k8s.cni.cncf.io/v1
177-
kind: NetworkAttachmentDefinition
178-
register: _ci_multus_molecule_nads_cleanup_out
179-
failed_when: >-
180-
(_ci_multus_molecule_nads_cleanup_out is not defined) or
181-
(_ci_multus_molecule_nads_cleanup_out is failed) or
182-
(_ci_multus_molecule_nads_cleanup_out.resources | length > 0)
183-
184-
- name: Get all namespaces
185-
kubernetes.core.k8s_info:
186-
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
187-
api_key: "{{ cifmw_openshift_token | default(omit)}}"
188-
context: "{{ cifmw_openshift_context | default(omit)}}"
189-
kind: Namespace
190-
register: _ci_multus_molecule_ns_out
191-
192-
- name: Assert that multus namespace is absent
193-
vars:
194-
ns_names: >-
195-
{{
196-
_ci_multus_molecule_ns_out.resources |
197-
default([]) |
198-
map(attribute='metadata.name')
199-
}}
200-
ansible.builtin.assert:
201-
that: "cifmw_ci_multus_namespace not in ns_names"

roles/ci_multus/molecule/default/molecule.yml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,37 @@ log: true
77
provisioner:
88
name: ansible
99
log: true
10-
env:
11-
ANSIBLE_STDOUT_CALLBACK: yaml
10+
playbooks:
11+
side_effect: side_effect.yml
12+
inventory:
13+
host_vars:
14+
instance:
15+
_expected_multus_networks:
16+
- default
17+
- patchnetwork
18+
cifmw_ci_multus_net_info_patch_1:
19+
patchnetwork:
20+
gw_v4: 192.168.122.1
21+
network_name: patchnetwork
22+
network_v4: 192.168.122.0/24
23+
interface_name: eth2
24+
tools:
25+
multus:
26+
ipv4_ranges:
27+
- start: 192.168.122.30
28+
end: 192.168.122.70
29+
30+
cifmw_path: "{{ ansible_user_dir }}/.crc/bin:{{ ansible_user_dir }}/.crc/bin/oc:{{ ansible_user_dir }}/bin:{{ ansible_env.PATH }}"
31+
cifmw_openshift_kubeconfig: "{{ ansible_user_dir }}/.crc/machines/crc/kubeconfig"
32+
testpod_name: "pod-testnad"
33+
prerun: false
34+
scenario:
35+
test_sequence:
36+
- destroy
37+
- create
38+
- converge
39+
- verify ../resources/verify.yml
40+
- verify verify_crc.yml
41+
- side_effect ../resources/clean.yml
42+
- verify ../resources/verify_clean.yml
43+
- verify verify_clean_crc.yml

roles/ci_multus/molecule/default/side_effect.yml

Whitespace-only changes.

0 commit comments

Comments
 (0)