diagnostics: Use curl instead of wget for URLs

wget does not seem to support interface scoping for IPv6 addresses.  For
example, http_proxy=http://[fe80::babe:ff:ffff:babe%eth0]:8118/ . Curl
supports this.

This fixes most of the failures for IPv6 related addresses.  Hide the
last failure as there does not seem to be a proper fix from OS level:
when using link local addresses, if a hostname is resolved to IPv6 link
local address, it is not scoped to that interface.  It can't properly be
used by any tool then.
This commit is contained in:
Sunil Mohan Adapa 2016-06-01 20:37:35 +05:30 committed by James Valleroy
parent 97b77e3719
commit d3f386733f
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
9 changed files with 19 additions and 15 deletions

View File

@ -285,17 +285,20 @@ def _check_port(port, kind='tcp', listen_address=None):
return False
def diagnose_url(url, kind=None, env=None, extra_options=None, wrapper=None,
expected_output=None):
def diagnose_url(url, kind=None, env=None, check_certificate=True,
extra_options=None, wrapper=None, expected_output=None):
"""Run a diagnostic on whether a URL is accessible.
Kind can be '4' for IPv4 or '6' for IPv6.
"""
command = ['wget', '-q', '-O', '-', url]
command = ['curl', '-f', '-w', '%{response_code}', url]
if wrapper:
command.insert(0, wrapper)
if not check_certificate:
command.append('-k')
if extra_options:
command.extend(extra_options)
@ -303,14 +306,16 @@ def diagnose_url(url, kind=None, env=None, extra_options=None, wrapper=None,
command.append({'4': '-4', '6': '-6'}[kind])
try:
output = subprocess.check_output(command, env=env)
process = subprocess.run(
command, env=env, check=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = 'passed'
if expected_output and expected_output not in output.decode():
if expected_output and expected_output not in process.stdout.decode():
result = 'failed'
except subprocess.CalledProcessError as exception:
result = 'failed'
# Authorization failed is a success
if exception.returncode == 6:
if exception.stdout.decode().strip() == '401':
result = 'passed'
except FileNotFoundError:
result = 'error'

View File

@ -88,6 +88,6 @@ def diagnose():
results.append(action_utils.diagnose_port_listening(8112, 'tcp4'))
results.append(action_utils.diagnose_port_listening(8112, 'tcp6'))
results.extend(action_utils.diagnose_url_on_all(
'https://{host}/deluge', extra_options=['--no-check-certificate']))
'https://{host}/deluge', check_certificate=False))
return results

View File

@ -51,6 +51,6 @@ def diagnose():
results.append(action_utils.diagnose_port_listening(8000, 'tcp4'))
results.append(action_utils.diagnose_port_listening(8000, 'tcp6'))
results.extend(action_utils.diagnose_url_on_all(
'http://{host}/plinth/', extra_options=['--no-check-certificate']))
'http://{host}/plinth/', check_certificate=False))
return results

View File

@ -85,6 +85,6 @@ def diagnose():
results = []
results.extend(action_utils.diagnose_url_on_all(
'https://{host}/ikiwiki', extra_options=['--no-check-certificate']))
'https://{host}/ikiwiki', check_certificate=False))
return results

View File

@ -102,7 +102,7 @@ def diagnose():
results = []
results.extend(action_utils.diagnose_url_on_all(
'https://{host}/owncloud', extra_options=['--no-check-certificate']))
'https://{host}/owncloud', check_certificate=False))
return results

View File

@ -91,6 +91,6 @@ def diagnose():
results.append(action_utils.diagnose_port_listening(5232, 'tcp4'))
results.append(action_utils.diagnose_port_listening(5232, 'tcp6'))
results.extend(action_utils.diagnose_url_on_all(
'https://{host}/radicale', extra_options=['--no-check-certificate']))
'https://{host}/radicale', check_certificate=False))
return results

View File

@ -96,6 +96,6 @@ def diagnose():
results = []
results.extend(action_utils.diagnose_url_on_all(
'https://{host}/roundcube', extra_options=['--no-check-certificate']))
'https://{host}/roundcube', check_certificate=False))
return results

View File

@ -95,7 +95,6 @@ def diagnose():
results.append(action_utils.diagnose_port_listening(9091, 'tcp4'))
results.append(action_utils.diagnose_port_listening(9091, 'tcp6'))
results.extend(action_utils.diagnose_url_on_all(
'https://{host}/transmission',
extra_options=['--no-check-certificate']))
'https://{host}/transmission', check_certificate=False))
return results

View File

@ -87,6 +87,6 @@ def diagnose():
results = []
results.extend(action_utils.diagnose_url_on_all(
'https://{host}/tt-rss', extra_options=['--no-check-certificate']))
'https://{host}/tt-rss', check_certificate=False))
return results