From 6c4114a3e6970cbe82adec421c0bdaa9259468b7 Mon Sep 17 00:00:00 2001 From: Hugo Brito Date: Mon, 24 Oct 2022 14:12:49 -0300 Subject: [PATCH] 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 Change-Id: I51ba0e77abc90872fb0ac832f18bc9ca2c9c5828 --- .../dcmanagerclient/utils.py | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/distributedcloud-client/dcmanagerclient/utils.py b/distributedcloud-client/dcmanagerclient/utils.py index 5426116e..f7dd2e6a 100644 --- a/distributedcloud-client/dcmanagerclient/utils.py +++ b/distributedcloud-client/dcmanagerclient/utils.py @@ -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