Skip to content

Commit

Permalink
[fwutil]: Set default socket timeout for FW download to 30 sec. (#821)
Browse files Browse the repository at this point in the history
Signed-off-by: Nazarii Hnydyn <nazariig@mellanox.com>
  • Loading branch information
nazariig authored Mar 1, 2020
1 parent 81c5930 commit c5c5ffc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions fwutil/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import click
import os
import json
import socket
import urllib
import subprocess
import sonic_device_util
Expand Down Expand Up @@ -45,7 +46,8 @@ class URL(object):
PB_INFO_SEPARATOR = " | "
PB_FULL_TERMINAL_WIDTH = 0

TMP_PATH = "/tmp"
DOWNLOAD_TIMEOUT = 30
DOWNLOAD_PATH_TEMPLATE = "/tmp/{}"

def __init__(self, url):
self.__url = url
Expand Down Expand Up @@ -115,13 +117,21 @@ def retrieve(self):
if not extension:
raise RuntimeError("Filename is malformed: did not find an extension")

default_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(self.DOWNLOAD_TIMEOUT)

try:
filename, headers = urllib.urlretrieve(
self.__url,
"{}/{}".format(self.TMP_PATH, basename),
self.DOWNLOAD_PATH_TEMPLATE.format(basename),
self.__reporthook
)
except:
if os.path.exists(self.DOWNLOAD_PATH_TEMPLATE.format(basename)):
os.remove(self.DOWNLOAD_PATH_TEMPLATE.format(basename))
raise
finally:
socket.setdefaulttimeout(default_timeout)
self.__pb_reset()

return filename, headers
Expand Down

0 comments on commit c5c5ffc

Please sign in to comment.