Skip to content

Commit 7c482ae

Browse files
committed
Update rhel-7 branch with bugfixes from rhel-6, bump version
2 parents 8359ecd + caf5e4b commit 7c482ae

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

etc/redhat-access-insights.spec

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
Name: redhat-access-insights
55
Summary: Uploads Insights information to Red Hat on a periodic basis
6-
Version: 1.0.8
7-
Release: 10%{?dist}
6+
Version: 1.0.9
7+
Release: 0%{?dist}
88
Source0: https://github.com/redhataccess/insights-client/archive/redhat-access-insights-%{version}.tar.gz
99
Epoch: 0
1010
License: GPLv2+
@@ -83,6 +83,9 @@ test "x$RPM_BUILD_ROOT" != "x" && rm -rf $RPM_BUILD_ROOT
8383
/usr/share/man/man5/*.5.gz
8484

8585
%changelog
86+
* Thu Apr 07 2016 Jeremy Crafts <[email protected]> - 1.0.9-0
87+
- Bugfixes for connection test and stdout options
88+
8689
* Fri Mar 04 2016 Jeremy Crafts <[email protected]> - 1.0.8-0
8790
- Fix scheduling-related issues
8891
- Add status check for registration with API

redhat_access_insights/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def set_up_options(parser):
382382
default=constants.default_conf_file)
383383
parser.add_option('--to-stdout',
384384
help='print archive to stdout; '
385-
'sets --silent and --no-upload',
385+
'sets --quiet and --no-upload',
386386
dest='to_stdout',
387387
default=False,
388388
action='store_true')
@@ -466,6 +466,9 @@ def handle_startup(options, config):
466466
validate_remove_file()
467467
sys.exit()
468468

469+
if options.to_stdout:
470+
options.no_upload = True
471+
469472
# Generate /etc/machine-id if it does not exist
470473
new = False
471474
# force-reregister -- remove machine-id files nd registration files before trying to register again

redhat_access_insights/connection.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def _validate_hostnames(self):
193193
logger.debug(e)
194194
logger.error(
195195
"Could not resolve hostname: %s", endpoint_url.geturl())
196+
sys.exit(1)
196197
if self.proxies is not None:
197198
proxy_url = urlparse(self.proxies['https'])
198199
try:
@@ -210,7 +211,7 @@ def _validate_hostnames(self):
210211
except socket.gaierror as e:
211212
logger.debug(e)
212213
logger.error("Could not resolve proxy %s", proxy_url.geturl())
213-
traceback.print_exc()
214+
sys.exit(1)
214215

215216
def _test_urls(self, url, method):
216217
"""
@@ -277,23 +278,35 @@ def _test_openssl(self):
277278
sock = socket.socket()
278279
sock.setblocking(1)
279280
if self.proxies:
280-
connect_str = 'CONNECT {0} HTTP/1.0\r\n'.format(hostname)
281+
connect_str = 'CONNECT {0} HTTP/1.0\r\n'.format(hostname[0])
281282
if self.proxy_auth:
282283
connect_str += 'Proxy-Authorization: {0}\r\n'.format(self.proxy_auth)
283284
connect_str += '\r\n'
284-
proxy = urlparse(self.proxies).netloc.split(':')
285-
sock.connect((proxy[0], int(proxy[1])))
285+
proxy = urlparse(self.proxies['https']).netloc.split(':')
286+
try:
287+
sock.connect((proxy[0], int(proxy[1])))
288+
except Exception as e:
289+
logger.debug(e)
290+
logger.error('Failed to connect to proxy %s. Connection refused.' % self.proxies['https'])
291+
sys.exit(1)
286292
sock.send(connect_str)
287-
sock.recv(4096)
293+
res = sock.recv(4096)
294+
if 'HTTP/1.0 200 Connection established' not in res:
295+
logger.error('Failed to connect to %s. Invalid hostname.' % self.base_url)
296+
sys.exit(1)
288297
else:
289298
try:
290299
sock.connect((hostname[0], 443))
291300
except socket.gaierror:
292-
logger.error('Error: Failed to connect to %s. Invalid hostname.' % base_url)
301+
logger.error('Error: Failed to connect to %s. Invalid hostname.' % self.base_url)
293302
sys.exit(1)
294303
ctx = SSL.Context(SSL.TLSv1_METHOD)
295304
if type(self.cert_verify) is not bool:
296-
ctx.load_verify_locations(self.cert_verify, None)
305+
if os.path.isfile(self.cert_verify):
306+
ctx.load_verify_locations(self.cert_verify, None)
307+
else:
308+
logger.error('Error: Invalid cert path: %s' % self.cert_verify)
309+
sys.exit(1)
297310
ctx.set_verify(SSL.VERIFY_PEER, self._verify_check)
298311
ssl_conn = SSL.Connection(ctx, sock)
299312
ssl_conn.set_connect_state()
@@ -317,7 +330,8 @@ def _test_openssl(self):
317330
logger.info(self._generate_cert_str(server_cert.get_subject(), 'subject=/'))
318331
logger.info(self._generate_cert_str(server_cert.get_issuer(), 'issuer=/'))
319332
logger.info('---')
320-
except SSL.Error:
333+
except SSL.Error as e:
334+
logger.debug('SSL error: %s' % e)
321335
success = False
322336
logger.error('Certificate chain test failed!')
323337
ssl_conn.shutdown()
@@ -581,9 +595,6 @@ def register(self, options):
581595
"""
582596
Register this machine
583597
"""
584-
585-
delete_unregistered_file()
586-
587598
client_hostname = determine_hostname()
588599
# This will undo a blacklist
589600
logger.debug("API: Create system")
@@ -598,6 +609,8 @@ def register(self, options):
598609

599610
message = system.headers.get("x-rh-message", "")
600611

612+
delete_unregistered_file()
613+
601614
# Do grouping
602615
if options.group is not None:
603616
self.do_group(options.group)

redhat_access_insights/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class InsightsConstants(object):
77
app_name = 'redhat-access-insights'
8-
version = '1.0.8'
8+
version = '1.0.9'
99
auth_method = 'BASIC'
1010
log_level = 'DEBUG'
1111
sleep_time = 300

0 commit comments

Comments
 (0)