|
9 | 9 | import json
|
10 | 10 | import logging
|
11 | 11 | import platform
|
| 12 | +import sys |
12 | 13 | import warnings
|
13 | 14 | import errno
|
14 | 15 | # import io
|
|
30 | 31 | write_registered_file,
|
31 | 32 | os_release_info,
|
32 | 33 | largest_spec_in_archive,
|
33 |
| - size_in_mb) |
| 34 | + size_in_mb, |
| 35 | + _get_rhsm_identity) |
34 | 36 | from .cert_auth import rhsmCertificate
|
35 | 37 | from .constants import InsightsConstants as constants
|
36 | 38 | from insights import cleaner, package_info
|
|
64 | 66 |
|
65 | 67 |
|
66 | 68 | 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") |
68 | 72 |
|
69 | 73 |
|
70 | 74 | def _api_request_failed(exception, message='The Insights API could not be reached.'):
|
@@ -449,10 +453,20 @@ def handle_fail_rcs(self, req):
|
449 | 453 | req.status_code)
|
450 | 454 | logger.debug("HTTP Status Text: %s", req.reason)
|
451 | 455 | 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) |
456 | 470 | if req.status_code == 402:
|
457 | 471 | # failed registration because of entitlement limit hit
|
458 | 472 | logger.debug('Registration failed by 402 error.')
|
@@ -1096,7 +1110,12 @@ def get_advisor_report(self):
|
1096 | 1110 | if host_details["total"] < 1:
|
1097 | 1111 | _host_not_found()
|
1098 | 1112 | 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()) |
1100 | 1119 |
|
1101 | 1120 | if not os.path.exists("/var/lib/insights"):
|
1102 | 1121 | os.makedirs("/var/lib/insights", mode=0o755)
|
@@ -1124,7 +1143,9 @@ def checkin(self):
|
1124 | 1143 | logger.info("Checking in...")
|
1125 | 1144 |
|
1126 | 1145 | 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") |
1128 | 1149 | return False
|
1129 | 1150 |
|
1130 | 1151 | try:
|
|
0 commit comments