aboutsummaryrefslogtreecommitdiffstats
path: root/docker/services/nova-api.yaml
blob: ee73f7049998dbca97fee639a241035955d66daf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
heat_template_version: pike

description: >
  OpenStack containerized Nova API service

parameters:
  DockerNovaApiImage:
    description: image
    type: string
  DockerNovaConfigImage:
    description: The container image to use for the nova config_volume
    type: string
  EndpointMap:
    default: {}
    description: Mapping of service endpoint -> protocol. Typically set
                 via parameter_defaults in the resource registry.
    type: json
  ServiceData:
    default: {}
    description: Dictionary packing service data
    type: json
  ServiceNetMap:
    default: {}
    description: Mapping of service_name -> network name. Typically set
                 via parameter_defaults in the resource registry.  This
                 mapping overrides those in ServiceNetMapDefaults.
    type: json
  DefaultPasswords:
    default: {}
    type: json
  RoleName:
    default: ''
    description: Role name on which the service is applied
    type: string
  RoleParameters:
    default: {}
    description: Parameters specific to the role
    type: json
  EnableInternalTLS:
    type: boolean
    default: false
  UpgradeRemoveUnusedPackages:
    default: false
    description: Remove package if the service is being disabled during upgrade
    type: boolean

conditions:

  internal_tls_enabled: {equals: [{get_param: EnableInternalTLS}, true]}

resources:

  ContainersCommon:
    type: ./containers-common.yaml

  MySQLClient:
    type: ../../puppet/services/database/mysql-client.yaml

  NovaApiBase:
    type: ../../puppet/services/nova-api.yaml
    properties:
      EndpointMap: {get_param: EndpointMap}
      ServiceData: {get_param: ServiceData}
      ServiceNetMap: {get_param: ServiceNetMap}
      DefaultPasswords: {get_param: DefaultPasswords}
      RoleName: {get_param: RoleName}
      RoleParameters: {get_param: RoleParameters}

