Skip to content

Commit

Permalink
[nova] Merge cell update with db-migration
Browse files Browse the repository at this point in the history
We first need to create the api-database,
then we can update the cell-mapping
and then finally we can update the individual
cell databases (whereas cell0 is updated with cell1).

In order to orchestrate that, we place all those
operations in one script.
  • Loading branch information
fwiesel committed Jul 21, 2022
1 parent 328588d commit c1431cd
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 178 deletions.
2 changes: 0 additions & 2 deletions openstack/nova/templates/bin-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ data:
{{ include (print .Template.BasePath "/bin/_db-migrate.tpl") . | indent 4 }}
db-online-migrate: |
{{ include (print .Template.BasePath "/bin/_db-online-migrate.tpl") . | indent 4 }}
db-update-cells: |
{{ include (print .Template.BasePath "/bin/_db-update-cells.tpl") . | indent 4 }}
106 changes: 104 additions & 2 deletions openstack/nova/templates/bin/_db-migrate.tpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,111 @@
#!/usr/bin/env bash
set -e
set -x
set -euo pipefail

# First create/update the api db, as it contains the cell-mappings
nova-manage api_db sync

# Now update the cell-mappings
update_cell() {
cell_name="${1}"; shift
cell_uuid="${1}"; shift
transport_url="${1}"; shift
wanted_transport_url="${1}"; shift
database_connection="${1}"; shift
wanted_database_connection="${1}"; shift

needs_update="false"
if [ "${transport_url}" != "${wanted_transport_url}" ]; then
needs_update="true"
echo "Updating ${cell_name} transport-url..."
fi
if [ "${database_connection}" != "${wanted_database_connection}" ]; then
needs_update="true"
echo "Updating ${cell_name} database_connection..."
fi
if [ "${needs_update}" = "true" ]; then
nova-manage cell_v2 update_cell \
--cell_uuid ${cell_uuid} \
--transport-url "${wanted_transport_url}" \
--database_connection "${wanted_database_connection}"
fi
}


IFS=$'\n'
found_cell0="false"
found_cell1="false"
found_cell2="false"
for line in $(nova-manage cell_v2 list_cells --verbose | grep ':/'); do
cell_name=$(echo "$line" | cut -d'|' -f2 | tr -d '[:space:]')
cell_uuid=$(echo "$line" | cut -d'|' -f3 | tr -d '[:space:]')
transport_url=$(echo "$line" | cut -d'|' -f4 | tr -d '[:space:]')
database_connection=$(echo "$line" | cut -d'|' -f5 | tr -d '[:space:]')
echo "Processing Cell $cell_uuid"

if [ "${cell_name}" = "None" ]; then
echo "Renaming default cell to cell1"
nova-manage cell_v2 update_cell --cell_uuid $cell_uuid --name "cell1"
cell_name="cell1"
fi

case "${cell_name}" in
cell0)
found_cell0="true"
update_cell "${cell_name}" "${cell_uuid}" \
"${transport_url}" "none:/" \
"${database_connection}" "{{ include "cell0_db_path" . }}"
;;
cell1)
found_cell1="true"
update_cell "${cell_name}" "${cell_uuid}" \
"${transport_url}" "{{ tuple . .Values.rabbitmq | include "rabbitmq._transport_url" }}" \
"${database_connection}" "{{ tuple . .Values.dbName .Values.dbUser (default .Values.dbPassword .Values.global.dbPassword) | include "db_url_mysql" }}"
;;
{{ if .Values.cell2.enabled }}
{{.Values.cell2.name}})
found_cell2="true"
echo "Found existing cell2..."
update_cell "${cell_name}" "${cell_uuid}" \
"${transport_url}" "{{ include "cell2_transport_url" . }}" \
"${database_connection}" "{{ include "cell2_db_path" . }}"
;;
{{- end }}
esac
done

if [ "${found_cell0}" = "false" ]; then
echo "Creating cell0..."
nova-manage cell_v2 map_cell0 \
--database_connection "{{ include "cell0_db_path" . }}"
fi
if [ "${found_cell1}" = "false" ]; then
echo "Creating cell1..."
nova-manage cell_v2 create_cell --verbose \
--name "cell1" \
--transport-url "{{ tuple . .Values.rabbitmq | include "rabbitmq._transport_url" }}" \
--database_connection "{{ tuple . .Values.dbName .Values.dbUser (default .Values.dbPassword .Values.global.dbPassword) | include "db_url_mysql" }}"
nova-manage cell_v2 discover_hosts
fi

{{ if .Values.cell2.enabled }}
if [ "$found_cell2" = "false" ]; then
echo "Creating cell2..."
nova-manage cell_v2 create_cell --verbose \
--name "{{.Values.cell2.name}}" \
--transport-url "{{ include "cell2_transport_url" . }}" \
--database_connection "{{ include "cell2_db_path" . }}"
fi
{{- end }}

echo "Migrating cell0 and cell1"
nova-manage db sync
nova-manage db null_instance_uuid_scan --delete

{{- if .Values.cell2.enabled }}

echo "Migrating cell2"
nova-manage --config-file /etc/nova/nova-cell2.conf db sync --local_cell
nova-manage --config-file /etc/nova/nova-cell2.conf db null_instance_uuid_scan --delete
{{- end }}

# online data migration run by online-migration-job
6 changes: 2 additions & 4 deletions openstack/nova/templates/bin/_db-online-migrate.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/sh

set -x
set -e
#!/usr/bin/env bash
set -euxo pipefail

nova_manage="nova-manage --config-file /etc/nova/nova.conf"
available_commands_text=$(nova-manage --help | awk '/Command categories/ {getline; print $0}')
Expand Down
98 changes: 0 additions & 98 deletions openstack/nova/templates/bin/_db-update-cells.tpl

This file was deleted.

11 changes: 0 additions & 11 deletions openstack/nova/templates/cell2-conductor-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ spec:
{{ tuple . "nova" "conductor" | include "kubernetes_pod_anti_affinity" | indent 6 }}
terminationGracePeriodSeconds: {{ .Values.defaults.default.graceful_shutdown_timeout | add 5 }}
hostname: nova-conductor
initContainers:
- name: nova-db-sync
image: {{ required ".Values.global.registry is missing" .Values.global.registry}}/ubuntu-source-nova-api:{{.Values.imageVersionNovaApi | default .Values.imageVersionNova | default .Values.imageVersion | required "Please set nova.imageVersion or similar"}}
command: ['sh', '-c', 'nova-manage db sync --local_cell']
volumeMounts:
- mountPath: /etc/nova
name: etcnova
- mountPath: /etc/nova/nova.conf
name: nova-etc
subPath: nova-cell2.conf
readOnly: true
containers:
- name: nova-conductor
image: {{ required ".Values.global.registry is missing" .Values.global.registry}}/ubuntu-source-nova-conductor:{{.Values.imageVersionNovaConductor | default .Values.imageVersionNova | default .Values.imageVersion | required "Please set nova.imageVersion or similar"}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ spec:
name: nova-etc
subPath: api-paste.ini
readOnly: true
{{- if .Values.cell2.enabled }}
- mountPath: /etc/nova/nova-cell2.conf
name: nova-etc
subPath: nova-cell2.conf
readOnly: true
{{- end }}
{{- if .Values.audit.enabled }}
- mountPath: /etc/nova/nova_audit_map.yaml
name: nova-etc
Expand Down
61 changes: 0 additions & 61 deletions openstack/nova/templates/update-cells-job.yaml

This file was deleted.

0 comments on commit c1431cd

Please sign in to comment.