def test_positive_generate_entitlements_report(self): """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 VirtualMachine(distro=DISTRO_RHEL7) as vm: vm.install_katello_ca() vm.register_contenthost(self.org_setup.label, self.ak_setup.name) assert vm.subscribed rt = (entities.ReportTemplate().search( query={'search': 'name="Subscription - Entitlement Report"'}) [0].read()) res = rt.generate( data={ "organization_id": self.org_setup.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
def test_positive_report_add_userinput(self): """Add user input to template, use it in template, generate template :id: a4a577db-144e-4761-a42e-e86887464986 :setup: User with reporting access rights :steps: 1. PUT /api/templates/:template_id/template_inputs/:id ... # add user input :expectedresults: User input is assigned to the report template and used in template :CaseImportance: High """ host_name = gen_string('alpha').lower() input_name = gen_string('alpha').lower() input_value = gen_string('alpha').lower() template_name = gen_string('alpha').lower() template = '<%= "value=\\"" %><%= input(\'{0}\') %><%= "\\"" %>'.format( input_name) entities.Host(name=host_name).create() rt = entities.ReportTemplate(name=template_name, template=template).create() entities.TemplateInput( name=input_name, input_type="user", template=rt.id, ).create() ti = entities.TemplateInput(template=rt.id).search()[0].read() self.assertEquals(input_name, ti.name) res = rt.generate(data={"input_values": {input_name: input_value}}) self.assertEquals('value="{}"'.format(input_value), res)
def test_positive_schedule_entitlements_report(self): """Schedule a report using the Entitlements 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/115-Entitlements/schedule_report/ :expectedresults: Report is scheduled and contains all necessary information for entitlements. :CaseImportance: High """ with VirtualMachine(distro=DISTRO_RHEL7) as vm: vm.install_katello_ca() vm.register_contenthost(self.org_setup.label, self.ak_setup.name) assert vm.subscribed rt = (entities.ReportTemplate().search( query={'search': 'name="Entitlements"'})[0].read()) scheduled_csv = rt.schedule_report( data={ 'id': '{}-Entitlements'.format(rt.id), 'organization_id': self.org_setup.id, 'report_format': 'csv', }) data_csv = rt.report_data(data={ 'id': rt.id, 'job_id': scheduled_csv['job_id'] }) assert vm.hostname in data_csv assert DEFAULT_SUBSCRIPTION_NAME in data_csv
def test_positive_generate_report_filter(self): """Generate Host - Statuses report :id: a4b677cb-144e-4761-a42e-e93887464986 :setup: User with reporting access rights, some report template, at least two hosts :steps: 1. POST /api/report_templates/:id/generate ... # define input_values :expectedresults: Report is generated (only) for the host specified by the filter :CaseImportance: High """ host1_name = gen_string('alpha').lower() host2_name = gen_string('alpha').lower() entities.Host(name=host1_name).create() entities.Host(name=host2_name).create() rt = entities.ReportTemplate().search( query={'search': 'name="Host - Statuses"'})[0].read() res = rt.generate(data={"input_values": {"hosts": host2_name}}) self.assertIn("Service Level", res) self.assertNotIn(host1_name, res) self.assertIn(host2_name, res)
def test_import_filtered_templates_from_git_with_negate(self, module_org): """Assure templates with a given filter regex are NOT pulled from git repo. :id: a6857454-249b-4a2e-9b53-b5d7b4eb34e3 :Steps: 1. Using nailgun or direct API call import the templates NOT matching with regex e.g: `^freebsd.*` refer to: `/apidoc/v2/template/import.html` using the {'negate': true} in POST body to negate the filter regex. :expectedresults: 1. Assert result is {'message': 'success'} 2. Assert templates mathing the regex were not pulled. :CaseImportance: Medium """ prefix = gen_string('alpha') filtered_imported_templates = entities.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'automation', 'filter': 'robottelo', 'organization_ids': [module_org.id], 'prefix': prefix, 'negate': True, }) not_imported_count = [ template['imported'] for template in filtered_imported_templates['message']['templates'] ].count(False) assert not_imported_count == 9 ptemplates = entities.ProvisioningTemplate().search( query={ 'per_page': '100', 'search': 'name~jenkins', 'organization_id': module_org.id }) assert len(ptemplates) == 6 ptables = entities.PartitionTable().search( query={ 'per_page': '100', 'search': 'name~jenkins', 'organization_id': module_org.id }) assert len(ptables) == 1 rtemplates = entities.ReportTemplate().search( query={ 'per_page': '100', 'search': 'name~jenkins', 'organization_id': module_org.id }) assert len(rtemplates) == 1
def test_positive_schedule_entitlements_report(setup_content): """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 VMBroker(nick='rhel7', host_classes={'host': ContentHost}) as vm: ak, org = setup_content vm.install_katello_ca() vm.register_contenthost(org.label, ak.name) assert vm.subscribed rt = (entities.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
def test_positive_CRUDL(self): """Create, Read, Update, Delete, List :id: a2a577db-144e-4761-a42e-e83885464786 :setup: User with reporting access rights :steps: 1. Create Report Template 2. List Report Templates, verify it's there 3. Read Report Template 4. Update Report Template, read again 5. Delete Report template, check it's not present :expectedresults: All operations succeed, no template present in the end :CaseImportance: Critical """ # Create rt = None name = None template1 = gen_string('alpha') for name in valid_data_list(): rt = entities.ReportTemplate(name=name, template=template1).create() # List res = entities.ReportTemplate().search( query={'search': 'name="{}"'.format(name)}) self.assertIn(name, list(map(lambda x: x.name, res))) # Read rt = entities.ReportTemplate(id=rt.id).read() self.assertEqual(name, rt.name) self.assertEqual(template1, rt.template) # Update template2 = gen_string('alpha') entities.ReportTemplate(id=rt.id, template=template2).update(['template']) rt = entities.ReportTemplate(id=rt.id).read() self.assertEqual(template2, rt.template) # Delete entities.ReportTemplate(id=rt.id).delete() with self.assertRaises(HTTPError): rt = entities.ReportTemplate(id=rt.id).read()
def test_positive_generate_report_nofilter(): """Generate Host - Statuses report :id: a4b687db-144e-4761-a42e-e93887464986 :setup: User with reporting access rights, some report template, at least two hosts :steps: 1. POST /api/report_templates/:id/generate :expectedresults: Report is generated for all hosts visible to user :CaseImportance: Critical """ host_name = gen_string('alpha').lower() entities.Host(name=host_name).create() rt = entities.ReportTemplate().search(query={'search': 'name="Host - Statuses"'})[0].read() res = rt.generate() assert "Service Level" in res assert host_name in res
def test_positive_CRUDL(name): """Create, Read, Update, Delete, List :id: a2a577db-144e-4761-a42e-e83885464786 :parametrized: yes :setup: User with reporting access rights :steps: 1. Create Report Template 2. List Report Templates, verify it's there 3. Read Report Template 4. Update Report Template, read again 5. Delete Report template, check it's not present :expectedresults: All operations succeed, no template present in the end :CaseImportance: Critical """ # Create template1 = gen_string('alpha') rt = entities.ReportTemplate(name=name, template=template1).create() # List res = entities.ReportTemplate().search(query={'search': f'name="{name}"'}) assert name in list(map(lambda x: x.name, res)) # Read rt = entities.ReportTemplate(id=rt.id).read() assert name == rt.name assert template1 == rt.template # Update template2 = gen_string('alpha') entities.ReportTemplate(id=rt.id, template=template2).update(['template']) rt = entities.ReportTemplate(id=rt.id).read() assert template2 == rt.template # Delete entities.ReportTemplate(id=rt.id).delete() with pytest.raises(HTTPError): rt = entities.ReportTemplate(id=rt.id).read()
def test_positive_lock_clone_nodelete_unlock_report(self): """Lock report template. Check it can be cloned and can't be deleted or edited. Unlock. Check it can be deleted and edited. :id: a4c577db-144e-4761-a42e-e83887464986 :setup: User with reporting access rights, some report template that is not locked :steps: 1. Create template 2. Lock template 3. Clone template, check cloned data 4. Try to delete template 5. Try to edit template 6. Unlock template 7. Edit template 8. Delete template :expectedresults: Report is locked :CaseImportance: High :BZ: 1680458 """ # 1. Create template template_name = gen_string('alpha').lower() template_clone_name = gen_string('alpha').lower() template1 = gen_string('alpha') template2 = gen_string('alpha') rt = entities.ReportTemplate(name=template_name, template=template1).create() # 2. Lock template entities.ReportTemplate(id=rt.id, locked=True).update(["locked"]) rt = rt.read() self.assertTrue(rt.locked) # 3. Clone template, check cloned data rt.clone(data={'name': template_clone_name}) cloned_rt = (entities.ReportTemplate().search( query={'search': 'name="{}"'.format(template_clone_name)}) [0].read()) self.assertEquals(template_clone_name, cloned_rt.name) self.assertEquals(template1, cloned_rt.template) # 4. Try to delete template if not is_open('BZ:1680458'): with self.assertRaises(HTTPError): rt.delete() # In BZ1680458, exception is thrown but template is deleted anyway self.assertNotEquals( 0, len(entities.ReportTemplate().search( query={'search': 'name="{}"'.format(template_name)})), ) # 5. Try to edit template with self.assertRaises(HTTPError): entities.ReportTemplate(id=rt.id, template=template2).update(["template"]) rt = rt.read() self.assertEquals(template1, rt.template) # 6. Unlock template entities.ReportTemplate(id=rt.id, locked=False).update(["locked"]) rt = rt.read() self.assertFalse(rt.locked) # 7. Edit template entities.ReportTemplate(id=rt.id, template=template2).update(["template"]) rt = rt.read() self.assertEquals(template2, rt.template) # 8. Delete template rt.delete() self.assertEquals( 0, len(entities.ReportTemplate().search( query={'search': 'name="{}"'.format(template_name)})), )
def test_positive_import_filtered_templates_from_git( self, module_org, module_location): """Assure only templates with a given filter regex are pulled from git repo. :id: 628a95d6-7a4e-4e56-ad7b-d9fecd34f765 :Steps: 1. Using nailgun or direct API call import only the templates matching with regex e.g: `^atomic.*` refer to: `/apidoc/v2/template/import.html` :expectedresults: 1. Assert result is {'message': 'success'} and template imported 2. Assert no other template has been imported but only those matching specified regex. NOTE: Templates are always imported with a prefix defaults to `community` unless it is specified as empty string 3. Assert json output doesnt have 'Name is not matching filter condition, skipping' info message for imported template :CaseImportance: High """ prefix = gen_string('alpha') filtered_imported_templates = entities.Template().imports( data={ 'repo': FOREMAN_TEMPLATE_IMPORT_URL, 'branch': 'automation', 'filter': 'robottelo', 'organization_ids': [module_org.id], 'location_ids': [module_location.id], 'prefix': prefix, }) imported_count = [ template['imported'] for template in filtered_imported_templates['message']['templates'] ].count(True) assert imported_count == 8 ptemplates = entities.ProvisioningTemplate().search( query={ 'per_page': 100, 'search': f'name~{prefix}', 'organization_id': module_org.id, 'location_id': module_location.id, }) assert len(ptemplates) == 5 ptables = entities.PartitionTable().search( query={ 'per_page': 100, 'search': f'name~{prefix}', 'organization_id': module_org.id, 'location_id': module_location.id, }) assert len(ptables) == 1 jtemplates = entities.JobTemplate().search( query={ 'per_page': 100, 'search': f'name~{prefix}', 'organization_id': module_org.id, 'location_id': module_location.id, }) assert len(jtemplates) == 1 rtemplates = entities.ReportTemplate().search( query={ 'per_page': 10, 'search': f'name~{prefix}', 'organization_id': module_org.id, 'location_id': module_location.id, }) assert len(rtemplates) == 1