vmaccess: better error messages
@@ -79,12 +79,11 @@ def enable():
remove_user = protect_settings.get('remove_user')
if remove_user and _is_sshd_config_modified(protect_settings):
- hutil.error("Cannot reset sshd_config and remove a user in one operation.")
waagent.AddExtensionEvent(name=hutil.get_name(),
op=waagent.WALAEventOperation.Enable,
isSuccess=False,
message="(03002)Argument error, conflicting operations")
- hutil.do_exit(1, 'Enable', 'error', '0', 'Enable failed.')
+ raise Exception("Cannot reset sshd_config and remove a user in one operation.")
# check port each time the VM boots up
if reset_ssh:
@@ -106,7 +105,7 @@ def enable():
op=waagent.WALAEventOperation.Enable,
isSuccess=False,
message="(03002)Argument error, invalid remove_user")
- raise Exception("invalid remove_user")
+ raise Exception("'remove_user' does not match the regular expression '^[a-z][-a-z0-9_]*$'")
waagent.AddExtensionEvent(name=hutil.get_name(), op="scenario", isSuccess=True, message="remove-user")
_remove_user_account(remove_user, hutil)
@@ -121,7 +120,7 @@ def enable():
except Exception as e:
hutil.error(("Failed to enable the extension with error: {0}, "
"stack trace: {1}").format(str(e), traceback.format_exc()))
- hutil.do_exit(1, 'Enable', 'error', '0', 'Enable failed.')
+ hutil.do_exit(1, 'Enable', 'error', '0', "Enable failed: {0}".format(str(e)))
def _forcibly_reset_chap(hutil):
@@ -196,7 +195,7 @@ def _set_user_account_pub_key(protect_settings, hutil):
op=waagent.WALAEventOperation.Enable,
isSuccess=False,
message="(03002)Argument error, invalid username")
- raise Exception("invalid username")
+ raise Exception("'username' does not match the regular expression '^[a-z][-a-z0-9_]*$'")
user_pass = protect_settings.get('password')
cert_txt = protect_settings.get('ssh_key')
