Skip to content

Commit

Permalink
Move winrm_exception.InvalidCredentials handling back to wsman.py.
Browse files Browse the repository at this point in the history
Signed-off-by: Nashwan Azhari <nazhari@cloudbasesolutions.com>
  • Loading branch information
aznashwan authored and Dany9966 committed Mar 18, 2024
1 parent c84305a commit 9242203
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
17 changes: 4 additions & 13 deletions coriolis/osmorphing/osmount/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import uuid

from oslo_log import log as logging
from winrm import exceptions as winrm_exceptions

from coriolis import exception
from coriolis.osmorphing.osmount import base
Expand Down Expand Up @@ -37,23 +36,15 @@ def check_os(self):
"(get-ciminstance Win32_OperatingSystem).Caption")
LOG.debug("Windows version: %s", version_info)
return True
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
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
12 changes: 12 additions & 0 deletions coriolis/wsman.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ 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:
if shell_id:
self._protocol.close_shell(shell_id)
Expand Down

0 comments on commit 9242203

Please sign in to comment.