Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ospdo adoption mariadb copy #690

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion tests/roles/dataplane_adoption/tasks/nova_ffu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{ shell_header }}
{{ oc_header }}
{{ mariadb_copy_shell_vars_dst }}
oc exec openstack-cell1-galera-0 -c galera -- mysql -rs -uroot -p$PODIFIED_DB_ROOT_PASSWORD \
oc exec openstack-cell1-galera-0 -n {{ rhoso_namespace }} -c galera -- mysql -rs -uroot -p$PODIFIED_DB_ROOT_PASSWORD \
-e "select a.version from nova_cell1.services a join nova_cell1.services b where a.version!=b.version and a.binary='nova-compute';"
register: records_check_results
until: records_check_results.rc == 0 and records_check_results.stdout_lines | length == 0
Expand Down
24 changes: 16 additions & 8 deletions tests/roles/get_services_configuration/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
pull_openstack_configuration_ssh_shell_vars: |
CONTROLLER1_SSH="{{ controller1_ssh }}"

- name: execute alternative tasks when source env is OSPdO
ansible.builtin.include_role:
name: mariadb_copy
tasks_from: env_vars_src_ospdo.yaml
when: ospdo_src| bool

- name: get src database service environment variables
ansible.builtin.include_role:
name: mariadb_copy
Expand All @@ -18,7 +24,7 @@
{{ shell_header }}
{{ oc_header }}
{{ mariadb_copy_shell_vars_src }}
export PULL_OPENSTACK_CONFIGURATION_DATABASES=$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
export PULL_OPENSTACK_CONFIGURATION_DATABASES=$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} {{ mysql_client_override }} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
mysql -rsh "$SOURCE_MARIADB_IP" -uroot -p"$SOURCE_DB_ROOT_PASSWORD" -e 'SHOW databases;')
echo "$PULL_OPENSTACK_CONFIGURATION_DATABASES"
register: _databases_check
Expand All @@ -30,7 +36,7 @@
{{ oc_header }}
{{ mariadb_copy_shell_vars_src }}
run_mysqlcheck() {
export PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK=$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
export PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK=$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} {{ mysql_client_override }} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
mysqlcheck --all-databases -h "${SOURCE_MARIADB_IP}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD}" | grep -v OK)
}
run_mysqlcheck
Expand All @@ -53,7 +59,7 @@
{{ shell_header }}
{{ oc_header }}
{{ mariadb_copy_shell_vars_src }}
export PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS=$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
export PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS=$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} {{ mysql_client_override }} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
mysql -rsh "${SOURCE_MARIADB_IP}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD}" nova_api -e \
'select uuid,name,transport_url,database_connection,disabled from cell_mappings;')
echo "$PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS"
Expand All @@ -64,7 +70,7 @@
{{ shell_header }}
{{ oc_header }}
{{ mariadb_copy_shell_vars_src }}
export PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES=$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
export PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES=$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} {{ mysql_client_override }} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
mysql -rsh "$SOURCE_MARIADB_IP" -uroot -p"$SOURCE_DB_ROOT_PASSWORD" nova_api -e \
"select host from nova.services where services.binary='nova-compute';")
echo "$PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES"
Expand Down Expand Up @@ -94,15 +100,17 @@
{{ shell_header }}
{{ oc_header }}
{{ mariadb_copy_shell_vars_src }}
{{ pull_openstack_configuration_ssh_shell_vars }}

cat > ~/.source_cloud_exported_variables << EOF
PULL_OPENSTACK_CONFIGURATION_DATABASES="$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
PULL_OPENSTACK_CONFIGURATION_DATABASES="$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} {{ mysql_client_override }} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
mysql -rsh $SOURCE_MARIADB_IP -uroot -p$SOURCE_DB_ROOT_PASSWORD -e 'SHOW databases;')"
PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK="$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
PULL_OPENSTACK_CONFIGURATION_MYSQLCHECK_NOK="$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} {{ mysql_client_override }} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
mysqlcheck --all-databases -h $SOURCE_MARIADB_IP -u root -p$SOURCE_DB_ROOT_PASSWORD | grep -v OK)"
PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS="$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
PULL_OPENSTACK_CONFIGURATION_NOVADB_MAPPED_CELLS="$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} {{ mysql_client_override }} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
mysql -rsh $SOURCE_MARIADB_IP -uroot -p$SOURCE_DB_ROOT_PASSWORD nova_api -e \
'select uuid,name,transport_url,database_connection,disabled from cell_mappings;')"
PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES="$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
PULL_OPENSTACK_CONFIGURATION_NOVA_COMPUTE_HOSTNAMES="$(oc run mariadb-client ${MARIADB_CLIENT_ANNOTATIONS} {{ mysql_client_override }} -q --image ${MARIADB_IMAGE} -i --rm --restart=Never -- \
mysql -rsh $SOURCE_MARIADB_IP -uroot -p$SOURCE_DB_ROOT_PASSWORD nova_api -e \
"select host from nova.services where services.binary='nova-compute';")"
PULL_OPENSTACK_CONFIGURATION_NOVAMANAGE_CELL_MAPPINGS="$($CONTROLLER1_SSH sudo podman exec -it nova_api nova-manage cell_v2 list_cells)"
Expand Down
14 changes: 14 additions & 0 deletions tests/roles/mariadb_copy/defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@ mariadb_copy_tmp_dir: tmp/mariadb
storage_reclaim_policy: delete
source_galera_members: |-
["{{ edpm_node_hostname }}"]={{ source_mariadb_ip|default(external_mariadb_ip) }}

