Merge "Remove baremetal cron jobs on docker upgrade"
[apex-tripleo-heat-templates.git] / docker / services / nova-api.yaml
1 heat_template_version: pike
2
3 description: >
4   OpenStack containerized Nova API service
5
6 parameters:
7   DockerNovaApiImage:
8     description: image
9     type: string
10   DockerNovaConfigImage:
11     description: The container image to use for the nova 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   EnableInternalTLS:
40     type: boolean
41     default: false
42
43 conditions:
44
45   internal_tls_enabled: {equals: [{get_param: EnableInternalTLS}, true]}
46
47 resources:
48
49   ContainersCommon:
50     type: ./containers-common.yaml
51
52   MySQLClient:
53     type: ../../puppet/services/database/mysql-client.yaml
54
55   NovaApiBase:
56     type: ../../puppet/services/nova-api.yaml
57     properties:
58       EndpointMap: {get_param: EndpointMap}
59       ServiceData: {get_param: ServiceData}
60       ServiceNetMap: {get_param: ServiceNetMap}
61       DefaultPasswords: {get_param: DefaultPasswords}
62       RoleName: {get_param: RoleName}
63       RoleParameters: {get_param: RoleParameters}
64
65 outputs:
66   role_data:
67     description: Role data for the Nova API role.
68     value:
69       service_name: {get_attr: [NovaApiBase, role_data, service_name]}
70       config_settings:
71         map_merge:
72           - get_attr: [NovaApiBase, role_data, config_settings]
73           - apache::default_vhost: false
74       step_config: &step_config
75         list_join:
76           - "\n"
77           - - "['Nova_cell_v2'].each |String $val| { noop_resource($val) }"
78             - {get_attr: [NovaApiBase, role_data, step_config]}
79             - {get_attr: [MySQLClient, role_data, step_config]}
80       service_config_settings: {get_attr: [NovaApiBase, role_data, service_config_settings]}
81       # BEGIN DOCKER SETTINGS
82       puppet_config:
83         config_volume: nova
84         puppet_tags: nova_config
85         step_config: *step_config
86         config_image: {get_param: DockerNovaConfigImage}
87       kolla_config:
88         /var/lib/kolla/config_files/nova_api.json:
89           command: /usr/sbin/httpd -DFOREGROUND
90           config_files:
91             - source: "/var/lib/kolla/config_files/src/*"
92               dest: "/"
93               merge: true
94               preserve_properties: true
95           permissions:
96             - path: /var/log/nova
97               owner: nova:nova
98               recurse: true
99         /var/lib/kolla/config_files/nova_api_cron.json:
100           command: /usr/sbin/crond -n
101           config_files:
102             - source: "/var/lib/kolla/config_files/src/*"
103               dest: "/"
104               merge: true
105               preserve_properties: true
106           permissions:
107             - path: /var/log/nova
108               owner: nova:nova
109               recurse: true
110       docker_config:
111         # db sync runs before permissions set by kolla_config
112         step_2:
113           nova_init_logs:
114             image: &nova_api_image {get_param: DockerNovaApiImage}
115             privileged: false
116             user: root
117             volumes:
118               - /var/log/containers/nova:/var/log/nova
119             command: ['/bin/bash', '-c', 'mkdir -p /var/log/httpd; chown -R nova:nova /var/log/nova']
120         step_3:
121           nova_api_db_sync:
122             start_order: 0
123             image: *nova_api_image
124             net: host
125             detach: false
126             user: root
127             volumes: &nova_api_bootstrap_volumes
128               list_concat:
129                 - {get_attr: [ContainersCommon, volumes]}
130                 -
131                   - /var/lib/config-data/nova/etc/my.cnf.d/tripleo.cnf:/etc/my.cnf.d/tripleo.cnf:ro
132                   - /var/lib/config-data/nova/etc/nova/:/etc/nova/:ro
133                   - /var/log/containers/nova:/var/log/nova
134             command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage api_db sync'"
135           # FIXME: we probably want to wait on the 'cell_v2 update' in order for this
136           # to be capable of upgrading a baremetal setup. This is to ensure the name
137           # of the cell is 'default'
138           nova_api_map_cell0:
139             start_order: 1
140             image: *nova_api_image
141             net: host
142             detach: false
143             user: root
144             volumes: *nova_api_bootstrap_volumes
145             command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage cell_v2 map_cell0'"
146           nova_api_create_default_cell:
147             start_order: 2
148             image: *nova_api_image
149             net: host
150             detach: false
151             volumes: *nova_api_bootstrap_volumes
152             # NOTE: allowing the exit code 2 is a dirty way of making
153             # this idempotent (if the resource already exists a conflict
154             # is raised)
155             exit_codes: [0,2]
156             user: root
157             command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage cell_v2 create_cell --name=default'"
158           nova_db_sync:
159             start_order: 3
160             image: *nova_api_image
161             net: host
162             detach: false
163             volumes: *nova_api_bootstrap_volumes
164             user: root
165             command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage db sync'"
166         step_4:
167           nova_api:
168             start_order: 2
169             image: *nova_api_image
170             net: host
171             user: root
172             privileged: true
173             restart: always
174             volumes:
175               list_concat:
176                 - {get_attr: [ContainersCommon, volumes]}
177                 -
178                   - /var/lib/kolla/config_files/nova_api.json:/var/lib/kolla/config_files/config.json:ro
179                   - /var/lib/config-data/puppet-generated/nova/:/var/lib/kolla/config_files/src:ro
180                   - /var/log/containers/nova:/var/log/nova
181                   -
182                     if:
183                       - internal_tls_enabled
184                       - /etc/pki/tls/certs/httpd:/etc/pki/tls/certs/httpd:ro
185                       - ''
186                   -
187                     if:
188                       - internal_tls_enabled
189                       - /etc/pki/tls/private/httpd:/etc/pki/tls/private/httpd:ro
190                       - ''
191             environment:
192               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
193           nova_api_cron:
194             image: *nova_api_image
195             net: host
196             user: root
197             privileged: false
198             restart: always
199             volumes:
200               list_concat:
201                 - {get_attr: [ContainersCommon, volumes]}
202                 -
203                   - /var/lib/kolla/config_files/nova_api_cron.json:/var/lib/kolla/config_files/config.json:ro
204                   - /var/lib/config-data/puppet-generated/nova/:/var/lib/kolla/config_files/src:ro
205                   - /var/log/containers/nova:/var/log/nova
206             environment:
207               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
208         step_5:
209           nova_api_discover_hosts:
210             start_order: 1
211             image: *nova_api_image
212             net: host
213             detach: false
214             volumes: *nova_api_bootstrap_volumes
215             user: root
216             command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage cell_v2 discover_hosts'"
217       metadata_settings:
218         get_attr: [NovaApiBase, role_data, metadata_settings]
219       host_prep_tasks:
220         - name: create persistent logs directory
221           file:
222             path: /var/log/containers/nova
223             state: directory
224       upgrade_tasks:
225         - name: Stop and disable nova_api service
226           tags: step2
227           service: name=openstack-nova-api state=stopped enabled=no
228         - name: remove old nova cron jobs
229           file:
230             path: /var/spool/cron/nova
231             state: absent