From 3d28153ea148e6047083c2418b8905cbbd7b6c68 Mon Sep 17 00:00:00 2001 From: James Slagle Date: Tue, 4 May 2021 17:38:58 -0400 Subject: [PATCH] Check for passwords at old path during tripleo deploy Commit ecafbae4ee7c403a3ef62e362c261585aabbec5c updated tripleo deploy to use a different working directory. That broke upgrades because the passwords file was still at the old path, and the passwords can not change during a tripleo deploy upgrade. This patch checks the old location for a passwords file, and if present, migrates it to the new location. Signed-off-by: James Slagle Change-Id: I547ba1a7409290f4888e53dd45a883c263f0670f --- .../tests/v1/tripleo/test_tripleo_deploy.py | 17 +++++++++++++++-- tripleoclient/v1/tripleo_deploy.py | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py index 2d0381ae6..80068e05b 100644 --- a/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py +++ b/tripleoclient/tests/v1/tripleo/test_tripleo_deploy.py @@ -20,6 +20,8 @@ import tempfile import yaml from heatclient import exc as hc_exc + +from tripleoclient import constants from tripleoclient import exceptions from tripleoclient.tests import fakes from tripleoclient.tests.v1.test_plugin import TestPluginV1 @@ -231,7 +233,14 @@ class TestDeployUndercloud(TestPluginV1): self.temp_homedir, 'tripleo-undercloud-passwords.yaml') mock_pw.return_value = pw_dict - mock_exists.return_value = True + + old_pw_file = os.path.join(constants.CLOUD_HOME_DIR, + 'tripleo-undercloud-passwords.yaml') + + def mock_file_exists(file_name): + return not file_name == old_pw_file + mock_exists.side_effect = mock_file_exists + with open(t_pw_conf_path, 'w') as t_pw: t_pw.write('parameter_defaults: {ExistingKey: xyz, ' 'LegacyPass: pick-me-legacy-tht, ' @@ -276,8 +285,12 @@ class TestDeployUndercloud(TestPluginV1): mock_pw.return_value = pw_dict + old_pw_file = os.path.join(constants.CLOUD_HOME_DIR, + 'tripleo-undercloud-passwords.yaml') + def mock_file_exists(file_name): - return not file_name.startswith('/etc/keystone') + return not (file_name.startswith('/etc/keystone') or + file_name == old_pw_file) mock_exists.side_effect = mock_file_exists with open(t_pw_conf_path, 'w') as t_pw: t_pw.write('parameter_defaults: {ExistingKey: xyz, ' diff --git a/tripleoclient/v1/tripleo_deploy.py b/tripleoclient/v1/tripleo_deploy.py index 94ea52a8e..5a77b1875 100644 --- a/tripleoclient/v1/tripleo_deploy.py +++ b/tripleoclient/v1/tripleo_deploy.py @@ -275,6 +275,8 @@ class Deploy(command.Command): def _update_passwords_env(self, output_dir, user, upgrade=None, passwords=None, stack_name='undercloud'): + old_pw_file = os.path.join(constants.CLOUD_HOME_DIR, + 'tripleo-' + stack_name + '-passwords.yaml') pw_file = os.path.join(output_dir, 'tripleo-' + stack_name + '-passwords.yaml') undercloud_pw_file = os.path.join(constants.CLOUD_HOME_DIR, @@ -285,10 +287,22 @@ class Deploy(command.Command): stack_env = {'parameter_defaults': {}} stack_env['parameter_defaults'] = password_utils.generate_passwords( stack_env=stack_env) + # Check for the existence of a passwords file in the old location. + if os.path.exists(old_pw_file): + self.log.warning("Migrating {} to {}.".format( + old_pw_file, pw_file)) + try: + os.rename(old_pw_file, pw_file) + except Exception as e: + self.log.error("Error moving {} to {}".format( + old_pw_file, pw_file)) + self.log.error(e) + raise e if os.path.exists(pw_file): with open(pw_file) as pf: stack_env['parameter_defaults'].update( yaml.safe_load(pf.read())['parameter_defaults']) + self.log.warning("Reading passwords from %s" % pw_file) if upgrade: # Getting passwords that were managed by instack-undercloud so