Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1327179: Check proxy configuration at GUI startup #1414

Merged
merged 1 commit into from
Jul 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/subscription_manager/gui/managergui.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import urllib2
import webbrowser
import os
import socket


import rhsm.config as config
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a catch all here? Is there no way to be more specific?

log.info("Attempted bad proxy: %s" % e)
finally:
s.close()
if result:
log.error("proxy connetion error: %s" % result)
return False
else:
return True