Skip to content

Commit 8022f9e

Browse files
bogdandodanpawlik
authored andcommitted
Add molecule test for multi-stack osp deploy
Also make the vars as facts to keep the logic around it testable Signed-off-by: Bohdan Dobrelia <[email protected]>
1 parent d5a6419 commit 8022f9e

File tree

10 files changed

+226
-58
lines changed

10 files changed

+226
-58
lines changed

.ansible-lint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exclude_paths:
1212
- zuul.d/projects.yaml # Generated, pyYAML is bad at indentation
1313
- zuul.d/molecule.yaml # Generated, pyYAML is bad at indentation
1414
- ci/
15+
- roles/adoption_osp_deploy/molecule/default/vars.yaml # vars_file
1516
- roles/ci_gen_kustomize_values/molecule/default/files/networking-environment-definition.yml # Generated
1617
- roles/ci_gen_kustomize_values/molecule/default/files/3-ocp-net-def.yml # Generated
1718
- roles/ci_gen_kustomize_values/molecule/default/converge.yml # invalid due to calls to "lookup('file')"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM registry.access.redhat.com/ubi9/ubi-init
2+
3+
RUN curl -o /etc/yum.repos.d/delorean.repo https://trunk.rdoproject.org/centos9-master/current/delorean.repo && \
4+
dnf upgrade -y && \
5+
dnf -y install sudo python3 python3-libselinux selinux-policy git python3-pip && \
6+
git clone https://github.com/openstack-k8s-operators/repo-setup && \
7+
cd repo-setup && \
8+
pip install -r requirements.txt && \
9+
python3 setup.py install && \
10+
dnf clean all -y
11+
12+
CMD [ '/sbin/init' ]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
gather_facts: false
5+
6+
vars_files:
7+
- vars.yaml
8+
vars:
9+
# Vars required by prepare_overcloud.yml
10+
cifmw_libvirt_manager_images_path: /tmp/images
11+
cifmw_libvirt_manager_image_name: centos-stream-9.qcow2
12+
cifmw_adoption_osp_deploy_repos: []
13+
cifmw_adoption_source_scenario_path: "."
14+
cifmw_basedir: "{{ playbook_dir }}"
15+
16+
tasks:
17+
- name: Gather stack nodes and facts
18+
ansible.builtin.include_tasks: ../../tasks/gather_stack_nodes.yml
19+
loop: "{{ stacks }}"
20+
loop_control:
21+
loop_var: _stack
22+
23+
- name: Store result for verification as persistent fact
24+
ansible.builtin.set_fact:
25+
tripleo_nodes_stack: "{{ _tripleo_nodes_stack }}"
26+
cacheable: true
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: podman
6+
platforms:
7+
- name: instance
8+
image: registry.access.redhat.com/ubi9/ubi-init
9+
dockerfile: containerfile
10+
command: /sbin/init
11+
pre_build_image: true
12+
provisioner:
13+
inventory:
14+
hosts:
15+
all:
16+
hosts:
17+
instance:
18+
ansible_python_interpreter: /usr/bin/python3
19+
name: ansible
20+
log: true
21+
env:
22+
ANSIBLE_STDOUT_CALLBACK: yaml
23+
verifier:
24+
name: ansible
25+
scenario:
26+
test_sequence:
27+
- destroy
28+
- create
29+
- prepare
30+
- converge
31+
- verify
32+
- destroy
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
stacks:
2+
- stackname: overcloud
3+
network_data_file: "network_data.yaml.j2"
4+
vips_data_file: "vips_data_overcloud.yaml"
5+
stack_nodes:
6+
- osp-controllers
7+
- stackname: cell1
8+
network_data_file: "network_data.yaml.j2"
9+
vips_data_file: "vips_data_cell1.yaml"
10+
stack_nodes:
11+
- cell1-osp-computes
12+
- cell1-osp-controllers
13+
- stackname: cell2
14+
network_data_file: "network_data.yaml.j2"
15+
vips_data_file: "vips_data_cell2.yaml"
16+
stack_nodes:
17+
- cell2-osp-computes
18+
- cell2-osp-controllers
19+
20+
expected_nodes:
21+
overcloud:
22+
- osp-controller-uni05epsilon-0
23+
cell1:
24+
- cell1-osp-compute-uni05epsilon-0
25+
- cell1-osp-controller-uni05epsilon-0
26+
cell2:
27+
- cell2-osp-compute-uni05epsilon-0
28+
- cell2-osp-controller-uni05epsilon-0
29+
30+
cifmw_adoption_osp_deploy_scenario:
31+
hostname_groups_map:
32+
cell1-osp-computes: cell1-novacompute
33+
cell1-osp-controllers: cell1-controller
34+
cell2-osp-computes: cell2-novacompute
35+
cell2-osp-controllers: cell2-controller
36+
osp-controllers: overcloud-controller
37+
roles_groups_map:
38+
# map ansible groups to tripleo Role names
39+
osp-controllers: Controller
40+
cell1-osp-controllers: CellController
41+
cell2-osp-controllers: CellController
42+
43+
# Vars to simulate playbook execution context
44+
_vm_groups:
45+
cell1-osp-computes:
46+
- cell1-osp-compute-uni05epsilon-0
47+
cell1-osp-controllers:
48+
- cell1-osp-controller-uni05epsilon-0
49+
cell2-osp-computes:
50+
- cell2-osp-compute-uni05epsilon-0
51+
cell2-osp-controllers:
52+
- cell2-osp-controller-uni05epsilon-0
53+
controllers:
54+
- controller-0
55+
ocps:
56+
- ocp-master-0
57+
- ocp-master-1
58+
- ocp-master-2
59+
osp-controllers:
60+
- osp-controller-uni05epsilon-0
61+
osp-underclouds:
62+
- osp-undercloud-uni05epsilon-0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- name: Verify
3+
hosts: all
4+
gather_facts: false
5+
vars_files:
6+
- vars.yaml
7+
tasks:
8+
- name: "Set _tripleo_nodes_stack from persistent fact"
9+
ansible.builtin.set_fact:
10+
tripleo_nodes_stack: "{{ hostvars[inventory_hostname]._tripleo_nodes_stack }}"
11+
when: hostvars[inventory_hostname]._tripleo_nodes_stack is defined
12+
13+
- name: "Assert gathered nodes for stacks"
14+
ansible.builtin.assert:
15+
that:
16+
- "tripleo_nodes_stack[_stack.stackname] is defined"
17+
- "tripleo_nodes_stack[_stack.stackname] | type_debug == 'list'"
18+
- "tripleo_nodes_stack[_stack.stackname] | sort == expected_nodes[_stack.stackname] | sort"
19+
fail_msg: "Verification failed for gathered nodes in stack {{ _stack.stackname }}"
20+
success_msg: "Successfully verified gathered nodes for stack {{ _stack.stackname }}"
21+
loop: "{{ stacks }}"
22+
loop_control:
23+
loop_var: _stack
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
- name: Get main facts for the overcloud stack
3+
ansible.builtin.set_fact:
4+
_overcloud_name: >-
5+
{{
6+
_stack.stackname |
7+
default('overcloud')
8+
}}
9+
_network_data_file: >-
10+
{{
11+
[cifmw_adoption_source_scenario_path,
12+
_stack.network_data_file
13+
] | path_join
14+
}}
15+
16+
- name: Gather other facts for stack {{ _overcloud_name }}"
17+
ansible.builtin.set_fact:
18+
_hostname_map_translation: >-
19+
{{
20+
cifmw_adoption_osp_deploy_scenario.hostname_groups_map |
21+
ansible.utils.keep_keys(target=_stack.stack_nodes)
22+
}}
23+
_role_map_translation: >-
24+
{{
25+
cifmw_adoption_osp_deploy_scenario.roles_groups_map |
26+
ansible.utils.keep_keys(target=_stack.stack_nodes)
27+
}}
28+
_network_data_file_dest: >-
29+
{{
30+
[ansible_user_dir,
31+
'network_data_' ~ _overcloud_name ~'.yaml'
32+
] | path_join
33+
}}
34+
35+
_network_data_extension: "{{ _network_data_file | splitext | last }}"
36+
_vips_data_file: >-
37+
{{
38+
[cifmw_adoption_source_scenario_path,
39+
_stack.vips_data_file
40+
] | path_join
41+
}}
42+
_vips_data_file_dest: >-
43+
{{
44+
[ansible_user_dir,
45+
'vips_data_' ~ _overcloud_name ~ '.yaml'
46+
] | path_join
47+
}}
48+
_source_cmd: "source {{ ansible_user_dir }}/stackrc"
49+
_network_provision_output: "network_provision_{{ _overcloud_name }}_out.yaml"
50+
_vips_provision_output: "vips_provision_{{ _overcloud_name }}_out.yaml"
51+
52+
- name: "Gather nodes for stack {{ _overcloud_name }}"
53+
when: group.key is in _hostname_map_translation
54+
vars:
55+
tripleo_nodes_stack: "{{ _tripleo_nodes_stack | default({}) }}"
56+
ansible.builtin.set_fact:
57+
_tripleo_nodes_stack: >-
58+
{{
59+
tripleo_nodes_stack | combine({ _overcloud_name: (tripleo_nodes_stack.get(_overcloud_name, []) + group.value) })
60+
}}
61+
loop: "{{ _vm_groups | dict2items }}"
62+
loop_control:
63+
loop_var: group
64+
label: "{{ group.key }}"

