Exemplo n.º 1
0
    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")
Exemplo n.º 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)
Exemplo n.º 3
0
    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")