def test_basic_mdu(self):
        """
        Basic test of mdu
        """
        ReportData.drop_collection()
        rhel_entry = TestData.create_entry(RHEL, mem_high=True)
        rhel_entry.save()            
        lookup = ReportData.objects.all()
        self.assertEqual(len(lookup), 1)          
        
        delta=timedelta(days=1)
        start = datetime.now() - delta
        end = datetime.now() + delta        
        
        

        filter_args = {
               "memtotal__gt": rhel_entry.memtotal - 1,
               "product": rhel_entry.product,
               "contract_id": rhel_entry.contract_id,
               "support": rhel_entry.support,
               "memtotal__lt": rhel_entry.memtotal + 1,
               "consumer_uuid": rhel_entry.consumer_uuid,
               "sla": rhel_entry.sla
        }
        
        args = {
            "start": start.strftime(constants.epoch),
            "end": end.strftime(constants.epoch),
            "filter_args_dict": filter_args,
            "description": {"Product": RHEL}
        }        
        test_dict = MaxUsage.get_MDU_MCU(**args)
        result = test_dict['mdu'][1]
        self.assertEqual(result[1], 1, "correct mdu found")
Exemple #2
0
def max_report(request):
    data = utils.data_from_post(request);

    response_data = MaxUsage.get_MDU_MCU(**data)
    
    response_data['start'] = data['start'] 
    response_data['end'] = data["end"]
    response_data['description'] = data["description"]
    response_data['filter_args'] = data["filter_args_dict"]
    
    return create_response(response_data)
    def test_advanced_mcu_mdu(self):
                """
                three report data entries, each w/ unique instance_ident
                2 in the same $hour
                1 in $hour + 1
                mcu = 2 , mdu = 3
                """
                delta_day=timedelta(days=1)
                delta_hour=timedelta(hours=1)
                start = datetime.now() - delta_day
                end = datetime.now() + delta_day  
                hour_plus_1 = datetime.now() + delta_hour
                
                ReportData.drop_collection()
                rhel_entry = TestData.create_entry(RHEL,
                                                   instance_identifier="00:10")
                rhel_entry.save()
                rhel_entry = TestData.create_entry(RHEL,
                                                   instance_identifier="00:11")
                rhel_entry.save() 
                rhel_entry = TestData.create_entry(RHEL,
                                                   date=hour_plus_1,
                                                   instance_identifier="00:12")
                rhel_entry.save()                 
                lookup = ReportData.objects.all()
                self.assertEqual(len(lookup), 3)          

                filter_args = {
                       "memtotal__gt": rhel_entry.memtotal - 1,
                       "product": rhel_entry.product,
                       "contract_id": rhel_entry.contract_id,
                       "support": rhel_entry.support,
                       "memtotal__lt": rhel_entry.memtotal + 1,
                       "consumer_uuid": rhel_entry.consumer_uuid,
                       "sla": rhel_entry.sla
                }
                
                args = {
                    "start": start.strftime(constants.epoch),
                    "end": end.strftime(constants.epoch),
                    "filter_args_dict": filter_args,
                    "description": {"Product": RHEL}
                }
                
                
                test_dict = MaxUsage.get_MDU_MCU(**args)
                mdu = test_dict['mdu'][1]
                mcu = test_dict['mcu'][1]
                self.assertEqual(mdu[1], 3, "correct mdu found") 
                self.assertEqual(mcu[1], 2, "correct mcu found") 
Exemple #4
0
def generic_count(product,
                  rhic,
                  start,
                  end,
                  contract_number,
                  environment,
                  config):
    product_config = config
        
    # Generic parameters to filter on
    filter_args_dict = {'consumer_uuid': str(rhic.uuid), 
                        'product': product.engineering_ids,
                        'sla': product.sla,
                        'support': product.support_level,
                        'contract_id': contract_number}
    if environment != "All":
        filter_args_dict['environment'] = environment
    
    #add custom business rules
    filter_args_high = dict(filter_args_dict)
    filter_args_low = dict(filter_args_dict)
    facts_high = ""
    facts_low = ""
    
    for key, values in product_config.items():
        if key == 'calculation':
            continue
        if(values):
            filter_args_low[key + '__gt'] = values['low_gt'] 
            filter_args_low[key + '__lt'] = values['low_lt']
            facts_low += values['low_desc']
           
            filter_args_high[key + '__gt'] = values['high_gt']
            if values['high_lt'] == -1:
                _LOG.debug('-1, parameter will not be added to query')
            else:
                filter_args_high[key + '__lt'] = values['high_lt']
            facts_high += values['high_desc']
     
    compliant_high = False
    compliant_low = False
    if product_config['calculation'] == 'hourly':
       
        high = ReportData.objects.filter(date__gt=start,
                                         date__lt=end,
                                         **filter_args_high).count()
        low = ReportData.objects.filter(date__gt=start,
                                        date__lt=end,
                                        **filter_args_low).count()
        if high:
            compliant_high = MaxUsage.get_MCU_Compliant(start,
                                                         end,
                                                         filter_args_high,
                                                         product.name)
            
        if low:
            compliant_low = MaxUsage.get_MCU_Compliant(start,
                                                        end,
                                                        filter_args_low,
                                                        product.name)

    
    results = {'high_count': high,
               'facts_high': facts_high,
               'filter_args_high': filter_args_high,
               'compliant_high': compliant_high,
               'low_count': low,
               'facts_low': facts_low,
               'filter_args_low': filter_args_low,
               'compliant_low': compliant_low }
                                
    return results