diff --git a/cfme/tests/automate/test_common_methods.py b/cfme/tests/automate/test_common_methods.py index fc8caf4a25..2952231d74 100644 --- a/cfme/tests/automate/test_common_methods.py +++ b/cfme/tests/automate/test_common_methods.py @@ -129,7 +129,7 @@ class TestDropdownView(InfraVmSummaryView): @pytest.mark.tier(3) @pytest.mark.meta(automates=[1720432]) -def test_miq_password_decrypt(klass): +def test_miq_password_decrypt(appliance, klass): """ Polarion: assignee: ghubale @@ -142,9 +142,9 @@ def test_miq_password_decrypt(klass): # Ruby script for decrypting password script = ( 'require "manageiq-password"\n' - 'root_password = MiqPassword.encrypt("abc")\n' + f'root_password = {appliance.password_gem}.encrypt("abc")\n' '$evm.log("info", "Root Password is #{root_password}")\n' - 'root_password_decrypted = MiqPassword.decrypt(root_password)\n' + f'root_password_decrypted = {appliance.password_gem}.decrypt(root_password)\n' '$evm.log("info", "Decrypted password is #{root_password_decrypted}")' ) diff --git a/cfme/utils/appliance/__init__.py b/cfme/utils/appliance/__init__.py index 70206d69d7..54b1292a4c 100644 --- a/cfme/utils/appliance/__init__.py +++ b/cfme/utils/appliance/__init__.py @@ -569,12 +569,20 @@ def seal_for_templatizing(self): ssh_client.run_command('echo "vm.swappiness = 1" >> /etc/sysctl.conf', ensure_host=True) + @cached_property + def password_gem(self): + return VersionPicker({ + Version.lowest(): 'MiqPassword', + '5.11': 'ManageIQ::Password' + }).pick(self.version) + def _encrypt_string(self, string): try: # Let's not log passwords logging.disable(logging.CRITICAL) result = self.ssh_client.run_rails_command( - "\"puts MiqPassword.encrypt('{}')\"".format(string)) + f'"puts {self.password_gem}.encrypt(\'{string}\')"' + ) return result.output.strip() finally: logging.disable(logging.NOTSET) diff --git a/scripts/harden_security.py b/scripts/harden_security.py index 709dcb2459..8b83dc43ee 100755 --- a/scripts/harden_security.py +++ b/scripts/harden_security.py @@ -77,6 +77,9 @@ def generate_key(address): def update_db_yaml(address): with SSHClient(hostname=address, **ssh_creds) as client: client.run_command('cd /var/www/miq/vmdb') + # TODO Issue 8595, MiqPassword alias/gem will go away + # IPAppliance.password_gem property version picks the gem name + # We only have an address here, will have to look for the gem. result = client.run_rails_command( '\'puts MiqPassword.encrypt("smartvm");\'') if result.failed: