Skip to content

Commit ce05bc4

Browse files
committed
fix(client): Update log messages when unregistered
* Card ID: CCT-265 This patch updates the logging messages shown to the user when the host is not registered with subscription-manager or when the host is not registered with insights-client. Signed-off-by: pkoprda <[email protected]>
1 parent fb9822f commit ce05bc4

File tree

4 files changed

+54
-21
lines changed

4 files changed

+54
-21
lines changed

insights/client/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def get_egg_url(self):
120120
else:
121121
raise ConnectionError("%s: %s" % (response.status_code, response.reason))
122122
except ConnectionError as e:
123-
logger.warning("Unable to fetch egg url %s: %s. Defaulting to /release", url, str(e))
123+
logger.debug("Unable to fetch egg url %s: %s. Defaulting to /release", url, str(e))
124124
return '/release'
125125

126126
def fetch(self, force=False):
@@ -556,7 +556,9 @@ def show_results(self):
556556
print(json.dumps(insights_data, indent=1))
557557
except IOError as e:
558558
if e.errno == errno.ENOENT:
559-
raise Exception("Error: no report found. Run insights-client --check-results to update the report cache: %s" % e)
559+
raise Exception("Error: no report found. "
560+
"Check the results to update the report cache: %s"
561+
"\n# insights-client --check-results" % e)
560562
else:
561563
raise e
562564

insights/client/connection.py

+29-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import json
1010
import logging
1111
import platform
12+
import sys
1213
import warnings
1314
import errno
1415
# import io
@@ -30,7 +31,8 @@
3031
write_registered_file,
3132
os_release_info,
3233
largest_spec_in_archive,
33-
size_in_mb)
34+
size_in_mb,
35+
_get_rhsm_identity)
3436
from .cert_auth import rhsmCertificate
3537
from .constants import InsightsConstants as constants
3638
from insights import cleaner, package_info
@@ -64,7 +66,9 @@
6466

6567

6668
def _host_not_found():
67-
raise Exception("Error: failed to find host with matching machine-id. Run insights-client --status to check registration status")
69+
raise Exception("Error: failed to find host with matching machine-id. "
70+
"Check the registration status:\n"
71+
"# insights-client --status")
6872

6973

7074
def _api_request_failed(exception, message='The Insights API could not be reached.'):
@@ -449,10 +453,20 @@ def handle_fail_rcs(self, req):
449453
req.status_code)
450454
logger.debug("HTTP Status Text: %s", req.reason)
451455
if req.status_code == 401:
452-
logger.error("Please ensure that the system is registered "
453-
"with RHSM for CERT auth, or that correct "
454-
"credentials are set in %s for BASIC auth.", self.config.conf)
455-
logger.log(NETWORK, "HTTP Response Text: %s", req.text)
456+
# check if the host is registered with subscription-manager
457+
if not _get_rhsm_identity():
458+
logger.error(
459+
"This host has not yet been registered, please ensure "
460+
"that the system is registered with subscription-manager "
461+
"and then with insights-client.\n"
462+
"\n1. Register with subscription-manager"
463+
"\n# subscription-manager register\n"
464+
"\n2. Register with insights-client"
465+
"\n# insights-client --register"
466+
)
467+
sys.exit(constants.sig_kill_bad)
468+
else:
469+
logger.log(NETWORK, "HTTP Response Text: %s", req.text)
456470
if req.status_code == 402:
457471
# failed registration because of entitlement limit hit
458472
logger.debug('Registration failed by 402 error.')
@@ -1096,7 +1110,12 @@ def get_advisor_report(self):
10961110
if host_details["total"] < 1:
10971111
_host_not_found()
10981112
if host_details["total"] > 1:
1099-
raise Exception("Error: multiple hosts detected (insights_id = %s). To fix this error, run command: insights-client --unregister && insights-client --register" % generate_machine_id())
1113+
raise Exception("Error: multiple hosts detected (insights_id = %s). "
1114+
"To fix this error, unregister this host first and then register again.\n"
1115+
"\n1. Unregister with insights-client"
1116+
"\n# insights-client --unregister\n"
1117+
"\n2. Register with insights-client"
1118+
"\n# insights-client --register" % generate_machine_id())
11001119

11011120
if not os.path.exists("/var/lib/insights"):
11021121
os.makedirs("/var/lib/insights", mode=0o755)
@@ -1124,7 +1143,9 @@ def checkin(self):
11241143
logger.info("Checking in...")
11251144