roles/adoption_osp_deploy/tasks/generate_adoption_vars.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
{%- endif -%}
3939
_compute_1_net: "{{ cifmw_networking_env_definition.instances[_compute_1_name] | default({'networks': {'ctlplane': {'ip_v4': '192.168.122.100'}}}) }}"
4040
_stack_names: "{{ cifmw_adoption_osp_deploy_scenario.stacks | map(attribute='stackname') | list }}"
41+
_default_cell_name: "{{ cifmw_adoption_osp_deploy_scenario.default_cell_name | default('cell1') }}"
4142
_compute_1_ip: "{{ _compute_1_net.networks.ctlplane[ip_version|default('ip_v4')] }}"
4243
ansible.builtin.template:
4344
src: "adoption_vars.yaml.j2"

roles/adoption_osp_deploy/tasks/prepare_overcloud.yml

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -22,63 +22,9 @@
2222
- user_dir
2323

2424
- name: Prepare enviornment for 17.1 overcloud deployment
25-
vars:
26-
_overcloud_name: >-
27-
{{
28-
_stack.stackname |
29-
default('overcloud')
30-
}}
31-
_hostname_map_translation: >-
32-
{{
33-
cifmw_adoption_osp_deploy_scenario.hostname_groups_map |
34-
ansible.utils.keep_keys(target=_stack.stack_nodes)
35-
}}
36-
_role_map_translation: >-
37-
{{
38-
cifmw_adoption_osp_deploy_scenario.roles_groups_map |
39-
ansible.utils.keep_keys(target=_stack.stack_nodes)
40-
}}
41-
_network_data_file: >-
42-
{{
43-
[cifmw_adoption_source_scenario_path,
44-
_stack.network_data_file
45-
] | path_join
46-
}}
47-
_network_data_file_dest: >-
48-
{{
49-
[ansible_user_dir,
50-
'network_data_' ~ _overcloud_name ~'.yaml'
51-
] | path_join
52-
}}
53-
_network_data_extension: "{{ _network_data_file | splitext | last }}"
54-
_vips_data_file: >-
55-
{{
56-
[cifmw_adoption_source_scenario_path,
57-
_stack.vips_data_file
58-
] | path_join
59-
}}
60-
_vips_data_file_dest: >-
61-
{{
62-
[ansible_user_dir,
63-
'vips_data_' ~ _overcloud_name ~ '.yaml'
64-
] | path_join
65-
}}
66-
_source_cmd: "source {{ ansible_user_dir }}/stackrc"
67-
_network_provision_output: "network_provision_{{ _overcloud_name }}_out.yaml"
68-
_vips_provision_output: "vips_provision_{{ _overcloud_name }}_out.yaml"
6925
block:
70-
- name: "Gather nodes for stack {{ _overcloud_name }}"
71-
when: group.key is in _hostname_map_translation
72-
ansible.builtin.set_fact:
73-
_tripleo_nodes_stack: >-
74-
{{
75-
(_tripleo_nodes_stack | default({})) |
76-
combine({ _overcloud_name: (_tripleo_nodes_stack[_overcloud_name] | default([]) + group.value) })
77-
}}
78-
loop: "{{ _vm_groups | dict2items }}"
79-
loop_control:
80-
loop_var: group
81-
label: "{{ group.key }}"
26+
- name: Gather stack nodes and facts
27+
ansible.builtin.include_tasks: gather_stack_nodes.yml
8228

8329
- name: Ensure overcloud vms are started
8430
vars:

roles/adoption_osp_deploy/templates/adoption_vars.yaml.j2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ edpm_networkers: |
2626
{% endfor %}
2727
{% endif %}
2828

29-
source_galera_members:
3029
{%+ if multi_cell|default(false) +%}
30+
source_galera_members:
3131
{% for stack in _stack_names %}
3232
{% if stack == 'overcloud' %}
3333
{% set cell = 'default' %}
@@ -44,6 +44,7 @@ source_galera_members:
4444
{% endfor %}
4545
{% endfor %}
4646
{%+ else +%}
47+
source_galera_members: |
4748
{% for controller in _vm_groups['osp-controllers'] %}
4849
{% set node_nets = cifmw_networking_env_definition.instances[controller] %}
4950
["{{ controller }}.{{ cifmw_adoption_osp_deploy_scenario.cloud_domain }}"]="{{ node_nets.networks.internalapi[ip_version|default('ip_v4')] }}"
@@ -53,7 +54,7 @@ source_galera_members:
5354
edpm_nodes:
5455
{% for stack in _stack_names %}
5556
{% if stack == 'overcloud' %}
56-
{% set cell = 'default' %}
57+
{% set cell = _default_cell_name %}
5758
{% set prefix = '' %}
5859
{% else %}
5960
{% set cell = stack %}

0 commit comments

Comments
 (0)