2
0
Эх сурвалжийг харах

Merge pull request #252 from Dany9966/wsman-download-err-msg

Adds error message on WSMan File Download failure.
Daniel Vincze 3 жил өмнө
parent
commit
4f2a60b2d9
1 өөрчлөгдсөн 20 нэмэгдсэн , 13 устгасан
  1. 20 13
      coriolis/wsman.py

+ 20 - 13
coriolis/wsman.py

@@ -143,19 +143,26 @@ class WSManConnection(object):
     def download_file(self, url, remote_path):
         LOG.debug("Downloading: \"%(url)s\" to \"%(path)s\"",
                   {"url": url, "path": remote_path})
-        # Nano Server does not have Invoke-WebRequest and additionally
-        # this is also faster
-        self.exec_ps_command(
-            "[Net.ServicePointManager]::SecurityProtocol = "
-            "[Net.SecurityProtocolType]::Tls12;"
-            "if(!([System.Management.Automation.PSTypeName]'"
-            "System.Net.Http.HttpClient').Type) {$assembly = "
-            "[System.Reflection.Assembly]::LoadWithPartialName("
-            "'System.Net.Http')}; (new-object System.Net.Http.HttpClient)."
-            "GetStreamAsync('%(url)s').Result.CopyTo("
-            "(New-Object IO.FileStream '%(outfile)s', Create, Write, None), "
-            "1MB)" % {"url": url, "outfile": remote_path},
-            ignore_stdout=True)
+        try:
+            # Nano Server does not have Invoke-WebRequest and additionally
+            # this is also faster
+            self.exec_ps_command(
+                "[Net.ServicePointManager]::SecurityProtocol = "
+                "[Net.SecurityProtocolType]::Tls12;"
+                "if(!([System.Management.Automation.PSTypeName]'"
+                "System.Net.Http.HttpClient').Type) {$assembly = "
+                "[System.Reflection.Assembly]::LoadWithPartialName("
+                "'System.Net.Http')}; (new-object System.Net.Http.HttpClient)."
+                "GetStreamAsync('%(url)s').Result.CopyTo("
+                "(New-Object IO.FileStream '%(outfile)s', Create, Write, "
+                "None), 1MB)" % {"url": url, "outfile": remote_path},
+                ignore_stdout=True)
+        except exception.CoriolisException as ex:
+            LOG.trace(utils.get_exception_details())
+            raise exception.CoriolisException(
+                "Failed to download file from URL: %s to path: %s. Please "
+                "check logs for more details." % (
+                    url, remote_path)) from ex
 
     def write_file(self, remote_path, content):
         self.exec_ps_command(