dpa_dir: "../.."
dpa_tests_dir: "{{ dpa_dir }}/tests"

mysql_client_override: ""

# ospdo env:
# Whether source env is OSPD Director Operator
# i.e. https://github.com/openstack-k8s-operators/osp-director-operator
ospdo_src: false
# rhoso namespace
rhoso_namespace: "openstack"
# director operator namespace
org_namespace: "openstack"
5 changes: 3 additions & 2 deletions tests/roles/mariadb_copy/tasks/env_vars_dst.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
ansible.builtin.shell: |
{{ shell_header }}
{{ oc_header }}
oc get svc --selector "mariadb/name=openstack" -ojsonpath='{.items[0].spec.clusterIP}'
oc get svc --selector "mariadb/name=openstack" -n {{ rhoso_namespace }} -ojsonpath='{.items[0].spec.clusterIP}'
register: podified_mariadb_ip_result

- name: get podified cell1 MariaDB IP
ansible.builtin.shell: |
{{ shell_header }}
{{ oc_header }}
oc get svc --selector "mariadb/name=openstack-cell1" -ojsonpath='{.items[0].spec.clusterIP}'
oc get svc --selector "mariadb/name=openstack-cell1" -n {{ rhoso_namespace }} -ojsonpath='{.items[0].spec.clusterIP}'
register: podified_cell1_mariadb_ip_result

- name: set MariaDB copy shell vars
Expand All @@ -19,6 +19,7 @@
PODIFIED_MARIADB_IP={{ podified_mariadb_ip_result.stdout }}
PODIFIED_CELL1_MARIADB_IP={{ podified_cell1_mariadb_ip_result.stdout }}
PODIFIED_DB_ROOT_PASSWORD="{{ podified_db_root_password }}"
MARIADB_CLIENT_ANNOTATIONS="-n {{ rhoso_namespace }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't set this variable here, it will override the setting from env_vars_src.yaml. Both env_vars_src.yaml and env_vars_dst.yaml are sourced one after another. AFAIU we need to be able to use mariadb_copy_shell_vars_dst and mariadb_copy_shell_vars_src together. Also think about how this translates to the docs. There are no distinctions between src/dst vars. MARIADB_CLIENT_ANNOTATIONS is set once and stays that way.

Does the OSPDO use case require running the data copy pods in both namespaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK , I'll leave the MARIADB_CLIENT_ANNOTATIONS as it was before and not override it.
I'll add the correct namespace throughout the needed oc commands...


# The CHARACTER_SET and collation should match the source DB
# if the do not then it will break foreign key relationships
Expand Down
1 change: 1 addition & 0 deletions tests/roles/mariadb_copy/tasks/env_vars_src.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
)
SOURCE_DB_ROOT_PASSWORD="{{ source_db_root_password|default(external_db_root_password) }}"
MARIADB_CLIENT_ANNOTATIONS='--annotations=k8s.v1.cni.cncf.io/networks=internalapi'
when: not ospdo_src| bool
37 changes: 37 additions & 0 deletions tests/roles/mariadb_copy/tasks/env_vars_src_ospdo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- name: set OSPdO env vars
block:
- name: register source_mariadb_ip
ansible.builtin.shell: |
oc -n {{ org_namespace }} get cm tripleo-exports-default -o json | jq -r '.data["ctlplane-export.yaml"]'| sed -e '0,/ MysqlInternal/d' | sed -n '0,/host_nobrackets/s/^.*host_nobrackets\:\s*\(.*\)$/\1/p'
register: source_mariadb_ip

- name: register controller node
no_log: "{{ use_no_log }}"
ansible.builtin.shell: |
oc get vmi -n{{ org_namespace }} -o jsonpath='{.items[0].metadata.labels.kubevirt\.io/nodeName}'
register: controller_node

