Handle KeyboardInterrupt on password prompt

If the user interrupts the password prompt manually
the error message is not handling and the output is
the error traceback. This commits change it to output
a better message.

Test Plan:
PASS - Interrupts password prompt using
dcmanager subcloub-backup (create/delete/restore)
without --sysadmin-password parameter.

Story: 2010116
Task: 46165

Signed-off-by: Hugo Brito <hugo.brito@windriver.com>
Change-Id: I51ba0e77abc90872fb0ac832f18bc9ca2c9c5828
This commit is contained in:
Hugo Brito 2022-10-24 14:12:49 -03:00 committed by Hugo Nicodemos
parent 2f842d5ba7
commit 6c4114a3e6
1 changed files with 16 additions and 11 deletions

View File

@ -89,16 +89,21 @@ def get_contents_if_file(contents_or_file_name):
def prompt_for_password(password_type='sysadmin'):
while True:
password = getpass.getpass(
"Enter the " + password_type + " password for the subcloud: ")
if len(password) < 1:
print("Password cannot be empty")
continue
try:
password = getpass.getpass(
"Enter the " + password_type + " password for the subcloud: ")
if len(password) < 1:
print("Password cannot be empty")
continue
confirm = getpass.getpass(
"Re-enter " + password_type + " password to confirm: ")
if password != confirm:
print("Passwords did not match")
continue
break
confirm = getpass.getpass(
"Re-enter " + password_type + " password to confirm: ")
if password != confirm:
print("Passwords did not match")
continue
break
except KeyboardInterrupt:
raise exceptions.DCManagerClientException(
"\nPassword prompt interrupted."
)
return password