virtinst: early detect ftp connection errors

It fixes two problems:

i) "ftp://" was accepted as valid URL but then it causes this
exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/ftplib.py", line 387, in login
    resp = self.sendcmd('USER ' + user)
  File "/usr/lib64/python2.7/ftplib.py", line 243, in sendcmd
    self.putcmd(cmd)
  File "/usr/lib64/python2.7/ftplib.py", line 178, in putcmd
    self.putline(line)
  File "/usr/lib64/python2.7/ftplib.py", line 173, in putline
    self.sock.sendall(line)
AttributeError: 'NoneType' object has no attribute 'sendall'

ii) only a cryptic error message "Unable to complete install: '[Errno
-2] Name or service not known'" was showed to users when the DNS
lookup failed.  The exception is now intercepted and decorated with
more information.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1086554

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2014-04-14 14:49:21 +02:00
parent 4ccb1d862b
commit 1d312a520e
1 changed files with 10 additions and 3 deletions

View File

@ -151,9 +151,16 @@ class _FTPImageFetcher(_URIImageFetcher):
self.ftp = None
def prepareLocation(self):
url = urlparse.urlparse(self._make_path(""))
self.ftp = ftplib.FTP(url[1])
self.ftp.login()
try:
url = urlparse.urlparse(self._make_path(""))
if not url[1]:
raise ValueError(_("Invalid install location"))
self.ftp = ftplib.FTP(url[1])
self.ftp.login()
except Exception, e:
raise ValueError(_("Opening URL %s failed: %s.") %
(self.location, str(e)))
def hasFile(self, filename):
path = self._make_path(filename)