Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not inhibit upgrade with SCA enabled manifest #615

Merged
merged 1 commit into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'])
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. """