Retrieve root password from leaderdb if needed
Within update_root_password if there is no root password in the config() object then cfg['root-password'] will return None. set_mysql_root_password is then called with None which triggers a TypeError. The desired root password is in the leaderdb so fallback to retrieving it from there if it is not in config(). unit_tests/test_utils.py was also updated to fix the behaviour of config.changed to mimic that of the real method in charm helpers. Change-Id: I8d22a66f335c0c8e893cda699a55056476e6d9d5
This commit is contained in:
parent
b68d29ce6c
commit
f8adca19e2
|
@ -841,7 +841,7 @@ def update_root_password():
|
|||
m_helper = get_db_helper()
|
||||
|
||||
# password that needs to be set
|
||||
new_root_passwd = cfg['root-password']
|
||||
new_root_passwd = cfg['root-password'] or root_password()
|
||||
m_helper.set_mysql_root_password(new_root_passwd)
|
||||
|
||||
# check the password was changed
|
||||
|
|
|
@ -640,3 +640,17 @@ class TestUpdateBootstrapUUID(CharmTestCase):
|
|||
|
||||
mock_leader_set.assert_called_with(
|
||||
settings={'mysql.passwd': new_password})
|
||||
|
||||
@mock.patch.object(percona_utils, 'leader_get')
|
||||
@mock.patch.object(percona_utils, 'get_db_helper')
|
||||
def test_update_root_password_None(self, mock_get_db_helper,
|
||||
mock_leader_get):
|
||||
# Test fix for 1744961
|
||||
my_mock = mock.Mock()
|
||||
mock_get_db_helper.return_value = my_mock
|
||||
self.config.side_effect = self.test_config.get
|
||||
leader_config = {'root-password': 'leaderpass'}
|
||||
mock_leader_get.side_effect = lambda k: leader_config[k]
|
||||
|
||||
percona_utils.update_root_password()
|
||||
my_mock.set_mysql_root_password.assert_called_once_with('leaderpass')
|
||||
|
|
|
@ -83,6 +83,8 @@ class TestConfig(object):
|
|||
self.config_prev.pop(k)
|
||||
|
||||
def changed(self, k):
|
||||
if not self.config_prev:
|
||||
return True
|
||||
return self.get(k) != self.previous(k)
|
||||
|
||||
def get(self, attr=None):
|
||||
|
|
Loading…
Reference in New Issue