Subject: virtinst: early detect ftp connection errors From: Giuseppe Scrivano gscrivan@redhat.com Mon Apr 14 14:49:21 2014 +0200 Date: Mon Apr 14 15:20:18 2014 +0200: Git: 1d312a520e92e89da1b4d958b9de0270eecc6b4b It fixes two problems: i) "ftp://" was accepted as valid URL but then it causes this exception: Traceback (most recent call last): File "", line 1, in 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 diff --git a/virtinst/urlfetcher.py b/virtinst/urlfetcher.py index 7075929..3f2744b 100644 --- a/virtinst/urlfetcher.py +++ b/virtinst/urlfetcher.py @@ -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)