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