MariaDB: update password cleanly

This PS updates the password update logic to operate cleanly under all
senarios.

Change-Id: I675a344b00984c63cec34919f84a5e9dd8aa5b4e
Signed-off-by: Pete Birley <pete@port.direct>
This commit is contained in:
Pete Birley 2019-04-03 13:05:28 -05:00 committed by Pete Birley
parent 8863bcfc11
commit db209e0bb5

View File

@ -238,7 +238,7 @@ def mysqld_write_cluster_conf(mode='run'):
# Function to setup mysqld
def mysqld_bootstrap():
"""Boostrap the db if no data found in the 'bootstrap_test_dir'"""
"""Bootstrap the db if no data found in the 'bootstrap_test_dir'"""
logger.info("Boostrapping Mariadb")
mysql_data_dir = '/var/lib/mysql'
bootstrap_test_dir = "{0}/mysql".format(mysql_data_dir)
@ -726,7 +726,10 @@ def run_mysqld(cluster='existing'):
'--defaults-file=/etc/mysql/admin_user.cnf'
], logger)
logger.info("Setting the root password to the current value")
mysql_data_dir = '/var/lib/mysql'
db_test_dir = "{0}/mysql".format(mysql_data_dir)
if os.path.isdir(db_test_dir):
logger.info("Setting the admin passwords to the current value")
template = (
"CREATE OR REPLACE USER '{0}'@'%' IDENTIFIED BY \'{1}\' ;\n"
"GRANT ALL ON *.* TO '{0}'@'%' WITH GRANT OPTION ;\n"
@ -740,12 +743,16 @@ def run_mysqld(cluster='existing'):
f.write(template)
f.close()
run_cmd_with_logging([
'mysqld', '--bind-address=127.0.0.1',
'--wsrep_cluster_address=gcomm://',
'mysqld', '--bind-address=127.0.0.1', '--wsrep-on=false',
"--init-file={0}".format(bootstrap_sql_file)
], logger)
os.remove(bootstrap_sql_file)
else:
logger.info(
"This is a fresh node joining the cluster for the 1st time, not attempting to set admin passwords"
)
logger.info("Launching MariaDB")
run_cmd_with_logging(mysqld_cmd, logger)