Skip to content

Commit

Permalink
fix some registration quirks related to the platform (#1651)
Browse files Browse the repository at this point in the history
* fix some registration quirks related to the platform
- skip registration check for --support (RHIPLAT1-748)
- skip --unregister call, log message (RHIPLAT1-749)
- skip --register call, log message (RHIPLAT1-750)
- short-circuit --status, log message (RHIPLAT1-751)

* FLAKE

* move logging and checks to API functions. phase calls reg normally

* fix goof
  • Loading branch information
gravitypriest committed Jan 30, 2019
1 parent db7c6f1 commit 2ac4331
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 11 deletions.
17 changes: 16 additions & 1 deletion insights/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,22 @@ def register(self):
False - machine is unregistered
None - could not reach the API
"""
return client.handle_registration(self.config, self.connection)
if self.config.legacy_upload:
return client.handle_registration(self.config, self.connection)
else:
if self.config.register:
logger.info('Registration is not applicable to the platform.')
logger.debug('Platform upload. Bypassing registration.')
return True

@_net
def unregister(self):
"""
returns (bool): True success, False failure
"""
if not self.config.legacy_upload:
logger.info('Registration is not applicable to the platform.')
return True
return client.handle_unregistration(self.config, self.connection)

@_net
Expand Down Expand Up @@ -425,6 +434,12 @@ def get_registration_status(self):
'unreg_date': Date the machine was unregistered | None,
'unreachable': API could not be reached}
"""
if not self.config.legacy_upload:
return {
'messages': ['Registration is not applicable for platform uploads.'],
'unreachable': False,
'status': True
}
return client.get_registration_status(self.config, self.connection)

@_net
Expand Down
1 change: 1 addition & 0 deletions insights/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def register(config, pconn):
return pconn.register()


# TODO: eventually remove this function. Only valid for legacy stuff
def handle_registration(config, pconn):
'''
Handle the registration process
Expand Down
4 changes: 0 additions & 4 deletions insights/client/phase/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ def post_update(client, config):
else:
sys.exit(constants.sig_kill_bad)

if not config.legacy_upload:
logger.debug('Platform upload. Bypassing registration.')
return

reg = client.register()
if reg is None:
# API unreachable
Expand Down
9 changes: 5 additions & 4 deletions insights/client/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ def _support_diag_dump(self):
pconn = InsightsConnection(self.config)
logger.info('Insights version: %s', get_nvr())

reg_check = registration_check(pconn)
cfg_block.append('Registration check:')
for key in reg_check:
cfg_block.append(key + ': ' + str(reg_check[key]))
if self.config.legacy_upload:
reg_check = registration_check(pconn)
cfg_block.append('Registration check:')
for key in reg_check:
cfg_block.append(key + ': ' + str(reg_check[key]))

lastupload = 'never'
if os.path.isfile(constants.lastupload_file):
Expand Down
4 changes: 2 additions & 2 deletions insights/tests/client/phase/test_post_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def patch_insights_config(old_function):
@patch_insights_config
def test_post_update_legacy_upload_off(insights_config, insights_client):
"""
Registration is not processed when platform upload
Registration is still called when platform upload
"""
insights_config.return_value.load_all.return_value.legacy_upload = False
try:
post_update()
except SystemExit:
pass
insights_client.return_value.register.assert_not_called()
insights_client.return_value.register.assert_called_once()


@patch("insights.client.phase.v1.InsightsClient")
Expand Down
27 changes: 27 additions & 0 deletions insights/tests/client/support/test_collect_support_info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: UTF-8 -*-

from insights.client.config import InsightsConfig
from insights.client.support import InsightsSupport
from mock.mock import Mock, patch

Expand Down Expand Up @@ -31,3 +32,29 @@ def test_support_diag_dump_insights_connection(insights_connection, registration
support._support_diag_dump()

insights_connection.assert_called_once_with(config)


@patch('insights.client.support.InsightsConnection')
@patch('insights.client.support.registration_check')
def test_registration_check_legacy_upload_on(registration_check, InsightsConnection):
'''
Check registration when legacy_upload=True
'''
config = InsightsConfig(legacy_upload=True)
support = InsightsSupport(config)
support.collect_support_info()

registration_check.assert_called_once()


@patch('insights.client.support.InsightsConnection')
@patch('insights.client.support.registration_check')
def test_skip_registration_check_legacy_upload_off(registration_check, InsightsConnection):
'''
Don't check registration when legacy_upload=False
'''
config = InsightsConfig(legacy_upload=False)
support = InsightsSupport(config)
support.collect_support_info()

registration_check.assert_not_called()
44 changes: 44 additions & 0 deletions insights/tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,47 @@ def test_delete_archive_internal():
_delete_archive_internal(config, arch)
assert not os.path.exists(arch.tmp_dir)
assert not os.path.exists(arch.archive_tmp_dir)


@patch('insights.client.client.handle_registration')
def test_platform_register_skip(handle_registration):
'''
handle_registration not called when platform upload
'''
config = InsightsConfig(legacy_upload=False)
client = InsightsClient(config)
assert client.register() # short circuits to True
handle_registration.assert_not_called()


@patch('insights.client.client.handle_unregistration')
def test_platform_unregister_skip(handle_unregistration):
'''
handle_registration not called when platform upload
'''
config = InsightsConfig(legacy_upload=False)
client = InsightsClient(config)
assert client.unregister() # short circuits to True
handle_unregistration.assert_not_called()


@patch('insights.client.client.handle_registration')
def test_legacy_register(handle_registration):
'''
handle_unregistration called when legacy upload
'''
config = InsightsConfig(legacy_upload=True)
client = InsightsClient(config)
client.register()
handle_registration.assert_called_once()


@patch('insights.client.client.handle_unregistration')
def test_legacy_unregister(handle_unregistration):
'''
handle_unregistration called when legacy upload
'''
config = InsightsConfig(legacy_upload=True)
client = InsightsClient(config)
client.unregister()
handle_unregistration.assert_called_once()

0 comments on commit 2ac4331

Please sign in to comment.