From 389013bda148e4932391183f2cdf3cfa19e44d0a Mon Sep 17 00:00:00 2001 From: Rabi Mishra Date: Tue, 24 Mar 2020 15:49:24 +0530 Subject: [PATCH] Remove mistral dependency for password generation completely It was partly done in https://review.opendev.org713070. Change-Id: I9713f4c369be587df766db7ca90499bcb9d9b6d0 --- tripleo_common/tests/utils/test_passwords.py | 19 ++----------------- tripleo_common/tests/utils/test_plan.py | 17 +++-------------- tripleo_common/utils/passwords.py | 6 ++---- tripleo_common/utils/plan.py | 3 +-- 4 files changed, 8 insertions(+), 37 deletions(-) diff --git a/tripleo_common/tests/utils/test_passwords.py b/tripleo_common/tests/utils/test_passwords.py index 66ecb396b..326c87243 100644 --- a/tripleo_common/tests/utils/test_passwords.py +++ b/tripleo_common/tests/utils/test_passwords.py @@ -38,12 +38,6 @@ class TestPasswords(base.TestCase): self.assertEqual(len(key), 40) def test_get_snmpd_readonly_user_password(self): - - mock_mistral = mock.Mock() - mock_mistral.environments.get.return_value = mock.Mock(variables={ - "undercloud_ceilometer_snmpd_password": self.snmp_test_pw - }) - with mock.patch(self.open_builtins, mock.mock_open(read_data="data")): with mock.patch('yaml.load') as mock_yaml: with mock.patch('os.path.exists') as mock_exists: @@ -53,9 +47,7 @@ class TestPasswords(base.TestCase): 'SnmpdReadonlyUserPassword': self.snmp_test_pw } } - value = password_utils.get_snmpd_readonly_user_password( - mock_mistral - ) + value = password_utils.get_snmpd_readonly_user_password() self.assertEqual(value, self.snmp_test_pw) @@ -70,13 +62,6 @@ class TestPasswords(base.TestCase): uuidutils.generate_uuid(dashed=False), uuidutils.generate_uuid(dashed=False)] - snmpd_password = uuidutils.generate_uuid(dashed=False) - - mock_mistral = mock.Mock() - mock_mistral.environments.get.return_value = mock.Mock(variables={ - "undercloud_ceilometer_snmpd_password": snmpd_password - }) - # generate_passwords will be called multiple times # but the order is based on how the strings are hashed, and thus # not really predictable. So, make sure it is a unique one of the @@ -90,7 +75,7 @@ class TestPasswords(base.TestCase): 'SnmpdReadonlyUserPassword': self.snmp_test_pw } } - value = password_utils.generate_passwords(mock_mistral) + value = password_utils.generate_passwords() self.assertIn(value['KeystoneCredential0'], keys) self.assertIn(value['KeystoneCredential1'], keys) self.assertIn(value['KeystoneFernetKey0'], keys) diff --git a/tripleo_common/tests/utils/test_plan.py b/tripleo_common/tests/utils/test_plan.py index 37916e796..5222c72fd 100644 --- a/tripleo_common/tests/utils/test_plan.py +++ b/tripleo_common/tests/utils/test_plan.py @@ -630,9 +630,7 @@ class PlanTest(base.TestCase): } mock_orchestration.resources.get.return_value = mock_resource - mock_workflow = mock.MagicMock() - result = plan_utils.generate_passwords(swift, mock_orchestration, - mock_workflow) + result = plan_utils.generate_passwords(swift, mock_orchestration) for password_param_name in constants.PASSWORD_PARAMETER_NAMES: self.assertTrue(password_param_name in result, @@ -685,10 +683,7 @@ class PlanTest(base.TestCase): 'parameter_defaults': {} } - mock_workflow = mock.MagicMock() - - result = plan_utils.generate_passwords(swift, mock_orchestration, - mock_workflow) + result = plan_utils.generate_passwords(swift, mock_orchestration) # ensure old passwords used and no new generation self.assertEqual(_EXISTING_PASSWORDS, result) @@ -738,9 +733,7 @@ class PlanTest(base.TestCase): } mock_orchestration.resources.get.return_value = mock_resource - mock_workflow = mock.MagicMock() result = plan_utils.generate_passwords(swift, mock_orchestration, - mock_workflow, rotate_passwords=True) # ensure passwords in the DO_NOT_ROTATE_LIST are not modified @@ -808,9 +801,7 @@ class PlanTest(base.TestCase): 'MysqlRootPassword' ] - mock_workflow = mock.MagicMock() result = plan_utils.generate_passwords(swift, mock_orchestration, - mock_workflow, rotate_passwords=True, rotate_pw_list=rotate_list) @@ -868,9 +859,7 @@ class PlanTest(base.TestCase): } } - mock_workflow = mock.MagicMock() - result = plan_utils.generate_passwords(swift, mock_orchestration, - mock_workflow) + result = plan_utils.generate_passwords(swift, mock_orchestration) existing_passwords["AdminPassword"] = "ExistingPasswordInHeat" # ensure old passwords used and no new generation diff --git a/tripleo_common/utils/passwords.py b/tripleo_common/utils/passwords.py index 918367f68..13bae4369 100644 --- a/tripleo_common/utils/passwords.py +++ b/tripleo_common/utils/passwords.py @@ -34,15 +34,13 @@ KEYSTONE_FERNET_REPO = '/etc/keystone/fernet-keys/' LOG = logging.getLogger(__name__) -def generate_passwords(mistralclient=None, stack_env=None, +def generate_passwords(stack_env=None, rotate_passwords=False): """Create the passwords needed for deploying OpenStack via t-h-t. This will create the set of passwords required by the undercloud and overcloud installers that use tripleo-heat-templates and return them - as a dict. The mistralclient is optional and only used to obtain - the previously stored SnmpdReadonlyUserPassword supplied by the - undercloud to the overcloud deployment. + as a dict. """ passwords = {} diff --git a/tripleo_common/utils/plan.py b/tripleo_common/utils/plan.py index 7c56536ce..1ed63798d 100644 --- a/tripleo_common/utils/plan.py +++ b/tripleo_common/utils/plan.py @@ -372,7 +372,7 @@ def update_plan_environment_with_image_parameters( return env -def generate_passwords(swift, heat, mistral, +def generate_passwords(swift, heat, mistral=None, container=constants.DEFAULT_CONTAINER_NAME, rotate_passwords=False, rotate_pw_list=None): """Generates passwords needed for Overcloud deployment @@ -417,7 +417,6 @@ def generate_passwords(swift, heat, mistral, stack_env = None passwords = password_utils.generate_passwords( - mistralclient=mistral, stack_env=stack_env, rotate_passwords=rotate_passwords )