Skip to content

Commit

Permalink
fix(client): Status code should indicate registration status
Browse files Browse the repository at this point in the history
* Card ID: CCT-1059

Status code returned by `insights-client --status` should indicate
whether a host is registered or not. This change ensures that the exit
code is 0 if the host is registered and 1 if it is not.

Signed-off-by: pkoprda <pkoprda@redhat.com>
  • Loading branch information
pkoprda committed Jan 24, 2025
1 parent f28e238 commit 39e2165
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion insights/client/phase/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ def post_update(client, config):
if config.status:
if reg_check:
logger.info('This host is registered.')
sys.exit(constants.sig_kill_ok)
else:
logger.info('This host is unregistered.')
sys.exit(constants.sig_kill_ok)
sys.exit(constants.sig_kill_bad)

# put this first to avoid conflicts with register
if config.unregister:
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 @@ -105,13 +105,13 @@ def test_post_update_check_status_registered(insights_config, insights_client, _
def test_post_update_check_status_unregistered(insights_config, insights_client, _isfile):
"""
Just check status.
If unregistered, exit with 100 exit code (kill parent)
If unregistered, exit with 101 exit code (kill parent)
"""
insights_config.return_value.load_all.return_value.status = True
insights_client.return_value.get_registration_status = MagicMock(return_value=False)
with raises(SystemExit) as exc_info:
post_update()
assert exc_info.value.code == 100
assert exc_info.value.code == 101
insights_client.return_value.clear_local_registration.assert_not_called()
insights_client.return_value.set_display_name.assert_not_called()

Expand Down

0 comments on commit 39e2165

Please sign in to comment.