- name: register source_db_root_pass
no_log: "{{ use_no_log }}"
ansible.builtin.shell: |
oc get secret -n {{ org_namespace }} tripleo-passwords -o jsonpath='{.data.*}'| base64 -d |grep MysqlRootPassword|sed 's/.*: //g'
register: source_db_root_pass

- name: set src MariaDB copy shell vars
no_log: "{{ use_no_log }}"
ansible.builtin.set_fact:
mariadb_copy_shell_vars_src: |
MARIADB_IMAGE=quay.io/podified-antelope-centos9/openstack-mariadb:current-podified
STORAGE_CLASS=host-nfs-storageclass
SOURCE_MARIADB_IP={{ source_mariadb_ip.stdout }}
declare -A SOURCE_GALERA_MEMBERS
SOURCE_GALERA_MEMBERS=(
["standalone.localdomain"]={{ source_mariadb_ip.stdout }}
)
SOURCE_DB_ROOT_PASSWORD={{ source_db_root_pass.stdout }}
MARIADB_CLIENT_ANNOTATIONS="-n {{ org_namespace }}"
CONTROLLER_NODE={{ controller_node.stdout }}

- name: set default NS to {{ rhoso_namespace }}
ansible.builtin.shell: |
oc project {{ rhoso_namespace }}
15 changes: 12 additions & 3 deletions tests/roles/mariadb_copy/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
ansible.builtin.include_tasks:
file: env_vars_src.yaml

- name: execute alternative tasks when source env is OSPdO
ansible.builtin.include_role:
name: mariadb_copy
tasks_from: env_vars_src_ospdo.yaml
when: ospdo_src| bool

- name: get the destination database service environment variables
ansible.builtin.include_tasks:
file: env_vars_dst.yaml
Expand All @@ -18,6 +24,7 @@
kind: PersistentVolumeClaim
metadata:
name: mariadb-data
namespace: {{ org_namespace }}
spec:
storageClassName: $STORAGE_CLASS
accessModes:
Expand All @@ -32,10 +39,12 @@
name: mariadb-copy-data
annotations:
openshift.io/scc: anyuid
k8s.v1.cni.cncf.io/networks: internalapi
k8s.v1.cni.cncf.io/networks: {{ copy_pods_custom_networks | default('internalapi') }}
namespace: {{ org_namespace }}
labels:
app: adoption
spec:
{{ copy_pods_custom_spec|default('') }}
containers:
- image: $MARIADB_IMAGE
command: [ "sh", "-c", "sleep infinity"]
Expand All @@ -62,7 +71,7 @@
ansible.builtin.shell: |
{{ shell_header }}
{{ oc_header }}
oc wait --for condition=Ready pod/mariadb-copy-data --timeout=10s
oc wait --for condition=Ready -n {{ org_namespace }} pod/mariadb-copy-data --timeout=10s
register: mariadb_data_pod_result
until: mariadb_data_pod_result is success
retries: 25
Expand All @@ -76,7 +85,7 @@
{{ mariadb_copy_shell_vars_src }}
for i in "${!SOURCE_GALERA_MEMBERS[@]}"; do
echo "Checking for the database node $i WSREP status Synced"
oc rsh mariadb-copy-data mysql \
oc rsh -n {{ org_namespace }} mariadb-copy-data mysql \
-h "${SOURCE_GALERA_MEMBERS[$i]}" -uroot -p"$SOURCE_DB_ROOT_PASSWORD" \
-e "show global status like 'wsrep_local_state_comment'" | \
grep -qE "\bSynced\b"
Expand Down
6 changes: 6 additions & 0 deletions tests/roles/mariadb_copy/tasks/mariadb_verify.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
- name: execute alternative tasks when source env is ODPdO
ansible.builtin.include_role:
name: mariadb_copy
tasks_from: env_vars_src_ospdo.yaml
when: ospdo_src| bool

- name: get the source database service environment variables
ansible.builtin.include_tasks:
file: env_vars_src.yaml
Expand Down
2 changes: 1 addition & 1 deletion tests/roles/mariadb_copy/templates/dump_dbs.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Note Filter the information and performance schema tables
# Gnocchi is no longer used as a metric store, skip dumping gnocchi database as well
# Migrating Aodh alarms from previous release is not supported, hence skip aodh database
oc rsh mariadb-copy-data << EOF
oc rsh -n "{{ org_namespace }}" mariadb-copy-data << EOF
mysql -h"${SOURCE_MARIADB_IP}" -uroot -p"${SOURCE_DB_ROOT_PASSWORD}" \
-N -e "show databases" | grep -E -v "schema|mysql|gnocchi|aodh" | \
while read dbname; do
Expand Down
8 changes: 4 additions & 4 deletions tests/roles/mariadb_copy/templates/post_checks.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
{% endif %}

