Просмотр исходного кода

Raise clear error message on invalid Windows minion WinRM creds.

Signed-off-by: Nashwan Azhari <nazhari@cloudbasesolutions.com>
Nashwan Azhari 2 лет назад
Родитель
Сommit
c84305ab69
2 измененных файлов с 20 добавлено и 2 удалено
  1. 16 0
      coriolis/osmorphing/osmount/windows.py
  2. 4 2
      coriolis/wsman.py

+ 16 - 0
coriolis/osmorphing/osmount/windows.py

@@ -5,6 +5,7 @@ import re
 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
@@ -36,7 +37,22 @@ class WindowsMountTools(base.BaseOSMountTools):
                 "(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.CoriolisException:
+            LOG.debug(
+                "Failed Windows OSMount OS check: %s",
+                utils.get_exception_details())
             pass
 
     def _run_diskpart_script(self, script):

+ 4 - 2
coriolis/wsman.py

@@ -100,8 +100,9 @@ class WSManConnection(object):
     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,
@@ -116,7 +117,8 @@ class WSManConnection(object):
 
             return (std_out, std_err, exit_code)
         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))