Merge "uc/deploy: try to keep passwords from undercloud-passwords.conf"
This commit is contained in:
@@ -57,7 +57,6 @@ class TestUndercloudDeploy(TestPluginV1):
|
|||||||
with mock.patch('six.moves.builtins.open', mock_open_context):
|
with mock.patch('six.moves.builtins.open', mock_open_context):
|
||||||
self.cmd._update_passwords_env(self.temp_homedir)
|
self.cmd._update_passwords_env(self.temp_homedir)
|
||||||
|
|
||||||
mock_open_context.assert_called_with(pw_conf_path, 'w')
|
|
||||||
mock_open_handle = mock_open_context()
|
mock_open_handle = mock_open_context()
|
||||||
mock_dump.assert_called_once_with({'parameter_defaults': pw_dict},
|
mock_dump.assert_called_once_with({'parameter_defaults': pw_dict},
|
||||||
mock_open_handle,
|
mock_open_handle,
|
||||||
@@ -83,16 +82,16 @@ class TestUndercloudDeploy(TestPluginV1):
|
|||||||
with open(t_pw_conf_path, 'w') as t_pw:
|
with open(t_pw_conf_path, 'w') as t_pw:
|
||||||
t_pw.write('parameter_defaults: {ExistingKey: xyz}\n')
|
t_pw.write('parameter_defaults: {ExistingKey: xyz}\n')
|
||||||
|
|
||||||
mock_open_context = mock.mock_open(
|
with open(pw_conf_path, 'w') as t_pw:
|
||||||
read_data='parameter_defaults: {ExistingKey: xyz}\n')
|
t_pw.write('[auth]\nundercloud_db_password = abc\n')
|
||||||
with mock.patch('six.moves.builtins.open', mock_open_context):
|
|
||||||
self.cmd._update_passwords_env(self.temp_homedir,
|
self.cmd._update_passwords_env(self.temp_homedir,
|
||||||
passwords={'ADefault': 456,
|
passwords={'ADefault': 456,
|
||||||
'ExistingKey':
|
'ExistingKey':
|
||||||
'dontupdate'})
|
'dontupdate'})
|
||||||
mock_open_context.assert_called_with(pw_conf_path, 'w')
|
|
||||||
expected_dict = {'parameter_defaults': {'GeneratedPassword': 123,
|
expected_dict = {'parameter_defaults': {'GeneratedPassword': 123,
|
||||||
'ExistingKey': 'xyz',
|
'ExistingKey': 'xyz',
|
||||||
|
'MysqlRootPassword': 'abc',
|
||||||
'ADefault': 456}}
|
'ADefault': 456}}
|
||||||
mock_dump.assert_called_once_with(expected_dict,
|
mock_dump.assert_called_once_with(expected_dict,
|
||||||
mock.ANY,
|
mock.ANY,
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ from heatclient.common import event_utils
|
|||||||
from heatclient.common import template_utils
|
from heatclient.common import template_utils
|
||||||
from heatclient.common import utils as heat_utils
|
from heatclient.common import utils as heat_utils
|
||||||
from openstackclient.i18n import _
|
from openstackclient.i18n import _
|
||||||
|
from six.moves import configparser
|
||||||
|
|
||||||
from tripleoclient import constants
|
from tripleoclient import constants
|
||||||
from tripleoclient import exceptions
|
from tripleoclient import exceptions
|
||||||
@@ -111,12 +112,34 @@ class DeployUndercloud(command.Command):
|
|||||||
undercloud_pw_file = os.path.join(output_dir,
|
undercloud_pw_file = os.path.join(output_dir,
|
||||||
'undercloud-passwords.conf')
|
'undercloud-passwords.conf')
|
||||||
stack_env = {'parameter_defaults': {}}
|
stack_env = {'parameter_defaults': {}}
|
||||||
|
|
||||||
|
# Getting passwords that were managed by instack-undercloud so
|
||||||
|
# we can upgrade to a containerized undercloud and keep old passwords.
|
||||||
|
legacy_env = {}
|
||||||
|
if os.path.exists(undercloud_pw_file):
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read(undercloud_pw_file)
|
||||||
|
for k, v in config.items('auth'):
|
||||||
|
# Manage exceptions
|
||||||
|
if k == 'undercloud_db_password':
|
||||||
|
k = 'MysqlRootPassword'
|
||||||
|
elif k == 'undercloud_rabbit_username':
|
||||||
|
k = 'RabbitUserName'
|
||||||
|
elif k == 'undercloud_heat_encryption_key':
|
||||||
|
k = 'HeatAuthEncryptionKey'
|
||||||
|
else:
|
||||||
|
k = ''.join(i.capitalize() for i in k.split('_')[1:])
|
||||||
|
legacy_env[k] = v
|
||||||
|
|
||||||
if os.path.exists(pw_file):
|
if os.path.exists(pw_file):
|
||||||
with open(pw_file) as pf:
|
with open(pw_file) as pf:
|
||||||
stack_env = yaml.safe_load(pf.read())
|
stack_env = yaml.safe_load(pf.read())
|
||||||
|
|
||||||
pw = password_utils.generate_passwords(stack_env=stack_env)
|
pw = password_utils.generate_passwords(stack_env=stack_env)
|
||||||
stack_env['parameter_defaults'].update(pw)
|
stack_env['parameter_defaults'].update(pw)
|
||||||
|
# Override what has been generated by tripleo-common with old passwords
|
||||||
|
# if any.
|
||||||
|
stack_env['parameter_defaults'].update(legacy_env)
|
||||||
|
|
||||||
if passwords:
|
if passwords:
|
||||||
# These passwords are the DefaultPasswords so we only
|
# These passwords are the DefaultPasswords so we only
|
||||||
|
|||||||
Reference in New Issue
Block a user