def test_generic_config_RHEL_JBOSS_same_rhic(self): ReportData.drop_collection() # create 1 RHEL, 2 JBoss entry_high = TestData.create_entry(RHEL, mem_high=True) entry_high.save(safe=True) entry_high = TestData.create_entry(JBoss, socket=5) entry_high.save(safe=True) entry_low = TestData.create_entry(JBoss, socket=4 ) entry_low.save(safe=True) delta=timedelta(days=1) start = datetime.now() - delta end = datetime.now() + delta environment = "us-east-1" lookup = ReportData.objects.all() self.assertEqual(len(lookup), 3) #test for RHEL Match rhic = RHIC.objects.filter(uuid=products_dict[RHEL][1])[0] p = Product.objects.filter(name=RHEL, sla=rhic.sla, support_level=rhic.support_level)[0] results_dicts = Product_Def.get_count(p, rhic, start, end, rhic.contract, environment, report_biz_rules) self.assertEqual(len(results_dicts), 1) #test for JBoss match rhic = RHIC.objects.filter(uuid=products_dict[JBoss][1])[0] p = Product.objects.filter(name=JBoss, sla=rhic.sla, support_level=rhic.support_level)[0] results_dicts = Product_Def.get_count(p, rhic, start, end, rhic.contract, environment, report_biz_rules) results_dicts = Product_Def.get_count(p, rhic, start, end, rhic.contract, environment, report_biz_rules) self.assertEqual(len(results_dicts), 2)
def hours_per_consumer(start, end, list_of_rhics=None, contract_number=None, environment="All", return_failed_only=False): results = [] rules = Rules() report_biz_rules = rules.get_rules() if contract_number: list_of_rhics = list(RHIC.objects.filter(contract=contract_number)) if list_of_rhics: account_num = RHIC.objects.get(uuid=list_of_rhics[0].uuid).account_id for rhic in list_of_rhics: rhic_list = [] account_num = str(RHIC.objects.filter(uuid=str(rhic.uuid))[0].account_id) contract_num = str(RHIC.objects.filter(uuid=str(rhic.uuid))[0].contract) ''' There can be multiple contracts under an account. The contract is an embedded document under account and can not be filtered directly. Iterating through the list of contracts under an account is the only way I can think of to get the correct contract ''' list_of_products = get_list_of_products(account_num, contract_num) products_contract = [(prod.name) for prod in list_of_products] intersect = set(products_contract).intersection(set(rhic.products)) for p in (p for p in list_of_products if p.name in intersect): # _LOG.info(p.name, p.sla, p.support_level) results_dicts = [] results_dicts = Product_Def.get_count(p, rhic, start, end, contract_num, environment, report_biz_rules) if results_dicts: for result in results_dicts: if not return_failed_only: rhic_list.append(result) else: if not result['compliant']: rhic_list.append(result) if rhic_list: results.append(rhic_list) return results
def test_rhel_memory_results(self): contract_num = "3116649" environment = "us-east-1" end = datetime.now() delta=timedelta(days=1) start = datetime.now() - delta p = Product.objects.filter(name=RHEL)[0] rhic = RHIC.objects.filter(uuid=products_dict[RHEL][1])[0] results_dicts = Product_Def.get_count(p, rhic, start, end, contract_num, environment, report_biz_rules) self.assertTrue('> ' in results_dicts[0]['facts'], ' > 8GB found') rhel02 = TestData.create_entry(RHEL, mem_high=False) rhel02.save() end = datetime.now() #verify two items in db lookup = ReportData.objects.all() self.assertEqual(len(lookup), 2) #RHEL w/ > 8GB and < 8GB memory are considered two different products #The result dict should have two items in the list (2 products, 1 count each) results_dicts = Product_Def.get_count(p, rhic, start, end, contract_num, environment, report_biz_rules) self.assertEqual(len(results_dicts), 2)
def test_rhel_basic_results(self): delta=timedelta(days=1) start = datetime.now() - delta end = datetime.now() + delta contract_num = "3116649" environment = "us-east-1" lookup = ReportData.objects.all() self.assertEqual(len(lookup), 1) #test perfect match p = Product.objects.filter(name=RHEL)[0] rhic = RHIC.objects.filter(uuid=products_dict[RHEL][1])[0] results_dicts = Product_Def.get_count(p, rhic, start, end, contract_num, environment, report_biz_rules) self.assertEqual(len(results_dicts), 1) test_object = Product.objects.filter(name=RHEL)[0] test_object.name = "fail" try: results_dicts = Product_Def.get_count(test_object, rhic, start, end, contract_num, environment, report_biz_rules) except KeyError: self.assertTrue(1, 'key error appropriately found, no results returned') except Exception: self.assertTrue(0,'key error not found, error') # test result not found where rhic uuid does not match test_object = RHIC.objects.filter(uuid="8d401b5e-2fa5-4cb6-be64-5f57386fda86")[0] test_object.uuid = "1234" results_dicts = Product_Def.get_count(p, test_object, start, end, contract_num, environment, report_biz_rules) self.assertFalse(results_dicts, 'no results returned') # test no results are found if usage date is not in range test_object = datetime.now() results_dicts = Product_Def.get_count(p, rhic, test_object, end, contract_num, environment, report_biz_rules) self.assertFalse(results_dicts, 'no results returned') test_object = start results_dicts = Product_Def.get_count(p, rhic, start, test_object, contract_num, environment, report_biz_rules) self.assertFalse(results_dicts, 'no results returned') #test if contract number is not a match test_object = "1234" results_dicts = Product_Def.get_count(p, rhic, start, end, test_object, environment, report_biz_rules) self.assertFalse(results_dicts, 'no results returned') #test if environment is not a match test_object = "env_hell" results_dicts = Product_Def.get_count(p, rhic, start, end, contract_num, test_object, report_biz_rules) self.assertFalse(results_dicts, 'no results returned')
def test_generic_config_RHEL(self): ReportData.drop_collection() entry_high = TestData.create_entry(RHEL, mem_high=True) entry_high.save(safe=True) delta=timedelta(days=1) start = datetime.now() - delta end = datetime.now() + delta contract_num = "3116649" environment = "us-east-1" lookup = ReportData.objects.all() self.assertEqual(len(lookup), 1) #test perfect match p = Product.objects.filter(name=RHEL)[0] #print(products_dict[RHEL][1]) rhic = RHIC.objects.filter(uuid=products_dict[RHEL][1])[0] results_dicts = Product_Def.get_count(p, rhic, start, end, contract_num, environment, report_biz_rules) self.assertEqual(len(results_dicts), 1)
def test_find_each_product(self): ReportData.drop_collection() count = 0 for key, value in products_dict.items(): count += 1 entry = TestData.create_entry(key, mem_high=True) entry.save(safe=True) lookup = len(ReportData.objects.all()) self.assertEqual(lookup, count) end = datetime.now() delta=timedelta(days=1) start = datetime.now() - delta for key, value in products_dict.items(): rhic = RHIC.objects.filter(uuid=value[1])[0] p = Product.objects.filter(name=key, sla=rhic.sla, support_level=rhic.support_level)[0] results_dicts = Product_Def.get_count(p, rhic, start, end, rhic.contract, "us-east-1", report_biz_rules) self.assertEqual(len(results_dicts), 1)
def test_rhel_data_range_results_60day(self): contract_num = "3116649" environment = "us-east-1" search_date_start = datetime.now() - timedelta(days=60) search_date_end = datetime.now() delta = timedelta(days=10) rhel = TestData.create_entry(RHEL, mem_high=True, date=(datetime.now() - delta)) rhel.save() lookup = ReportData.objects.all() self.assertEqual(len(lookup), 2) #test that there are now two objects in the database p = Product.objects.filter(name=RHEL)[0] rhic = RHIC.objects.filter(uuid=products_dict[RHEL][1])[0] results_dicts = Product_Def.get_count(p, rhic, search_date_start, search_date_end, contract_num, environment, report_biz_rules) #lenth of list should be one per product self.assertEqual(len(results_dicts), 1) #dictionary should contain the count of checkins self.assertEqual(results_dicts[0]['count'], 2)