outputs:
  role_data:
    description: Role data for the Nova API role.
    value:
      service_name: {get_attr: [NovaApiBase, role_data, service_name]}
      config_settings:
        map_merge:
          - get_attr: [NovaApiBase, role_data, config_settings]
          - apache::default_vhost: false
      logging_source: {get_attr: [NovaApiBase, role_data, logging_source]}
      logging_groups: {get_attr: [NovaApiBase, role_data, logging_groups]}
      step_config: &step_config
        list_join:
          - "\n"
          - - "['Nova_cell_v2'].each |String $val| { noop_resource($val) }"
            - {get_attr: [NovaApiBase, role_data, step_config]}
            - {get_attr: [MySQLClient, role_data, step_config]}
      service_config_settings: {get_attr: [NovaApiBase, role_data, service_config_settings]}
      # BEGIN DOCKER SETTINGS
      puppet_config:
        config_volume: nova
        puppet_tags: nova_config
        step_config: *step_config
        config_image: {get_param: DockerNovaConfigImage}
      kolla_config:
        /var/lib/kolla/config_files/nova_api.json:
          command: /usr/sbin/httpd -DFOREGROUND
          config_files:
            - source: "/var/lib/kolla/config_files/src/*"
              dest: "/"
              merge: true
              preserve_properties: true
          permissions:
            - path: /var/log/nova
              owner: nova:nova
              recurse: true
        /var/lib/kolla/config_files/nova_api_cron.json:
          command: /usr/sbin/crond -n
          config_files:
            - source: "/var/lib/kolla/config_files/src/*"
              dest: "/"
              merge: true
              preserve_properties: true
          permissions:
            - path: /var/log/nova
              owner: nova:nova
              recurse: true
      docker_config_scripts:
        nova_api_discover_hosts.sh:
          mode: "0700"
          content: |
            #!/bin/bash
            export OS_PROJECT_DOMAIN_NAME=$(crudini --get /etc/nova/nova.conf keystone_authtoken project_domain_name)
            export OS_USER_DOMAIN_NAME=$(crudini --get /etc/nova/nova.conf keystone_authtoken user_domain_name)
            export OS_PROJECT_NAME=$(crudini --get /etc/nova/nova.conf keystone_authtoken project_name)
            export OS_USERNAME=$(crudini --get /etc/nova/nova.conf keystone_authtoken username)
            export OS_PASSWORD=$(crudini --get /etc/nova/nova.conf keystone_authtoken password)
            export OS_AUTH_URL=$(crudini --get /etc/nova/nova.conf keystone_authtoken auth_url)
            export OS_AUTH_TYPE=password
            export OS_IDENTITY_API_VERSION=3

            echo "(cellv2) Running cell_v2 host discovery"
            timeout=600
            loop_wait=30
            declare -A discoverable_hosts
            for host in $(hiera -c /etc/puppet/hiera.yaml cellv2_discovery_hosts | sed -e '/^nil$/d' |  tr "," " "); do discoverable_hosts[$host]=1; done
            timeout_at=$(( $(date +"%s") + ${timeout} ))
            echo "(cellv2) Waiting ${timeout} seconds for hosts to register"
            finished=0
            while : ; do
              for host in $(openstack -q compute service list -c 'Host' -c 'Zone' -f value | awk '$2 != "internal" { print $1 }'); do
                if (( discoverable_hosts[$host] == 1 )); then
                  echo "(cellv2) compute node $host has registered"
                  unset discoverable_hosts[$host]
                fi
              done
              finished=1
              for host in "${!discoverable_hosts[@]}"; do
                if (( ${discoverable_hosts[$host]} == 1 )); then
                  echo "(cellv2) compute node $host has not registered"
                  finished=0
                fi
              done
              remaining=$(( $timeout_at - $(date +"%s") ))
              if (( $finished == 1 )); then
                echo "(cellv2) All nodes registered"
                break
              elif (( $remaining <= 0 )); then
                echo "(cellv2) WARNING: timeout waiting for nodes to register, running host discovery regardless"
                echo "(cellv2) Expected host list:" $(hiera -c /etc/puppet/hiera.yaml cellv2_discovery_hosts | sed -e '/^nil$/d' | sort -u |  tr ',' ' ')
                echo "(cellv2) Detected host list:" $(openstack -q compute service list -c 'Host' -c 'Zone' -f value | awk '$2 != "internal" { print $1 }' | sort -u | tr '\n', ' ')
                break
              else
                echo "(cellv2) Waiting ${remaining} seconds for hosts to register"
                sleep $loop_wait
              fi
            done
            echo "(cellv2) Running host discovery..."
            su nova -s /bin/bash -c "/usr/bin/nova-manage cell_v2 discover_hosts --verbose"
      docker_config:
        # db sync runs before permissions set by kolla_config
        step_2:
          nova_init_logs:
            image: &nova_api_image {get_param: DockerNovaApiImage}
            privileged: false
            user: root
            volumes:
              - /var/log/containers/nova:/var/log/nova
              - /var/log/containers/httpd/nova-api:/var/log/httpd
            command: ['/bin/bash', '-c', 'chown -R nova:nova /var/log/nova']
        step_3:
          nova_api_db_sync:
            start_order: 0
            image: *nova_api_image
            net: host
            detach: false
            user: root
            volumes: &nova_api_bootstrap_volumes
              list_concat:
                - {get_attr: [ContainersCommon, volumes]}
                -
                  - /var/lib/config-data/nova/etc/my.cnf.d/tripleo.cnf:/etc/my.cnf.d/tripleo.cnf:ro
                  - /var/lib/config-data/nova/etc/nova/:/etc/nova/:ro
                  - /var/log/containers/nova:/var/log/nova
                  - /var/log/containers/httpd/nova-api:/var/log/httpd
            command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage api_db sync'"
          # FIXME: we probably want to wait on the 'cell_v2 update' in order for this
          # to be capable of upgrading a baremetal setup. This is to ensure the name
          # of the cell is 'default'
          nova_api_map_cell0:
            start_order: 1
            image: *nova_api_image
            net: host
            detach: false
            user: root
            volumes: *nova_api_bootstrap_volumes
            command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage cell_v2 map_cell0'"
          nova_api_create_default_cell:
            start_order: 2
            image: *nova_api_image
            net: host
            detach: false
            volumes: *nova_api_bootstrap_volumes
            # NOTE: allowing the exit code 2 is a dirty way of making
            # this idempotent (if the resource already exists a conflict
            # is raised)
            exit_codes: [0,2]
            user: root
            command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage cell_v2 create_cell --name=default'"
          nova_db_sync:
            start_order: 3
            image: *nova_api_image
            net: host
            detach: false
            volumes: *nova_api_bootstrap_volumes
            user: root
            command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage db sync'"
        step_4:
          nova_api:
            start_order: 2
            image: *nova_api_image
            net: host
            user: root
            privileged: true
            restart: always
            volumes:
              list_concat:
                - {get_attr: [ContainersCommon, volumes]}
                -
                  - /var/lib/kolla/config_files/nova_api.json:/var/lib/kolla/config_files/config.json:ro
                  - /var/lib/config-data/puppet-generated/nova/:/var/lib/kolla/config_files/src:ro
                  - /var/log/containers/nova:/var/log/nova
                  - /var/log/containers/httpd/nova-api:/var/log/httpd
                  -
                    if:
                      - internal_tls_enabled
                      - /etc/pki/tls/certs/httpd:/etc/pki/tls/certs/httpd:ro
                      - ''
                  -
                    if:
                      - internal_tls_enabled
                      - /etc/pki/tls/private/httpd:/etc/pki/tls/private/httpd:ro
                      - ''
            environment:
              - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
          nova_api_cron:
            image: *nova_api_image
            net: host
            user: root
            privileged: false
            restart: always
            healthcheck:
              test: /bin/true
            volumes:
              list_concat:
                - {get_attr: [ContainersCommon, volumes]}
                -
                  - /var/lib/kolla/config_files/nova_api_cron.json:/var/lib/kolla/config_files/config.json:ro
                  - /var/lib/config-data/puppet-generated/nova/:/var/lib/kolla/config_files/src:ro
                  - /var/log/containers/nova:/var/log/nova
                  - /var/log/containers/httpd/nova-api:/var/log/httpd
            environment:
              - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
        step_5:
          nova_api_discover_hosts:
            start_order: 1
            image: *nova_api_image
            net: host
            detach: false
            volumes:
              list_concat:
                - *nova_api_bootstrap_volumes
                -
                  - /var/lib/config-data/nova/etc/my.cnf.d/tripleo.cnf:/etc/my.cnf.d/tripleo.cnf:ro
                  - /var/lib/config-data/nova/etc/nova/:/etc/nova/:ro
                  - /var/log/containers/nova:/var/log/nova
                  - /var/lib/docker-config-scripts/nova_api_discover_hosts.sh:/nova_api_discover_hosts.sh:ro
            user: root
            command: "/usr/bin/bootstrap_host_exec nova_api /nova_api_discover_hosts.sh"
      metadata_settings:
        get_attr: [NovaApiBase, role_data, metadata_settings]
      host_prep_tasks:
        - name: create persistent logs directory
          file:
            path: "{{ item }}"
            state: directory
          with_items:
            - /var/log/containers/nova
            - /var/log/containers/httpd/nova-api
      upgrade_tasks:
        - name: Stop and disable nova_api service
          tags: step2
          service: name=openstack-nova-api state=stopped enabled=no
        - name: Remove openstack-nova-api package if operator requests it
          yum: name=openstack-nova-api state=removed
          tags: step2
          ignore_errors: True
          when: {get_param: UpgradeRemoveUnusedPackages}
        - name: remove old nova cron jobs
          tags: step2
          file:
            path: /var/spool/cron/nova
            state: absent