11261145
if not self._fetch_system_by_machine_id():
1127-
logger.error("This host is not registered. To register, run 'insights-client --register'.")
1146+
logger.error("This host is not registered. "
1147+
"Use --register to register this host:\n"
1148+
"# insights-client --register")
11281149
return False
11291150

11301151
try:

insights/client/phase/v1.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from insights.client.config import InsightsConfig
1212
from insights.client.constants import InsightsConstants as constants
1313
from insights.client.support import InsightsSupport
14-
from insights.client.utilities import validate_remove_file, print_egg_versions
14+
from insights.client.utilities import validate_remove_file, print_egg_versions, _get_rhsm_identity
1515
from insights.client.schedule import get_scheduler
1616

1717
logger = logging.getLogger(__name__)
@@ -56,10 +56,6 @@ def get_phases():
5656
@phase
5757
def pre_update(client, config):
5858

59-
# Check if BASIC auth is used to print a WARNING message
60-
if config.authmethod == 'BASIC':
61-
logger.warning('WARN: BASIC authentication method is being deprecated. Please consider using CERT authentication method.')
62-
6359
if config.version:
6460
logger.info(constants.version)
6561
sys.exit(constants.sig_kill_ok)
@@ -165,6 +161,17 @@ def post_update(client, config):
165161

166162
# -------delete everything below this line-------
167163
if config.legacy_upload:
164+
if not _get_rhsm_identity():
165+
logger.error(
166+
"This host has not yet been registered, please ensure "
167+
"that the system is registered with subscription-manager "
168+
"and then with insights-client.\n"
169+
"\n1. Register with subscription-manager"
170+
"\n# subscription-manager register\n"
171+
"\n2. Register with insights-client"
172+
"\n# insights-client --register"
173+
)
174+
sys.exit(constants.sig_kill_bad)
168175
if config.status:
169176
reg_check = client.get_registration_status()
170177
for msg in reg_check['messages']:
@@ -251,8 +258,9 @@ def post_update(client, config):
251258

252259
# halt here if unregistered
253260
if not reg_check and not config.register:
254-
logger.info('This host has not been registered. '
255-
'Use --register to register this host.')
261+
logger.error("This host has not been registered. "
262+
"Use --register to register this host.\n"
263+
"# insights-client --register")
256264
sys.exit(constants.sig_kill_bad)
257265

258266
# --register was called

insights/tests/client/phase/test_LEGACY_post_update.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ def test_post_update_legacy_upload_off(insights_config, insights_client):
3737
insights_client.return_value.get_machine_id.assert_called_once()
3838

3939

40+
@patch("insights.client.phase.v1._get_rhsm_identity", return_value=True)
4041
@patch("insights.client.phase.v1.InsightsClient")
4142
@patch_insights_config
42-
def test_post_update_legacy_upload_on(insights_config, insights_client):
43+
def test_post_update_legacy_upload_on(insights_config, insights_client, _get_rhsm_identity):
4344
"""
4445
Registration is processed in legacy_upload=True
4546
"""
@@ -52,10 +53,10 @@ def test_post_update_legacy_upload_on(insights_config, insights_client):
5253
insights_client.return_value.register.assert_called_once()
5354

5455

56+
@patch("insights.client.phase.v1._get_rhsm_identity", return_value=True)
5557
@patch("insights.client.phase.v1.InsightsClient")
5658
@patch_insights_config
57-
# @patch("insights.client.phase.v1.InsightsClient")
58-
def test_exit_ok(insights_config, insights_client):
59+
def test_exit_ok(insights_config, insights_client, _get_rhsm_identity):
5960
"""
6061
Support collection replaces the normal client run.
6162
"""
@@ -64,9 +65,10 @@ def test_exit_ok(insights_config, insights_client):
6465
assert exc_info.value.code == 0
6566

6667

68+
@patch("insights.client.phase.v1._get_rhsm_identity", return_value=True)
6769
@patch("insights.client.phase.v1.InsightsClient")
6870
@patch_insights_config
69-
def test_post_update_no_upload(insights_config, insights_client):
71+
def test_post_update_no_upload(insights_config, insights_client, _get_rhsm_identity):
7072
"""
7173
No-upload short circuits this phase
7274
"""

0 commit comments

Comments
 (0)