Skip to content

Commit d1f28cb

Browse files
committed
Do not create dangling symlinks for containerized RHSM
When setting RHSM into the container mode, we are creating symlinks to /etc/rhsm and /etc/pki/entitlement directories. However, this creates dangling symlinks if RHSM is not installed or user manually removes one of these dirs. If any of these directories is missing, skip other actions and log the warning. Usually it means that RHSM is not actually used or installed at all, so in these cases we can do the skip. The only corner case when system could use RHSM without /etc/pki/entitlement is when RHSM is configured to put these certificate on a different path, and we do not support nor cover such a scenario as we are not scanning the RHSM configuration at all. This also solves the problems on systems that does not have RHSM available at all.
1 parent 5b0c1d9 commit d1f28cb

File tree

1 file changed

+16
-0
lines changed
  • repos/system_upgrade/common/libraries

1 file changed

+16
-0
lines changed

repos/system_upgrade/common/libraries/rhsm.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,29 @@ def set_container_mode(context):
325325
could be affected and the generated repo file in the container could be
326326
affected as well (e.g. when the release is set, using rhsm, on the host).
327327
328+
We want to put RHSM into the container mode always when /etc/rhsm and
329+
/etc/pki/entitlement directories exists, even when leapp is executed with
330+
--no-rhsm option. If any of these directories are missing, skip other
331+
actions - most likely RHSM is not installed in such a case.
332+
328333
:param context: An instance of a mounting.IsolatedActions class
329334
:type context: mounting.IsolatedActions class
330335
"""
331336
if not context.is_isolated():
332337
api.current_logger().error('Trying to set RHSM into the container mode'
333338
'on host. Skipping the action.')
334339
return
340+
# TODO(pstodulk): check "rhsm identity" whether system is registered
341+
# and the container mode should be required
342+
if (not os.path.exists(context.full_path('/etc/rhsm'))
343+
or not os.path.exists(context.full_path('/etc/pki/entitlement'))):
344+
api.current_logger().warning(
345+
'Cannot set the container mode for the subscription-manager as'
346+
' one of required directories is missing. Most likely RHSM is not'
347+
' installed. Skipping other actions.'
348+
)
349+
return
350+
335351
try:
336352
context.call(['ln', '-s', '/etc/rhsm', '/etc/rhsm-host'])
337353
context.call(['ln', '-s', '/etc/pki/entitlement', '/etc/pki/entitlement-host'])

0 commit comments

Comments
 (0)