def mocked_get_rhsm_info(context): assert context, 'The actor did not provide library with valid context.' info = RHSMInfo() info.attached_skus = ['SKU1', 'SKU2'] info.available_repos = ['Repo1', 'Repo2'] info.enabled_repos = ['Repo2'] info.release = '7.9' info.existing_product_certificates = ['Cert1', 'Cert2', 'Cert3'] info.sca_detected = True return info
def test_sku_report_has_no_skus(monkeypatch): monkeypatch.setattr(rhsm, 'skip_rhsm', lambda: False) monkeypatch.setattr(api, 'consume', lambda x: (RHSMInfo(attached_skus=[]),)) monkeypatch.setattr(checkrhsmsku, 'create_report', create_report_mocked()) checkrhsmsku.process() assert checkrhsmsku.create_report.called == 1 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_no_skus(monkeypatch, current_actor_context): with monkeypatch.context() as context: context.setenv('LEAPP_DEVEL_SKIP_RHSM', '0') current_actor_context.feed(RHSMInfo(attached_skus=[])) current_actor_context.run() reports = list(current_actor_context.consume(Report)) assert reports and len(reports) == 1 report_fields = reports[0].report assert report_fields['severity'] == 'high' assert report_fields[ 'title'] == 'The system is not registered or subscribed.'
def scan_rhsm_info(context): """ Gather all the RHSM information of the source system. It's not intended for gathering RHSM info about the target system within a container. :param context: An instance of a mounting.IsolatedActions class :type context: mounting.IsolatedActions class :return: An instance of an RHSMInfo model. :rtype: RHSMInfo model """ info = RHSMInfo() info.attached_skus = get_attached_skus(context) info.available_repos = get_available_repo_ids(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
def test_sku_report_skipped(monkeypatch): monkeypatch.setattr(rhsm, 'skip_rhsm', lambda: True) monkeypatch.setattr(api, 'consume', lambda x: (RHSMInfo(attached_skus=[]),)) monkeypatch.setattr(checkrhsmsku, 'create_report', create_report_mocked()) checkrhsmsku.process() assert not checkrhsmsku.create_report.called
def test_sku_report_skipped(monkeypatch, current_actor_context): with monkeypatch.context() as context: context.setenv('LEAPP_DEVEL_SKIP_RHSM', '1') current_actor_context.feed(RHSMInfo(attached_skus=[])) current_actor_context.run() assert not list(current_actor_context.consume(Report))