Skip to content

Commit d2b7135

Browse files
authored
Merge pull request #6060 from fangge1212/set_password
Set user password fix
2 parents 300932f + 8e62241 commit d2b7135

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

libvirt/tests/src/virsh_cmd/domain/virsh_set_user_password.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,40 +76,29 @@ def run(test, params, env):
7676
ret = process.run(cmd, shell=True)
7777
libvirt.check_exit_status(ret)
7878
en_passwd = str(ret.stdout_text.strip())
79-
passwd = en_passwd
79+
passwd = en_passwd.replace('$', r'\$')
8080

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

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

93-
# Login with old password
94-
try:
95-
session = remote.wait_for_login("ssh", vm_ip, "22", set_user_name, ori_passwd,
96-
r"[\#\$]\s*$", timeout=10)
97-
session.close()
98-
except remote.LoginAuthenticationError:
99-
logging.debug("Login with old password failed as expected.")
100-
101-
# Change the password back in VM
102-
ret = virsh.set_user_password(vm_name, set_user_name, ori_passwd, False,
103-
option=option, debug=True)
104-
libvirt.check_exit_status(ret)
105-
106-
# Login with the original password
107-
try:
108-
session = remote.wait_for_login("ssh", vm_ip, "22", set_user_name, ori_passwd,
109-
r"[\#\$]\s*$", timeout=30)
110-
session.close()
111-
except remote.LoginAuthenticationError as e:
112-
logging.debug(e)
95+
finally:
96+
# Recover VM
97+
if vm.is_alive():
98+
# always restore root password in case previously case execution is broken
99+
if status_error != "yes":
100+
virsh.set_user_password(vm_name, set_user_name, ori_passwd, False,
101+
option=option, debug=True)
113102

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

0 commit comments

Comments
 (0)