Fix cinder-{backup,volume} container with pacemaker
[apex-tripleo-heat-templates.git] / docker / services / pacemaker / cinder-volume.yaml
1 heat_template_version: pike
2
3 description: >
4   OpenStack containerized Cinder Volume service
5
6 parameters:
7   DockerCinderVolumeImage:
8     description: image
9     type: string
10   DockerCinderConfigImage:
11     description: The container image to use for the cinder config_volume
12     type: string
13   EndpointMap:
14     default: {}
15     description: Mapping of service endpoint -> protocol. Typically set
16                  via parameter_defaults in the resource registry.
17     type: json
18   ServiceData:
19     default: {}
20     description: Dictionary packing service data
21     type: json
22   ServiceNetMap:
23     default: {}
24     description: Mapping of service_name -> network name. Typically set
25                  via parameter_defaults in the resource registry.  This
26                  mapping overrides those in ServiceNetMapDefaults.
27     type: json
28   DefaultPasswords:
29     default: {}
30     type: json
31   RoleName:
32     default: ''
33     description: Role name on which the service is applied
34     type: string
35   RoleParameters:
36     default: {}
37     description: Parameters specific to the role
38     type: json
39   # custom parameters for the Cinder volume role
40   CinderEnableIscsiBackend:
41     default: true
42     description: Whether to enable or not the Iscsi backend for Cinder
43     type: boolean
44   CinderLVMLoopDeviceSize:
45     default: 10280
46     description: The size of the loopback file used by the cinder LVM driver.
47     type: number
48
49 resources:
50
51   MySQLClient:
52     type: ../../../puppet/services/database/mysql-client.yaml
53
54   CinderBase:
55     type: ../../../puppet/services/cinder-volume.yaml
56     properties:
57       EndpointMap: {get_param: EndpointMap}
58       ServiceData: {get_param: ServiceData}
59       ServiceNetMap: {get_param: ServiceNetMap}
60       DefaultPasswords: {get_param: DefaultPasswords}
61       RoleName: {get_param: RoleName}
62       RoleParameters: {get_param: RoleParameters}
63
64 outputs:
65   role_data:
66     description: Role data for the Cinder Volume role.
67     value:
68       service_name: {get_attr: [CinderBase, role_data, service_name]}
69       config_settings:
70         map_merge:
71           - get_attr: [CinderBase, role_data, config_settings]
72           - tripleo::profile::base::lvm::enable_udev: false
73             tripleo::profile::pacemaker::cinder::volume_bundle::cinder_volume_docker_image: &cinder_volume_image_pcmklatest
74               list_join:
75                 - ':'
76                 - - yaql:
77                       data: {get_param: DockerCinderVolumeImage}
78                       expression: $.data.rightSplit(separator => ":", maxSplits => 1)[0]
79                   - 'pcmklatest'
80             cinder::volume::manage_service: false
81             cinder::volume::enabled: false
82             cinder::host: hostgroup
83       logging_source: {get_attr: [CinderBase, role_data, logging_source]}
84       logging_groups: {get_attr: [CinderBase, role_data, logging_groups]}
85       step_config: &step_config
86         list_join:
87           - "\n"
88           - - "include ::tripleo::profile::base::lvm"
89             - get_attr: [CinderBase, role_data, step_config]
90             - get_attr: [MySQLClient, role_data, step_config]
91       service_config_settings: {get_attr: [CinderBase, role_data, service_config_settings]}
92       # BEGIN DOCKER SETTINGS
93       puppet_config:
94         config_volume: cinder
95         puppet_tags: cinder_config,file,concat,file_line
96         step_config: *step_config
97         config_image: {get_param: DockerCinderConfigImage}
98       kolla_config:
99         /var/lib/kolla/config_files/cinder_volume.json:
100           command: /usr/bin/cinder-volume --config-file /usr/share/cinder/cinder-dist.conf --config-file /etc/cinder/cinder.conf
101           config_files:
102             - source: "/var/lib/kolla/config_files/src/*"
103               dest: "/"
104               merge: true
105               preserve_properties: true
106             - source: "/var/lib/kolla/config_files/src-ceph/"
107               dest: "/etc/ceph/"
108               merge: true
109               preserve_properties: true
110             - source: "/var/lib/kolla/config_files/src-iscsid/*"
111               dest: "/"
112               merge: true
113               preserve_properties: true
114           permissions:
115             - path: /var/log/cinder
116               owner: cinder:cinder
117               recurse: true
118       docker_config:
119         step_1:
120           cinder_volume_image_tag:
121             start_order: 1
122             detach: false
123             net: host
124             user: root
125             command:
126               - '/bin/bash'
127               - '-c'
128               - str_replace:
129                   template:
130                     "/usr/bin/docker tag 'CINDERVOLUME_IMAGE' 'CINDERVOLUME_IMAGE_PCMKLATEST'"
131                   params:
132                     CINDERVOLUME_IMAGE: {get_param: DockerCinderVolumeImage}
133                     CINDERVOLUME_IMAGE_PCMKLATEST: *cinder_volume_image_pcmklatest
134             image: {get_param: DockerCinderVolumeImage}
135             volumes:
136               - /etc/hosts:/etc/hosts:ro
137               - /etc/localtime:/etc/localtime:ro
138               - /dev/shm:/dev/shm:rw
139               - /etc/sysconfig/docker:/etc/sysconfig/docker:ro
140               - /usr/bin:/usr/bin:ro
141               - /var/run/docker.sock:/var/run/docker.sock:rw
142         step_3:
143           cinder_volume_init_logs:
144             start_order: 0
145             image: {get_param: DockerCinderVolumeImage}
146             privileged: false
147             user: root
148             volumes:
149               - /var/log/containers/cinder:/var/log/cinder
150             command: ['/bin/bash', '-c', 'chown -R cinder:cinder /var/log/cinder']
151         step_5:
152           cinder_volume_init_bundle:
153             start_order: 0
154             detach: false
155             net: host
156             user: root
157             command:
158               - '/bin/bash'
159               - '-c'
160               - str_replace:
161                   template:
162                     list_join:
163                       - '; '
164                       - - "cp -a /tmp/puppet-etc/* /etc/puppet; echo '{\"step\": 5}' > /etc/puppet/hieradata/docker.json"
165                         - "FACTER_uuid=docker puppet apply --tags file_line,concat,augeas,TAGS --debug -v -e 'CONFIG'"
166                   params:
167                     TAGS: 'pacemaker::resource::bundle,pacemaker::property,pacemaker::constraint::location'
168                     CONFIG: 'include ::tripleo::profile::base::pacemaker;include ::tripleo::profile::pacemaker::cinder::volume_bundle'
169             image: {get_param: DockerCinderVolumeImage}
170             volumes:
171               - /etc/hosts:/etc/hosts:ro
172               - /etc/localtime:/etc/localtime:ro
173               - /etc/puppet:/tmp/puppet-etc:ro
174               - /usr/share/openstack-puppet/modules:/usr/share/openstack-puppet/modules:ro
175               - /etc/corosync/corosync.conf:/etc/corosync/corosync.conf:ro
176               - /dev/shm:/dev/shm:rw
177       host_prep_tasks:
178         - name: create persistent directories
179           file:
180             path: "{{ item }}"
181             state: directory
182           with_items:
183             - /var/log/containers/cinder
184             - /var/lib/cinder
185         - name: ensure ceph configurations exist
186           file:
187             path: /etc/ceph
188             state: directory
189         - name: cinder_enable_iscsi_backend fact
190           set_fact:
191             cinder_enable_iscsi_backend: {get_param: CinderEnableIscsiBackend}
192         - name: cinder create LVM volume group dd
193           command:
194             list_join:
195             - ''
196             - - 'dd if=/dev/zero of=/var/lib/cinder/cinder-volumes bs=1 count=0 seek='
197               - str_replace:
198                   template: VALUE
199                   params:
200                     VALUE: {get_param: CinderLVMLoopDeviceSize}
201               - 'M'
202           args:
203             creates: /var/lib/cinder/cinder-volumes
204           when: cinder_enable_iscsi_backend
205         - name: cinder create LVM volume group
206           shell: |
207             if ! losetup /dev/loop2; then
208               losetup /dev/loop2 /var/lib/cinder/cinder-volumes
209             fi
210             if ! pvdisplay | grep cinder-volumes; then
211               pvcreate /dev/loop2
212             fi
213             if ! vgdisplay | grep cinder-volumes; then
214               vgcreate cinder-volumes /dev/loop2
215             fi
216           args:
217             executable: /bin/bash
218             creates: /dev/loop2
219           when: cinder_enable_iscsi_backend
220       upgrade_tasks:
221         - name: get bootstrap nodeid
222           tags: common
223           command: hiera -c /etc/puppet/hiera.yaml bootstrap_nodeid
224           register: bootstrap_node
225         - name: set is_bootstrap_node fact
226           tags: common
227           set_fact: is_bootstrap_node={{bootstrap_node.stdout|lower == ansible_hostname|lower}}
228         - name: Disable the openstack-cinder-volume cluster resource
229           tags: step2
230           pacemaker_resource:
231             resource: openstack-cinder-volume
232             state: disable
233             wait_for_resource: true
234           register: output
235           retries: 5
236           until: output.rc == 0
237           when: is_bootstrap_node
238         - name: Delete the stopped openstack-cinder-volume cluster resource.
239           tags: step2
240           pacemaker_resource:
241             resource: openstack-cinder-volume
242             state: delete
243             wait_for_resource: true
244           register: output
245           retries: 5
246           until: output.rc == 0
247           when: is_bootstrap_node
248         - name: Disable cinder_volume service from boot
249           tags: step2
250           service: name=openstack-cinder-volume enabled=no
251       update_tasks:
252         - name: Get docker Cinder-Volume image
253           set_fact:
254             docker_image: {get_param: DockerCinderVolumeImage}
255             docker_image_latest: *cinder_volume_image_pcmklatest
256           when: step == '2'
257         - name: Get previous Cinder-Volume image id
258           shell: "docker images | awk '/cinder-volume.* pcmklatest/{print $3}'"
259           register: cinder_volume_image_id
260         - block:
261             - name: Get a list of container using Cinder-Volume image
262               shell: "docker ps -q -f 'ancestor={{cinder_volume_image_id.stdout}}'"
263               register: cinder_volume_containers_to_destroy
264             # It will be recreated with the delpoy step.
265             - name: Remove any container using the same Cinder-Volume image
266               shell: "docker rm -fv {{item}}"
267               with_items: "{{ cinder_volume_containers_to_destroy.stdout_lines }}"
268             - name: Remove previous Cinder-Volume images
269               shell: "docker rmi -f {{cinder_volume_image_id.stdout}}"
270           when:
271             - step == '2'
272             - cinder_volume_image_id.stdout != ''
273         - name: Pull latest Cinder-Volume images
274           command: "docker pull {{docker_image}}"
275           when: step == "2"
276         - name: Retag pcmklatest to latest Cinder-Volume image
277           shell: "docker tag {{docker_image}} {{docker_image_latest}}"
278           when: step == "2"
279         # Got to check that pacemaker_is_active is working fine with bundle.
280         # TODO: pacemaker_is_active resource doesn't support bundle.