def test_positive_end_to_end_crud_and_list(self): """CRUD test + list test for report templates :id: 2a143ddf-683f-49e2-badb-f9a387cfc53c :setup: User with reporting access rights and following setup: create - doesn't require other setup list - at least two report templates info - some report template update - some report template that is not locked delete - some report template that is not locked :steps: 1. hammer report-template create ... 2. hammer report-template list ... 3. hammer report-template info ... 4. hammer report-template update ... # change some value 5. hammer report-template delete ... :expectedresults: Report is created, report templates are listed, data about report template is showed, report template is updated, and deleted. :CaseImportance: Critical """ # create name = gen_string('alpha') report_template = make_report_template({'name': name}) self.assertEqual(report_template['name'], name) # list - create second template tmp_name = gen_string('alpha') tmp_report_template = make_report_template({'name': tmp_name}) result_list = ReportTemplate.list() self.assertIn(name, [rt['name'] for rt in result_list]) # info result = ReportTemplate.info({'id': report_template['id']}) self.assertEqual(result['name'], name) # update new_name = gen_string('alpha') result = ReportTemplate.update({ 'name': report_template['name'], 'new-name': new_name }) self.assertEqual(result[0]['name'], new_name) rt_list = ReportTemplate.list() self.assertNotIn(name, [rt['name'] for rt in rt_list]) # delete tmp ReportTemplate.delete({'name': tmp_report_template['name']}) with self.assertRaises(CLIReturnCodeError): ReportTemplate.info({'id': tmp_report_template['id']})
def test_positive_clone_locked_report(self): """Clone locked report template :id: cc843731-b9c2-4fc9-9e15-d1ee5d967cda :setup: User with reporting access rights, some report template that is locked :steps: 1. hammer report-template clone ... :expectedresults: Report is cloned :CaseImportance: Medium """ name = gen_string('alpha') report_template = make_report_template({'name': name}) ReportTemplate.update({ 'name': report_template['name'], 'locked': 1, 'default': 1 }) new_name = gen_string('alpha') ReportTemplate.clone({ 'id': report_template['id'], 'new-name': new_name }) result_list = ReportTemplate.list() self.assertIn(new_name, [rt['name'] for rt in result_list]) result_info = ReportTemplate.info({'id': report_template['id']}) self.assertEqual(result_info['locked'], 'yes') self.assertEqual(result_info['default'], 'yes')
def test_positive_generate_ansible_template(self): """Report template named 'Ansible Inventory' (default name is specified in settings) must be present in Satellite 6.7 and later in order to provide enhanced functionality for Ansible Tower inventory synchronization with Satellite. :id: f1f7adfc-9601-4498-95c8-3e82e2b36583 :setup: 1. A user with minimal required permissions: 'Ansible Tower Inventory Reader' role 2. A fake host to be checked in report output :steps: 1. Check settings for default Ansible Inventory template name and ensure the template is present 2. Try to render the template using the user with ATIR role 3. Check the fake host is present in the output :expectedresults: Report template is present, renederable and provides output :CaseImportance: Medium """ settings = Settings.list({'search': 'name=ansible_inventory_template'}) assert 1 == len(settings) template_name = settings[0]['value'] report_list = ReportTemplate.list() assert template_name in [rt['name'] for rt in report_list] login = gen_string('alpha').lower() password = gen_string('alpha').lower() loc = Location.info({'name': DEFAULT_LOC}) org = Org.info({'name': DEFAULT_ORG}) user = make_user( { 'login': login, 'password': password, 'organization-ids': org['id'], 'location-ids': loc['id'], } ) User.add_role({'login': user['login'], 'role': 'Ansible Tower Inventory Reader'}) host_name = gen_string('alpha').lower() host = make_fake_host({'name': host_name}) schedule = ReportTemplate.with_user(username=user['login'], password=password).schedule( {'name': template_name} ) report_data = ReportTemplate.with_user( username=user['login'], password=password ).report_data({'id': template_name, 'job-id': schedule[0].split("Job ID: ", 1)[1]}) assert host['name'] in [item.split(',')[1] for item in report_data if len(item) > 0]
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_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])