def test_negative_generate_hostpkgcompare_nonexistent_host(): """Try to generate 'Host - compare content hosts packages' report with nonexistent hosts inputs :id: 572fb387-86e0-40e2-b2df-ef5c26433610 :setup: Installed Satellite :steps: 1. hammer report-template generate --name 'Host - compare content hosts packages' --inputs 'Host 1 = nonexistent1, Host 2 = nonexistent2' :expectedresults: report is not generated, sane error shown :CaseImportance: Medium :BZ: 1860351 """ with pytest.raises(CLIReturnCodeError) as cm: ReportTemplate.generate({ 'name': 'Host - compare content hosts packages', 'inputs': 'Host 1 = nonexistent1, ' 'Host 2 = nonexistent2', }) assert "At least one of the hosts couldn't be found" in cm.exception.stderr
def test_positive_generate_entitlements_report_multiple_formats(self): """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. :CaseImportance: High :BZ: 1830289 """ with VirtualMachine(distro=DISTRO_RHEL7) as vm: vm.install_katello_ca() vm.register_contenthost(self.setup_org['label'], self.setup_new_ak['name']) assert vm.subscribed result_html = ReportTemplate.generate( { 'organization': self.setup_org['name'], 'name': 'Subscription - Entitlement Report', 'report-format': 'html', 'inputs': 'Days from Now=no limit', } ) assert vm.hostname in result_html[2] assert self.setup_subs_id[0]['name'] in result_html[2] result_yaml = ReportTemplate.generate( { 'organization': self.setup_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 vm.hostname in entry elif 'Subscription Name:' in entry: assert self.setup_subs_id[0]['name'] in entry result_csv = ReportTemplate.generate( { 'organization': self.setup_org['name'], 'name': 'Subscription - Entitlement Report', 'report-format': 'csv', 'inputs': 'Days from Now=no limit', } ) assert vm.hostname in result_csv[1] assert self.setup_subs_id[0]['name'] in result_csv[1] # BZ 1830289 assert 'Subscription Quantity' in result_csv[0]
def test_positive_generate_entitlements_report_multiple_formats( local_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(local_org['label'], local_ak['name']) assert client.subscribed result_html = ReportTemplate.generate({ 'organization': local_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 = ReportTemplate.generate({ 'organization': local_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 = ReportTemplate.generate({ 'organization': local_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 Quantity' in result_csv
def test_positive_generate_report_nofilter_and_with_filter(): """Generate Host Status report without filter and with filter :id: 5af03399-b918-468a-9306-1c76dda6a369 :setup: User with reporting access rights, some report template, at least two hosts :steps: 0. use default report template called Host - Statuses 1. hammer report-template generate --id ... # do not specify any filter 2. hammer report-template generate --id ... # specify filter :expectedresults: nofilter - Report is generated for all hosts visible for user filter - Report is generated for the host specified by the filter :CaseImportance: Critical """ host_name = gen_alpha() host1 = make_fake_host({'name': host_name}) host_name_2 = gen_alpha() host2 = make_fake_host({'name': host_name_2}) result_list = ReportTemplate.list() assert 'Host - Statuses' in [rt['name'] for rt in result_list] rt_host_statuses = ReportTemplate.info({'name': 'Host - Statuses'}) result_no_filter = ReportTemplate.generate( {'name': rt_host_statuses['name']}) assert host1['name'] in [ item.split(',')[0] for item in result_no_filter.splitlines() ] assert host2['name'] in [ item.split(',')[0] for item in result_no_filter.splitlines() ] result = ReportTemplate.generate({ 'name': rt_host_statuses['name'], 'inputs': (rt_host_statuses['template-inputs'][0]['name'] + '=' + f'name={host1["name"]}'), }) assert host1['name'] in [ item.split(',')[0] for item in result.splitlines() ] assert host2['name'] not in [ item.split(',')[0] for item in result.splitlines() ]
def test_positive_generate_with_name_and_org(self): """Generate Host Status report, specifying template name and organization :id: 5af03399-b918-468a-1306-1c76dda6f369 :setup: User with reporting access rights, some report template, some host :steps: 0. use default report template called Host statuses 1. hammer report-template generate --name ... --organization ... :expectedresults: Report successfully generated (in BZ, it results in "ERF42-5227 [Foreman::Exception]: unknown parent permission for api/v2/report_templates#generate") :CaseImportance: Medium :BZ: 1750924 """ host_name = gen_string('alpha') host = make_fake_host({'name': host_name}) result = ReportTemplate.generate({ 'name': 'Host statuses', 'organization': DEFAULT_ORG }) self.assertIn(host['name'], [item.split(',')[0] for item in result])
def test_positive_generate_report_nofilter_and_with_filter(self): """Generate Host Status report without filter and with filter :id: 5af03399-b918-468a-9306-1c76dda6a369 :setup: User with reporting access rights, some report template, at least two hosts :steps: 0. use default report template called Host statuses 1. hammer report-template generate --id ... # do not specify any filter 2. hammer report-template generate --id ... # specify filter :expectedresults: nofilter - Report is generated for all hosts visible for user filter - Report is generated for the host specified by the filter :CaseImportance: Critical """ host_name = gen_string('alpha') host1 = make_fake_host({'name': host_name}) host_name_2 = gen_string('alpha') host2 = make_fake_host({'name': host_name_2}) result_list = ReportTemplate.list() self.assertIn('Host statuses', [rt['name'] for rt in result_list]) rt_host_statuses = ReportTemplate.info({'name': 'Host statuses'}) result_no_filter = ReportTemplate.generate({ 'name': rt_host_statuses['name'], }) self.assertIn(host1['name'], [item.split(',')[0] for item in result_no_filter]) self.assertIn(host2['name'], [item.split(',')[0] for item in result_no_filter]) result = ReportTemplate.generate({ 'name': rt_host_statuses['name'], 'inputs': (rt_host_statuses['template-inputs'][0]['name'] + "=" + 'name={0}'.format(host1['name'])) }) self.assertIn(host1['name'], [item.split(',')[0] for item in result]) self.assertNotIn(host2['name'], [item.split(',')[0] for item in result])
def test_positive_generate_report_sanitized(self): """Generate report template where there are values in comma outputted which might brake CSV format :id: 84b577db-144e-4961-a42e-e93887464986 :setup: User with reporting access rights, Host Statuses report, a host with OS that has comma in its name :steps: 1. hammer report-template generate ... :expectedresults: Report is generated in proper CSV format (value with comma is quoted) :CaseImportance: Medium """ os_name = gen_string('alpha') + "," + gen_string('alpha') architecture = make_architecture() partition_table = make_partition_table() medium = make_medium() os = make_os({ 'name': os_name, 'architecture-ids': architecture['id'], 'medium-ids': medium['id'], 'partition-table-ids': partition_table['id'], }) host_name = gen_string('alpha') host = make_fake_host({ 'name': host_name, 'architecture-id': architecture['id'], 'medium-id': medium['id'], 'operatingsystem-id': os['id'], 'partition-table-id': partition_table['id'] }) report_template = make_report_template({ 'content': REPORT_TEMPLATE_FILE, }) result = ReportTemplate.generate({ 'name': report_template['name'], }) self.assertIn('Name,Operating System', result) # verify header of custom template self.assertIn( '{0},"{1}"'.format(host['name'], host['operating-system']['operating-system']), result)
def test_positive_generate_report_sanitized(): """Generate report template where there are values in comma outputted which might brake CSV format :id: 84b577db-144e-4961-a42e-e93887464986 :setup: User with reporting access rights, Host Statuses report, a host with OS that has comma in its name :steps: 1. hammer report-template generate ... :expectedresults: Report is generated in proper CSV format (value with comma is quoted) :CaseImportance: Medium """ # create a name that has a comma in it, some randomized text, and no spaces. os_name = gen_alpha(start='test', separator=',').replace(' ', '') architecture = make_architecture() partition_table = make_partition_table() medium = make_medium() os = make_os({ 'name': os_name, 'architecture-ids': architecture['id'], 'medium-ids': medium['id'], 'partition-table-ids': partition_table['id'], }) host_name = gen_alpha() host = make_fake_host({ 'name': host_name, 'architecture-id': architecture['id'], 'medium-id': medium['id'], 'operatingsystem-id': os['id'], 'partition-table-id': partition_table['id'], }) report_template = make_report_template({'content': REPORT_TEMPLATE_FILE}) result = ReportTemplate.generate({'name': report_template['name']}) assert 'Name,Operating System' in result # verify header of custom template assert f'{host["name"]},"{host["operating-system"]["operating-system"]}"' in result
def test_positive_generate_hostpkgcompare(local_org, local_ak, local_content_view, local_environment): """Generate 'Host - compare content hosts packages' report :id: 572fb387-86f2-40e2-b2df-e8ec26433610 :setup: Installed Satellite with Organization, Activation key, Content View, Content Host, Subscriptions, and synced fake repo. :steps: 1. hammer report-template generate --name 'Host - compare content hosts package' ... :expectedresults: report is scheduled and generated containing all the expected information regarding host packages :CaseImportance: Medium :BZ: 1860430 """ # Add subscription to Satellite Tools repo to activation key setup_org_for_a_rh_repo({ 'product': PRDS['rhel'], 'repository-set': REPOSET['rhst7'], 'repository': REPOS['rhst7']['name'], 'organization-id': local_org['id'], 'content-view-id': local_content_view['id'], 'lifecycle-environment-id': local_environment['id'], 'activationkey-id': local_ak['id'], }) setup_org_for_a_custom_repo({ 'url': FAKE_6_YUM_REPO, 'organization-id': local_org['id'], 'content-view-id': local_content_view['id'], 'lifecycle-environment-id': local_environment['id'], 'activationkey-id': local_ak['id'], }) hosts_info = [] with VMBroker(nick='rhel7', host_classes={'host': ContentHost}, _count=2) as hosts: for client in hosts: # Create RHEL hosts via broker and register content host client.install_katello_ca() # Register content host, install katello-agent client.register_contenthost(local_org['label'], local_ak['name']) assert client.subscribed hosts_info.append(Host.info({'name': client.hostname})) client.enable_repo(REPOS['rhst7']['id']) client.install_katello_agent() hosts_info.sort(key=lambda host: host['name']) host1, host2 = hosts_info Host.package_install({ 'host-id': host1['id'], 'packages': FAKE_0_CUSTOM_PACKAGE_NAME }) Host.package_install({ 'host-id': host1['id'], 'packages': FAKE_1_CUSTOM_PACKAGE }) Host.package_install({ 'host-id': host2['id'], 'packages': FAKE_2_CUSTOM_PACKAGE }) result = ReportTemplate.generate({ 'name': 'Host - compare content hosts packages', 'inputs': f'Host 1 = {host1["name"]}, ' f'Host 2 = {host2["name"]}', }) result.remove('') assert len(result) > 1 headers = f'Package,{host1["name"]},{host2["name"]},Architecture,Status' assert headers == result[0] items = [item.split(',') for item in result[1:]] assert len(items) for item in items: assert len(item) == 5 name, host1version, host2version, arch, status = item assert len(name) assert ((host1version == '-' and name in host2version) or (name in host1version and host2version == '-') or (name in host1version and name in host2version)) assert arch in [ 'x86_64', 'i686', 's390x', 'ppc64', 'ppc64le', 'noarch' ] assert status in ( 'same version', f'{host1["name"]} only', f'{host2["name"]} only', f'lower in {host1["name"]}', f'greater in {host1["name"]}', ) # test for specific installed packages if name == FAKE_0_CUSTOM_PACKAGE_NAME: assert status == f'{host1["name"]} only' if name == FAKE_1_CUSTOM_PACKAGE_NAME: assert (status == f'lower in {host1["name"]}' or status == f'greater in {host2["name"]}')
def test_positive_generate_hostpkgcompare(self): """Generate 'Host - compare content hosts packages' report :id: 572fb387-86f2-40e2-b2df-e8ec26433610 :setup: Installed Satellite with Organization, Activation key, Content View, Content Host, Subscriptions, and synced fake repo. :steps: 1. hammer report-template generate --name 'Host - compare content hosts package' ... :expectedresults: report is scheduled and generated containing all the expected information regarding host packages :CaseImportance: Medium :BZ: 1860430 """ # Add subscription to Satellite Tools repo to activation key setup_org_for_a_rh_repo( { 'product': PRDS['rhel'], 'repository-set': REPOSET['rhst7'], 'repository': REPOS['rhst7']['name'], 'organization-id': self.setup_org['id'], 'content-view-id': self.setup_content_view['id'], 'lifecycle-environment-id': self.setup_env['id'], 'activationkey-id': self.setup_new_ak['id'], } ) hosts = [] for i in [0, 1]: # Create VM and register content host client = VirtualMachine(distro=DISTRO_RHEL7) client.create() self.addCleanup(vm_cleanup, client) client.install_katello_ca() # Register content host, install katello-agent client.register_contenthost(self.setup_org['label'], self.setup_new_ak['name']) self.assertTrue(client.subscribed) hosts.append(Host.info({'name': client.hostname})) client.enable_repo(REPOS['rhst7']['id']) client.install_katello_agent() hosts.sort(key=lambda host: host['name']) host1, host2 = hosts Host.package_install({'host-id': host1['id'], 'packages': FAKE_0_CUSTOM_PACKAGE_NAME}) Host.package_install({'host-id': host1['id'], 'packages': FAKE_1_CUSTOM_PACKAGE}) Host.package_install({'host-id': host2['id'], 'packages': FAKE_2_CUSTOM_PACKAGE}) result = ReportTemplate.generate( { 'name': 'Host - compare content hosts packages', 'inputs': f"Host 1 = {host1['name']}, " f"Host 2 = {host2['name']}", } ) result.remove('') self.assertGreater(len(result), 1) headers = f'Package,{host1["name"]},{host2["name"]},Architecture,Status' self.assertEqual(headers, result[0]) items = [item.split(',') for item in result[1:]] self.assertGreater(len(items), 0) for item in items: self.assertEqual(len(item), 5) name, host1version, host2version, arch, status = item self.assertGreater(len(name), 0) assert ( (host1version == '-' and name in host2version) or (name in host1version and host2version == '-') or (name in host1version and name in host2version) ) self.assertIn(arch, ['x86_64', 'i686', 's390x', 'ppc64', 'ppc64le', 'noarch']) assert status in ( 'same version', f'{host1["name"]} only', f'{host2["name"]} only', f'lower in {host1["name"]}', f'greater in {host1["name"]}', ) # test for specific installed packages if name == FAKE_0_CUSTOM_PACKAGE_NAME: assert status == f'{host1["name"]} only' if name == FAKE_1_CUSTOM_PACKAGE_NAME: assert ( status == f'lower in {host1["name"]}' or status == f'greater in {host2["name"]}' )