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

Raise clear error message on invalid Windows minion WinRM creds. #295

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions coriolis/osmorphing/osmount/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ def check_os(self):
"(get-ciminstance Win32_OperatingSystem).Caption")
LOG.debug("Windows version: %s", version_info)
return True
except exception.NotAuthorized:
# NOTE: Unauthorized exceptions should be propagated.
raise
except exception.CoriolisException:
LOG.debug(
"Failed Windows OSMount OS check: %s",
utils.get_exception_details())
pass
return False

def _run_diskpart_script(self, script):
"""Executes the given script with diskpart.exe.
Expand Down
18 changes: 16 additions & 2 deletions coriolis/wsman.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ def set_timeout(self, timeout):
def _exec_command(self, cmd, args=[], timeout=None):
timeout = int(timeout or self._conn_timeout)
self.set_timeout(timeout)
shell_id = self._protocol.open_shell(codepage=CODEPAGE_UTF8)
shell_id = None
try:
shell_id = self._protocol.open_shell(codepage=CODEPAGE_UTF8)
command_id = self._protocol.run_command(shell_id, cmd, args)
try:
(std_out,
Expand All @@ -115,8 +116,21 @@ def _exec_command(self, cmd, args=[], timeout=None):
self._protocol.cleanup_command(shell_id, command_id)

return (std_out, std_err, exit_code)
except winrm_exceptions.InvalidCredentialsError as ex:
raise exception.NotAuthorized(
message="The WinRM connection credentials are invalid. "
"If you are using a template with a default "
"pre-baked username/password, please ensure "
"that you have passed the credentials to the "
"destination Coriolis plugin you have selected,"
" either via the Target Environment parameters "
"set when creating the Migration/Replica, or "
"by setting it in the destination plugin's "
"dedicated section of the coriolis.conf "
"static configuration file.") from ex
finally:
self._protocol.close_shell(shell_id)
if shell_id:
self._protocol.close_shell(shell_id)

def exec_command(self, cmd, args=[], timeout=None):
LOG.debug("Executing WSMAN command: %s", str([cmd] + args))
Expand Down
Loading