Only delete heat data in the DB if it exists

The undercloud upgrade script that deletes users may
not work if re-run or if other scripts clean DB data
during the upgrade.
Only delete users and database if it still exists in
the DB.

Change-Id: I36e3b33a824f3ae6d1da97ea53527c2b4519ea3c
Related-Bug: #1943440
Related-Bug: #1943330
This commit is contained in:
Damien Ciabrini 2021-09-23 09:12:50 +02:00 committed by Michele Baldessari
parent dc8c0a89a8
commit f58e759e18
1 changed files with 4 additions and 4 deletions

View File

@ -213,20 +213,20 @@ def drop_db():
subprocess.check_call([
'sudo', 'podman', 'exec', '-u', 'root',
'mysql', 'mysql', 'heat', '-e',
'drop database heat'])
'drop database if exists heat'])
LOG.info("Dropping Heat users")
subprocess.check_call([
'sudo', 'podman', 'exec', '-u', 'root',
'mysql', 'mysql', '-e',
'drop user \'heat\'@\'{}\''.format(_get_ctlplane_ip())])
'drop user if exists \'heat\'@\'{}\''.format(_get_ctlplane_ip())])
subprocess.check_call([
'sudo', 'podman', 'exec', '-u', 'root',
'mysql', 'mysql', '-e',
'drop user \'heat\'@\'{}\''.format(_get_ctlplane_vip())])
'drop user if exists \'heat\'@\'{}\''.format(_get_ctlplane_vip())])
subprocess.check_call([
'sudo', 'podman', 'exec', '-u', 'root',
'mysql', 'mysql', '-e',
'drop user \'heat\'@\'%\''])
'drop user if exists \'heat\'@\'%\''])
def export_passwords(heat, stack, stack_dir):