[Kimchi-devel] [PATCH v4 2/3] Fix verification of remote ISO
Christy Perez
christy at linux.vnet.ibm.com
Wed Aug 13 13:55:52 UTC 2014
On 08/12/2014 08:02 PM, Aline Manera wrote:
>
> On 08/12/2014 02:38 PM, Christy Perez wrote:
>> Currently the entire ISO is grabbed, which times out.
>> Use httplib to connect to the server and just get
>> the head of the http object.
>>
>> Signed-off-by: Christy Perez <christy at linux.vnet.ibm.com>
>> ---
>> src/kimchi/utils.py | 26 ++++++++++++++++++++++----
>> 1 file changed, 22 insertions(+), 4 deletions(-)
>>
>> diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
>> index 9ed8802..efd3ba9 100644
>> --- a/src/kimchi/utils.py
>> +++ b/src/kimchi/utils.py
>> @@ -28,9 +28,10 @@
>> import traceback
>> import urllib2
>> import xml.etree.ElementTree as ET
>> +from httplib import HTTPConnection, HTTPException
>> from multiprocessing import Process, Queue
>> from threading import Timer
>> -
>> +from urlparse import urlparse
>> from cherrypy.lib.reprconf import Parser
>>
>> from kimchi.asynctask import AsyncTask
>> @@ -138,14 +139,31 @@ def import_module(module_name):
>> return __import__(module_name, globals(), locals(), [''])
>>
>>
>> +def url_to_fqdn(path):
>> + parse_result = urlparse(path)
>> + return parse_result.netloc
>> +
>> +
>> def check_url_path(path):
>> try:
>> - code = urllib2.urlopen(path).getcode()
>> + code = ''
>> + server_name = url_to_fqdn(path)
>
>> + url_parts = path.split('://') # [0] = prefix, [1] = rest of URL
>> + if len(url_parts) > 1 and server_name == url_parts[1] :
>
> You can use urlparse(path) here too and check the existence of a path
Thanks. I'd just copied that from somewhere else, so I'll update that to
do the same if it works in that situation as well -- and send a v5.
>
> parse_result = urlparse(path)
> server_name = parse_result.netloc
> urlpath = parse_result.path
>
> if not urlpath:
> ...
> else:
> ...
>
> As you need to update it, I think we can also remove url_to_fqdn()
> function as it is not used in other place
>
>
>> + # Just a server, as with a repo.
>> + code = urllib2.urlopen(path).getcode()
>> + else:
>> + # socket.gaierror could be raised,
>> + # which is a child class of IOError
>> + conn = HTTPConnection(server_name, timeout=15)
>> + # Don't try to get the whole file:
>> + conn.request('HEAD', path)
>> + code = conn.getresponse().status
>> + conn.close()
>> if code != 200:
>> return False
>> - except (urllib2.URLError, ValueError):
>> + except (urllib2.URLError, HTTPException, IOError, ValueError):
>> return False
>> -
>> return True
>>
>>
>
More information about the Kimchi-devel
mailing list