Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set user password fix #6060

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()