Merge lp:~bloodearnest/conn-check/ipv6 into lp:conn-check

Proposed by Simon Davy on 2018-06-04
Status: Merged
Approved by: Simon Davy on 2018-06-04
Approved revision: 139
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~bloodearnest/conn-check/ipv6
Merge into: lp:conn-check
Diff against target: 103 lines (+22/-23)
2 files modified
Makefile (+2/-1)
conn_check/checks.py (+20/-22)
To merge this branch: bzr merge lp:~bloodearnest/conn-check/ipv6
Reviewer Review Type Date Requested Status
Simon Davy Approve on 2018-06-04
Tom Wardill 2018-06-04 Approve on 2018-06-04
Wes Mason (community) Approve on 2018-06-04
Review via email: mp+347357@code.launchpad.net

Commit message

Use newer HostnameEndpoint api for tcp checks, which supports ipv6.

Note: udp checks still don't support ipv6, as that is more complex, and of less use, given that very few services (only txstatsd to my knowledge) support the response required.

To post a comment you must log in.
Wes Mason (wesmason) wrote :

lgtm

review: Approve
Tom Wardill (twom) :
review: Approve
lp:~bloodearnest/conn-check/ipv6 updated on 2018-06-04
139. By Simon Davy on 2018-06-04

separte pip/setuptools upgrade

Simon Davy (bloodearnest) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2018-01-29 17:27:38 +0000
3+++ Makefile 2018-06-04 15:00:56 +0000
4@@ -12,7 +12,8 @@
5 virtualenv $(ENV)
6
7 build: $(ENV)
8- $(ENV)/bin/pip install -U setuptools pip
9+ $(ENV)/bin/pip install -U pip
10+ $(ENV)/bin/pip install -U setuptools
11 $(ENV)/bin/pip install -r devel-requirements.txt
12 $(ENV)/bin/python setup.py develop
13
14
15=== modified file 'conn_check/checks.py'
16--- conn_check/checks.py 2018-01-29 14:07:24 +0000
17+++ conn_check/checks.py 2018-06-04 15:00:56 +0000
18@@ -1,11 +1,10 @@
19 from __future__ import print_function
20 from future import standard_library
21-standard_library.install_aliases()
22-
23-from io import StringIO
24+standard_library.install_aliases() # NOQA
25
26 from email.mime.text import MIMEText
27 import glob
28+from io import StringIO
29 import os
30 from pkg_resources import resource_stream
31 import sys
32@@ -21,9 +20,12 @@
33 Deferred,
34 inlineCallbacks,
35 )
36+from twisted.internet.endpoints import HostnameEndpoint, wrapClientTLS
37+from twisted.internet.ssl import optionsForClientTLS
38 from twisted.internet.protocol import (
39 ClientCreator,
40 DatagramProtocol,
41+ Factory,
42 Protocol,
43 )
44 from twisted.mail.smtp import ESMTPSenderFactory
45@@ -31,6 +33,7 @@
46
47 from txrequests import Session
48 from requests.auth import HTTPDigestAuth
49+from requests.exceptions import ConnectionError, SSLError
50
51 try:
52 from requests.packages.urllib3 import disable_warnings
53@@ -93,26 +96,21 @@
54 def do_tcp_check(host, port, tls=False, tls_verify=True,
55 timeout=None):
56 """Generic connection check function."""
57- if not isIPAddress(host):
58- try:
59- ip = yield reactor.resolve(host, timeout=(1, timeout))
60- except DNSLookupError:
61- raise ValueError("dns resolution failed")
62- else:
63- ip = host
64- creator = ClientCreator(reactor, TCPCheckProtocol)
65+
66 try:
67+ endpoint = HostnameEndpoint(reactor, host, port, timeout=timeout)
68+
69 if tls:
70- context = VerifyingContextFactory(tls_verify, CA_CERTS)
71- yield creator.connectSSL(ip, port, context,
72- timeout=timeout)
73- else:
74- yield creator.connectTCP(ip, port, timeout=timeout)
75+ endpoint = wrapClientTLS(
76+ optionsForClientTLS(hostname=host),
77+ endpoint,
78+ )
79+
80+ yield endpoint.connect(Factory.forProtocol(TCPCheckProtocol))
81+ except DNSLookupError:
82+ raise ValueError("dns lookup error")
83 except TimeoutError:
84- if ip == host:
85- raise ValueError("timed out")
86- else:
87- raise ValueError("timed out connecting to {}".format(ip))
88+ raise ValueError("timed out connecting to {}".format(host))
89
90
91 def make_tcp_check(host, port, timeout=None, **kwargs):
92@@ -403,9 +401,9 @@
93 def make_redis_check(host, port, password=None, timeout=None,
94 **kwargs):
95 """Make a check for the configured redis server."""
96- if sys.version_info[0] >= 3:
97+ if sys.version_info[0] >=3:
98 print('Redis checks are not supported in python 3.\n'
99- 'This may help: https://github.com/deldotdr/txRedis/pull/58')
100+ 'This may help: https://github.com/deldotdr/txRedis/pull/58')
101 import txredis
102 subchecks = []
103 subchecks.append(make_tcp_check(host, port, timeout=timeout))

Subscribers

People subscribed via source and target branches

to all changes: