44from __future__ import print_function
55from __future__ import absolute_import
66import requests
7+ import urllib3
78import socket
89import os
910import six
@@ -481,6 +482,31 @@ def _test_auth_config(self):
481482
482483 return not errors
483484
485+ def _test_url_config (self ):
486+ logger .info ("URL configuration:" )
487+
488+ urls = [("Base URL" , self .base_url )]
489+ if self .proxies :
490+ for proxy_protocol , proxy_url in self .proxies .items ():
491+ proxy_description = "{} proxy URL" .format (proxy_protocol .upper ())
492+ urls .append ((proxy_description , proxy_url ))
493+
494+ valid = True
495+ for description , url in urls :
496+ try :
497+ urllib3 .util .url .parse_url (url )
498+ except urllib3 .exceptions .LocationParseError :
499+ valid = False
500+ logger .error (" %s: %s (INVALID!)" , description , url )
501+ else :
502+ logger .info (" %s: %s" , description , url )
503+ if not self .proxies :
504+ logger .info (" No proxy." )
505+
506+ logger .info ("" )
507+
508+ return valid
509+
484510 def _dump_urls (self ):
485511 base_parsed = urlparse (self .base_url )
486512 if base_parsed .hostname .endswith ("stage.redhat.com" ):
@@ -496,20 +522,13 @@ def _dump_urls(self):
496522 logger .info ("Running Connection Tests against %s..." , hostname_desc )
497523
498524 urls = [
499- (self .base_url , "Base" ),
500525 (self .upload_url , "Upload" ),
501526 (self .inventory_url , "Inventory" ),
502527 (self .ping_url , "Ping" ),
503528 ]
504529 for url , title in urls :
505530 logger .info (" %s URL: %s" , title , url )
506531
507- if self .proxies :
508- for proxy_type , proxy_url in self .proxies .items ():
509- logger .info (" %s proxy: %s" , proxy_type .upper (), proxy_url )
510- else :
511- logger .info (" Proxy: not set" )
512-
513532 logger .info ("" )
514533
515534 def _test_connection (self , scheme , hostname ):
@@ -537,9 +556,10 @@ def test_connection(self, rc=0):
537556 """
538557 Test connection to Red Hat
539558 """
540- auth_config_ok = self ._test_auth_config ()
541- if not auth_config_ok :
542- return 1
559+ for config_test in [self ._test_auth_config , self ._test_url_config ]:
560+ success = config_test ()
561+ if not success :
562+ return 1
543563
544564 self ._dump_urls ()
545565
0 commit comments