Skip to content

Commit

Permalink
Do not inhibit upgrade with SCA enabled manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
Rezney committed Nov 25, 2020
1 parent 4b5bfae commit e69f7d8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
from leapp.reporting import create_report


SCA_TEXT = "Content Access Mode is set to Simple Content Access"


def process():
if not rhsm.skip_rhsm():
for info in api.consume(RHSMInfo):
if not info.attached_skus:
if not info.attached_skus and not info.sca_detected:
create_report([
reporting.Title('The system is not registered or subscribed.'),
reporting.Summary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ def test_sku_report_has_no_skus(monkeypatch):
assert checkrhsmsku.create_report.report_fields['title'] == 'The system is not registered or subscribed.'
assert checkrhsmsku.create_report.report_fields['severity'] == 'high'
assert 'inhibitor' in checkrhsmsku.create_report.report_fields['flags']


def test_sku_report_has_sca(monkeypatch):
monkeypatch.setattr(rhsm, 'skip_rhsm', lambda: False)
monkeypatch.setattr(api, 'consume', lambda x: (RHSMInfo(attached_skus=[], sca_detected=True),))
monkeypatch.setattr(checkrhsmsku, 'create_report', create_report_mocked())
checkrhsmsku.process()
assert not checkrhsmsku.create_report.called
30 changes: 30 additions & 0 deletions repos/system_upgrade/el7toel8/libraries/rhsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
_RETRY_SLEEP = 5
_DEFAULT_RHSM_REPOFILE = '/etc/yum.repos.d/redhat.repo'

SCA_TEXT = "Content Access Mode is set to Simple Content Access"


def _rhsm_retry(max_attempts, sleep=None):
"""
Expand Down Expand Up @@ -118,6 +120,33 @@ def get_attached_skus(context):
return _RE_SKU_CONSUMED.findall(result['stdout'])


@with_rhsm
def get_rhsm_status(context):
"""
Retrieve "subscription-manager status" output.
:param context: An instance of a mounting.IsolatedActions class
:type context: mounting.IsolatedActions class
:return: "subscription manager status" output
:rtype: String
"""
with _handle_rhsm_exceptions():
result = context.call(['subscription-manager', 'status'], env={'LANG': 'en_US.UTF-8'})
return result['stdout']


def is_manifest_sca(context):
"""
Check if SCA manifest is used in Satellite.
:param context: An instance of a mounting.IsolatedActions class
:type context: mounting.IsolatedActions class
:return: True if SCA manifest is used else False
:rtype: Boolean
"""
return SCA_TEXT in get_rhsm_status(context)


def get_available_repo_ids(context):
"""
Retrieve repo ids of all the repositories available through the subscription-manager.
Expand Down Expand Up @@ -354,4 +383,5 @@ def scan_rhsm_info(context):
info.enabled_repos = get_enabled_repo_ids(context)
info.release = get_release(context)
info.existing_product_certificates.extend(get_existing_product_certificates(context))
info.sca_detected = is_manifest_sca(context)
return info
2 changes: 2 additions & 0 deletions repos/system_upgrade/el7toel8/models/rhsminfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ class RHSMInfo(Model):
""" Repositories that are enabled on the current system through the subscription-manager. """
existing_product_certificates = fields.List(fields.String(), default=[])
""" Product certificates that are currently installed on the system. """
sca_detected = fields.Boolean(default=False)
""" Info about whether SCA manifest was used or not. """

0 comments on commit e69f7d8

Please sign in to comment.