Skip to content

Commit 56875eb

Browse files
committed
cinder adoption: generalize the netapp code (also iSCSI)
- reduce the usage of set_facts by defining local variables (inspired by a recent manila change); - generalize (and thus rename) the netapp/NFS playbook to support also iSCSI in addition to NFS. The code is mostly the same, NFS just just needs to check for an additional file and a protocol-specific template needs to be used.
1 parent 603b6ca commit 56875eb

File tree

5 files changed

+127
-66
lines changed

5 files changed

+127
-66
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
- name: Slurp cinder.conf from controller
2+
become: true
3+
ansible.builtin.shell: |
4+
{{ shell_header }}
5+
CONTROLLER1_SCP="{{ controller1_ssh | regex_replace('^ssh', 'scp')}}"
6+
${CONTROLLER1_SCP}:{{ cinder_tripleo_path }} {{ cinder_conf_path }}
7+
chmod a+r {{ cinder_conf_path }}
8+
9+
- name: Stat the retrieved cinder.conf file
10+
ansible.builtin.stat:
11+
path: "{{ cinder_conf_path }}"
12+
register: cinder_conf
13+
14+
- name: Fail if cinder.conf is not present
15+
when: not cinder_conf.stat.exists
16+
ansible.builtin.fail:
17+
msg: "cinder.conf does not exist"
18+
19+
- name: Check the cinder share config file for ontap-nfs
20+
when: cinder_volume_backend == 'ontap-nfs'
21+
block:
22+
- name: Slurp cinder share config file from controller
23+
become: true
24+
ansible.builtin.shell: |
25+
{{ shell_header }}
26+
CONTROLLER1_SCP="{{ controller1_ssh | regex_replace('^ssh', 'scp')}}"
27+
${CONTROLLER1_SCP}:{{ cinder_tripleo_nfs_shares_config_path }} {{ cinder_nfs_shares_conf_path }}
28+
chmod a+r {{ cinder_nfs_shares_conf_path }}
29+
30+
- name: Stat the retrieved cinder share config file
31+
ansible.builtin.stat:
32+
path: "{{ cinder_nfs_shares_conf_path }}"
33+
register: cinder_nfs_shares_conf
34+
35+
- name: Fail if cinder share config file is not present
36+
when: not cinder_nfs_shares_conf.stat.exists
37+
ansible.builtin.fail:
38+
msg: "{{ cinder_nfs_shares_conf_path }} does not exist"
39+
40+
- name: Deploy Podified Cinder-Volume - Netapp
41+
vars:
42+
cinder_netapp_config: |
43+
{% set cinder_netapp_conf = {} %}
44+
{% for item in cinder_volume_netapp_vars %}
45+
{% set value = lookup('ansible.builtin.ini', item, file=cinder_conf_path, section=cinder_netapp_backend, allow_no_value=True) %}
46+
{% set _ = cinder_netapp_conf.__setitem__(item, value) %}
47+
{% endfor %}
48+
{{ cinder_netapp_conf }}
49+
cinder_netapp_share_config:
50+
nfs_server: "{{ (lookup('file', cinder_nfs_shares_conf_path, errors='warn')).split(':')[0] | default('') | trim }}"
51+
nfs_path: "{{ (lookup('file', cinder_nfs_shares_conf_path, errors='warn')).split(':')[1] | default('') | trim }}"
52+
cinder_configuration_template:
53+
ontap-nfs: 'cinder_volume_netapp_nfs.yaml.j2'
54+
ontap-iscsi: 'cinder_volume_netapp_iscsi.yaml.j2'
55+
block:
56+
- name: Fail if cinder_netapp_config params are not defined
57+
when: |
58+
cinder_netapp_config.netapp_login is not defined or
59+
cinder_netapp_config.netapp_password is not defined or
60+
cinder_netapp_config.netapp_vserver is not defined or
61+
cinder_netapp_config.netapp_server_hostname is not defined
62+
ansible.builtin.fail:
63+
msg:
64+
- 'Missing required Netapp input'
65+
66+
- name: Fail if cinder_netapp_share_config params are not defined
67+
when: |
68+
cinder_volume_backend == 'ontap-nfs' and
69+
(not cinder_netapp_share_config.nfs_server or
70+
not cinder_netapp_share_config.nfs_path)
71+
ansible.builtin.fail:
72+
msg:
73+
- 'Missing required cinder share input'
74+
75+
- name: Render Netapp OpenShift Secret template
76+
ansible.builtin.template:
77+
src: "{{ role_path }}/templates/cinder-volume-ontap-secrets.yaml.j2"
78+
dest: /tmp/cinder-volume-ontap-secrets.yaml
79+
mode: "0600"
80+
81+
- name: Render cinder netapp OpenShift patch file template
82+
ansible.builtin.template:
83+
src: "{{ role_path }}/templates/{{ cinder_configuration_template[cinder_volume_backend] }}"
84+
dest: /tmp/cinder_volume_netapp_config.yaml
85+
mode: "0600"
86+
87+
- name: Apply the rendered Netapp secret in the openstack namespace
88+
ansible.builtin.shell: |
89+
{{ shell_header }}
90+
{{ oc_header }}
91+
oc apply -f /tmp/cinder-volume-ontap-secrets.yaml
92+
93+
- name: Configure the appropriate netapp backend
94+
ansible.builtin.shell: |
95+
{{ shell_header }}
96+
{{ oc_header }}
97+
oc patch openstackcontrolplane openstack --type=merge --patch-file=/tmp/cinder_volume_netapp_config.yaml

