Fix an error when generate root password during DB initialization

This issue was occurring with percona database (v5.6).

Error logs:
`An error occurred preparing datastore: (pymysql.err.InternalError)
 (1372, 'Password hash should be a 41-digit hexadecimal number'`

Tested with re-enable root function for both v5.6 and v5.7.

Change-Id: Ied67c7c243d3f8c644708548cce71ea2aa3cf2e7
Story: #2006546
Task: #36629
(cherry picked from commit e84718c782)
This commit is contained in:
Nguyen Van Trung 2019-09-14 12:28:28 +07:00 committed by Lingxian Kong
parent 560857232a
commit 83ab791001
3 changed files with 5 additions and 5 deletions

View File

@ -382,7 +382,7 @@ class SetPassword(object):
'user_host': self.host,
'new_password': self.new_password}
return ("SET PASSWORD FOR '%(user_name)s'@'%(user_host)s' = "
"'%(new_password)s';" % properties)
"PASSWORD('%(new_password)s');" % properties)
class DropUser(object):

View File

@ -468,13 +468,13 @@ class MySqlAdminTest(trove_testtools.TestCase):
def test_change_passwords(self):
user = [{"name": "test_user", "host": "%", "password": "password"}]
expected = ("SET PASSWORD FOR 'test_user'@'%' = 'password';")
expected = ("SET PASSWORD FOR 'test_user'@'%' = PASSWORD('password');")
with patch.object(self.mock_client, 'execute') as mock_execute:
self.mySqlAdmin.change_passwords(user)
self._assert_execute_call(expected, mock_execute)
def test_update_attributes_password(self):
expected = ("SET PASSWORD FOR 'test_user'@'%' = 'password';")
expected = ("SET PASSWORD FOR 'test_user'@'%' = PASSWORD('password');")
user = MagicMock()
user.name = "test_user"
user.host = "%"
@ -1409,7 +1409,7 @@ class MySqlAppTest(trove_testtools.TestCase):
self.mySqlApp.secure_root()
update_root_password, _ = self.mock_execute.call_args_list[0]
update_expected = ("SET PASSWORD FOR 'root'@'localhost' = "
"'some_password';")
"PASSWORD('some_password');")
remove_root, _ = self.mock_execute.call_args_list[1]
remove_expected = ("DELETE FROM mysql.user WHERE "

View File

@ -403,7 +403,7 @@ class SetPasswordTest(QueryTestBase):
uu = sql_query.SetPassword(user=username, host=hostname,
new_password=new_password)
self.assertEqual("SET PASSWORD FOR 'root'@'localhost' = "
"'new_password';", str(uu))
"PASSWORD('new_password');", str(uu))
class DropUserTest(QueryTestBase):