Skip to content

Commit

Permalink
Update rhel-7 branch with bugfixes from rhel-6, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Crafts committed Apr 7, 2016
2 parents 8359ecd + caf5e4b commit 7c482ae
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
7 changes: 5 additions & 2 deletions etc/redhat-access-insights.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

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

%changelog
* Thu Apr 07 2016 Jeremy Crafts <[email protected]> - 1.0.9-0
- Bugfixes for connection test and stdout options

* Fri Mar 04 2016 Jeremy Crafts <[email protected]> - 1.0.8-0
- Fix scheduling-related issues
- Add status check for registration with API
Expand Down
5 changes: 4 additions & 1 deletion redhat_access_insights/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def set_up_options(parser):
default=constants.default_conf_file)
parser.add_option('--to-stdout',
help='print archive to stdout; '
'sets --silent and --no-upload',
'sets --quiet and --no-upload',
dest='to_stdout',
default=False,
action='store_true')
Expand Down Expand Up @@ -466,6 +466,9 @@ def handle_startup(options, config):
validate_remove_file()
sys.exit()

if options.to_stdout:
options.no_upload = True

# Generate /etc/machine-id if it does not exist
new = False
# force-reregister -- remove machine-id files nd registration files before trying to register again
Expand Down
35 changes: 24 additions & 11 deletions redhat_access_insights/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def _validate_hostnames(self):
logger.debug(e)
logger.error(
"Could not resolve hostname: %s", endpoint_url.geturl())
sys.exit(1)
if self.proxies is not None:
proxy_url = urlparse(self.proxies['https'])
try:
Expand All @@ -210,7 +211,7 @@ def _validate_hostnames(self):
except socket.gaierror as e:
logger.debug(e)
logger.error("Could not resolve proxy %s", proxy_url.geturl())
traceback.print_exc()
sys.exit(1)

def _test_urls(self, url, method):
"""
Expand Down Expand Up @@ -277,23 +278,35 @@ def _test_openssl(self):
sock = socket.socket()
sock.setblocking(1)
if self.proxies:
connect_str = 'CONNECT {0} HTTP/1.0\r\n'.format(hostname)
connect_str = 'CONNECT {0} HTTP/1.0\r\n'.format(hostname[0])
if self.proxy_auth:
connect_str += 'Proxy-Authorization: {0}\r\n'.format(self.proxy_auth)
connect_str += '\r\n'
proxy = urlparse(self.proxies).netloc.split(':')
sock.connect((proxy[0], int(proxy[1])))
proxy = urlparse(self.proxies['https']).netloc.split(':')
try:
sock.connect((proxy[0], int(proxy[1])))
except Exception as e:
logger.debug(e)
logger.error('Failed to connect to proxy %s. Connection refused.' % self.proxies['https'])
sys.exit(1)
sock.send(connect_str)
sock.recv(4096)
res = sock.recv(4096)
if 'HTTP/1.0 200 Connection established' not in res:
logger.error('Failed to connect to %s. Invalid hostname.' % self.base_url)
sys.exit(1)
else:
try:
sock.connect((hostname[0], 443))
except socket.gaierror:
logger.error('Error: Failed to connect to %s. Invalid hostname.' % base_url)
logger.error('Error: Failed to connect to %s. Invalid hostname.' % self.base_url)
sys.exit(1)
ctx = SSL.Context(SSL.TLSv1_METHOD)
if type(self.cert_verify) is not bool:
ctx.load_verify_locations(self.cert_verify, None)
if os.path.isfile(self.cert_verify):
ctx.load_verify_locations(self.cert_verify, None)
else:
logger.error('Error: Invalid cert path: %s' % self.cert_verify)
sys.exit(1)
ctx.set_verify(SSL.VERIFY_PEER, self._verify_check)
ssl_conn = SSL.Connection(ctx, sock)
ssl_conn.set_connect_state()
Expand All @@ -317,7 +330,8 @@ def _test_openssl(self):
logger.info(self._generate_cert_str(server_cert.get_subject(), 'subject=/'))
logger.info(self._generate_cert_str(server_cert.get_issuer(), 'issuer=/'))
logger.info('---')
except SSL.Error:
except SSL.Error as e:
logger.debug('SSL error: %s' % e)
success = False
logger.error('Certificate chain test failed!')
ssl_conn.shutdown()
Expand Down Expand Up @@ -581,9 +595,6 @@ def register(self, options):
"""
Register this machine
"""

delete_unregistered_file()

client_hostname = determine_hostname()
# This will undo a blacklist
logger.debug("API: Create system")
Expand All @@ -598,6 +609,8 @@ def register(self, options):

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

delete_unregistered_file()

# Do grouping
if options.group is not None:
self.do_group(options.group)
Expand Down
2 changes: 1 addition & 1 deletion redhat_access_insights/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class InsightsConstants(object):
app_name = 'redhat-access-insights'
version = '1.0.8'
version = '1.0.9'
auth_method = 'BASIC'
log_level = 'DEBUG'
sleep_time = 300
Expand Down

0 comments on commit 7c482ae

Please sign in to comment.