Skip to content

Commit

Permalink
Merge pull request #6060 from fangge1212/set_password
Browse files Browse the repository at this point in the history
Set user password fix
  • Loading branch information
Yingshun authored Feb 11, 2025
2 parents 300932f + 8e62241 commit d2b7135
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions libvirt/tests/src/virsh_cmd/domain/virsh_set_user_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,40 +76,29 @@ def run(test, params, env):
ret = process.run(cmd, shell=True)
libvirt.check_exit_status(ret)
en_passwd = str(ret.stdout_text.strip())
passwd = en_passwd
passwd = en_passwd.replace('$', r'\$')

ret = virsh.set_user_password(vm_name, set_user_name, passwd,
encrypted=encrypted, option=option, debug=True)
libvirt.check_exit_status(ret)

# Login with new password
logging.debug("Trying to log in with new password")
try:
session = remote.wait_for_login("ssh", vm_ip, "22", set_user_name, new_passwd,
r"[\#\$]\s*$", timeout=30)
session.close()
except remote.LoginAuthenticationError as e:
logging.debug(e)
test.fail("Failed to login with new password")

# Login with old password
try:
session = remote.wait_for_login("ssh", vm_ip, "22", set_user_name, ori_passwd,
r"[\#\$]\s*$", timeout=10)
session.close()
except remote.LoginAuthenticationError:
logging.debug("Login with old password failed as expected.")

# Change the password back in VM
ret = virsh.set_user_password(vm_name, set_user_name, ori_passwd, False,
option=option, debug=True)
libvirt.check_exit_status(ret)

# Login with the original password
try:
session = remote.wait_for_login("ssh", vm_ip, "22", set_user_name, ori_passwd,
r"[\#\$]\s*$", timeout=30)
session.close()
except remote.LoginAuthenticationError as e:
logging.debug(e)
finally:
# Recover VM
if vm.is_alive():
# always restore root password in case previously case execution is broken
if status_error != "yes":
virsh.set_user_password(vm_name, set_user_name, ori_passwd, False,
option=option, debug=True)

if start_ga:
# Stop guest agent in vm
Expand All @@ -124,12 +113,5 @@ def run(test, params, env):
test.error("Deleting user '%s' got failed: '%s'" %
(set_user_name, output))
session.close()
finally:
# Recover VM
if vm.is_alive():
# always restore root password in case previously case execution is broken
if status_error != "yes":
virsh.set_user_password(vm_name, set_user_name, ori_passwd, False,
option=option, debug=True)
vm.destroy(gracefully=False)
vmxml_bak.sync()

0 comments on commit d2b7135

Please sign in to comment.