tests/roles/cinder_adoption/tasks/cinder_volume_netapp_nfs.yaml

Lines changed: 0 additions & 56 deletions
This file was deleted.

tests/roles/cinder_adoption/tasks/volume_backend.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
{{ oc_header }}
66
oc patch openstackcontrolplane openstack --type=merge --patch '{{ cinder_volume_backend_patch }}'
77
8-
- name: deploy podified Cinder volume with netapp NFS
9-
when: cinder_volume_backend == 'ontap-nfs'
10-
ansible.builtin.include_tasks: cinder_volume_netapp_nfs.yaml
8+
- name: deploy podified Cinder volume with netapp NFS or iSCSI
9+
when: >
10+
cinder_volume_backend == 'ontap-nfs' or
11+
cinder_volume_backend == 'ontap-iscsi'
12+
ansible.builtin.include_tasks: cinder_volume_netapp.yaml
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Define the "cinder-volume-ontap-secrets" Secret that contains sensitive
2-
# information pertaining to the [ontap] backend.
2+
# information pertaining to the ontap-based backends.
33
apiVersion: v1
44
kind: Secret
55
metadata:
@@ -11,9 +11,11 @@ type: Opaque
1111
stringData:
1212
ontap-cinder-secrets: |
1313
[{{ cinder_netapp_backend }}]
14-
netapp_server_hostname = {{ cinder_volume_netapp_config.netapp_server_hostname }}
15-
netapp_login = {{ cinder_volume_netapp_config.netapp_login }}
16-
netapp_password = {{ cinder_volume_netapp_config.netapp_password }}
17-
netapp_vserver = {{ cinder_volume_netapp_config.netapp_vserver }}
18-
nas_host = {{ cinder_volume_nfs_server }}
19-
nas_share_path = {{ cinder_volume_nfs_path }}
14+
netapp_server_hostname = {{ cinder_netapp_config.netapp_server_hostname }}
15+
netapp_login = {{ cinder_netapp_config.netapp_login }}
16+
netapp_password = {{ cinder_netapp_config.netapp_password }}
17+
netapp_vserver = {{ cinder_netapp_config.netapp_vserver }}
18+
{% if cinder_volume_backend == 'ontap-nfs' %}
19+
nas_host = {{ cinder_netapp_share_config.nfs_server }}
20+
nas_share_path = {{ cinder_netapp_share_config.nfs_path }}
21+
{% endif %}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
spec:
2+
cinder:
3+
template:
4+
cinderVolumes:
5+
ontap-iscsi:
6+
networkAttachments:
7+
- storage
8+
customServiceConfig: |
9+
[{{ cinder_netapp_backend }}]
10+
volume_backend_name=ontap-iscsi
11+
volume_driver=cinder.volume.drivers.netapp.common.NetAppDriver
12+
netapp_storage_protocol=iscsi
13+
netapp_storage_family=ontap_cluster
14+
consistencygroup_support=True
15+
customServiceConfigSecrets:
16+
- cinder-volume-ontap-secrets

0 commit comments

Comments
 (0)