diff --git a/tests/foreman/api/test_reporttemplates.py b/tests/foreman/api/test_reporttemplates.py index 2dabfb8bc25..da167d8c8f0 100644 --- a/tests/foreman/api/test_reporttemplates.py +++ b/tests/foreman/api/test_reporttemplates.py @@ -14,7 +14,6 @@ import re -from broker import Broker from fauxfactory import gen_string import pytest from requests import HTTPError @@ -23,7 +22,6 @@ from robottelo.config import settings from robottelo.constants import ( DEFAULT_ARCHITECTURE, - DEFAULT_SUBSCRIPTION_NAME, FAKE_1_CUSTOM_PACKAGE, FAKE_1_CUSTOM_PACKAGE_NAME, FAKE_2_CUSTOM_PACKAGE, @@ -31,14 +29,13 @@ REPOS, REPOSET, ) -from robottelo.hosts import ContentHost from robottelo.utils.datafactory import parametrized, valid_data_list from robottelo.utils.issue_handlers import is_open @pytest.fixture(scope='module') -def setup_content(module_entitlement_manifest_org, module_target_sat): - org = module_entitlement_manifest_org +def setup_content(module_sca_manifest_org, module_target_sat): + org = module_sca_manifest_org rh_repo_id = module_target_sat.api_factory.enable_rhrepo_and_fetchid( basearch='x86_64', org_id=org.id, @@ -64,10 +61,11 @@ def setup_content(module_entitlement_manifest_org, module_target_sat): ak = module_target_sat.api.ActivationKey( content_view=cv, max_hosts=100, organization=org, environment=lce, auto_attach=True ).create() - subscription = module_target_sat.api.Subscription(organization=org).search( - query={'search': f'name="{DEFAULT_SUBSCRIPTION_NAME}"'} - )[0] - ak.add_subscriptions(data={'quantity': 1, 'subscription_id': subscription.id}) + all_content = ak.product_content(data={'content_access_mode_all': '1'})['results'] + content_label = [repo['label'] for repo in all_content if repo['name'] == custom_repo.name][0] + ak.content_override( + data={'content_overrides': [{'content_label': content_label, 'value': '1'}]} + ) return ak, org @@ -660,100 +658,6 @@ def test_negative_nonauthor_of_report_cant_download_it(): """ -@pytest.mark.tier3 -def test_positive_generate_entitlements_report(setup_content, target_sat): - """Generate a report using the Subscription - Entitlement Report template. - - :id: 722e8802-367b-4399-bcaa-949daab26632 - - :setup: Installed Satellite with Organization, Activation key, - Content View, Content Host, and Subscriptions. - - :steps: - - 1. Get - /api/report_templates/130-Subscription - Entitlement Report/generate/id/report_format - - :expectedresults: Report is generated showing all necessary information for entitlements. - - :CaseImportance: High - """ - with Broker(nick='rhel7', host_class=ContentHost) as vm: - ak, org = setup_content - result = vm.api_register( - target_sat, - organization=org, - activation_keys=[ak.name], - ) - assert result.status == 0, f'Failed to register host: {result.stderr}' - assert vm.subscribed - rt = ( - target_sat.api.ReportTemplate() - .search(query={'search': 'name="Subscription - Entitlement Report"'})[0] - .read() - ) - res = rt.generate( - data={ - "organization_id": org.id, - "report_format": "json", - "input_values": {"Days from Now": "no limit"}, - } - ) - assert res[0]['Host Name'] == vm.hostname - assert res[0]['Subscription Name'] == DEFAULT_SUBSCRIPTION_NAME - - -@pytest.mark.tier3 -def test_positive_schedule_entitlements_report(setup_content, target_sat): - """Schedule a report using the Subscription - Entitlement Report template. - - :id: 5152c518-b0da-4c27-8268-2be78289249f - - :setup: Installed Satellite with Organization, Activation key, - Content View, Content Host, and Subscriptions. - - :steps: - - 1. POST /api/report_templates/130-Subscription - Entitlement Report/schedule_report/ - - :expectedresults: Report is scheduled and contains all necessary - information for entitlements. - - :CaseImportance: High - """ - with Broker(nick='rhel7', host_class=ContentHost) as vm: - ak, org = setup_content - result = vm.api_register( - target_sat, - organization=org, - activation_keys=[ak.name], - ) - assert result.status == 0, f'Failed to register host: {result.stderr}' - assert vm.subscribed - rt = ( - target_sat.api.ReportTemplate() - .search(query={'search': 'name="Subscription - Entitlement Report"'})[0] - .read() - ) - scheduled_csv = rt.schedule_report( - data={ - 'id': f'{rt.id}-Subscription - Entitlement Report', - 'organization_id': org.id, - 'report_format': 'csv', - "input_values": {"Days from Now": "no limit"}, - } - ) - data_csv, _ = wait_for( - rt.report_data, - func_kwargs={'data': {'id': rt.id, 'job_id': scheduled_csv['job_id']}}, - fail_condition=None, - timeout=300, - delay=10, - ) - assert vm.hostname in data_csv - assert DEFAULT_SUBSCRIPTION_NAME in data_csv - - @pytest.mark.no_containers @pytest.mark.tier3 def test_positive_generate_job_report(setup_content, module_target_sat, content_hosts): @@ -811,8 +715,7 @@ def test_positive_generate_job_report(setup_content, module_target_sat, content_ 'input_values': {"job_id": job["id"]}, } ) - assert res[0]['Host'] == content_hosts[0].hostname - assert res[1]['Host'] == content_hosts[1].hostname + assert {i['Host'] for i in res} == {i.hostname for i in content_hosts} assert '/root' in res[0]['stdout'] assert '/root' in res[1]['stdout'] diff --git a/tests/foreman/cli/test_reporttemplates.py b/tests/foreman/cli/test_reporttemplates.py index 42fb511e1e6..497ae41b077 100644 --- a/tests/foreman/cli/test_reporttemplates.py +++ b/tests/foreman/cli/test_reporttemplates.py @@ -19,7 +19,6 @@ from robottelo.constants import ( DEFAULT_LOC, DEFAULT_ORG, - DEFAULT_SUBSCRIPTION_NAME, FAKE_0_CUSTOM_PACKAGE_NAME, FAKE_1_CUSTOM_PACKAGE, FAKE_1_CUSTOM_PACKAGE_NAME, @@ -34,28 +33,28 @@ @pytest.fixture(scope='module') -def local_environment(module_entitlement_manifest_org, module_target_sat): +def local_environment(module_sca_manifest_org, module_target_sat): """Create a lifecycle environment with CLI factory""" return module_target_sat.cli_factory.make_lifecycle_environment( - {'organization-id': module_entitlement_manifest_org.id} + {'organization-id': module_sca_manifest_org.id} ) @pytest.fixture(scope='module') -def local_content_view(module_entitlement_manifest_org, module_target_sat): +def local_content_view(module_sca_manifest_org, module_target_sat): """Create content view, repository, and product""" new_product = module_target_sat.cli_factory.make_product( - {'organization-id': module_entitlement_manifest_org.id} + {'organization-id': module_sca_manifest_org.id} ) new_repo = module_target_sat.cli_factory.make_repository({'product-id': new_product['id']}) module_target_sat.cli.Repository.synchronize({'id': new_repo['id']}) content_view = module_target_sat.cli_factory.make_content_view( - {'organization-id': module_entitlement_manifest_org.id} + {'organization-id': module_sca_manifest_org.id} ) module_target_sat.cli.ContentView.add_repository( { 'id': content_view['id'], - 'organization-id': module_entitlement_manifest_org.id, + 'organization-id': module_sca_manifest_org.id, 'repository-id': new_repo['id'], } ) @@ -64,9 +63,7 @@ def local_content_view(module_entitlement_manifest_org, module_target_sat): @pytest.fixture(scope='module') -def local_ak( - module_entitlement_manifest_org, local_environment, local_content_view, module_target_sat -): +def local_ak(module_sca_manifest_org, local_environment, local_content_view, module_target_sat): """Promote a content view version and create an activation key with CLI Factory""" cvv = module_target_sat.cli.ContentView.info({'id': local_content_view['id']})['versions'][0] module_target_sat.cli.ContentView.version_promote( @@ -76,26 +73,12 @@ def local_ak( { 'lifecycle-environment-id': local_environment['id'], 'content-view': local_content_view['name'], - 'organization-id': module_entitlement_manifest_org.id, + 'organization-id': module_sca_manifest_org.id, 'auto-attach': False, } ) -@pytest.fixture(scope='module') -def local_subscription(module_entitlement_manifest_org, local_ak, module_target_sat): - for subscription in module_target_sat.cli.Subscription.list( - {'organization-id': module_entitlement_manifest_org.id}, per_page=False - ): - if subscription['name'] == DEFAULT_SUBSCRIPTION_NAME: - break - module_target_sat.cli.ActivationKey.add_subscription( - {'id': local_ak['id'], 'subscription-id': subscription['id']} - ) - - return subscription - - @pytest.mark.tier2 def test_positive_report_help(module_target_sat): """hammer level of help included in test: @@ -754,161 +737,9 @@ def test_positive_generate_ansible_template(module_target_sat): assert host['name'] in [item.split(',')[1] for item in report_data.split('\n') if len(item) > 0] -@pytest.mark.no_containers -@pytest.mark.tier3 -def test_positive_generate_entitlements_report_multiple_formats( - module_sca_manifest_org, local_ak, local_subscription, rhel7_contenthost, target_sat -): - """Generate an report using the Subscription - Entitlement Report template - in html, yaml, and csv format. - - :id: f2b74916-1298-4d20-9c24-a2c2b3a3e9a9 - - :setup: Installed Satellite with Organization, Activation key, - Content View, Content Host, and Subscriptions. - - :steps: - 1. hammer report-template generate --organization '' --id '' --report-format '' - - :expectedresults: report is generated containing all the expected information - regarding entitlements. - - :BZ: 1830289 - - :parametrized: yes - - :customerscenario: true - """ - client = rhel7_contenthost - client.install_katello_ca(target_sat) - client.register_contenthost(module_sca_manifest_org.label, local_ak['name']) - assert client.subscribed - result_html = target_sat.cli.ReportTemplate.generate( - { - 'organization': module_sca_manifest_org.name, - 'name': 'Subscription - Entitlement Report', - 'report-format': 'html', - 'inputs': 'Days from Now=no limit', - } - ) - assert client.hostname in result_html - assert local_subscription['name'] in result_html - result_yaml = target_sat.cli.ReportTemplate.generate( - { - 'organization': module_sca_manifest_org.name, - 'name': 'Subscription - Entitlement Report', - 'report-format': 'yaml', - 'inputs': 'Days from Now=no limit', - } - ) - for entry in result_yaml: - if '-Name:' in entry: - assert client.hostname in entry - elif 'Subscription Name:' in entry: - assert local_subscription['name'] in entry - result_csv = target_sat.cli.ReportTemplate.generate( - { - 'organization': module_sca_manifest_org.name, - 'name': 'Subscription - Entitlement Report', - 'report-format': 'csv', - 'inputs': 'Days from Now=no limit', - } - ) - assert client.hostname in result_csv - assert local_subscription['name'] in result_csv - # BZ 1830289 - assert 'Subscription Total Quantity' in result_csv - - -@pytest.mark.tier3 -def test_positive_schedule_entitlements_report( - module_entitlement_manifest_org, local_ak, local_subscription, rhel7_contenthost, target_sat -): - """Schedule an report using the Subscription - Entitlement Report template in csv format. - - :id: 572fb387-86e0-40e2-b2df-e8ec26433610 - - - :setup: Installed Satellite with Organization, Activation key, - Content View, Content Host, and Subscriptions. - - :steps: - 1. hammer report-template schedule --organization '' --id '' --report-format '' - - - :expectedresults: report is scheduled and generated containing all the expected information - regarding entitlements. - - :parametrized: yes - """ - client = rhel7_contenthost - result = client.register( - module_entitlement_manifest_org, - None, - local_ak.name, - target_sat, - ) - assert result.status == 0, f'Failed to register host: {result.stderr}' - assert client.subscribed - scheduled_csv = target_sat.cli.ReportTemplate.schedule( - { - 'name': 'Subscription - Entitlement Report', - 'organization': module_entitlement_manifest_org.name, - 'report-format': 'csv', - 'inputs': 'Days from Now=no limit', - } - ) - data_csv = target_sat.cli.ReportTemplate.report_data( - { - 'name': 'Subscription - Entitlement Report', - 'job-id': scheduled_csv.split('\n', 1)[0].split('Job ID: ', 1)[1], - } - ) - assert client.hostname in data_csv - assert local_subscription['name'] in data_csv - - -@pytest.mark.tier3 -def test_entitlements_report_no_inputs_field( - module_entitlement_manifest_org, - module_location, - local_ak, - local_subscription, - rhel7_contenthost, - target_sat, -): - """Generate an report using the Subscription - Entitlement Report template - without passing in the 'Days from Now' argument in the inputs field, to test the - default setting - - :id: 5c4e52b9-314c-470d-9946-3d6e05c85b7e - - :steps: - 1. hammer report-template generate --organization '' --id '' --report-format '' - - :expectedresults: report is generated, and the Days From Now field isn't required - - :BZ: 1943306 - - :customerscenario: true - """ - client = rhel7_contenthost - client.register(module_entitlement_manifest_org, module_location, local_ak['name'], target_sat) - assert client.subscribed - result = target_sat.cli.ReportTemplate.generate( - { - 'organization': module_entitlement_manifest_org.name, - 'name': 'Subscription - Entitlement Report', - 'report-format': 'csv', - } - ) - # Only care that the Days from Now field isn't required, do not care about content - assert 'Subscription Total Quantity' in result - - @pytest.mark.tier3 def test_positive_generate_hostpkgcompare( - module_entitlement_manifest_org, local_ak, local_content_view, local_environment, target_sat + module_sca_manifest_org, local_ak, local_content_view, local_environment, target_sat ): """Generate 'Host - compare content hosts packages' report @@ -934,7 +765,7 @@ def test_positive_generate_hostpkgcompare( 'product': PRDS['rhel'], 'repository-set': REPOSET['rhst7'], 'repository': REPOS['rhst7']['name'], - 'organization-id': module_entitlement_manifest_org.id, + 'organization-id': module_sca_manifest_org.id, 'content-view-id': local_content_view['id'], 'lifecycle-environment-id': local_environment['id'], 'activationkey-id': local_ak['id'], @@ -944,7 +775,7 @@ def test_positive_generate_hostpkgcompare( target_sat.cli_factory.setup_org_for_a_custom_repo( { 'url': settings.repos.yum_6.url, - 'organization-id': module_entitlement_manifest_org.id, + 'organization-id': module_sca_manifest_org.id, 'content-view-id': local_content_view['id'], 'lifecycle-environment-id': local_environment['id'], 'activationkey-id': local_ak['id'], @@ -956,7 +787,7 @@ def test_positive_generate_hostpkgcompare( for client in hosts: # Create RHEL hosts via broker and register content host result = client.register( - module_entitlement_manifest_org, + module_sca_manifest_org, None, local_ak.name, target_sat, @@ -1048,7 +879,7 @@ def test_negative_generate_hostpkgcompare_nonexistent_host(module_target_sat): @pytest.mark.rhel_ver_list([7, 8, 9]) @pytest.mark.tier3 def test_positive_generate_installed_packages_report( - module_entitlement_manifest_org, + module_sca_manifest_org, local_ak, local_content_view, local_environment, @@ -1078,7 +909,7 @@ def test_positive_generate_installed_packages_report( target_sat.cli_factory.setup_org_for_a_custom_repo( { 'url': settings.repos.yum_6.url, - 'organization-id': module_entitlement_manifest_org.id, + 'organization-id': module_sca_manifest_org.id, 'content-view-id': local_content_view['id'], 'lifecycle-environment-id': local_environment['id'], 'activationkey-id': local_ak['id'], @@ -1086,7 +917,7 @@ def test_positive_generate_installed_packages_report( ) client = rhel_contenthost result = client.register( - module_entitlement_manifest_org, + module_sca_manifest_org, None, local_ak.name, target_sat, @@ -1096,7 +927,7 @@ def test_positive_generate_installed_packages_report( client.execute(f'yum -y install {FAKE_0_CUSTOM_PACKAGE_NAME} {FAKE_1_CUSTOM_PACKAGE}') result_html = target_sat.cli.ReportTemplate.generate( { - 'organization': module_entitlement_manifest_org.name, + 'organization': module_sca_manifest_org.name, 'name': 'Host - All Installed Packages', 'report-format': 'html', 'inputs': f'Hosts filter={client.hostname}', diff --git a/tests/foreman/ui/test_reporttemplates.py b/tests/foreman/ui/test_reporttemplates.py index 1a79c39e826..ecb15196c67 100644 --- a/tests/foreman/ui/test_reporttemplates.py +++ b/tests/foreman/ui/test_reporttemplates.py @@ -12,18 +12,15 @@ """ -import csv import json import os from pathlib import Path, PurePath from lxml import etree import pytest -import yaml from robottelo.config import robottelo_tmp_dir, settings from robottelo.constants import ( - DEFAULT_SUBSCRIPTION_NAME, FAKE_0_CUSTOM_PACKAGE_NAME, FAKE_1_CUSTOM_PACKAGE, PRDS, @@ -366,7 +363,7 @@ def test_positive_autocomplete(session): @pytest.mark.tier2 def test_positive_schedule_generation_and_get_mail( - session, module_entitlement_manifest_org, module_location, target_sat + session, module_sca_manifest_org, module_location, target_sat ): """Schedule generating a report. Request the result be sent via e-mail. @@ -421,9 +418,7 @@ def test_positive_schedule_generation_and_get_mail( target_sat.get(remote_path=str(gzip_path), local_path=str(local_gzip_file)) assert os.system(f'gunzip {local_gzip_file}') == 0 data = json.loads(local_file.read_text()) - subscription_search = target_sat.api.Subscription( - organization=module_entitlement_manifest_org - ).search() + subscription_search = target_sat.api.Subscription(organization=module_sca_manifest_org).search() assert len(data) >= len(subscription_search) > 0 keys_expected = [ 'Account number', @@ -479,86 +474,6 @@ def test_negative_nonauthor_of_report_cant_download_it(session): """ -@pytest.mark.tier3 -@pytest.mark.no_containers -def test_positive_gen_entitlements_reports_multiple_formats( - session, module_setup_content, rhel7_contenthost, target_sat -): - """Generate reports using the Subscription - Entitlement Report template - in html, yaml, json, and csv format. - - :id: b268663d-c213-4e59-8f81-61bec0838b1e - - - :setup: Installed Satellite with Organization, Activation key, - Content View, Content Host, and Subscriptions. - - :steps: - 1. Monitor -> Report Templates - 2. Subscription - Entitlement Report -> Generate - 3. Click the dropdown to select output format - 4. Submit - - :expectedresults: Reports are generated containing all the expected information - regarding Entitlements for each output format. - - :parametrized: yes - - :CaseImportance: High - """ - client = rhel7_contenthost - client.install_katello_ca(target_sat) - org, ak, _, _ = module_setup_content - org.sca_disable() - subscription = target_sat.api.Subscription(organization=org).search( - query={'search': f'name="{DEFAULT_SUBSCRIPTION_NAME}"'} - )[0] - ak.add_subscriptions(data={'quantity': 1, 'subscription_id': subscription.id}) - client.register(org.label, None, ak.name, target_sat) - assert client.subscribed - with session: - session.location.select('Default Location') - result_json = session.reporttemplate.generate( - 'Subscription - Entitlement Report', values={'output_format': 'JSON'} - ) - with open(result_json) as json_file: - data_json = json.load(json_file) - assert any(entitlement['Host Name'] == client.hostname for entitlement in data_json) - assert any( - entitlement['Subscription Name'] == DEFAULT_SUBSCRIPTION_NAME - for entitlement in data_json - ) - result_yaml = session.reporttemplate.generate( - 'Subscription - Entitlement Report', values={'output_format': 'YAML'} - ) - with open(result_yaml) as yaml_file: - data_yaml = yaml.load(yaml_file, Loader=yaml.FullLoader) - assert any(entitlement['Host Name'] == client.hostname for entitlement in data_yaml) - assert any( - entitlement['Subscription Name'] == DEFAULT_SUBSCRIPTION_NAME - for entitlement in data_yaml - ) - result_csv = session.reporttemplate.generate( - 'Subscription - Entitlement Report', values={'output_format': 'CSV'} - ) - with open(result_csv) as csv_file: - data_csv = csv.DictReader(csv_file) - items = list(data_csv) - assert any(entitlement['Host Name'] == client.hostname for entitlement in items) - assert any( - entitlement['Subscription Name'] == DEFAULT_SUBSCRIPTION_NAME for entitlement in items - ) - result_html = session.reporttemplate.generate( - 'Subscription - Entitlement Report', values={'output_format': 'HTML'} - ) - with open(result_html) as html_file: - parser = etree.HTMLParser() - tree = etree.parse(html_file, parser) - tree_result = etree.tostring(tree.getroot(), pretty_print=True, method='html').decode() - assert client.hostname in tree_result - assert DEFAULT_SUBSCRIPTION_NAME in tree_result - - @pytest.mark.rhel_ver_list([7, 8, 9]) @pytest.mark.tier3 def test_positive_generate_all_installed_packages_report(