Skip to content

Commit c2c7484

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 b846f29 commit c2c7484

File tree

5 files changed

+77
-37
lines changed

5 files changed

+77
-37
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

+31-10
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 is unregistered, please ensure that "
460+
"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.')
@@ -795,7 +809,7 @@ def unregister(self):
795809
write_to_disk(constants.machine_id_file, delete=True)
796810
logger.info("Successfully unregistered this host.")
797811
return True
798-
logger.info('This host is not registered, unregistration is not applicable.')
812+
logger.info('This host is unregistered, unregistration is not applicable.')
799813
return False
800814

801815
# -LEGACY-
@@ -1066,7 +1080,7 @@ def get_diagnosis(self):
10661080
'''
10671081
if not self._fetch_system_by_machine_id():
10681082
logger.error("Could not get diagnosis data.\n"
1069-
"This host is not registered. Use --register to register this host:\n"
1083+
"This host is unregistered. Use --register to register this host:\n"
10701084
"# insights-client --register")
10711085
return False
10721086

@@ -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 unregistered. "
1147+
"Use --register to register this host:\n"
1148+
"# insights-client --register")
11281149
return False
11291150

11301151
try:

insights/client/phase/v1.py

+32-19
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,30 @@ def post_update(client, config):
165161

166162
# -------delete everything below this line-------
167163
if config.legacy_upload:
164+
if config.offline or config.no_upload or config.module:
165+
# create a machine id first thing. we'll need it for all uploads
166+
logger.debug('Machine ID: %s', client.get_machine_id())
167+
logger.debug("CONFIG: %s", config)
168+
if config.offline:
169+
logger.debug('Running client in offline mode. Bypassing registration.')
170+
elif config.no_upload:
171+
logger.debug("Running client without uploading. Bypassing registration.")
172+
else:
173+
logger.debug('Running a specified module. Bypassing registration.')
174+
return
175+
176+
if not _get_rhsm_identity():
177+
logger.error(
178+
"This host is unregistered, please ensure that "
179+
"the system is registered with subscription-manager "
180+
"and then with insights-client.\n"
181+
"\n1. Register with subscription-manager"
182+
"\n# subscription-manager register\n"
183+
"\n2. Register with insights-client"
184+
"\n# insights-client --register"
185+
)
186+
sys.exit(constants.sig_kill_bad)
187+
168188
if config.status:
169189
reg_check = client.get_registration_status()
170190
for msg in reg_check['messages']:
@@ -182,16 +202,6 @@ def post_update(client, config):
182202
else:
183203
sys.exit(constants.sig_kill_bad)
184204

185-
if config.offline or config.no_upload:
186-
# create a machine id first thing. we'll need it for all uploads
187-
logger.debug('Machine ID: %s', client.get_machine_id())
188-
logger.debug("CONFIG: %s", config)
189-
if config.offline:
190-
logger.debug('Running client in offline mode. Bypassing registration.')
191-
else:
192-
logger.debug("Running client without uploading. Bypassing registration.")
193-
return
194-
195205
if config.display_name and not config.register:
196206
# setting display name independent of registration
197207
if client.set_display_name(config.display_name):
@@ -217,16 +227,18 @@ def post_update(client, config):
217227
return
218228
# -------delete everything above this line-------
219229

220-
if config.offline or config.no_upload or config.payload:
230+
if config.offline or config.no_upload or config.payload or config.module:
221231
# create a machine id first thing. we'll need it for all uploads
222232
logger.debug('Machine ID: %s', client.get_machine_id())
223233
logger.debug("CONFIG: %s", config)
224234
if config.offline:
225235
logger.debug('Running client in offline mode. Bypassing registration.')
226236
elif config.no_upload:
227237
logger.debug("Running client without uploading. Bypassing registration.")
228-
else:
238+
elif config.payload:
229239
logger.debug('Uploading a specified archive. Bypassing registration.')
240+
else:
241+
logger.debug('Running a specified module. Bypassing registration.')
230242
return
231243

232244
# check registration status before anything else
@@ -251,8 +263,9 @@ def post_update(client, config):
251263

252264
# halt here if unregistered
253265
if not reg_check and not config.register:
254-
logger.info('This host has not been registered. '
255-
'Use --register to register this host.')
266+
logger.error("This host is unregistered. "
267+
"Use --register to register this host.\n"
268+
"# insights-client --register")
256269
sys.exit(constants.sig_kill_bad)
257270

258271
# --register was called

insights/tests/client/phase/test_LEGACY_post_update.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def patch_insights_config(old_function):
1818
"return_value.load_all.return_value.list_specs": False,
1919
"return_value.load_all.return_value.show_results": False,
2020
"return_value.load_all.return_value.check_results": False,
21-
"return_value.load_all.return_value.no_upload": False})
21+
"return_value.load_all.return_value.no_upload": False,
22+
"return_value.load_all.return_value.module": False})
2223
return patcher(old_function)
2324

2425

@@ -37,9 +38,10 @@ def test_post_update_legacy_upload_off(insights_config, insights_client):
3738
insights_client.return_value.get_machine_id.assert_called_once()
3839

3940

41+
@patch("insights.client.phase.v1._get_rhsm_identity", return_value=True)
4042
@patch("insights.client.phase.v1.InsightsClient")
4143
@patch_insights_config
42-
def test_post_update_legacy_upload_on(insights_config, insights_client):
44+
def test_post_update_legacy_upload_on(insights_config, insights_client, _get_rhsm_identity):
4345
"""
4446
Registration is processed in legacy_upload=True
4547
"""
@@ -52,10 +54,10 @@ def test_post_update_legacy_upload_on(insights_config, insights_client):
5254
insights_client.return_value.register.assert_called_once()
5355

5456

57+
@patch("insights.client.phase.v1._get_rhsm_identity", return_value=True)
5558
@patch("insights.client.phase.v1.InsightsClient")
5659
@patch_insights_config
57-
# @patch("insights.client.phase.v1.InsightsClient")
58-
def test_exit_ok(insights_config, insights_client):
60+
def test_exit_ok(insights_config, insights_client, _get_rhsm_identity):
5961
"""
6062
Support collection replaces the normal client run.
6163
"""
@@ -64,9 +66,10 @@ def test_exit_ok(insights_config, insights_client):
6466
assert exc_info.value.code == 0
6567

6668

69+
@patch("insights.client.phase.v1._get_rhsm_identity", return_value=True)
6770
@patch("insights.client.phase.v1.InsightsClient")
6871
@patch_insights_config
69-
def test_post_update_no_upload(insights_config, insights_client):
72+
def test_post_update_no_upload(insights_config, insights_client, _get_rhsm_identity):
7073
"""
7174
No-upload short circuits this phase
7275
"""

insights/tests/client/phase/test_post_update.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def patch_insights_config(old_function):
2424
"return_value.load_all.return_value.list_specs": False,
2525
"return_value.load_all.return_value.show_results": False,
2626
"return_value.load_all.return_value.check_results": False,
27-
"return_value.load_all.return_value.no_upload": False})
27+
"return_value.load_all.return_value.no_upload": False,
28+
"return_value.load_all.return_value.module": False})
2829
return patcher(old_function)
2930

3031
# DRY this at some point... for the love of god

0 commit comments

Comments
 (0)