From 6df3f6458c61d6e334a40001a10868477490497c Mon Sep 17 00:00:00 2001 From: William Poteat Date: Tue, 3 May 2016 11:38:06 -0400 Subject: [PATCH] 1327179: Check proxy configuration at GUI startup Reports an error on the command line and log and then exits. --- src/subscription_manager/gui/managergui.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/subscription_manager/gui/managergui.py b/src/subscription_manager/gui/managergui.py index 77cef772c4..c6deb36d60 100644 --- a/src/subscription_manager/gui/managergui.py +++ b/src/subscription_manager/gui/managergui.py @@ -27,6 +27,7 @@ import urllib2 import webbrowser import os +import socket import rhsm.config as config @@ -57,6 +58,7 @@ from subscription_manager.gui.utils import handle_gui_exception, linkify from subscription_manager.gui.reposgui import RepositoriesDialog from subscription_manager.overrides import Overrides +from subscription_manager.cli import system_exit _ = gettext.gettext @@ -150,6 +152,8 @@ def __init__(self, backend=None, facts=None, auto_launch_registration=False): super(MainWindow, self).__init__() + if not self.test_proxy_connection(): + system_exit(os.EX_UNAVAILABLE, _("Proxy connnection failed, please check your settings.")) self.backend = backend or Backend() self.identity = require(IDENTITY) @@ -508,3 +512,21 @@ def _get_online_doc_url(self): # Use the default if there is no translation. url = ONLINE_DOC_FALLBACK_URL return url + + def test_proxy_connection(self): + result = None + if not cfg.get("server", "proxy_hostname"): + return True + try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(10) + result = s.connect_ex((cfg.get("server", "proxy_hostname"), int(cfg.get("server", "proxy_port") or config.DEFAULT_PROXY_PORT))) + except Exception as e: + log.info("Attempted bad proxy: %s" % e) + finally: + s.close() + if result: + log.error("proxy connetion error: %s" % result) + return False + else: + return True