From 732bf83800f4d76c91daca858c61594bb453f88e Mon Sep 17 00:00:00 2001 From: Bohdan Dobrelia Date: Fri, 6 Dec 2024 17:17:47 +0100 Subject: [PATCH] Refactor comments in commands into asciidocs native Illustrate how commands in scripts could have comments that become (almost as is) native ascii docs foot-notes. When copying code into docs, the minimal adjustments will be needed, like adding '$' prefix (or '>' for multiline commands). Signed-off-by: Bohdan Dobrelia --- ...rating-databases-to-mariadb-instances.adoc | 359 +++++++++--------- ...pology-specific-service-configuration.adoc | 125 +++--- .../roles/common_defaults/defaults/main.yaml | 8 +- .../mariadb_copy/templates/post_checks.bash | 26 +- .../mariadb_copy/templates/restore_dbs.bash | 34 +- 5 files changed, 281 insertions(+), 271 deletions(-) diff --git a/docs_user/modules/proc_migrating-databases-to-mariadb-instances.adoc b/docs_user/modules/proc_migrating-databases-to-mariadb-instances.adoc index 81efd0b6f..f7036c946 100644 --- a/docs_user/modules/proc_migrating-databases-to-mariadb-instances.adoc +++ b/docs_user/modules/proc_migrating-databases-to-mariadb-instances.adoc @@ -18,77 +18,75 @@ Migrate your databases from the original {rhos_prev_long} ({OpenStackShort}) dep + ---- ifeval::["{build}" != "downstream"] -STORAGE_CLASS=local-storage -MARIADB_IMAGE=quay.io/podified-antelope-centos9/openstack-mariadb:current-podified +$ STORAGE_CLASS=local-storage +$ MARIADB_IMAGE=quay.io/podified-antelope-centos9/openstack-mariadb:current-podified endif::[] ifeval::["{build}" == "downstream"] -STORAGE_CLASS=local-storage -MARIADB_IMAGE=registry.redhat.io/rhosp-dev-preview/openstack-mariadb-rhel9:18.0 +$ STORAGE_CLASS=local-storage +$ MARIADB_IMAGE=registry.redhat.io/rhosp-dev-preview/openstack-mariadb-rhel9:18.0 endif::[] -CELLS="default cell1 cell2" -DEFAULT_CELL_NAME="cell3" -RENAMED_CELLS="cell1 cell2 $DEFAULT_CELL_NAME" - -NAMESPACE="openstack" - -# The CHARACTER_SET and collation should match the source DB -# if the do not then it will break foreign key relationships -# for any tables that are created in the future as part of db sync -CHARACTER_SET=utf8 -COLLATION=utf8_general_ci - -declare -A PODIFIED_DB_ROOT_PASSWORD -for CELL in $(echo "super $RENAMED_CELLS"); do - PODIFIED_DB_ROOT_PASSWORD[$CELL]=$(oc get -o json secret/osp-secret | jq -r .data.DbRootPassword | base64 -d) -done - -declare -A PODIFIED_MARIADB_IP -for CELL in $(echo "super $RENAMED_CELLS"); do - if [ "$CELL" = "super" ]; then - PODIFIED_MARIADB_IP[$CELL]=$(oc get svc --selector "mariadb/name=openstack" -ojsonpath='{.items[0].spec.clusterIP}') - else - PODIFIED_MARIADB_IP[$CELL]=$(oc get svc --selector "mariadb/name=openstack-$CELL" -ojsonpath='{.items[0].spec.clusterIP}') - fi -done - -declare -A TRIPLEO_PASSWORDS -for CELL in $(echo $CELLS); do - if [ "$CELL" = "default" ]; then - TRIPLEO_PASSWORDS[default]="$HOME/overcloud-passwords.yaml" - else - # in a split-stack source cloud, it should take a stack-specific passwords file instead - TRIPLEO_PASSWORDS[$CELL]="$HOME/overcloud-passwords.yaml" - fi -done - -declare -A SOURCE_DB_ROOT_PASSWORD -for CELL in $(echo $CELLS); do - SOURCE_DB_ROOT_PASSWORD[$CELL]=$(cat ${TRIPLEO_PASSWORDS[$CELL]} | grep ' MysqlRootPassword:' | awk -F ': ' '{ print $2; }') -done - -declare -A SOURCE_MARIADB_IP -SOURCE_MARIADB_IP[default]=** -SOURCE_MARIADB_IP[cell1]=** -SOURCE_MARIADB_IP[cell2]=** -# ... +$ CELLS="default cell1 cell2" +$ DEFAULT_CELL_NAME="cell3" +$ RENAMED_CELLS="cell1 cell2 $DEFAULT_CELL_NAME" + +$ NAMESPACE="openstack" + +$ CHARACTER_SET=utf8 # <1> +$ COLLATION=utf8_general_ci + +$ declare -A PODIFIED_DB_ROOT_PASSWORD +$ for CELL in $(echo "super $RENAMED_CELLS"); do +> PODIFIED_DB_ROOT_PASSWORD[$CELL]=$(oc get -o json secret/osp-secret | jq -r .data.DbRootPassword | base64 -d) +> done + +$ declare -A PODIFIED_MARIADB_IP +$ for CELL in $(echo "super $RENAMED_CELLS"); do +> if [ "$CELL" = "super" ]; then +> PODIFIED_MARIADB_IP[$CELL]=$(oc get svc --selector "mariadb/name=openstack" -ojsonpath='{.items[0].spec.clusterIP}') +> else +> PODIFIED_MARIADB_IP[$CELL]=$(oc get svc --selector "mariadb/name=openstack-$CELL" -ojsonpath='{.items[0].spec.clusterIP}') +> fi +> done -declare -A SOURCE_GALERA_MEMBERS_DEFAULT -SOURCE_GALERA_MEMBERS_DEFAULT=( - ["standalone.localdomain"]=172.17.0.100 - # [...]=... -) -declare -A SOURCE_GALERA_MEMBERS_CELL1 -SOURCE_GALERA_MEMBERS_CELL1=( - # ... -) -declare -A SOURCE_GALERA_MEMBERS_CELL2 -SOURCE_GALERA_MEMBERS_CELL2=( - # ... -) +$ declare -A TRIPLEO_PASSWORDS +$ for CELL in $(echo $CELLS); do +> if [ "$CELL" = "default" ]; then +> TRIPLEO_PASSWORDS[default]="$HOME/overcloud-passwords.yaml" +> else +> # in a split-stack source cloud, it should take a stack-specific passwords file instead +> TRIPLEO_PASSWORDS[$CELL]="$HOME/overcloud-passwords.yaml" +> fi +> done + +$ declare -A SOURCE_DB_ROOT_PASSWORD +$ for CELL in $(echo $CELLS); do +> SOURCE_DB_ROOT_PASSWORD[$CELL]=$(cat ${TRIPLEO_PASSWORDS[$CELL]} | grep ' MysqlRootPassword:' | awk -F ': ' '{ print $2; }') +> done + +$ declare -A SOURCE_MARIADB_IP +$ SOURCE_MARIADB_IP[default]=** +$ SOURCE_MARIADB_IP[cell1]=** +$ SOURCE_MARIADB_IP[cell2]=** # ... + +$ declare -A SOURCE_GALERA_MEMBERS_DEFAULT +$ SOURCE_GALERA_MEMBERS_DEFAULT=( +> ["standalone.localdomain"]=172.17.0.100 +> # [...]=... +> ) +$ declare -A SOURCE_GALERA_MEMBERS_CELL1 +$ SOURCE_GALERA_MEMBERS_CELL1=( +> # ... +> ) +$ declare -A SOURCE_GALERA_MEMBERS_CELL2 +$ SOURCE_GALERA_MEMBERS_CELL2=( +> # ... +> ) ---- + +<1> The CHARACTER_SET and collation should match the source DB, if the do not then it will break foreign key relationships for any tables that are created in the future as part of db sync. + Here, `CELLS` and `RENAMED_CELLS` represent changes that are going to be made after importing databases: the `default` cell takes a new name from `DEFAULT_CELL_NAME`. In a multi-cell adoption scenario, it may retain its original 'default' name as well. @@ -187,16 +185,16 @@ $ oc wait --for condition=Ready pod/mariadb-copy-data --timeout=30s . Check that the source Galera database cluster(s) members are online and synced: + ---- -for CELL in $(echo $CELLS); do - MEMBERS=SOURCE_GALERA_MEMBERS_$(echo ${CELL}|tr '[:lower:]' '[:upper:]')[@] - for i in "${!MEMBERS}"; do - echo "Checking for the database node $i WSREP status Synced" - oc rsh mariadb-copy-data mysql \ - -h "$i" -uroot -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" \ - -e "show global status like 'wsrep_local_state_comment'" | \ - grep -qE "\bSynced\b" - done -done +$ for CELL in $(echo $CELLS); do +> MEMBERS=SOURCE_GALERA_MEMBERS_$(echo ${CELL}|tr '[:lower:]' '[:upper:]')[@] +> for i in "${!MEMBERS}"; do +> echo "Checking for the database node $i WSREP status Synced" +> oc rsh mariadb-copy-data mysql \ +> -h "$i" -uroot -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" \ +> -e "show global status like 'wsrep_local_state_comment'" | \ +> grep -qE "\bSynced\b" +> done +> done ---- + Each additional Nova v2 cell runs a dedicated Galera database cluster, so the checking is done for all of it. @@ -204,29 +202,29 @@ Each additional Nova v2 cell runs a dedicated Galera database cluster, so the ch . Get the count of source databases with the `NOK` (not-OK) status: + ---- -for CELL in $(echo $CELLS); do - oc rsh mariadb-copy-data mysql -h "${SOURCE_MARIADB_IP[$CELL]}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" -e "SHOW databases;" -end +$ for CELL in $(echo $CELLS); do +> oc rsh mariadb-copy-data mysql -h "${SOURCE_MARIADB_IP[$CELL]}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" -e "SHOW databases;" +> end ---- . Check that `mysqlcheck` had no errors: + ---- $ for CELL in $(echo $CELLS); do - set +u - . ~/.source_cloud_exported_variables_$CELL - set -u -done +> set +u +> . ~/.source_cloud_exported_variables_$CELL +> set -u +> done $ test -z "$PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK" || [ "x$PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK" = "x " ] && echo "OK" || echo "CHECK FAILED" ---- . Test the connection to the control plane "upcall" and cells' databases: + ---- -for CELL in $(echo "super $RENAMED_CELLS"); do - oc run mariadb-client -n $NAMESPACE --image $MARIADB_IMAGE -i --rm --restart=Never -- \ - mysql -rsh "${PODIFIED_MARIADB_IP[$CELL]}" -uroot -p"${PODIFIED_DB_ROOT_PASSWORD[$CELL]}" -e 'SHOW databases;' -done +$ for CELL in $(echo "super $RENAMED_CELLS"); do +> oc run mariadb-client -n $NAMESPACE --image $MARIADB_IMAGE -i --rm --restart=Never -- \ +> mysql -rsh "${PODIFIED_MARIADB_IP[$CELL]}" -uroot -p"${PODIFIED_DB_ROOT_PASSWORD[$CELL]}" -e 'SHOW databases;' +> done ---- + [NOTE] @@ -236,17 +234,17 @@ You must transition {compute_service_first_ref} services that are imported later + ---- $ for CELL in $(echo $CELLS); do - oc rsh mariadb-copy-data << EOF - mysql -h"${SOURCE_MARIADB_IP[$CELL]}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" \ - -N -e "show databases" | grep -E -v "schema|mysql|gnocchi|aodh" | \ - while read dbname; do - echo "Dumping $CELL cell \${dbname}"; - mysqldump -h"${SOURCE_MARIADB_IP[$CELL]}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" \ - --single-transaction --complete-insert --skip-lock-tables --lock-tables=0 \ - "\${dbname}" > /backup/"${CELL}.\${dbname}".sql; - done -EOF -done +> oc rsh mariadb-copy-data << EOF +> mysql -h"${SOURCE_MARIADB_IP[$CELL]}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" \ +> -N -e "show databases" | grep -E -v "schema|mysql|gnocchi|aodh" | \ +> while read dbname; do +> echo "Dumping $CELL cell \${dbname}"; +> mysqldump -h"${SOURCE_MARIADB_IP[$CELL]}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" \ +> --single-transaction --complete-insert --skip-lock-tables --lock-tables=0 \ +> "\${dbname}" > /backup/"${CELL}.\${dbname}".sql; +> done +> EOF +> done ---- + Note filtering the information and performance schema tables. @@ -256,58 +254,72 @@ Gnocchi is no longer used as a metric store as well + ---- $ for CELL in $(echo $CELLS); do - RCELL=$CELL - [ "$CELL" = "default" ] && RCELL=$DEFAULT_CELL_NAME - oc rsh mariadb-copy-data << EOF - oc rsh -n $NAMESPACE mariadb-copy-data << EOF - - declare -A db_name_map - db_name_map['nova']="nova_$RCELL" - db_name_map['ovs_neutron']='neutron' - db_name_map['ironic-inspector']='ironic_inspector' - - declare -A db_server_map - db_server_map['default']=${PODIFIED_MARIADB_IP['super']} - db_server_map["nova_$RCELL"]=${PODIFIED_MARIADB_IP[$RCELL]} - - declare -A db_server_password_map - db_server_password_map['default']=${PODIFIED_DB_ROOT_PASSWORD['super']} - db_server_password_map["nova_$RCELL"]=${PODIFIED_DB_ROOT_PASSWORD[$RCELL]} - - cd /backup - for db_file in \$(ls ${CELL}.*.sql); do - db_name=\$(echo \${db_file} | awk -F'.' '{ print \$2; }') - renamed_db_file="${RCELL}_new.\${db_name}.sql" - mv -f \${db_file} \${renamed_db_file} - if [[ -v "db_name_map[\${db_name}]" ]]; then - echo "renaming $CELL cell \${db_name} to $RCELL \${db_name_map[\${db_name}]}" - db_name=\${db_name_map[\${db_name}]} - fi - db_server=\${db_server_map["default"]} - if [[ -v "db_server_map[\${db_name}]" ]]; then - db_server=\${db_server_map[\${db_name}]} - fi - db_password=\${db_server_password_map['default']} - if [[ -v "db_server_password_map[\${db_name}]" ]]; then - db_password=\${db_server_password_map[\${db_name}]} - fi - echo "creating $RCELL cell \${db_name} in \${db_server}" - mysql -h"\${db_server}" -uroot "-p\${db_password}" -e \ - "CREATE DATABASE IF NOT EXISTS \${db_name} DEFAULT \ - CHARACTER SET ${CHARACTER_SET} DEFAULT COLLATE ${COLLATION};" - echo "importing $RCELL cell \${db_name} into \${db_server} from \${renamed_db_file}" - mysql -h "\${db_server}" -uroot "-p\${db_password}" "\${db_name}" < "\${renamed_db_file}" - done - - if [ "$CELL" = "default" ] ; then - mysql -h "\${db_server_map['default']}" -uroot -p"\${db_server_password_map['default']}" -e \ - "update nova_api.cell_mappings set name='$DEFAULT_CELL_NAME' where name='default';" - fi - mysql -h "\${db_server_map["nova_$RCELL"]}" -uroot -p"\${db_server_password_map["nova_$RCELL"]}" -e \ - "delete from nova_${RCELL}.services where host not like '%nova_${RCELL}-%' and services.binary != 'nova-compute';" -EOF -done +> RCELL=$CELL +> [ "$CELL" = "default" ] && RCELL=$DEFAULT_CELL_NAME +> oc rsh -n $NAMESPACE mariadb-copy-data << EOF +> declare -A db_name_map <1> +> db_name_map['nova']="nova_$RCELL" +> db_name_map['ovs_neutron']='neutron' +> db_name_map['ironic-inspector']='ironic_inspector' +> declare -A db_cell_map <2> +> db_cell_map['nova']="nova_$DEFAULT_CELL_NAME" +> db_cell_map["nova_$RCELL"]="nova_$RCELL" <3> +> declare -A db_server_map <4> +> db_server_map['default']=${PODIFIED_MARIADB_IP['super']} +> db_server_map["nova"]=${PODIFIED_MARIADB_IP[$DEFAULT_CELL_NAME]} +> db_server_map["nova_$RCELL"]=${PODIFIED_MARIADB_IP[$RCELL]} +> declare -A db_server_password_map <5> +> db_server_password_map['default']=${PODIFIED_DB_ROOT_PASSWORD['super']} +> db_server_password_map["nova"]=${PODIFIED_DB_ROOT_PASSWORD[$DEFAULT_CELL_NAME]} +> db_server_password_map["nova_$RCELL"]=${PODIFIED_DB_ROOT_PASSWORD[$RCELL]} +> cd /backup +> for db_file in \$(ls ${CELL}.*.sql); do +> db_name=\$(echo \${db_file} | awk -F'.' '{ print \$2; }') +> [[ "$CELL" != "default" && ! -v "db_cell_map[\${db_name}]" ]] && continue +> if [[ "$CELL" == "default" && -v "db_cell_map[\${db_name}]" ]] ; then +> target=$DEFAULT_CELL_NAME +> elif [[ "$CELL" == "default" && ! -v "db_cell_map[\${db_name}]" ]] ; then +> target=super +> else +> target=$RCELL +> fi <6> +> renamed_db_file="\${target}_new.\${db_name}.sql" +> mv -f \${db_file} \${renamed_db_file} +> if [[ -v "db_name_map[\${db_name}]" ]]; then +> echo "renaming $CELL cell \${db_name} to \$target \${db_name_map[\${db_name}]}" +> db_name=\${db_name_map[\${db_name}]} +> fi +> db_server=\${db_server_map["default"]} +> if [[ -v "db_server_map[\${db_name}]" ]]; then +> db_server=\${db_server_map[\${db_name}]} +> fi +> db_password=\${db_server_password_map['default']} +> if [[ -v "db_server_password_map[\${db_name}]" ]]; then +> db_password=\${db_server_password_map[\${db_name}]} +> fi +> echo "creating $CELL cell \${db_name} in \$target \${db_server}" +> mysql -h"\${db_server}" -uroot "-p\${db_password}" -e \ +> "CREATE DATABASE IF NOT EXISTS \${db_name} DEFAULT \ +> CHARACTER SET ${CHARACTER_SET} DEFAULT COLLATE ${COLLATION};" +> echo "importing $CELL cell \${db_name} into \$target \${db_server} from \${renamed_db_file}" +> mysql -h "\${db_server}" -uroot "-p\${db_password}" "\${db_name}" < "\${renamed_db_file}" +> done +> if [ "$CELL" = "default" ] ; then +> mysql -h "\${db_server_map['default']}" -uroot -p"\${db_server_password_map['default']}" -e \ +> "update nova_api.cell_mappings set name='$DEFAULT_CELL_NAME' where name='default';" +> fi +> mysql -h "\${db_server_map["nova_$RCELL"]}" -uroot -p"\${db_server_password_map["nova_$RCELL"]}" -e \ +> "delete from nova_${RCELL}.services where host not like '%nova_${RCELL}-%' and services.binary != 'nova-compute';" +> EOF +> done ---- ++ +<1> Defines which common databases to rename, when importing it +<2> Defines which cells' databases to import, and how to rename it, if needed. +<3> Omits importing cells' special `cell0` databases as we cannot consolidate its contents during adoption. +<4> Defines which databases to import into which servers (usually dedicated for cells). +<5> Defines root passwords map for database servers (we can only use the same password for now). +<6> Asigns which databases to import into which hosts, when extracting databases from `default` cell. .Verification @@ -320,39 +332,48 @@ For more information, see xref:proc_retrieving-topology-specific-service-configu $ set +u $ . ~/.source_cloud_exported_variables_default $ set -u -$ dbs=$(oc exec openstack-galera-0 -c galera -- mysql -rs -uroot -p"${PODIFIED_DB_ROOT_PASSWORD['super']}" -e 'SHOW databases;') +$ dbs=$(oc exec openstack-galera-0 -n $NAMESPACE -c galera -- mysql -rs -uroot -p"${PODIFIED_DB_ROOT_PASSWORD['super']}" -e 'SHOW databases;') $ echo $dbs | grep -Eq '\bkeystone\b' && echo "OK" || echo "CHECK FAILED" $ echo $dbs | grep -Eq '\bneutron\b' -$ echo "${PULL_OPENSTACK_CONFIGURATION_DATABASES[@]}" | grep -Eq '\bovs_neutron\b' && echo "OK" || echo "CHECK FAILED" -$ novadb_mapped_cells=$(oc exec openstack-galera-0 -c galera -- mysql -rs -uroot -p"${PODIFIED_DB_ROOT_PASSWORD['super']}" \ - nova_api -e 'select uuid,name,transport_url,database_connection,disabled from cell_mappings;') +$ echo "${PULL_OPENSTACK_CONFIGURATION_DATABASES[@]}" | grep -Eq '\bovs_neutron\b' && echo "OK" || echo "CHECK FAILED" <1> +$ novadb_mapped_cells=$(oc exec openstack-galera-0 -n $NAMESPACE -c galera -- mysql -rs -uroot -p"${PODIFIED_DB_ROOT_PASSWORD['super']}" \ +> nova_api -e 'select uuid,name,transport_url,database_connection,disabled from cell_mappings;') <2> $ uuidf='\S{8,}-\S{4,}-\S{4,}-\S{4,}-\S{12,}' $ left_behind=$(comm -23 \ - <(echo $PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS | grep -oE " $uuidf \S+") \ - <(echo $novadb_mapped_cells | tr -s "| " " " | grep -oE " $uuidf \S+")) +> <(echo $PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS | grep -oE " $uuidf \S+") \ +> <(echo $novadb_mapped_cells | tr -s "| " " " | grep -oE " $uuidf \S+")) $ changed=$(comm -13 \ - <(echo $PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS | grep -oE " $uuidf \S+") \ - <(echo $novadb_mapped_cells | tr -s "| " " " | grep -oE " $uuidf \S+")) +> <(echo $PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS | grep -oE " $uuidf \S+") \ +> <(echo $novadb_mapped_cells | tr -s "| " " " | grep -oE " $uuidf \S+")) $ test $(grep -Ec ' \S+$' <<<$left_behind) -eq 1 && echo "OK" || echo "CHECK FAILED" $ default=$(grep -E ' default$' <<<$left_behind) $ test $(grep -Ec ' \S+$' <<<$changed) -eq 1 && echo "OK" || echo "CHECK FAILED" $ grep -qE " $(awk '{print $1}' <<<$default) ${DEFAULT_CELL_NAME}$" <<<$changed && echo "OK" || echo "CHECK FAILED" - -# TODO align with tests -$ for CELL in $(echo $CELLS); do - set +u - . ~/.source_cloud_exported_variables_$CELL - set -u - RCELL=$CELL - [ "$CELL" = "default" ] && RCELL=$DEFAULT_CELL_NAME - c1dbs=$(oc exec openstack-$RCELL-galera-0 -n $NAMESPACE -c galera -- mysql -rs -uroot -p${PODIFIED_DB_ROOT_PASSWORD[$RCELL]} -e 'SHOW databases;') - echo $c1dbs | grep -Eq "\bnova_${RCELL}\b" && echo "OK" || echo "CHECK FAILED" - - novadb_svc_records=$(oc exec openstack-$RCELL-galera-0 -n $NAMESPACE -c galera -- mysql -rs -uroot -p${PODIFIED_DB_ROOT_PASSWORD[$RCELL]} \ - nova_$RCELL -e "select host from services where services.binary='nova-compute' order by host asc;") - diff -Z <(echo $novadb_svc_records) <(echo ${PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES[$RCELL]}) && echo "OK" || echo "CHECK FAILED" -done +$ for CELL in $(echo $RENAMED_CELLS); do <3> +> unset PULL_OPENSTACK_CONFIGURATION_DATABASES +> unset PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK +> unset PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES +> declare -A PULL_OPENSTACK_CONFIGURATION_DATABASES +> declare -A PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK +> declare -A PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES +> RCELL=$CELL +> [ "$CELL" = "$DEFAULT_CELL_NAME" ] && RCELL=default +> set +u +> . ~/.source_cloud_exported_variables_$RCELL +> set -u +> c1dbs=$(oc exec openstack-$CELL-galera-0 -n $NAMESPACE -c galera -- mysql -rs -uroot -p${PODIFIED_DB_ROOT_PASSWORD[$CELL]} -e 'SHOW databases;') <4> +> echo $c1dbs | grep -Eq "\bnova_${CELL}\b" && echo "OK" || echo "CHECK FAILED" +> novadb_svc_records=$(oc exec openstack-$CELL-galera-0 -n $NAMESPACE -c galera -- mysql -rs -uroot -p${PODIFIED_DB_ROOT_PASSWORD[$CELL]} \ +> nova_$CELL -e "select host from services where services.binary='nova-compute' order by host asc;") +> diff -Z <(echo "x$novadb_svc_records") <(echo "x${PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES[@]}") && echo "OK" || echo "CHECK FAILED" <5> +> done ---- ++ +<1> Ensures Neutron database is renamed from `ovs_neutron` +<2> Ensures `default`` cell is renamed to `$DEFAULT_CELL_NAME``, and the cell UUIDs retained intact +<3> Ensures the registered Compute services names have not changed +<4> Ensures Nova cells' DBs are extracted to separate database servers, and renamed from nova to nova_cell +<5> Ensures the registered Compute service name has not changed . Delete the `mariadb-data` pod and the `mariadb-copy-data` persistent volume claim that contains the database backup: + diff --git a/docs_user/modules/proc_retrieving-topology-specific-service-configuration.adoc b/docs_user/modules/proc_retrieving-topology-specific-service-configuration.adoc index a6df7f37c..a3b2d7d7d 100644 --- a/docs_user/modules/proc_retrieving-topology-specific-service-configuration.adoc +++ b/docs_user/modules/proc_retrieving-topology-specific-service-configuration.adoc @@ -25,19 +25,19 @@ $ declare -A TRIPLEO_PASSWORDS ifeval::["{OpenStackPreviousInstaller}" != "director_operator"] $ CELLS="default cell1 cell2" $ for CELL in $(echo $CELLS); do - TRIPLEO_PASSWORDS[$CELL]="$TRIPLEO_PASSWORD" -done +> TRIPLEO_PASSWORDS[$CELL]="$PASSWORD_FILE" +> done endif::[] ifeval::["{OpenStackPreviousInstaller}" == "director_operator"] $ CELLS="default" $ for CELL in $(echo $CELLS); do - oc get secret tripleo-passwords -n $NAMESPACE -o json | jq -r '.data["tripleo-overcloud-passwords.yaml"]' | base64 -d >"$TRIPLEO_PASSWORDS[$CELL]" -done +> oc get secret tripleo-passwords -n $NAMESPACE -o json | jq -r '.data["tripleo-overcloud-passwords.yaml"]' | base64 -d >"$TRIPLEO_PASSWORDS[$CELL]" +> done endif::[] $ declare -A SOURCE_DB_ROOT_PASSWORD $ for CELL in $(echo $CELLS); do - SOURCE_DB_ROOT_PASSWORD[$CELL]=$(cat ${TRIPLEO_PASSWORDS[$CELL]} | grep ' MysqlRootPassword:' | awk -F ': ' '{ print $2; }') -done +> SOURCE_DB_ROOT_PASSWORD[$CELL]=$(cat ${TRIPLEO_PASSWORDS[$CELL]} | grep ' MysqlRootPassword:' | awk -F ': ' '{ print $2; }') +> done ---- + ifeval::["{OpenStackPreviousInstaller}" == "director_operator"] @@ -57,29 +57,29 @@ $ export SOURCE_OVN_OVSDB_IP=172.17.0.160 # get this from the source OVN DB $ cpexport=$(oc -n "${NAMESPACE}" get cm tripleo-exports-default -o json | jq -r '.data["ctlplane-export.yaml"]') $ declare -A SOURCE_MARIADB_IP $ for CELL in $(echo $CELLS); do - SOURCE_MARIADB_IP[$CELL]=$(echo "$cpexport" | sed -e '0,/ MysqlInternal/d' | sed -n '0,/host_nobrackets/s/^.*host_nobrackets\:\s*\(.*\)$/\1/p') -done +> SOURCE_MARIADB_IP[$CELL]=$(echo "$cpexport" | sed -e '0,/ MysqlInternal/d' | sed -n '0,/host_nobrackets/s/^.*host_nobrackets\:\s*\(.*\)$/\1/p') +> done $ RUN_OVERRIDES='{ - "apiVersion": "v1", - "metadata": { - "annotations": { - "k8s.v1.cni.cncf.io/networks": "[{\"name\": \"internalapi-static\",\"namespace\": \"openstack\", \"ips\":[\"172.17.0.99/24\"]}]" - } - }, - "spec": { - "nodeName": "'"$CONTROLLER_NODE"'", - "securityContext": { - "allowPrivilegeEscalation": false, - "capabilities": { - "drop": ["ALL"] - }, - "runAsNonRoot": true, - "seccompProfile": { - "type": "RuntimeDefault" - } - } - } -}' +> "apiVersion": "v1", +> "metadata": { +> "annotations": { +> "k8s.v1.cni.cncf.io/networks": "[{\"name\": \"internalapi-static\",\"namespace\": \"openstack\", \"ips\":[\"172.17.0.99/24\"]}]" +> } +> }, +> "spec": { +> "nodeName": "'"$CONTROLLER_NODE"'", +> "securityContext": { +> "allowPrivilegeEscalation": false, +> "capabilities": { +> "drop": ["ALL"] +> }, +> "runAsNonRoot": true, +> "seccompProfile": { +> "type": "RuntimeDefault" +> } +> } +> } +> }' ---- + * With OSPdO, the `mariadb-client` needs to run on the same {rhocp_long} node where the {OpenStackShort} Controller node is running. In addition, the `internalapi-static` network needs to be attached to the pod. @@ -144,9 +144,9 @@ files for each stack. $ unset PULL_OPENSTACK_CONFIGURATION_DATABASES $ declare -xA PULL_OPENSTACK_CONFIGURATION_DATABASES $ for CELL in $(echo $CELLS); do - PULL_OPENSTACK_CONFIGURATION_DATABASES[$CELL]=$(oc run mariadb-client-1-$CELL ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ - mysql -rsh "${SOURCE_MARIADB_IP[$CELL]}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" -e 'SHOW databases;') -done +> PULL_OPENSTACK_CONFIGURATION_DATABASES[$CELL]=$(oc run mariadb-client-1-$CELL ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ +> mysql -rsh "${SOURCE_MARIADB_IP[$CELL]}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" -e 'SHOW databases;') +> done ---- + [NOTE] @@ -161,21 +161,20 @@ endif::[] $ unset PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK $ declare -xA PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK $ run_mysqlcheck() { - PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK=$(oc run mariadb-client-2-$1 ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ - mysqlcheck --all-databases -h ${SOURCE_MARIADB_IP[$CELL]} -u root -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" | grep -v OK) -} +> PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK=$(oc run mariadb-client-2-$1 ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ +> mysqlcheck --all-databases -h ${SOURCE_MARIADB_IP[$CELL]} -u root -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" | grep -v OK) +> } $ for CELL in $(echo $CELLS); do - run_mysqlcheck $CELL -done +> run_mysqlcheck $CELL +> done $ if [ "$PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK" != "" ]; then - # Try mysql_upgrade to fix mysqlcheck failure - for CELL in $(echo $CELLS); do - MYSQL_UPGRADE=$(oc run mariadb-client-3 ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ - mysql_upgrade -v -h ${SOURCE_MARIADB_IP[$CELL]} -u root -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}") - # rerun mysqlcheck to check if problem is resolved - run_mysqlcheck - done -fi +> for CELL in $(echo $CELLS); do +> MYSQL_UPGRADE=$(oc run mariadb-client-3 ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ +> mysql_upgrade -v -h ${SOURCE_MARIADB_IP[$CELL]} -u root -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}") +> # rerun mysqlcheck to check if problem is resolved +> run_mysqlcheck +> done +> fi ---- + @@ -194,10 +193,10 @@ export PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS=$(oc run mariadb-client- $ unset PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES $ declare -xA PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES $ for CELL in $(echo $CELLS); do - PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES[$CELL]=$(oc run mariadb-client-4-$CELL ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ - mysql -rsh "${SOURCE_MARIADB_IP[$CELL]}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" -e \ - "select host from nova.services where services.binary='nova-compute';") -done +> PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES[$CELL]=$(oc run mariadb-client-4-$CELL ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ +> mysql -rsh "${SOURCE_MARIADB_IP[$CELL]}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD[$CELL]}" -e \ +> "select host from nova.services where services.binary='nova-compute';") +> done ---- + @@ -222,22 +221,22 @@ $ declare -xA PULL_OPENSTACK_CONFIGURATION_DATABASES $ declare -xA PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK $ declare -xA PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES $ for CELL in $(echo $CELLS); do - cat > ~/.source_cloud_exported_variables_$CELL << EOF -PULL_OPENSTACK_CONFIGURATION_DATABASES[$CELL]="$(oc run mariadb-client-5-$CELL ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ - mysql -rsh ${SOURCE_MARIADB_IP[$CELL]} -uroot -p${SOURCE_DB_ROOT_PASSWORD[$CELL]} -e 'SHOW databases;')" -PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK[$CELL]="$(oc run mariadb-client-6-$CELL ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ - mysqlcheck --all-databases -h ${SOURCE_MARIADB_IP[$CELL]} -u root -p${SOURCE_DB_ROOT_PASSWORD[$CELL]} | grep -v OK)" -PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES[$CELL]="$(oc run mariadb-client-7-$CELL ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ - mysql -rsh ${SOURCE_MARIADB_IP[$CELL]} -uroot -p${SOURCE_DB_ROOT_PASSWORD[$CELL]} -e \ - "select host from nova.services where services.binary='nova-compute';")" -EOF - done +> cat > ~/.source_cloud_exported_variables_$CELL << EOF +> PULL_OPENSTACK_CONFIGURATION_DATABASES[$CELL]="$(oc run mariadb-client-5-$CELL ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ +> mysql -rsh ${SOURCE_MARIADB_IP[$CELL]} -uroot -p${SOURCE_DB_ROOT_PASSWORD[$CELL]} -e 'SHOW databases;')" +> PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK[$CELL]="$(oc run mariadb-client-6-$CELL ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ +> mysqlcheck --all-databases -h ${SOURCE_MARIADB_IP[$CELL]} -u root -p${SOURCE_DB_ROOT_PASSWORD[$CELL]} | grep -v OK)" +> PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES[$CELL]="$(oc run mariadb-client-7-$CELL ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ +> mysql -rsh ${SOURCE_MARIADB_IP[$CELL]} -uroot -p${SOURCE_DB_ROOT_PASSWORD[$CELL]} -e \ +> "select host from nova.services where services.binary='nova-compute';")" +> EOF +> done $ cat >> ~/.source_cloud_exported_variables_default << EOF -PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS="$(oc run mariadb-client-2 ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ - mysql -rsh ${SOURCE_MARIADB_IP['default']} -uroot -p${SOURCE_DB_ROOT_PASSWORD['default']} -e \ - 'select uuid,name,transport_url,database_connection,disabled from nova_api.cell_mappings;' || echo None)" -PULL_OPENSTACK_CONFIGURATION_NOVAMANAGE_CELL_MAPPINGS="$($CONTROLLER1_SSH sudo podman exec -it nova_conductor nova-manage cell_v2 list_cells)" -EOF +> PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS="$(oc run mariadb-client-2 ${MARIADB_RUN_OVERRIDES} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \ +> mysql -rsh ${SOURCE_MARIADB_IP['default']} -uroot -p${SOURCE_DB_ROOT_PASSWORD['default']} -e \ +> 'select uuid,name,transport_url,database_connection,disabled from nova_api.cell_mappings;' || echo None)" +> PULL_OPENSTACK_CONFIGURATION_NOVAMANAGE_CELL_MAPPINGS="$($CONTROLLER1_SSH sudo podman exec -it nova_conductor nova-manage cell_v2 list_cells)" +> EOF $ chmod 0600 ~/.source_cloud_exported_variables* ---- + diff --git a/tests/roles/common_defaults/defaults/main.yaml b/tests/roles/common_defaults/defaults/main.yaml index a1fcb518a..c173912d2 100644 --- a/tests/roles/common_defaults/defaults/main.yaml +++ b/tests/roles/common_defaults/defaults/main.yaml @@ -77,7 +77,7 @@ mariadb_copy_shell_vars_src: |- declare -A TRIPLEO_PASSWORDS for CELL in $(echo $CELLS); do - TRIPLEO_PASSWORDS[$CELL]="$TRIPLEO_PASSWORD" + TRIPLEO_PASSWORDS[$CELL]="$PASSWORD_FILE" done RUN_OVERRIDES=' ' @@ -97,6 +97,9 @@ mariadb_copy_shell_vars_src: |- {% endfor %} # Header for the destination database access +# The CHARACTER_SET and collation should match the source DB +# if the do not then it will break foreign key relationships +# for any tables that are created in the future as part of db sync mariadb_copy_shell_vars_dst: | {{ shell_header }} {{ oc_header }} @@ -105,9 +108,6 @@ mariadb_copy_shell_vars_dst: | NAMESPACE={{ deploy_ctlplane_ospdo | bool | ternary(rhoso_namespace, org_namespace) }} - # The CHARACTER_SET and collation should match the source DB - # if the do not then it will break foreign key relationships - # for any tables that are created in the future as part of db sync CHARACTER_SET=utf8 COLLATION=utf8_general_ci diff --git a/tests/roles/mariadb_copy/templates/post_checks.bash b/tests/roles/mariadb_copy/templates/post_checks.bash index 3ef48f73e..572ac2e10 100755 --- a/tests/roles/mariadb_copy/templates/post_checks.bash +++ b/tests/roles/mariadb_copy/templates/post_checks.bash @@ -5,17 +5,12 @@ set +u . ~/.source_cloud_exported_variables_default set -u - dbs=$(oc exec openstack-galera-0 -n $NAMESPACE -c galera -- mysql -rs -uroot -p"${PODIFIED_DB_ROOT_PASSWORD['super']}" -e 'SHOW databases;') echo $dbs | grep -Eq '\bkeystone\b' && echo "OK" || echo "CHECK FAILED" - -# ensure neutron db is renamed from ovs_neutron echo $dbs | grep -Eq '\bneutron\b' -echo "${PULL_OPENSTACK_CONFIGURATION_DATABASES[@]}" | grep -Eq '\bovs_neutron\b' && echo "OK" || echo "CHECK FAILED" - -# ensure default cell is renamed to $DEFAULT_CELL_NAME, and the cell UUIDs retained intact +echo "${PULL_OPENSTACK_CONFIGURATION_DATABASES[@]}" | grep -Eq '\bovs_neutron\b' && echo "OK" || echo "CHECK FAILED" # <1> novadb_mapped_cells=$(oc exec openstack-galera-0 -n $NAMESPACE -c galera -- mysql -rs -uroot -p"${PODIFIED_DB_ROOT_PASSWORD['super']}" \ - nova_api -e 'select uuid,name,transport_url,database_connection,disabled from cell_mappings;') + nova_api -e 'select uuid,name,transport_url,database_connection,disabled from cell_mappings;') # <2> uuidf='\S{8,}-\S{4,}-\S{4,}-\S{4,}-\S{12,}' left_behind=$(comm -23 \ <(echo $PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS | grep -oE " $uuidf \S+") \ @@ -27,9 +22,7 @@ test $(grep -Ec ' \S+$' <<<$left_behind) -eq 1 && echo "OK" || echo "CHECK FAILE default=$(grep -E ' default$' <<<$left_behind) test $(grep -Ec ' \S+$' <<<$changed) -eq 1 && echo "OK" || echo "CHECK FAILED" grep -qE " $(awk '{print $1}' <<<$default) ${DEFAULT_CELL_NAME}$" <<<$changed && echo "OK" || echo "CHECK FAILED" - -# ensure the registered Compute service names have not changed -for CELL in $(echo $RENAMED_CELLS); do +for CELL in $(echo $RENAMED_CELLS); do # <3> unset PULL_OPENSTACK_CONFIGURATION_DATABASES unset PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK unset PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES @@ -41,12 +34,15 @@ for CELL in $(echo $RENAMED_CELLS); do set +u . ~/.source_cloud_exported_variables_$RCELL set -u - # ensure nova cells' db are extracted to separate db servers and renamed from nova to nova_cell - c1dbs=$(oc exec openstack-$CELL-galera-0 -n $NAMESPACE -c galera -- mysql -rs -uroot -p${PODIFIED_DB_ROOT_PASSWORD[$CELL]} -e 'SHOW databases;') + c1dbs=$(oc exec openstack-$CELL-galera-0 -n $NAMESPACE -c galera -- mysql -rs -uroot -p${PODIFIED_DB_ROOT_PASSWORD[$CELL]} -e 'SHOW databases;') # <4> echo $c1dbs | grep -Eq "\bnova_${CELL}\b" && echo "OK" || echo "CHECK FAILED" - - # ensure the registered Compute service name has not changed novadb_svc_records=$(oc exec openstack-$CELL-galera-0 -n $NAMESPACE -c galera -- mysql -rs -uroot -p${PODIFIED_DB_ROOT_PASSWORD[$CELL]} \ nova_$CELL -e "select host from services where services.binary='nova-compute' order by host asc;") - diff -Z <(echo "x$novadb_svc_records") <(echo "x${PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES[@]}") && echo "OK" || echo "CHECK FAILED" + diff -Z <(echo "x$novadb_svc_records") <(echo "x${PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES[@]}") && echo "OK" || echo "CHECK FAILED" # <5> done + +# <1> Ensures Neutron database is renamed from `ovs_neutron` +# <2> Ensures `default`` cell is renamed to `$DEFAULT_CELL_NAME``, and the cell UUIDs retained intact +# <3> Ensures the registered Compute services names have not changed +# <4> Ensures Nova cells' DBs are extracted to separate database servers, and renamed from nova to nova_cell +# <5> Ensures the registered Compute service name has not changed diff --git a/tests/roles/mariadb_copy/templates/restore_dbs.bash b/tests/roles/mariadb_copy/templates/restore_dbs.bash index 49ac8cb22..596738d5b 100755 --- a/tests/roles/mariadb_copy/templates/restore_dbs.bash +++ b/tests/roles/mariadb_copy/templates/restore_dbs.bash @@ -8,44 +8,32 @@ for CELL in $(echo $CELLS); do RCELL=$CELL [ "$CELL" = "default" ] && RCELL=$DEFAULT_CELL_NAME oc rsh -n $NAMESPACE mariadb-copy-data << EOF - # db schemas to rename on import - declare -A db_name_map + declare -A db_name_map # <1> db_name_map['nova']="nova_$RCELL" db_name_map['ovs_neutron']='neutron' db_name_map['ironic-inspector']='ironic_inspector' - - # cells' db schemas to import for cells - declare -A db_cell_map + declare -A db_cell_map # <2> db_cell_map['nova']="nova_$DEFAULT_CELL_NAME" - db_cell_map["nova_$RCELL"]="nova_$RCELL" - # Omit importing cells' cell0 DBs as we cannot consolidate them - # db_cell_map["nova_cell0"]="nova_$RCELL" - - # db servers to import into - declare -A db_server_map + db_cell_map["nova_$RCELL"]="nova_$RCELL" # <3> + declare -A db_server_map # <4> db_server_map['default']=${PODIFIED_MARIADB_IP['super']} db_server_map["nova"]=${PODIFIED_MARIADB_IP[$DEFAULT_CELL_NAME]} db_server_map["nova_$RCELL"]=${PODIFIED_MARIADB_IP[$RCELL]} - - # db server root password map - declare -A db_server_password_map + declare -A db_server_password_map # <5> db_server_password_map['default']=${PODIFIED_DB_ROOT_PASSWORD['super']} db_server_password_map["nova"]=${PODIFIED_DB_ROOT_PASSWORD[$DEFAULT_CELL_NAME]} db_server_password_map["nova_$RCELL"]=${PODIFIED_DB_ROOT_PASSWORD[$RCELL]} - cd /backup for db_file in \$(ls ${CELL}.*.sql); do db_name=\$(echo \${db_file} | awk -F'.' '{ print \$2; }') - # Only import cells' DBs and omit everything else [[ "$CELL" != "default" && ! -v "db_cell_map[\${db_name}]" ]] && continue - # Route databases for importing, when extracting cell's / non-cell's DBs from 'default' cell if [[ "$CELL" == "default" && -v "db_cell_map[\${db_name}]" ]] ; then target=$DEFAULT_CELL_NAME elif [[ "$CELL" == "default" && ! -v "db_cell_map[\${db_name}]" ]] ; then - target=super # 'upcall' + target=super else target=$RCELL - fi + fi # <6> renamed_db_file="\${target}_new.\${db_name}.sql" mv -f \${db_file} \${renamed_db_file} if [[ -v "db_name_map[\${db_name}]" ]]; then @@ -67,7 +55,6 @@ for CELL in $(echo $CELLS); do echo "importing $CELL cell \${db_name} into \$target \${db_server} from \${renamed_db_file}" mysql -h "\${db_server}" -uroot "-p\${db_password}" "\${db_name}" < "\${renamed_db_file}" done - if [ "$CELL" = "default" ] ; then mysql -h "\${db_server_map['default']}" -uroot -p"\${db_server_password_map['default']}" -e \ "update nova_api.cell_mappings set name='$DEFAULT_CELL_NAME' where name='default';" @@ -76,3 +63,10 @@ for CELL in $(echo $CELLS); do "delete from nova_${RCELL}.services where host not like '%nova_${RCELL}-%' and services.binary != 'nova-compute';" EOF done + +# <1> Defines which common databases to rename, when importing it +# <2> Defines which cells' databases to import, and how to rename it, if needed. +# <3> Omits importing cells' special `cell0` databases as we cannot consolidate its contents during adoption. +# <4> Defines which databases to import into which servers (usually dedicated for cells). +# <5> Defines root passwords map for database servers (we can only use the same password for now). +# <6> Asigns which databases to import into which hosts, when extracting databases from `default` cell.