# use 'oc exec' and 'mysql -rs' to maintain formatting
dbs=$(oc exec openstack-galera-0 -c galera -- mysql -rs -uroot "-p$PODIFIED_DB_ROOT_PASSWORD" -e 'SHOW databases;')
dbs=$(oc exec openstack-galera-0 -n {{ rhoso_namespace }} -c galera -- mysql -rs -uroot "-p$PODIFIED_DB_ROOT_PASSWORD" -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 nova cell1 db is extracted to a separate db server and renamed from nova to nova_cell1
c1dbs=$(oc exec openstack-cell1-galera-0 -c galera -- mysql -rs -uroot "-p$PODIFIED_DB_ROOT_PASSWORD" -e 'SHOW databases;')
c1dbs=$(oc exec openstack-cell1-galera-0 -n {{ rhoso_namespace }} -c galera -- mysql -rs -uroot "-p$PODIFIED_DB_ROOT_PASSWORD" -e 'SHOW databases;')
echo $c1dbs | grep -Eq '\bnova_cell1\b' && echo "OK" || echo "CHECK FAILED"

# ensure default cell renamed to cell1, and the cell UUIDs retained intact
novadb_mapped_cells=$(oc exec openstack-galera-0 -c galera -- mysql -rs -uroot "-p$PODIFIED_DB_ROOT_PASSWORD" \
novadb_mapped_cells=$(oc exec openstack-galera-0 -n {{ rhoso_namespace }} -c galera -- mysql -rs -uroot "-p$PODIFIED_DB_ROOT_PASSWORD" \
nova_api -e 'select uuid,name,transport_url,database_connection,disabled from cell_mappings;')
uuidf='\S{8,}-\S{4,}-\S{4,}-\S{4,}-\S{12,}'
left_behind=$(comm -23 \
Expand All @@ -35,6 +35,6 @@ test $(grep -Ec ' \S+$' <<<$changed) -eq 1 && echo "OK" || echo "CHECK FAILED"
grep -qE " $(awk '{print $1}' <<<$default) cell1$" <<<$changed && echo "OK" || echo "CHECK FAILED"

# ensure the registered Compute service name has not changed
novadb_svc_records=$(oc exec openstack-cell1-galera-0 -c galera -- mysql -rs -uroot "-p$PODIFIED_DB_ROOT_PASSWORD" \
novadb_svc_records=$(oc exec openstack-cell1-galera-0 -n {{ rhoso_namespace }} -c galera -- mysql -rs -uroot "-p$PODIFIED_DB_ROOT_PASSWORD" \
nova_cell1 -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) && echo "OK" || echo "CHECK FAILED"
6 changes: 3 additions & 3 deletions tests/roles/mariadb_copy/templates/pre_checks.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{{ mariadb_copy_shell_vars_dst }}

# Test connection to podified DBs (show databases)
oc run mariadb-client --image $MARIADB_IMAGE -i --rm --restart=Never -- \
mysql -rsh "$PODIFIED_MARIADB_IP" -uroot -p"$PODIFIED_DB_ROOT_PASSWORD" -e 'SHOW databases;'
oc run mariadb-client --image $MARIADB_IMAGE -i --rm --restart=Never -- \
oc run mariadb-client -n {{ rhoso_namespace }} ${MARIADB_CLIENT_ANNOTATIONS} --image $MARIADB_IMAGE -i --rm --restart=Never -- \
mysql -rsh "$PODIFIED_MARIADB_IP" -n {{ rhoso_namespace }} -uroot -p"$PODIFIED_DB_ROOT_PASSWORD" -e 'SHOW databases;'
oc run mariadb-client -n {{ rhoso_namespace }} ${MARIADB_CLIENT_ANNOTATIONS} --image $MARIADB_IMAGE -i --rm --restart=Never -- \
mysql -rsh "$PODIFIED_CELL1_MARIADB_IP" -uroot -p"$PODIFIED_DB_ROOT_PASSWORD" -e 'SHOW databases;'
2 changes: 1 addition & 1 deletion tests/roles/mariadb_copy/templates/restore_dbs.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ mariadb_copy_shell_vars_src }}
{{ mariadb_copy_shell_vars_dst }}

oc rsh mariadb-copy-data << EOF
oc rsh -n {{ rhoso_namespace }} mariadb-copy-data << EOF
# db schemas to rename on import
declare -A db_name_map
db_name_map['nova']='nova_cell1'
Expand Down
Loading