def processTaskQueue(task_id):
    try:
        process=db.task_queue[task_id] 
        
        task_queue_query = db(db.task_queue.id==task_id)
        task_event_query = db((db.task_queue_event.task_id==task_id) & (db.task_queue_event.status != TASK_QUEUE_STATUS_IGNORE))
        #Update attention_time for task in the event table
        task_event_query.update(attention_time=get_datetime())
        #Call the corresponding function from vm_helper
        ret = task[process['task_type']](process['parameters'])
        #On return, update the status and end time in task event table
        task_event_query.update(status=ret[0], end_time=get_datetime())
        if ret[0] == TASK_QUEUE_STATUS_FAILED:
            #For failed task, change task status to Failed, it can be marked for retry by admin later
            task_queue_query.update(status=TASK_QUEUE_STATUS_FAILED)
            #Update task event with the error message
            task_event_query.update(error=ret[1],status=TASK_QUEUE_STATUS_FAILED)
        elif ret[0] == TASK_QUEUE_STATUS_SUCCESS:
            # For successful task, delete the task from queue 
            task_queue_query.delete()
        db.commit()
        logger.debug("Task done")
    except Exception as e:
        logger.error(e)
        etype, value, tb = sys.exc_info()
        msg=''.join(traceback.format_exception(etype, value, tb, 10))
        db(db.task_queue.id==task_id).update(status=-1)
Beispiel #2
0
def process_snapshot_vm(snapshot_type, vm_id = None, frequency=None):
    """
    Handles snapshot task
    Invoked when scheduler runs task of type 'snapshot_vm'"""
    
    logger.debug("ENTERING SNAPSHOT VM TASK........Snapshot Type: %s"% snapshot_type)
    try:
        if snapshot_type == SNAPSHOT_SYSTEM:
            params={'snapshot_type' : frequency, 'vm_id' : vm_id}
            task[VM_TASK_SNAPSHOT](params)

        else:    
            vms = db(db.vm_data.status.belongs(VM_STATUS_RUNNING, VM_STATUS_SUSPENDED, VM_STATUS_SHUTDOWN)).select()
            for vm_data in vms:
                flag = vm_data.snapshot_flag

                if(snapshot_type & flag):
                    logger.debug("snapshot_type" + str(snapshot_type))
                    vm_scheduler.queue_task(TASK_SNAPSHOT, 
                                            group_name = 'snapshot_task', 
                                            pvars = {'snapshot_type' : SNAPSHOT_SYSTEM, 'vm_id' : vm_data.id, 'frequency' : snapshot_type}, 
                                            start_time = request.now, 
                                            timeout = 60 * MINUTES)
    except:
        log_exception()
        pass
    finally:
        db.commit()
        logger.debug("EXITING SNAPSHOT VM TASK........")
def process_purge_shutdownvm():

    logger.info("ENTERING PURGE SHUTDOWN VM ........") 
    vmShutDownDays = config.get("GENERAL_CONF", "shutdown_vm_days")

    try:
        # Fetch all the VM's which are locked and whose delete warning date is not null. 
        for vm_data in db(db.vm_data.locked == True and db.vm_data.delete_warning_date!=None).select(db.vm_data.ALL):
            daysDiff=0
            daysDiff=(get_datetime()-vm_data.delete_warning_date).days
            if(daysDiff >=0 ):
                for vm_details in db(db.vm_event_log.vm_id==vm_data.id).select(db.vm_event_log.ALL,orderby = ~db.vm_event_log.id,limitby=(0,1)):
                    daysDiff=(get_datetime()-vm_details.timestamp).days
                    if(vm_details.new_value == "Shutdown" and int(daysDiff)>=int(vmShutDownDays)):
                        logger.info("Need to delete the VM ID:"+str(vm_data.id)) 
                        add_vm_task_to_queue(vm_data.id,VM_TASK_DELETE)
                        # make an entry in task queue so that scheduler can pick up and delete the VM.
                    else:
                        logger.info("No need to delete the VM ID:"+str(vm_data.id)+" as it is in use now. ")
                        db(db.vm_data.id == vm_details.vm_id).update(locked='F',delete_warning_date=None)
            else:
                logger.info("No need to process shutdown VM :"+str(vm_data.id))
    except:
        log_exception()
        pass
    finally:
        db.commit()
        logger.debug("EXITING PURGE SHUTDOWN VM ........")
def process_snapshot_vm(snapshot_type, vm_id = None, frequency=None):
    """
    Handles snapshot task
    Invoked when scheduler runs task of type 'snapshot_vm'"""
    
    logger.debug("ENTERING SNAPSHOT VM TASK........Snapshot Type: %s"% snapshot_type)
    try:
        if snapshot_type == SNAPSHOT_SYSTEM:
            params={'snapshot_type' : frequency, 'vm_id' : vm_id}
            task[VM_TASK_SNAPSHOT](params)

        else:    
            vms = db(db.vm_data.status.belongs(VM_STATUS_RUNNING, VM_STATUS_SUSPENDED, VM_STATUS_SHUTDOWN)).select()
            for vm_data in vms:
                flag = vm_data.snapshot_flag

                if(snapshot_type & flag):
                    logger.debug("snapshot_type" + str(snapshot_type))
                    vm_scheduler.queue_task(TASK_SNAPSHOT, 
                                            group_name = 'snapshot_task', 
                                            pvars = {'snapshot_type' : SNAPSHOT_SYSTEM, 'vm_id' : vm_data.id, 'frequency' : snapshot_type}, 
                                            start_time = request.now, 
                                            timeout = 60 * MINUTES)
    except:
        log_exception()
        pass
    finally:
        db.commit()
        logger.debug("EXITING SNAPSHOT VM TASK........")
Beispiel #5
0
def processTaskQueue(task_id):
    try:
        process = db.task_queue[task_id]

        task_queue_query = db(db.task_queue.id == task_id)
        task_event_query = db((db.task_queue_event.task_id == task_id) & (
            db.task_queue_event.status != TASK_QUEUE_STATUS_IGNORE))
        #Update attention_time for task in the event table
        task_event_query.update(attention_time=get_datetime())
        #Call the corresponding function from vm_helper
        ret = task[process['task_type']](process['parameters'])
        #On return, update the status and end time in task event table
        task_event_query.update(status=ret[0], end_time=get_datetime())
        if ret[0] == TASK_QUEUE_STATUS_FAILED:
            #For failed task, change task status to Failed, it can be marked for retry by admin later
            task_queue_query.update(status=TASK_QUEUE_STATUS_FAILED)
            #Update task event with the error message
            task_event_query.update(error=ret[1],
                                    status=TASK_QUEUE_STATUS_FAILED)
        elif ret[0] == TASK_QUEUE_STATUS_SUCCESS:
            # For successful task, delete the task from queue
            task_queue_query.delete()
        db.commit()
        logger.debug("Task done")
    except Exception as e:
        logger.error(e)
        etype, value, tb = sys.exc_info()
        msg = ''.join(traceback.format_exception(etype, value, tb, 10))
        db(db.task_queue.id == task_id).update(status=-1)
Beispiel #6
0
def process_container_queue(task_event_id):
    """
    Invoked when scheduler runs task of type 'Container_Task'
    For every task, function calls the corresponding handler
    and updates the database on the basis of the response 
    """
    logger.info("\n ENTERING Container_Task........")

    task_event_data = db.task_queue_event[task_event_id]
    task_queue_data = db.task_queue[task_event_data.task_id]
    container_data = db.container_data[
        task_event_data.cont_id] if task_event_data.cont_id != None else None
    try:
        #Update attention_time for task in the event table
        task_event_data.update_record(attention_time=get_datetime(),
                                      status=TASK_QUEUE_STATUS_PROCESSING)
        #Call the corresponding function from vm_helper
        logger.debug("Starting Container_Task processing...")
        ret = task[task_queue_data.task_type](task_queue_data.parameters)
        logger.debug("Completed Container_Task processing...")

        #On return, update the status and end time in task event table
        task_event_data.update_record(status=ret[0],
                                      message=ret[1],
                                      end_time=get_datetime())

        if ret[0] == TASK_QUEUE_STATUS_FAILED:

            logger.debug("Container_Task FAILED")
            logger.debug("Container_Task Error Message: %s" % ret[1])
            task_queue_data.update_record(status=TASK_QUEUE_STATUS_FAILED)

        elif ret[0] == TASK_QUEUE_STATUS_SUCCESS:
            # Create log event for the task
            logger.debug("Container_Task SUCCESSFUL")
            if container_data:
                _log_vm_event(container_data, task_queue_data)
            # For successful task, delete the task from queue
            if db.task_queue[task_queue_data.id]:
                del db.task_queue[task_queue_data.id]
            if 'request_id' in task_queue_data.parameters:
                del db.request_queue[task_queue_data.parameters['request_id']]

            if task_event_data.task_type not in (VM_TASK_MIGRATE_HOST,
                                                 VM_TASK_MIGRATE_DS):
                _send_cont_task_complete_mail(task_event_data)

    except:
        msg = log_exception()
        task_event_data.update_record(status=TASK_QUEUE_STATUS_FAILED,
                                      message=msg)

    finally:
        db.commit()
        logger.info("EXITING Container_Task........\n")
def process_unusedvm():
    logger.info("ENTERING PROCESS UNUSED VM ........")
    try:
        process_shutdown_unusedvm()
        process_purge_shutdownvm()
    except:
        log_exception()
        pass
    finally:
        db.commit()
        logger.debug("EXITING PROCESS UNUSED VM......")
Beispiel #8
0
def process_task_queue(task_event_id):
    logger.debug("\n ENTERING Testing Task........")    
    logger.debug(task_event_id)    
    task_event_data = db.task_queue_event[task_event_id]
    task_event = db.task_queue[task_event_id]
    logger.debug(task_event_data)
    logger.debug(" ..................... ")
    logger.debug(task_event)
    new_db=mdb.connect("127.0.0.1","root","baadal","baadal")
    cursor1=new_db.cursor()
    cursor1.execute("select task_type,requester_type,ip_addr from task_queue where id= %s",task_event_data.task_id)
    task_queue_data=cursor1.fetchall()
    cursor1.execute("select file_name from task_queue_event where id= %s",task_event_data.id)
    file_name=cursor1.fetchall()
    new_db.commit()
    cursor1.close() 
    logger.debug(task_queue_data)
    task_queue_data=task_queue_data[0]
    logger.debug(task_queue_data)
    attention_time=get_datetime()
    logger.debug(file_name[0][0])
    try:
      attention_time=get_datetime()
      task_event_data.update_record(attention_time=attention_time,status=TASK_QUEUE_STATUS_PROCESSING)
      logger.debug("Starting TASK processing...")
      file_name=file_name[0][0]
      my_logger=_get_configured_logger(file_name)
      task_type=task_queue_data[0]
      ip_address=task_queue_data[2]
      request_type=task_queue_data[1]
      if task_type in "Unit Testing":
         unit_testing(task_event_data.task_id,request_type,ip_address,my_logger)
         end_time=get_datetime()
         my_logger.debug(end_time)
         task_event_data.update_record(end_time=end_time,status=TASK_QUEUE_STATUS_SUCCESS)
         db.commit() 
      if task_type in "System Testing":
         system_testing(request_type,ip_address,my_logger)
         end_time=get_datetime()
         task_event_data.update_record(end_time=end_time,status=TASK_QUEUE_STATUS_SUCCESS)
      if task_type in "Integration Testing":
         integration_testing(request_type,ip_address,my_logger)
         end_time=get_datetime()
         task_event_data.update_record(end_time=end_time,status=TASK_QUEUE_STATUS_SUCCESS)
      if task_type in "Database Dependent Testing":
         database_dependent_testing(request_type,ip_address,my_logger)
         end_time=get_datetime()
         task_event_data.update_record(end_time=end_time,status=TASK_QUEUE_STATUS_SUCCESS)
    except:        
        end_time=get_datetime()
        task_event_data.update_record(end_time=end_time,status=TASK_QUEUE_STATUS_FAILED)
        #send_task_complete_mail(task_event_data,status)
    finally:
        db.commit()
Beispiel #9
0
def process_unusedvm():
    """
    Purge/shutdown the unused VM's
    """
    logger.info("ENTERING PROCESS UNUSED VM ........")
    try:
        process_shutdown_unusedvm()
        process_purge_shutdownvm()
    except:
        log_exception()
        pass
    finally:
        db.commit()
        logger.debug("EXITING PROCESS UNUSED VM......")
Beispiel #10
0
def process_task_queue(task_event_id):
    """
    Invoked when scheduler runs task of type 'vm_task'
    For every task, function calls the corresponding handler
    and updates the database on the basis of the response 
    """
    logger.info("\n ENTERING VM_TASK........")
    
    task_event_data = db.task_queue_event[task_event_id]
    task_queue_data = db.task_queue[task_event_data.task_id]
    vm_data = db.vm_data[task_event_data.vm_id] if task_event_data.vm_id != None else None
    try:
        #Update attention_time for task in the event table
        task_event_data.update_record(attention_time=get_datetime(), status=TASK_QUEUE_STATUS_PROCESSING)
        #Call the corresponding function from vm_helper
        logger.debug("Starting VM_TASK processing...")
        ret = task[task_queue_data.task_type](task_queue_data.parameters)
        logger.debug("Completed VM_TASK processing...")

        #On return, update the status and end time in task event table
        task_event_data.update_record(status=ret[0], message=ret[1], end_time=get_datetime())
        
        if ret[0] == TASK_QUEUE_STATUS_FAILED:

            logger.debug("VM_TASK FAILED")
            logger.debug("VM_TASK Error Message: %s" % ret[1])
            task_queue_data.update_record(status=TASK_QUEUE_STATUS_FAILED)

        elif ret[0] == TASK_QUEUE_STATUS_SUCCESS:
            # Create log event for the task
            logger.debug("VM_TASK SUCCESSFUL")
            if vm_data:
                _log_vm_event(vm_data, task_queue_data)
            # For successful task, delete the task from queue 
            if db.task_queue[task_queue_data.id]:
                del db.task_queue[task_queue_data.id]
            if 'request_id' in task_queue_data.parameters:
                del db.request_queue[task_queue_data.parameters['request_id']]
            
            if task_event_data.task_type not in (VM_TASK_MIGRATE_HOST, VM_TASK_MIGRATE_DS):
                _send_task_complete_mail(task_event_data)
        
    except:
        msg = log_exception()
        task_event_data.update_record(status=TASK_QUEUE_STATUS_FAILED, message=msg)
        
    finally:
        db.commit()
        logger.info("EXITING VM_TASK........\n")
Beispiel #11
0
def process_object_task(task_event_id):
    """Invoked when scheduler runs task of type 'object_task'
    For every task, function calls the corresponding handler
    and updates the database on the basis of the response """

    logger.info("\n ENTERING OBJECT_TASK	........")
    task_event_data = db.task_queue_event[task_event_id]
    task_queue_data = db.task_queue[task_event_data.task_id]
    object_data = db.object_store_data[task_event_data.parameters[
        'vm_id']] if task_event_data.parameters['vm_id'] != None else None
    try:
        #Update attention_time for task in the event table
        task_event_data.update_record(attention_time=get_datetime(),
                                      status=TASK_QUEUE_STATUS_PROCESSING)
        #Call the corresponding function from vm_helper
        logger.debug("Starting OBJECT_TASK processing...")
        ret = create_object_store(task_event_id, object_data)
        logger.debug("Completed OBJECT_TASK processing...")
        #On return, update the status and end time in task event table
        task_event_data.update_record(status=ret[0],
                                      message=ret[1],
                                      end_time=get_datetime())

        if ret[0] == TASK_QUEUE_STATUS_FAILED:
            logger.debug("OBJECT_TASK FAILED")
            logger.debug("OBJECT_TASK Error Message: %s" % ret[1])
            task_queue_data.update_record(status=TASK_QUEUE_STATUS_FAILED)

        elif ret[0] == TASK_QUEUE_STATUS_SUCCESS:
            # Create log event for the task
            logger.debug("OBJECT_TASK SUCCESSFUL")
            if object_data:
                logger.info("\n object_data: %s" % object_data)
            # For successful task, delete the task from queue
            if db.task_queue[task_queue_data.id]:
                del db.task_queue[task_queue_data.id]
            if 'request_id' in task_queue_data.parameters:
                del db.request_queue[task_queue_data.parameters['request_id']]

            _send_object_task_complete_mail(task_event_data,
                                            object_data['object_store_name'])
    except:
        msg = log_exception()
        task_event_data.update_record(status=TASK_QUEUE_STATUS_FAILED,
                                      message=msg)

    finally:
        db.commit()
        logger.info("EXITING OBJECT_TASK........\n")
def process_vmdaily_checks():
    """
    Function will check for the shutdown VM's and sends email to the user"""
    
    logger.info("Entering VM's Daily Checks........")

    try:
        process_sendwarning_unusedvm()
        process_sendwarning_shutdownvm()
    except:
        log_exception()
        pass
    finally:
        db.commit()
        logger.debug("EXITING VM DAILY CHECKS........")
Beispiel #13
0
def process_vmdaily_checks():
    """
    Check for the shutdown VM's and unused VM's and sends warning email to the user
    """
    logger.info("Entering VM's Daily Checks........")

    try:
        process_sendwarning_unusedvm()
        process_sendwarning_shutdownvm()
    except:
        log_exception()
        pass
    finally:
        db.commit()
        logger.debug("EXITING VM DAILY CHECKS........")
def process_sendwarning_unusedvm():

    logger.info("Entering send warning to unused VM........")

    try:
        ''' performing daily checks for network usage '''
        vmCPUThreshold  = config.get("GENERAL_CONF", "cpu_threshold_limit")
        vmreadThreshold = config.get("GENERAL_CONF", "nwRead_threshold_limit")
        vmwriteThreshold = config.get("GENERAL_CONF", "nwWrite_threshold_limit")

        thresholdcontext = dict(CPUThreshold=vmCPUThreshold,
                                ReadThreshold=vmreadThreshold,
                                WriteThreshold=vmwriteThreshold)

        logger.info("checking network usage with threshold values as CPUThreshold is:"+str(thresholdcontext['CPUThreshold'])+" WriteThreshold is :"+str(thresholdcontext['WriteThreshold'])+" ReadThreshold is :"+ str(thresholdcontext['ReadThreshold']))

        vms = db(db.vm_data.status.belongs(VM_STATUS_RUNNING, VM_STATUS_SUSPENDED) & (db.vm_data.shutdown_warning_date == None) & (db.vm_data.start_time < (get_datetime() - timedelta(days=20)))).select()
        '''check vm should have been created 20days back'''

        for vm in vms:
            logger.info("comparing threshold for the vm "+ str(vm.vm_identity))
            send_email=0
            retVal=compare_rrd_data_with_threshold(vm.vm_identity,thresholdcontext)
            if(retVal == True): 
                vm_users = []
                vm_name  = ""
                for user in db((db.user_vm_map.vm_id == vm.id) & (db.user_vm_map.vm_id == db.vm_data.id) & (db.vm_data.shutdown_warning_date == None )).select(db.user_vm_map.user_id,db.vm_data.vm_name):
                    send_email=1
                    vm_users.append(user.user_vm_map.user_id)
                    vm_name=user.vm_data.vm_name

                if (send_email == 1):
                    vm_shutdown_time=send_email_vm_warning(VM_TASK_WARNING_SHUTDOWN,vm_users,vm_name,'')
                    logger.debug("Mail sent for vm_name:"+str(vm_name)+"|shutdown time returned from the function:"+ str(vm_shutdown_time))
                    db(db.vm_data.id == vm.id).update(shutdown_warning_date=vm_shutdown_time)
                    db.commit()
                else:
                    logger.debug("Warning Email to use the VM has already been sent to VM_ID:"+str(vm.id))
            else:
                logger.info("VM:"+str(vm.id)+" is in use.. no need to send shutdown warning mail ...")
    except:
        log_exception()
        pass
    finally:
        db.commit()
        logger.debug("EXITING send warning to unused VM........")
Beispiel #15
0
def stress_testing():

    print "inside stress testing"
    import commands
    print request.vars
    email_id = request.vars['email_id']
    user_name = request.vars['user_name']
    name = request.vars['name']
    server_name = request.vars['server_name']
    print "server name is " + str(server_name)
    if name == None:
        print "inside name checking "
        ip_address = request.vars['ip_addr']
    else:
        print "else part of name checking"
        ip_address = name
    print "ip address of the testing system is : "
    print ip_address
    form = FORM(
        TABLE(
            TR(INPUT(_name='testcases0', _type='checkbox', _value="1"), 'All'),
            BR(), TR(INPUT(_type='submit', _value='submit'))))

    if form.process().accepted:
        test_case_no = request.vars['testcases0']
        print "test case list : " + str(test_case_no)
        if test_case_no != None:
            testcase_list = test_case_no
        task_event_id = db.task_queue.insert(ip_addr=ip_address,
                                             task_type='Stress Testing',
                                             requester_type=testcase_list,
                                             email_id=email_id,
                                             user_name=user_name)
        db.commit()
        task_type = 'Stress Testing'
        schedule_task(task_type, task_event_id, email_id, user_name,
                      server_name)

    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
Beispiel #16
0
def process_unusedvm_purge():

    logger.info("ENTERING PURGE UNUSED VM ........") 

    try:
        # Fetch all the VM's which are locked and whose delete warning date=today. 
        for vm_data in db(db.vm_data.locked == True).select(db.vm_data.ALL):
            for vm_details in db(db.vm_event_log.vm_id==vm_data.id).select(db.vm_event_log.ALL,orderby = ~db.vm_event_log.id,limitby=(0,1)):
                daysDiff=(get_datetime()-vm_data.delete_warning_date).days
                if(vm_details.new_value == "Shutdown" and daysDiff >= 0):
                    logger.info("Need to delete the VM ID:"+str(vm_data.id)) 
                    add_vm_task_to_queue(vm_data.id,VM_TASK_DELETE)
                    # make an entry in task queue so that scheduler can pick up and delete the VM.
    except:
        log_exception()
        pass
    finally:
        db.commit()
        logger.debug("EXITING PURGE UNUSED VM ........")
def process_sendwarning_shutdownvm():

    logger.info("Entering Process send warning mail to shutdown vm........")

    try:
        vmShutDownDays = config.get("GENERAL_CONF", "shutdown_vm_days")
        send_email=0

        for vm_id in db().select(db.vm_event_log.vm_id, distinct=True):
            for vm_details in db(db.vm_event_log.vm_id==vm_id['vm_id']).select(db.vm_event_log.ALL,orderby = ~db.vm_event_log.id,limitby=(0,1)):
                daysDiff=(get_datetime()-vm_details.timestamp).days
                vm_shutdown_time=vm_details.timestamp

                logger.info("VM details are VM_ID:" + str(vm_details['vm_id'])+ "|ID:"+str(vm_details['id'])+"|new_values is:"+str(vm_details['new_value'])+"|daysDiff:" + str(daysDiff)+"|vmShutDownDays:"+vmShutDownDays+"|vm_shutdown_time :"+str(vm_shutdown_time))

                if (vm_details.new_value == "Shutdown" and int(daysDiff)>=int(vmShutDownDays)):
                    vm_users = []
                    vm_name  = ""

                    for user in db((db.user_vm_map.vm_id == vm_details.vm_id) & (db.user_vm_map.vm_id == db.vm_data.id) & (db.vm_data.locked != True) & (db.vm_data.delete_warning_date == None )).select(db.user_vm_map.user_id,db.vm_data.vm_name):
                        send_email=1
                        vm_users.append(user.user_vm_map.user_id)
                        vm_name=user.vm_data.vm_name

                    if (send_email == 1):
                        vm_delete_time=send_email_vm_warning(VM_TASK_WARNING_DELETE,vm_users,vm_name,vm_shutdown_time)
                        logger.debug("Mail sent for vm_id:"+str(vm_details.vm_id)+"|vm_name:"+str(vm_name)+"|delete time:"+ str(vm_delete_time))
                        db(db.vm_data.id == vm_details.vm_id).update(locked=True, delete_warning_date=vm_delete_time) 
                        send_email=0
                    else:
                        logger.debug("Email has already been sent to VM_ID:"+str(vm_details.vm_id))

                else:
                    logger.info("VM:"+str(vm_details.vm_id)+" is not shutdown for: "+str(vmShutDownDays)+"(configured) days")


    except:
        log_exception()
        pass
    finally:
        db.commit()
        logger.debug("EXITING Send warning to shutdown vm........")
Beispiel #18
0
def stress_testing(): 

    print "inside stress testing"
    import commands
    print request.vars
    email_id=request.vars['email_id']
    user_name=request.vars['user_name']
    name=request.vars['name']
    server_name=request.vars['server_name']
    print "server name is " + str(server_name)
    if name == None :
       print "inside name checking "
       ip_address=request.vars['ip_addr'] 
    else :
       print "else part of name checking"
       ip_address=name         
    print "ip address of the testing system is : "
    print ip_address
    form = FORM(  TABLE
        (   TR(INPUT(_name='testcases0', _type='checkbox', _value="1"),'All'), 
            BR(),
            TR(INPUT(_type='submit',_value='submit'))
        )
        )
              
    if form.process().accepted:
        test_case_no=request.vars['testcases0']   
       	print "test case list : " + str(test_case_no)
        if test_case_no!=None:                
                testcase_list=test_case_no
    	task_event_id = db.task_queue.insert(ip_addr=ip_address,task_type ='Stress Testing',requester_type=testcase_list,email_id=email_id,user_name=user_name)
    	db.commit()
    	task_type='Stress Testing'  
    	schedule_task(task_type,task_event_id,email_id,user_name,server_name)
        
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
Beispiel #19
0
def process_vmdaily_checks():
    """
    Function will check for the shutdown VM's and sends email to the user"""
    
    logger.info("Entering VM's Daily Checks........")

    try: 
        vmShutDownDays = config.get("GENERAL_CONF", "shutdown_vm_days") 
        send_email=0

        for vm_id in db().select(db.vm_event_log.vm_id, distinct=True): 
            for vm_details in db(db.vm_event_log.vm_id==vm_id['vm_id']).select(db.vm_event_log.ALL,orderby = ~db.vm_event_log.id,limitby=(0,1)):
                daysDiff=(get_datetime()-vm_details.timestamp).days
                vm_shutdown_time=vm_details.timestamp

                logger.info("VM details are VM_ID:" + str(vm_details['vm_id'])+ "|ID:"+str(vm_details['id'])+"|new_values is:"+str(vm_details['new_value'])+"|daysDiff:" + str(daysDiff)+"|vmShutDownDays:"+vmShutDownDays+"|vm_shutdown_time :"+str(vm_shutdown_time))

                if (vm_details.new_value == "Shutdown" and int(daysDiff)>=int(vmShutDownDays)):
                    vm_users = []
                    vm_name  = ""

                    for user in db((db.user_vm_map.vm_id == vm_details.vm_id) & (db.user_vm_map.vm_id == db.vm_data.id) & (db.vm_data.locked !='T') & (db.vm_data.delete_warning_date == None )).select(db.user_vm_map.user_id,db.vm_data.vm_name): 
                        send_email=1
                        vm_users.append(user.user_vm_map.user_id) 
                        vm_name=user.vm_data.vm_name
                   
                    if (send_email == 1):
                        vm_delete_time = send_email_delete_vm_warning(vm_users,vm_name,vm_shutdown_time) 
                        logger.debug("Mail sent for vm_name:"+str(vm_name)+"|delete time returned from the function:"+ str(vm_delete_time)) 
                        db(db.vm_data.id == vm_details.vm_id).update(locked=True, delete_warning_date=vm_delete_time) 
                    else:
                        logger.debug("Email has already been sent to VM_ID:"+str(vm_details.vm_id))
                else:
                    logger.info("VM:"+str(vm_details.vm_id)+" is not shutdown ..") 
    except:
        log_exception()
        pass
    finally: 
        db.commit()
        logger.debug("EXITING VM DAILY CHECKS........")
def process_shutdown_unusedvm():
   
    logger.info("ENTERING SHUTDOWN UNUSED VM ........")

    try:
        # Fetch all the VM's which are locked and whose shutdown_warning_date=today. 
        vmCPUThreshold  = config.get("GENERAL_CONF", "cpu_threshold_limit")
        vmreadThreshold = config.get("GENERAL_CONF", "nwRead_threshold_limit")
        vmwriteThreshold = config.get("GENERAL_CONF", "nwWrite_threshold_limit")

        thresholdcontext = dict(CPUThreshold=vmCPUThreshold,
                                ReadThreshold=vmreadThreshold,
                                WriteThreshold=vmwriteThreshold)

        for vmData in db(db.vm_data.shutdown_warning_date!=None).select(db.vm_data.ALL):
            daysDiff=(get_datetime()-vmData.shutdown_warning_date).days
            if(daysDiff >= 0):
                '''Again compare the data for last 20 days from rrd logs '''
                retVal=compare_rrd_data_with_threshold(vmData.vm_identity,thresholdcontext) 
                logger.info(" DaysDiff are "+str(daysDiff)+" return value is "+str(retVal))
                if(retVal == True):
                    logger.info("Need to shutdown the VM ID:"+str(vmData.id))
                    add_vm_task_to_queue(vmData.id,VM_TASK_DESTROY)
                    # make an entry in task queue so that scheduler can pick up and shutdown the VM.
                else:
                    logger.info("No Need to shutdown the VM ID:"+str(vmData.id)+" as VM is in use now. ")
             
                #update db to clean the shutdown warning date 
                db(db.vm_data.id == vmData.id).update(shutdown_warning_date=None)
            else:
                logger.info("No need to process purge for the VM:"+str(vmData.id))
    except:
        log_exception()
        pass
    finally:
        db.commit()
        logger.debug("EXITING SHUTDOWN UNUSED VM ........")
Beispiel #21
0
def process_task_queue(task_event_id):
    logger.debug("\n ENTERING Testing Task........")
    logger.debug(task_event_id)
    task_event_data = db.task_queue_event[task_event_id]
    task_event = db.task_queue[task_event_id]
    logger.debug(task_event_data)
    logger.debug(" ..................... ")
    logger.debug(task_event)
    new_db = mdb.connect("127.0.0.1", "root", "baadal", "baadal")
    cursor1 = new_db.cursor()
    cursor1.execute(
        "select task_type,requester_type,ip_addr from task_queue where id= %s",
        task_event_data.task_id)
    task_queue_data = cursor1.fetchall()
    cursor1.execute("select file_name from task_queue_event where id= %s",
                    task_event_data.id)
    file_name = cursor1.fetchall()
    new_db.commit()
    cursor1.close()
    logger.debug(task_queue_data)
    task_queue_data = task_queue_data[0]
    logger.debug(task_queue_data)
    attention_time = get_datetime()
    logger.debug(file_name[0][0])
    try:
        attention_time = get_datetime()
        task_event_data.update_record(attention_time=attention_time,
                                      status=TASK_QUEUE_STATUS_PROCESSING)
        logger.debug("Starting TASK processing...")
        file_name = file_name[0][0]
        my_logger = _get_configured_logger(file_name)
        task_type = task_queue_data[0]
        ip_address = task_queue_data[2]
        request_type = task_queue_data[1]
        if task_type in "Unit Testing":
            unit_testing(task_event_data.task_id, request_type, ip_address,
                         my_logger)
            end_time = get_datetime()
            my_logger.debug(end_time)
            task_event_data.update_record(end_time=end_time,
                                          status=TASK_QUEUE_STATUS_SUCCESS)
            db.commit()
        if task_type in "System Testing":
            system_testing(request_type, ip_address, my_logger)
            end_time = get_datetime()
            task_event_data.update_record(end_time=end_time,
                                          status=TASK_QUEUE_STATUS_SUCCESS)
        if task_type in "Integration Testing":
            integration_testing(request_type, ip_address, my_logger)
            end_time = get_datetime()
            task_event_data.update_record(end_time=end_time,
                                          status=TASK_QUEUE_STATUS_SUCCESS)
        if task_type in "Database Dependent Testing":
            database_dependent_testing(request_type, ip_address, my_logger)
            end_time = get_datetime()
            task_event_data.update_record(end_time=end_time,
                                          status=TASK_QUEUE_STATUS_SUCCESS)
    except:
        end_time = get_datetime()
        task_event_data.update_record(end_time=end_time,
                                      status=TASK_QUEUE_STATUS_FAILED)
        #send_task_complete_mail(task_event_data,status)
    finally:
        db.commit()
Beispiel #22
0
def check_vm_sanity(host_id = 0):
    """
    Checks if database information of VM status is in sync with ground reality.
    In case of discrepancy database is updated.
        - For each host, get list of the domains(running and not running).
        - If VM has migrated to another host; host information updated in database.
        - If VM not in sync with actual state of VM; status of VM updated in DB.
        - If VM is not present in database, it is marked Orphan.
        - If VM is not found on any of the hosts, it is marked Undefined.
    """
    vmcheck=[]
    vm_list = []
    
    if host_id == 0:
        hosts=db(db.host.status == HOST_STATUS_UP).select()
    else:
        hosts=db(db.host.id == host_id).select()
    
    for host in hosts:
        try:
            logger.info('Starting sanity check for host %s' %(host.host_name))
            #Get list of the domains(running and not running) on the hypervisor
            domains = get_host_domains(host.host_ip.private_ip)
            for dom in domains:
                try:
                    domain_name = dom.name()
                    vm = db((db.vm_data.vm_identity == domain_name) & 
                            (db.vm_data.status.belongs(VM_STATUS_RUNNING, VM_STATUS_SUSPENDED, VM_STATUS_SHUTDOWN))).select().first()
                    
                    vm_state = dom.info()[0]
                    status = vminfo_to_state(vm_state)
                    if(vm):
                        if(vm.host_id != host.id):
                            vmcheck.append({'vm_id':vm.id,
                                            'host':host.host_name, 
                                            'host_id':host.id,
                                            'vmname':vm.vm_name,
                                            'status':status,
                                            'message':'Moved from '+vm.host_id.host_name+' to '+host.host_name, 'operation':'None'})#Bad VMs
                            #If VM has been migrated to another host; Host information updated
                            db(db.vm_data.vm_identity == domain_name).update(host_id = host.id)
                        else:
                            vmcheck.append({'vm_id':vm.id,
                                            'host':host.host_name,
                                            'host_id':host.id,
                                            'vmname':vm.vm_name,
                                            'status':status,
                                            'message':'VM is on expected host '+vm.host_id.host_name, 'operation':'None'})#Good VMs
                        if vm_state_map[vm_state] != vm.status:
                            logger.info("vm_identity="+str(domain_name)+" vm_state_map[vm_state]="+str(vm_state_map[vm_state])+"and vm.status is" + str(vm.status))
                            #If not in sync with actual state of VM; status of VM updated in DB
                            db(db.vm_data.vm_identity == domain_name).update(status = vm_state_map[vm_state])

                            #Adding into vm_event_log about the vm details
                            db.vm_event_log.insert(vm_id = vm.id,
                                                   attribute = 'VM Status',
                                                   requester_id = SYSTEM_USER,
                                                   old_value = get_vm_status(vm.status),
                                                   new_value = get_vm_status(vm_state_map[vm_state]))

                        vm_list.append(vm.vm_identity)
                            
                    elif vm_state != VIR_DOMAIN_CRASHED:
                        vmcheck.append({'host':host.host_name,
                                        'host_id':host.id,
                                        'vmname':dom.name(),
                                        'status':status,
                                        'message':'Orphan, VM is not in database', 
                                        'operation':'Orphan'})#Orphan VMs

                except Exception:
                    log_exception()
                    if(vm):
                        vmcheck.append({'vmname':vm.vm_name,
                                        'host':'Unknown',
                                        'host_id':'0',
                                        'status':'Unknown',
                                        'message':'Some Error Occurred', 
                                        'operation':'Error'})

        except:pass
        db.commit()
        
    if host_id == 0:
        db_vms=db(db.vm_data.status.belongs(VM_STATUS_RUNNING, VM_STATUS_SUSPENDED, VM_STATUS_SHUTDOWN)).select()
        for db_vm in db_vms:
            if(db_vm.vm_identity not in vm_list):
                vmcheck.append({'vmname':db_vm.vm_identity,
                                'host':db_vm.host_id.host_name,
                                'host_id':db_vm.host_id,
                                'status':'Undefined',
                                'message':'VM not found', 
                                'operation':'Undefined'})
            
    return vmcheck
def process_clone_task(task_event_id, vm_id):
    """
    Invoked when scheduler runs task of type 'clone_task'
    When multiple clones of a VM is requested, multiple tasks are created in scheduler,
    so that they can run concurrently. 
    This function ensures that the status of clone request is updated on the basis of all 
    corresponding asynchronous tasks """

    vm_data = db.vm_data[vm_id]
    logger.debug("ENTERING CLONE_TASK.......")
    logger.debug("Task Id: %s" % task_event_id)
    logger.debug("VM to be Cloned: %s" % vm_data.vm_name)
    task_event = db.task_queue_event[task_event_id]
    task_queue = db.task_queue[task_event.task_id]
    message = task_event.message if task_event.message != None else ''
    try:
        # Update attention time for first clone task
        if task_event.attention_time == None:
            task_event.update_record(attention_time=get_datetime())
        logger.debug("Starting VM Cloning...")
        ret = task[VM_TASK_CLONE](vm_id)
        logger.debug("Completed VM Cloning...")

        if ret[0] == TASK_QUEUE_STATUS_FAILED:
            logger.debug("VM Cloning Failed")
            logger.debug("Failure Message: %s" % ret[1])
            message = message + '\n' + vm_data.vm_name + ': ' + ret[1]
            vm_data.update_record(status = VM_STATUS_UNKNOWN)
        elif ret[0] == TASK_QUEUE_STATUS_SUCCESS:
            logger.debug("VM Cloning Successful")
            params = task_queue.parameters
            # Delete successful vms from list. So, that in case of retry, only failed requests are retried.
            params['clone_vm_id'].remove(vm_id)
            task_queue.update_record(parameters=params)
        
        clone_vm_list = task_event.parameters['clone_vm_id']
        # Remove VM id from the list. This is to check if all the clones for the task are processed.
        clone_vm_list.remove(vm_id)
        
        # Find the status of all clone tasks combined
        current_status = ret[0]
        if task_event.status != TASK_QUEUE_STATUS_PENDING and task_event.status != current_status:
            current_status = TASK_QUEUE_STATUS_PARTIAL_SUCCESS
        
        if not clone_vm_list: #All Clones are processed
            if current_status == TASK_QUEUE_STATUS_SUCCESS:
                del db.request_queue[task_queue.parameters['request_id']]
                del db.task_queue[task_queue.id]
            else:
                if 'request_id' in task_queue.parameters:
                    db.request_queue[task_queue.parameters['request_id']] = dict(status = REQ_STATUS_FAILED)
                task_queue.update_record(status=current_status)
            task_event.update_record(status=current_status, message=message, end_time=get_datetime())
        else:
            task_event.update_record(parameters={'clone_vm_id' : clone_vm_list}, status=current_status, message=message)

    except:
        msg = log_exception()
        vm_data = db.vm_data[vm_id]
        message = message + '\n' + vm_data.vm_name + ': ' + msg
        task_event.update_record(status=TASK_QUEUE_STATUS_FAILED, message=message)

    finally:
        db.commit()
        logger.debug("EXITING CLONE_TASK........")
Beispiel #24
0
def integration_testing():
    print "inside integration testing"
    import commands
    print request.vars
    email_id = request.vars['email_id']
    user_name = request.vars['user_name']
    name = request.vars['name']
    server_name = request.vars['server_name']
    print "server name is " + str(server_name)
    if name == None:
        print "inside name checking "
        ip_address = request.vars['ip_addr']
    else:
        print "else part of name checking"
        ip_address = name
    print "ip address of the testing system is : "
    print ip_address
    form = FORM(
        TABLE(
            TR(INPUT(_name='testcase114', _type='checkbox', _value="114"),
               'All'),
            TR(INPUT(_name='testcase49', _type='checkbox', _value="49"),
               'Maintain Idompotency'),
            TR(INPUT(_name='testcase50', _type='checkbox', _value="50"),
               'VM Graph(Memory)'),
            TR(INPUT(_name='testcase51', _type='checkbox', _value="51"),
               'VM Graph(CPU)'),
            TR(INPUT(_name='testcase52', _type='checkbox', _value="52"),
               'VM Graph(Network)'),
            TR(INPUT(_name='testcase53', _type='checkbox', _value="53"),
               'VM Graph(Disk)'),
            #TR(INPUT(_name='testcase54', _type='checkbox', _value="54"),'VM Performance   (Shutdown )'),
            #TR(INPUT(_name='testcase56', _type='checkbox', _value="56"),'User Request VM(Approved by Faculty,org-admin,admin)'),
            #TR(INPUT(_name='testcase57', _type='checkbox', _value="57"),'User Request VM(Approved by Faculty and Rejected by org-admin)'),
            # TR(INPUT(_name='testcase58', _type='checkbox', _value="58"),'User Request VM(Approved by Faculty,org-admin and Rejected by admin)'),
            # TR(INPUT(_name='testcase59', _type='checkbox', _value="59"),'User Request VM(Rejected by Faculty )'),
            TR(INPUT(_name='testcase54', _type='checkbox', _value="54"),
               'Performance Testing(1CPU,80GB HDD,256MB RAM)'),
            TR(INPUT(_name='testcase55', _type='checkbox', _value="55"),
               'Performance Testing(1CPU,80GB HDD,512MB RAM)'),
            TR(INPUT(_name='testcase56', _type='checkbox', _value="56"),
               'Performance Testing(1CPU,80GB HDD,1GB RAM)'),
            TR(INPUT(_name='testcase57', _type='checkbox', _value="57"),
               'Performance Testing(1CPU,80GB HDD,2GB RAM)'),
            TR(INPUT(_name='testcase58', _type='checkbox', _value="58"),
               'Performance Testing(2CPU,80GB HDD,2GB RAM)'),
            TR(INPUT(_name='testcase59', _type='checkbox', _value="59"),
               'Performance Testing(2CPU,80GB HDD,4GB RAM)'),
            TR(INPUT(_name='testcase60', _type='checkbox', _value="60"),
               'Performance Testing(4CPU,80GB HDD,4GB RAM)'),
            TR(INPUT(_name='testcase61', _type='checkbox', _value="61"),
               'Performance Testing(4CPU,80GB HDD,8GB RAM)'),
            TR(INPUT(_name='testcase62', _type='checkbox', _value="62"),
               'Performance Testing(8CPU,80GB HDD,8GB RAM)'),
            TR(INPUT(_name='testcase63', _type='checkbox', _value="63"),
               'Performance Testing(8CPU,80GB HDD,16GB RAM)'),
            #
            #     TR(INPUT(_name='testcase60', _type='checkbox', _value="60"),'Take VM snapshot    (Running )'),
            #    TR(INPUT(_name='testcase61', _type='checkbox', _value="61"),'Pause VM   (Running )'),
            #   TR(INPUT(_name='testcase62', _type='checkbox', _value="62"),'Add User to VM   (Running )'),
            #  TR(INPUT(_name='testcase65', _type='checkbox', _value="65"),'Delete VM    (Running)'),
            # TR(INPUT(_name='testcase64', _type='checkbox', _value="64"),'Gracefully shut down VM    (Running )'),
            # TR(INPUT(_name='testcase63', _type='checkbox', _value="63"),'Forcefully power off VM   (Running )'),
            # TR(INPUT(_name='testcase66', _type='checkbox', _value="66") ,'Migrate VM   (Running )'),
            #TR(INPUT(_name='testcase67', _type='checkbox', _value="67"),'Take VM snapshot   (Paused )'),
            #TR(INPUT(_name='testcase68', _type='checkbox', _value="68"),'Unpause VM   (Paused )'),
            #TR(INPUT(_name='testcase69', _type='checkbox', _value="69"),'Add User to VM  (Paused )'),
            #TR(INPUT(_name='testcase75', _type='checkbox', _value="75"),'Delete VM   (Paused )'),
            #TR(INPUT(_name='testcase71', _type='checkbox', _value="71"),'Forcefully power off VM   (Paused)'),
            #TR(INPUT(_name='testcase70', _type='checkbox', _value="70"),'Migrate VM   (Paused )'),
            #TR(INPUT(_name='testcase72', _type='checkbox', _value="72"),'Delete Add User  (Paused )'),
            #TR(INPUT(_name='testcase73', _type='checkbox', _value="73"),'Revert Snapshot  (Paused )'),
            # TR(INPUT(_name='testcase74', _type='checkbox', _value="74"),'Delete snapshot   (Paused )'),
            # TR(INPUT(_name='testcase76', _type='checkbox', _value="76"),'Turn on VM   (Shutdown )'),
            # TR(INPUT(_name='testcase77', _type='checkbox', _value="77"),'Add User to VM  (Shutdown)'),
            #TR(INPUT(_name='testcase80', _type='checkbox', _value="80"),'Delete VM   (Shutdown )'),
            # TR(INPUT(_name='testcase78', _type='checkbox', _value="78"),'Take VM snapshot   (Shutdown )'),
            #TR(INPUT(_name='testcase79', _type='checkbox', _value="79"),'Migrate VM   (Shutdown )'),
            #TR(INPUT(_name='testcase107', _type='checkbox', _value="107"),'User Request Attach Disk(Approved by Faculty,org-admin,admin)'),
            # TR(INPUT(_name='testcase71', _type='checkbox', _value="71"), 'Org-Admin Request VM(Rejected by admin)'),
            #TR(INPUT(_name='testcase109', _type='checkbox', _value="109"),'User Request Attach Disk(Approved by Faculty and Rejected by org-admin)'),
            #TR(INPUT(_name='testcase108', _type='checkbox', _value="108"),'User Request Attach Disk(Approved by Faculty,org-admin and Rejected by admin)'),
            # TR(INPUT(_name='testcase110', _type='checkbox', _value="110"),'User Request Attach Disk(Rejected by Faculty )'),
            # TR(INPUT(_name='testcase105', _type='checkbox', _value="105"),'Org-Admin  Attach Disk(Approved by admin)'),
            # TR(INPUT(_name='testcase106', _type='checkbox', _value="106"), 'Org-Admin Attach Disk(Rejected by admin)'),

            # TR(INPUT(_name='testcase102', _type='checkbox', _value="102"),'User Request Clone VM(Approved by Faculty and Rejected by org-admin)'),
            #   TR(INPUT(_name='testcase112', _type='checkbox', _value="112"),'User Request Clone VM(Rejected by Faculty )'),

            #   TR(INPUT(_name='testcase118', _type='checkbox', _value="118"),'User Request Clone VM(Approved by Faculty,org-admin,admin)'),
            #   TR(INPUT(_name='testcase119', _type='checkbox', _value="119"),'User Request Clone VM(Approved by Faculty and Rejected by org-admin)'),
            #     TR(INPUT(_name='testcase120', _type='checkbox', _value="120"),'User Request Clone VM(Approved by Faculty,org-admin and Rejected by admin)'),
            #    TR(INPUT(_name='testcase121', _type='checkbox', _value="121"),'User Request Edit VM Config(Rejected by Faculty )'),
            BR(),
            TR(INPUT(_type='submit', _value='submit'))))
    test_list = {
        '114': 'All',
        '49': 'Maintain Idompotency',
        '50': 'VM Graph(Memory)',
        '51': 'VM Graph(CPU)',
        '52': 'VM Graph(Network)',
        '53': 'VM Graph(Disk)',
        '54': 'Performance Testing(1CPU,80GB HDD,256MB RAM)',
        '55': 'Performance Testing(1CPU,80GB HDD,512MB RAM)',
        '56': 'Performance Testing(1CPU,80GB HDD,1GB RAM)',
        '57': 'Performance Testing(1CPU,80GB HDD,2GB RAM)',
        '58': 'Performance Testing(2CPU,80GB HDD,2GB RAM)',
        '59': 'Performance Testing(2CPU,80GB HDD,4GB RAM)',
        '60': 'Performance Testing(4CPU,80GB HDD,4GB RAM)',
        '61': 'Performance Testing(4CPU,80GB HDD,8GB RAM)',
        '62': 'Performance Testing(8CPU,80GB HDD,8GB RAM)',
        '63': 'Performance Testing(8CPU,80GB HDD,16GB RAM)'
    }
    if form.process().accepted:
        testcase_list = []
        test_case_list = []
        j = 0
        for i in range(49, 116):
            print "inside for loop"
            test_case_no = request.vars['testcase' + str(i)]
            logger.debug("i is : " + str(i))
            logger.debug("j is : " + str(j))
            logger.debug("test case no : " + str(test_case_no))
            if test_case_no == None:
                continue
            else:
                testcase_list.insert(j, i)
                test_case_list.append(test_list[str(i)])
            j += 1
        logger.debug("test cases are : " + str(testcase_list))
        task_event_id = db.task_queue.insert(ip_addr=ip_address,
                                             task_type='Integration Testing',
                                             requester_type=testcase_list,
                                             email_id=email_id,
                                             user_name=user_name)
        db.commit()
        task_type = 'Integration Testing'
        schedule_task(task_type, task_event_id, email_id, user_name,
                      server_name, test_case_list)
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
Beispiel #25
0
def system_testing():
    logger.debug("inside system testing")
    import commands
    print request.vars
    email_id=request.vars['email_id']
    user_name=request.vars['user_name']
    name=request.vars['name']
    server_name=request.vars['server_name']
    print "server name is " + str(server_name)
    if name == None :
       print "inside name checking "
       ip_address=request.vars['ip_addr'] 
    else :
       print "else part of name checking"
       ip_address=name         
    logger.debug("ip address of the testing system is : " + str(ip_address))
    form = FORM(  TABLE
        (  
           TR(INPUT(_name='testcases16', _type='checkbox', _value="16"),'All'),
           TR(INPUT(_name='testcases1', _type='checkbox', _value="1"),'Migrate'),
           TR(INPUT(_name='testcases2', _type='checkbox', _value="2"),'Gracefully shutdown'),
           TR(INPUT(_name='testcases3', _type='checkbox', _value="3"),'Paused'),
           TR(INPUT(_name='testcases4', _type='checkbox', _value="4"),'Delete'),
           TR(INPUT(_name='testcases5', _type='checkbox', _value="5"),'Force Shutdown'),
           TR(INPUT(_name='testcases6', _type='checkbox', _value="6"),'Attach Disk'),
           #TR(INPUT(_name='testcases7', _type='checkbox', _value="7"),'Baadal Shutdown'),
           TR(INPUT(_name='testcases8', _type='checkbox', _value="8"),'Clone VM'),
           TR(INPUT(_name='testcases9', _type='checkbox', _value="9"),'Edit VM Configuration'),
           #TR(INPUT(_name='testcases10', _type='checkbox', _value="10"),'VNC Access'),
           #TR(INPUT(_name='testcases11', _type='checkbox', _value="11"),'Sanity Check'),
           #TR(INPUT(_name='testcases12', _type='checkbox', _value="12"),'VM Snapshot '),
           #TR(INPUT(_name='testcases13', _type='checkbox', _value="13"),'Launch VM '),
           #TR(INPUT(_name='testcases14', _type='checkbox', _value="14"),'Wake On LAN '),
           #TR(INPUT(_name='testcases15', _type='checkbox', _value="15"),'Check Host Load Capacity (100 min)'),
           
           BR(),
           TR(INPUT(_type='submit',_value='submit'))
          )
      )
    test_list={'16':'All','1':'Migrate','2':'Gracefully shutdown','3':'Paused','4':'Delete','5':'Force Shutdown','6':'Attach Disk','7':'Baadal Shutdown','8':'Clone VM','9':'Edit VM Configuration','10':'VNC Access','11':'Sanity Check','12':'VM Snapshot','13':'Launch VM','14':'Wake On LAN','15':'Check Host Load Capacity'}   
    if form.process().accepted:
        testcase_list=[]
        test_case_list=[]
        j=0
        for i in range(1,18): 
            logger.debug(i)
            test_case_no=request.vars['testcases'+str(i)]    
            logger.debug("test case no  : " +str(test_case_no))       
            if test_case_no==None:                
                	continue
	   
            else:
                        testcase_list.insert(j,i)
                        test_case_list.append(test_list[str(i)])
            j+=1
        logger.debug("test case list : " + str(testcase_list))
        task_event_id = db.task_queue.insert(ip_addr=ip_address,task_type ='System Testing',requester_type=testcase_list,email_id=email_id,user_name=user_name)
        db.commit()
        task_type='System Testing'  
        schedule_task(task_type,task_event_id,email_id,user_name,server_name,test_case_list) 
   
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
Beispiel #26
0
def database_dependent_testing():
    print "database_dependent testing"
    import commands
    print request.vars
    email_id = request.vars['email_id']
    user_name = request.vars['user_name']
    name = request.vars['name']
    server_name = request.vars['server_name']
    print "server name is " + str(server_name)
    if name == None:
        print "inside name checking "
        ip_address = request.vars['ip_addr']
    else:
        print "else part of name checking"
        ip_address = name
    print "ip address of the testing system is : "
    print ip_address
    form = FORM(
        TABLE(
            TR(INPUT(_name='testcases7', _type='checkbox', _value="7"),
               'My VMs'),
            TR(INPUT(_name='testcases8', _type='checkbox', _value="8"),
               'My Pending Tasks'),
            TR(INPUT(_name='testcases9', _type='checkbox', _value="9"),
               'My Completed Tasks'),
            TR(INPUT(_name='testcases10', _type='checkbox', _value="10"),
               'My Failed Tasks'),
            TR(INPUT(_name='testcases18', _type='checkbox', _value="18"),
               'All VMs'),
            TR(
                INPUT(_name='testcases19', _type='checkbox', _value="19"),
                'Host and VMs',
            ),
            TR(INPUT(_name='testcases20', _type='checkbox', _value="20"),
               'Pending Tasks'),
            TR(INPUT(_name='testcases21', _type='checkbox', _value="21"),
               'Completed Tasks'),
            TR(INPUT(_name='testcases22', _type='checkbox', _value="22"),
               'Failed Tasks'),
            TR(INPUT(_name='testcases44', _type='checkbox', _value="44"),
               'Sanity Table'),
            TR(
                INPUT(_name='testcases17', _type='checkbox', _value="17"),
                'List All Org-Level VMs',
            ),
            TR(INPUT(_name='testcases45', _type='checkbox', _value="45"),
               'Pending User VM Requests(Install VM)'),
            TR(INPUT(_name='testcases46', _type='checkbox', _value="46"),
               'Pending User VM Requests(Clone VM)'),
            TR(INPUT(_name='testcases47', _type='checkbox', _value="47"),
               'Pending User VM Requests(Attach Disk)'),
            TR(INPUT(_name='testcases11', _type='checkbox', _value="11"),
               'Pending Faculty-Level VM Approvals(Install VM)'),
            TR(INPUT(_name='testcases12', _type='checkbox', _value="12"),
               'Pending Faculty-Level VM Approvals(Clone VM)'),
            TR(INPUT(_name='testcases13', _type='checkbox', _value="13"),
               'Pending Faculty-Level VM Approvals(Attach Disk)'),
            TR(INPUT(_name='testcases14', _type='checkbox', _value="14"),
               'Pending Org-Level VM Approvals(Install VM)'),
            TR(INPUT(_name='testcases15', _type='checkbox', _value="15"),
               'Pending Org-Level VM Approvals(Clone VM)'),
            TR(INPUT(_name='testcases16', _type='checkbox', _value="16"),
               'Pending Org-Level VM Approvals(Attach Disk)'), BR(),
            TR(INPUT(_type='submit', _value='submit'))))
    test_list = {
        '7': 'My VMs',
        '8': 'My Pending Tasks',
        '9': 'My Completed Tasks',
        '10': 'My Failed Tasks',
        '11': 'Pending Faculty-Level VM Approvals(Install VM)',
        '12': 'Pending Faculty-Level VM Approvals(Clone VM)',
        '13': 'Pending Faculty-Level VM Approvals(Attach Disk)',
        '14': 'Pending Org-Level VM Approvals(Install VM)',
        '15': 'Pending Org-Level VM Approvals(Clone VM)',
        '16': 'Pending Org-Level VM Approvals(Attach Disk)',
        '17': 'List All Org-Level VMs',
        '18': 'All VMs',
        '19': 'Host and VMs',
        '20': 'Pending Tasks',
        '21': 'Completed Tasks',
        '22': 'Failed Tasks',
        '44': 'Completed Tasks',
        '22': 'Sanity Table',
        '47': 'Pending User VM Requests(Attach Disk)',
        '45': 'Pending User VM Requests(Install VM)',
        '46': 'Pending User VM Requests(Clone VM)'
    }
    if form.process().accepted:
        testcase_list = []
        test_case_list = []
        j = 0
        for i in range(6, 49):
            print i
            test_case_no = request.vars['testcases' + str(i)]
            print "test case no  : " + str(test_case_no)
            if test_case_no == None:
                continue
            else:
                testcase_list.insert(j, i)
                test_case_list.append(test_list[str(i)])
            j += 1
        print "test case list : " + str(testcase_list)
        print test_case_list
        task_event_id = db.task_queue.insert(
            ip_addr=ip_address,
            task_type='Database Dependent Testing',
            requester_type=testcase_list,
            email_id=email_id,
            user_name=user_name)
        db.commit()
        task_type = 'Database Dependent Testing'
        schedule_task(task_type, task_event_id, email_id, user_name,
                      server_name, test_case_list)

    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
Beispiel #27
0
def system_testing():
    logger.debug("inside system testing")
    import commands
    print request.vars
    email_id = request.vars['email_id']
    user_name = request.vars['user_name']
    name = request.vars['name']
    server_name = request.vars['server_name']
    print "server name is " + str(server_name)
    if name == None:
        print "inside name checking "
        ip_address = request.vars['ip_addr']
    else:
        print "else part of name checking"
        ip_address = name
    logger.debug("ip address of the testing system is : " + str(ip_address))
    form = FORM(
        TABLE(
            TR(INPUT(_name='testcases16', _type='checkbox', _value="16"),
               'All'),
            TR(INPUT(_name='testcases1', _type='checkbox', _value="1"),
               'Migrate'),
            TR(INPUT(_name='testcases2', _type='checkbox', _value="2"),
               'Gracefully shutdown'),
            TR(INPUT(_name='testcases3', _type='checkbox', _value="3"),
               'Paused'),
            TR(INPUT(_name='testcases4', _type='checkbox', _value="4"),
               'Delete'),
            TR(INPUT(_name='testcases5', _type='checkbox', _value="5"),
               'Force Shutdown'),
            TR(INPUT(_name='testcases6', _type='checkbox', _value="6"),
               'Attach Disk'),
            #TR(INPUT(_name='testcases7', _type='checkbox', _value="7"),'Baadal Shutdown'),
            TR(INPUT(_name='testcases8', _type='checkbox', _value="8"),
               'Clone VM'),
            TR(INPUT(_name='testcases9', _type='checkbox', _value="9"),
               'Edit VM Configuration'),
            #TR(INPUT(_name='testcases10', _type='checkbox', _value="10"),'VNC Access'),
            #TR(INPUT(_name='testcases11', _type='checkbox', _value="11"),'Sanity Check'),
            #TR(INPUT(_name='testcases12', _type='checkbox', _value="12"),'VM Snapshot '),
            #TR(INPUT(_name='testcases13', _type='checkbox', _value="13"),'Launch VM '),
            #TR(INPUT(_name='testcases14', _type='checkbox', _value="14"),'Wake On LAN '),
            #TR(INPUT(_name='testcases15', _type='checkbox', _value="15"),'Check Host Load Capacity (100 min)'),
            BR(),
            TR(INPUT(_type='submit', _value='submit'))))
    test_list = {
        '16': 'All',
        '1': 'Migrate',
        '2': 'Gracefully shutdown',
        '3': 'Paused',
        '4': 'Delete',
        '5': 'Force Shutdown',
        '6': 'Attach Disk',
        '7': 'Baadal Shutdown',
        '8': 'Clone VM',
        '9': 'Edit VM Configuration',
        '10': 'VNC Access',
        '11': 'Sanity Check',
        '12': 'VM Snapshot',
        '13': 'Launch VM',
        '14': 'Wake On LAN',
        '15': 'Check Host Load Capacity'
    }
    if form.process().accepted:
        testcase_list = []
        test_case_list = []
        j = 0
        for i in range(1, 18):
            logger.debug(i)
            test_case_no = request.vars['testcases' + str(i)]
            logger.debug("test case no  : " + str(test_case_no))
            if test_case_no == None:
                continue

            else:
                testcase_list.insert(j, i)
                test_case_list.append(test_list[str(i)])
            j += 1
        logger.debug("test case list : " + str(testcase_list))
        task_event_id = db.task_queue.insert(ip_addr=ip_address,
                                             task_type='System Testing',
                                             requester_type=testcase_list,
                                             email_id=email_id,
                                             user_name=user_name)
        db.commit()
        task_type = 'System Testing'
        schedule_task(task_type, task_event_id, email_id, user_name,
                      server_name, test_case_list)

    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
Beispiel #28
0
def check_sanity():
    vmcheck = []
    vm_list = []
    hosts = db(db.host.status == HOST_STATUS_UP).select()
    for host in hosts:
        try:
            #Establish a read only remote connection to libvirtd
            #find out all domains running and not running
            #Since it might result in an error add an exception handler
            conn = libvirt.openReadOnly('qemu+ssh://root@' + host.host_ip +
                                        '/system')
            domains = []
            ids = conn.listDomainsID()
            for _id in ids:
                domains.append(conn.lookupByID(_id))
            names = conn.listDefinedDomains()
            for name in names:
                domains.append(conn.lookupByName(name))
            for dom in domains:
                try:
                    name = dom.name()
                    vm = db(db.vm_data.vm_name == name).select().first()
                    vm_state = dom.info()[0]
                    status = vminfo_to_state(vm_state)
                    if (vm):
                        if (vm.host_id != host.id):
                            vmcheck.append({
                                'host':
                                host.host_name,
                                'host_id':
                                host.id,
                                'vmname':
                                vm.vm_name,
                                'status':
                                status,
                                'message':
                                'Moved from ' + vm.host_id.host_name + ' to ' +
                                host.host_name,
                                'operation':
                                'None'
                            })  #Bad VMs
                            #If VM has been migrated to another host; Host information updated
                            db(db.vm_data.vm_name == name).update(
                                host_id=host.id)
                        else:
                            vmcheck.append({
                                'host':
                                host.host_name,
                                'host_id':
                                host.id,
                                'vmname':
                                vm.vm_name,
                                'status':
                                status,
                                'message':
                                'VM is on expected host ' +
                                vm.host_id.host_name,
                                'operation':
                                'None'
                            })  #Good VMs
                        if vm_state_map[vm_state] != vm.status:
                            #If not in sync with actual state of VM; status of VM updated in DB
                            db(db.vm_data.vm_name == name).update(
                                status=vm_state_map[vm_state])

                        vm_list.append(vm.vm_name)

                    else:
                        vmcheck.append({
                            'host': host.host_name,
                            'host_id': host.id,
                            'vmname': dom.name(),
                            'status': status,
                            'message': 'Orphan, VM is not in database',
                            'operation': 'Orphan'
                        })  #Orphan VMs

                except Exception as e:
                    logger.error(e)
                    if (vm):
                        vmcheck.append({
                            'vmname': vm.vm_name,
                            'host': 'Unknown',
                            'host_id': '0',
                            'status': 'Unknown',
                            'message': 'Some Error Occurred',
                            'operation': 'Error'
                        })

            domains = []
            names = []
            conn.close()
        except:
            pass
        db.commit()
        db_vms = db(
            db.vm_data.status.belongs(VM_STATUS_RUNNING, VM_STATUS_SUSPENDED,
                                      VM_STATUS_SHUTDOWN)).select()

        for db_vm in db_vms:
            if (db_vm.vm_name not in vm_list):
                vmcheck.append({
                    'vmname': db_vm.vm_name,
                    'host': db_vm.host_id.host_name,
                    'host_id': db_vm.host_id,
                    'status': 'Undefined',
                    'message': 'VM not found',
                    'operation': 'Undefined'
                })

    return vmcheck
Beispiel #29
0
###################################################################################

import os
from helper import get_context_path

def get_startup_data():
    from xml.dom import minidom

    xmldoc = minidom.parse(os.path.join(get_context_path(), 'static/startup_data.xml'))
    return xmldoc


if not db(db.constants).count():
    xmldoc = get_startup_data()
    itemlist = xmldoc.getElementsByTagName('table')
    
    for item in itemlist:
        
        tableref = db.get(item.attributes['name'].value)
        if tableref:
            rows = item.getElementsByTagName('row')
            attrib_dict = {}
            for row in rows:
                idx = False
                for attr in row.attributes.keys():
                    attrib_dict[attr] = row.attributes[attr].value
                    if attr == 'id': idx = True
                tableref.insert(**tableref._filter_fields(attrib_dict, id=idx))
    
            db.commit()
Beispiel #30
0
def integration_testing(): 
    print "inside integration testing"
    import commands
    print request.vars
    email_id=request.vars['email_id']
    user_name=request.vars['user_name']
    name=request.vars['name']
    server_name=request.vars['server_name']
    print "server name is " + str(server_name)
    if name == None :
       print "inside name checking "
       ip_address=request.vars['ip_addr'] 
    else :
       print "else part of name checking"
       ip_address=name         
    print "ip address of the testing system is : "
    print ip_address
    form = FORM(  TABLE
                  
                  (    TR(INPUT(_name='testcase114', _type='checkbox', _value="114"),'All'),
			TR(INPUT(_name='testcase49', _type='checkbox', _value="49"),'Maintain Idompotency'),
                       TR(INPUT(_name='testcase50', _type='checkbox', _value="50"),'VM Graph(Memory)'),
                       TR(INPUT(_name='testcase51', _type='checkbox', _value="51"),'VM Graph(CPU)'),
                       TR(INPUT(_name='testcase52', _type='checkbox', _value="52"),'VM Graph(Network)'),
                       TR(INPUT(_name='testcase53', _type='checkbox', _value="53"),'VM Graph(Disk)'),
                       #TR(INPUT(_name='testcase54', _type='checkbox', _value="54"),'VM Performance   (Shutdown )'),
                       #TR(INPUT(_name='testcase56', _type='checkbox', _value="56"),'User Request VM(Approved by Faculty,org-admin,admin)'),
                       #TR(INPUT(_name='testcase57', _type='checkbox', _value="57"),'User Request VM(Approved by Faculty and Rejected by org-admin)'),
                      # TR(INPUT(_name='testcase58', _type='checkbox', _value="58"),'User Request VM(Approved by Faculty,org-admin and Rejected by admin)'),
                      # TR(INPUT(_name='testcase59', _type='checkbox', _value="59"),'User Request VM(Rejected by Faculty )'),
                       TR(INPUT(_name='testcase54', _type='checkbox', _value="54"),'Performance Testing(1CPU,80GB HDD,256MB RAM)'),
			TR(INPUT(_name='testcase55', _type='checkbox', _value="55"),'Performance Testing(1CPU,80GB HDD,512MB RAM)'),
			TR(INPUT(_name='testcase56', _type='checkbox', _value="56"),'Performance Testing(1CPU,80GB HDD,1GB RAM)'),
			TR(INPUT(_name='testcase57', _type='checkbox', _value="57"),'Performance Testing(1CPU,80GB HDD,2GB RAM)'),
			TR(INPUT(_name='testcase58', _type='checkbox', _value="58"),'Performance Testing(2CPU,80GB HDD,2GB RAM)'),
			TR(INPUT(_name='testcase59', _type='checkbox', _value="59"),'Performance Testing(2CPU,80GB HDD,4GB RAM)'),
			TR(INPUT(_name='testcase60', _type='checkbox', _value="60"),'Performance Testing(4CPU,80GB HDD,4GB RAM)'),
			TR(INPUT(_name='testcase61', _type='checkbox', _value="61"),'Performance Testing(4CPU,80GB HDD,8GB RAM)'),
			TR(INPUT(_name='testcase62', _type='checkbox', _value="62"),'Performance Testing(8CPU,80GB HDD,8GB RAM)'),
			TR(INPUT(_name='testcase63', _type='checkbox', _value="63"),'Performance Testing(8CPU,80GB HDD,16GB RAM)'),
#                             
                  #     TR(INPUT(_name='testcase60', _type='checkbox', _value="60"),'Take VM snapshot    (Running )'),
                   #    TR(INPUT(_name='testcase61', _type='checkbox', _value="61"),'Pause VM   (Running )'),
                    #   TR(INPUT(_name='testcase62', _type='checkbox', _value="62"),'Add User to VM   (Running )'),
                     #  TR(INPUT(_name='testcase65', _type='checkbox', _value="65"),'Delete VM    (Running)'),
                      # TR(INPUT(_name='testcase64', _type='checkbox', _value="64"),'Gracefully shut down VM    (Running )'),
                      # TR(INPUT(_name='testcase63', _type='checkbox', _value="63"),'Forcefully power off VM   (Running )'),
                      # TR(INPUT(_name='testcase66', _type='checkbox', _value="66") ,'Migrate VM   (Running )'),
                       #TR(INPUT(_name='testcase67', _type='checkbox', _value="67"),'Take VM snapshot   (Paused )'),
                       #TR(INPUT(_name='testcase68', _type='checkbox', _value="68"),'Unpause VM   (Paused )'),
                       #TR(INPUT(_name='testcase69', _type='checkbox', _value="69"),'Add User to VM  (Paused )'),
                       #TR(INPUT(_name='testcase75', _type='checkbox', _value="75"),'Delete VM   (Paused )'),
                       #TR(INPUT(_name='testcase71', _type='checkbox', _value="71"),'Forcefully power off VM   (Paused)'),
                       #TR(INPUT(_name='testcase70', _type='checkbox', _value="70"),'Migrate VM   (Paused )'),
                       #TR(INPUT(_name='testcase72', _type='checkbox', _value="72"),'Delete Add User  (Paused )'),
                       #TR(INPUT(_name='testcase73', _type='checkbox', _value="73"),'Revert Snapshot  (Paused )'),
                      # TR(INPUT(_name='testcase74', _type='checkbox', _value="74"),'Delete snapshot   (Paused )'),
                      # TR(INPUT(_name='testcase76', _type='checkbox', _value="76"),'Turn on VM   (Shutdown )'),
                      # TR(INPUT(_name='testcase77', _type='checkbox', _value="77"),'Add User to VM  (Shutdown)'),
                       #TR(INPUT(_name='testcase80', _type='checkbox', _value="80"),'Delete VM   (Shutdown )'),
                      # TR(INPUT(_name='testcase78', _type='checkbox', _value="78"),'Take VM snapshot   (Shutdown )'),
                       #TR(INPUT(_name='testcase79', _type='checkbox', _value="79"),'Migrate VM   (Shutdown )'),
                       #TR(INPUT(_name='testcase107', _type='checkbox', _value="107"),'User Request Attach Disk(Approved by Faculty,org-admin,admin)'),
                       # TR(INPUT(_name='testcase71', _type='checkbox', _value="71"), 'Org-Admin Request VM(Rejected by admin)'),
                       #TR(INPUT(_name='testcase109', _type='checkbox', _value="109"),'User Request Attach Disk(Approved by Faculty and Rejected by org-admin)'),
                      #TR(INPUT(_name='testcase108', _type='checkbox', _value="108"),'User Request Attach Disk(Approved by Faculty,org-admin and Rejected by admin)'),
                      # TR(INPUT(_name='testcase110', _type='checkbox', _value="110"),'User Request Attach Disk(Rejected by Faculty )'),            
                     # TR(INPUT(_name='testcase105', _type='checkbox', _value="105"),'Org-Admin  Attach Disk(Approved by admin)'),
                   # TR(INPUT(_name='testcase106', _type='checkbox', _value="106"), 'Org-Admin Attach Disk(Rejected by admin)'),                    
                     
                   # TR(INPUT(_name='testcase102', _type='checkbox', _value="102"),'User Request Clone VM(Approved by Faculty and Rejected by org-admin)'),
                   #   TR(INPUT(_name='testcase112', _type='checkbox', _value="112"),'User Request Clone VM(Rejected by Faculty )'),
                   
                  #   TR(INPUT(_name='testcase118', _type='checkbox', _value="118"),'User Request Clone VM(Approved by Faculty,org-admin,admin)'),
                #   TR(INPUT(_name='testcase119', _type='checkbox', _value="119"),'User Request Clone VM(Approved by Faculty and Rejected by org-admin)'),
                 #     TR(INPUT(_name='testcase120', _type='checkbox', _value="120"),'User Request Clone VM(Approved by Faculty,org-admin and Rejected by admin)'),
                  #    TR(INPUT(_name='testcase121', _type='checkbox', _value="121"),'User Request Edit VM Config(Rejected by Faculty )'),
                   
                      BR(),
                      TR(INPUT(_type='submit',_value='submit'))
            )
     ) 
    test_list={'114':'All','49':'Maintain Idompotency','50':'VM Graph(Memory)','51':'VM Graph(CPU)','52':'VM Graph(Network)','53':'VM Graph(Disk)','54':'Performance Testing(1CPU,80GB HDD,256MB RAM)','55':'Performance Testing(1CPU,80GB HDD,512MB RAM)','56':'Performance Testing(1CPU,80GB HDD,1GB RAM)','57':'Performance Testing(1CPU,80GB HDD,2GB RAM)','58':'Performance Testing(2CPU,80GB HDD,2GB RAM)','59':'Performance Testing(2CPU,80GB HDD,4GB RAM)','60':'Performance Testing(4CPU,80GB HDD,4GB RAM)','61':'Performance Testing(4CPU,80GB HDD,8GB RAM)','62':'Performance Testing(8CPU,80GB HDD,8GB RAM)','63':'Performance Testing(8CPU,80GB HDD,16GB RAM)'}  
    if form.process().accepted:
        testcase_list=[]
        test_case_list=[]
        j=0
        for i in range(49,116):
            print "inside for loop"
            test_case_no=request.vars['testcase'+str(i)]
            logger.debug("i is : " + str(i))
            logger.debug("j is : " + str(j))
            logger.debug("test case no : " + str(test_case_no))
	    if test_case_no == None :
                continue            
            else:
                testcase_list.insert(j,i)
                test_case_list.append(test_list[str(i)])
            j+=1
        logger.debug("test cases are : " + str(testcase_list))
        task_event_id=db.task_queue.insert(ip_addr=ip_address,task_type='Integration Testing',requester_type=testcase_list,email_id=email_id,user_name=user_name)
        db.commit()
        task_type='Integration Testing'  
        schedule_task(task_type,task_event_id,email_id,user_name,server_name,test_case_list)
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
Beispiel #31
0
def unit_testing():
    print "inside unit testing"
    import commands
    print request.vars
    email_id=request.vars['email_id']
    user_name=request.vars['user_name']
    name=request.vars['name']
    server_name=request.vars['server_name']
    print "server name is " + str(server_name)
    if name == None :
       print "inside name checking "
       ip_address=request.vars['ip_addr'] 
    else :
       print "else part of name checking"
       ip_address=name         
    print "ip address of the testing system is : "
    print ip_address
    form = FORM(  TABLE
        (  TR(INPUT(_name='testcase54', _type='checkbox', _value="54"),'All'),
           TR(INPUT(_name='testcase1', _type='checkbox', _value="1"),'Login'),
           TR(INPUT(_name='testcase2', _type='checkbox', _value="2"),'Configure System: Add Host'),
           TR(INPUT(_name='testcase3', _type='checkbox', _value="3"),'Configure System: Add Template'),
           TR(INPUT(_name='testcase4', _type='checkbox', _value="4"),'Configure System: Add Datastore'),
           TR(INPUT(_name='testcase6', _type='checkbox', _value="6"),'Request VM'), 
           TR(INPUT(_name='testcase23', _type='checkbox', _value="23"),'Take VM snapshot(Running )'),    
           BR(),
           TR(INPUT(_type='submit',_value='submit'))
          )
        )
           #TR(INPUT(_name='testcases5', _type='checkbox', _value="5"),'Configure System:Add Security Domain'),  
           #TR(INPUT(_name='testcase23', _type='checkbox', _value="23"),'Take VM snapshot(Running )'),
           #TR(INPUT(_name='testcase24', _type='checkbox', _value="24"),'Pause VM(Running )'),
           #TR(INPUT(_name='testcase25', _type='checkbox', _value="25"),'Add User to VM   (Running )'),
           #TR(INPUT(_name='testcase26', _type='checkbox', _value="26"),'Gracefully shut down VM    (Running )'),
           #TR(INPUT(_name='testcase27', _type='checkbox', _value="27"),'Forcefully power off VM   (Running )'),
           #TR(INPUT(_name='testcase28', _type='checkbox', _value="28"),'Migrate VM(Running)'),
           #TR(INPUT(_name='testcase29', _type='checkbox', _value="29"),'Delete VM    (Running)'),
           #TR(INPUT(_name='testcase30', _type='checkbox', _value="30"),'Take VM snapshot   (Paused )'),
           #TR(INPUT(_name='testcase32', _type='checkbox', _value="31"),'Migrate VM(Paused)'),
           #TR(INPUT(_name='testcase32', _type='checkbox', _value="32"),'Unpause VM   (Paused )'),
          # TR(INPUT(_name='testcase33', _type='checkbox', _value="33"),'Add User to VM  (Paused )'),
          # TR(INPUT(_name='testcase34', _type='checkbox', _value="34"),'Delete Addtional User   (Paused )'),
           #TR(INPUT(_name='testcase35', _type='checkbox', _value="35"),'Forcefully power off VM   (Paused)'),
          # TR(INPUT(_name='testcase36', _type='checkbox', _value="36"),'Delete Snapshot    (Paused )'),
           #TR(INPUT(_name='testcase37', _type='checkbox', _value="37"),'Revert Snapshot    (Paused )'),
           #TR(INPUT(_name='testcase38', _type='checkbox', _value="38"),'Delete VM   (Paused )'),
          # TR(INPUT(_name='testcase39', _type='checkbox', _value="39"),'Turn on VM   (Shutdown )'),
           #TR(INPUT(_name='testcase40', _type='checkbox', _value="40"),'Add User to VM  (Shutdown)'),
          # TR(INPUT(_name='testcase41', _type='checkbox', _value="41"),'Migrate VM(Shutdown)'),
          # TR(INPUT(_name='testcase42', _type='checkbox', _value="42"),'Take VM snapshot   (Shutdown )'),
           #TR(INPUT(_name='testcase43', _type='checkbox', _value="43"),'Delete VM   (Shutdown )'),
           #TR(INPUT(_name='testcase44', _type='checkbox', _value="44"),'Sanity Table'),
          # TR(INPUT(_name='testcase45', _type='checkbox', _value="45"),'Pending User VM Requests(Install VM)'),
          # TR(INPUT(_name='testcase46', _type='checkbox', _value="46"),'Pending User VM Requests(Clone VM)'),
          # TR(INPUT(_name='testcase47', _type='checkbox', _value="47"),'Pending User VM Requests(Attach Disk)'),
           
           
     
    test_list={'54':'All','1':'Login','2':'Configure System: Add Host','3':'Configure System: Add Template','4':'Configure System: Add Datastore','5':'Configure System:Add Security Domain','6':'Request VM','23':'Take VM snapshot(Running )','24':'Pause VM(Running )','25':'Add User to VM   (Running )','26':'Gracefully shut down VM(Running )','4':'Configure System: Add Datastore','5':'Configure System:Add Security Domain','6':'Request VM'}   
    if form.process().accepted:
        testcase_list=[]
        test_case_list=[]
        j=0
        for i in range(1,95):
            test_case_no=request.vars['testcase'+str(i)]
            logger.debug(type(test_case_no))
            logger.debug("test case no is : " + str(test_case_no))            
            if test_case_no == None or test_case_no == "" :
                continue              
            else:
                testcase_list.insert(j,i)
                test_case_list.append(test_list[str(i)])
            j+=1
        logger.debug(testcase_list)
        task_event_id = db.task_queue.insert(ip_addr=ip_address,task_type ='Unit Testing',requester_type=testcase_list,email_id=email_id,user_name=user_name)
        db.commit()
        task_type='Unit Testing' 
        print task_event_id 
        schedule_task(task_type,task_event_id,email_id,user_name,server_name,test_case_list)     
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
Beispiel #32
0
###################################################################################

import os
from helper import get_context_path

def get_startup_data():
    from xml.dom import minidom

    xmldoc = minidom.parse(os.path.join(get_context_path(), 'private/startup_data.xml'))
    return xmldoc


if not db(db.constants).count():
    xmldoc = get_startup_data()
    itemlist = xmldoc.getElementsByTagName('table')
    
    for item in itemlist:
        
        tableref = db.get(item.attributes['name'].value)
        if tableref:
            rows = item.getElementsByTagName('row')
            attrib_dict = {}
            for row in rows:
                idx = False
                for attr in row.attributes.keys():
                    attrib_dict[attr] = row.attributes[attr].value
                    if attr == 'id': idx = True
                tableref.insert(**tableref._filter_fields(attrib_dict, id=idx))
    
            db.commit()
Beispiel #33
0
def process_clone_task(task_event_id, vm_id):
    """
    Invoked when scheduler runs task of type 'clone_task'
    When multiple clones of a VM is requested, multiple tasks are created in scheduler,
    so that they can run concurrently. 
    This function ensures that the status of clone request is updated on the basis of all 
    corresponding asynchronous tasks """

    vm_data = db.vm_data[vm_id]
    logger.debug("ENTERING CLONE_TASK.......")
    logger.debug("Task Id: %s" % task_event_id)
    logger.debug("VM to be Cloned: %s" % vm_data.vm_name)
    task_event = db.task_queue_event[task_event_id]
    task_queue = db.task_queue[task_event.task_id]
    message = task_event.message if task_event.message != None else ''
    try:
        # Update attention time for first clone task
        if task_event.attention_time == None:
            task_event.update_record(attention_time=get_datetime())
        logger.debug("Starting VM Cloning...")
        ret = task[VM_TASK_CLONE](vm_id)
        logger.debug("Completed VM Cloning...")

        if ret[0] == TASK_QUEUE_STATUS_FAILED:
            logger.debug("VM Cloning Failed")
            logger.debug("Failure Message: %s" % ret[1])
            message = message + '\n' + vm_data.vm_name + ': ' + ret[1]
            vm_data.update_record(status = VM_STATUS_UNKNOWN)
        elif ret[0] == TASK_QUEUE_STATUS_SUCCESS:
            logger.debug("VM Cloning Successful")
            params = task_queue.parameters
            # Delete successful vms from list. So, that in case of retry, only failed requests are retried.
            params['clone_vm_id'].remove(vm_id)
            task_queue.update_record(parameters=params)
        
        clone_vm_list = task_event.parameters['clone_vm_id']
        # Remove VM id from the list. This is to check if all the clones for the task are processed.
        clone_vm_list.remove(vm_id)
        
        # Find the status of all clone tasks combined
        current_status = ret[0]
        if task_event.status != TASK_QUEUE_STATUS_PENDING and task_event.status != current_status:
            current_status = TASK_QUEUE_STATUS_PARTIAL_SUCCESS
        
        if not clone_vm_list: #All Clones are processed
            if current_status == TASK_QUEUE_STATUS_SUCCESS:
                del db.request_queue[task_queue.parameters['request_id']]
                del db.task_queue[task_queue.id]
            else:
                if 'request_id' in task_queue.parameters:
                    db.request_queue[task_queue.parameters['request_id']] = dict(status = REQ_STATUS_FAILED)
                task_queue.update_record(status=current_status)
            task_event.update_record(status=current_status, message=message, end_time=get_datetime())
        else:
            task_event.update_record(parameters={'clone_vm_id' : clone_vm_list}, status=current_status, message=message)

    except:
        msg = log_exception()
        vm_data = db.vm_data[vm_id]
        message = message + '\n' + vm_data.vm_name + ': ' + msg
        task_event.update_record(status=TASK_QUEUE_STATUS_FAILED, message=message)

    finally:
        db.commit()
        logger.debug("EXITING CLONE_TASK........")
def check_cont_sanity():

    cont_check= []
    cont_list = []
    
    nodes = get_node_to_deploy()
    containers = list_container( showall=True);

    for node in nodes:
        ip_port = node['IP'].split(":")
        node_data = db(db.node_data.node_ip == str(ip_port[0])).select().first()
        if not node_data:
            db.node_data.insert(
                  node_name = node['Name'],
                  node_ip = ip_port[0],
                  node_port = ip_port[1],
                  CPUs = node['Reserved CPUs'],
                  memory = node['Reserved Memory'],
                  version = node['ServerVersion'])
            
    try:
        for container in containers:
            names = container['Names'][0].split("/")
            cont_data = db(db.container_data.name == names[2]).select().first()
            cont_list.append(names[2])
            if cont_data:
                updated = False
                if cont_data.status != cont_state_to_status(container['State']):
                    cont_data.update_record(status = cont_state_to_status(container['State']))
                    updated = True
                node_name = cont_data.current_node.node_name if cont_data.current_node else None
                if names[1] != node_name:
                    new_node = db(db.node_data.node_name == names[1]).select().first()
                    cont_data.update_record(current_node=new_node.id)
                    
                message = 'Information updated' if updated else 'As expected'
                cont_check.append({'cont_id':cont_data.id,
                                   'cont_uuid':container['Id'],
                                   'node_name': names[1], 
                                   'cont_name':names[2],
                                   'status':container['State'],
                                   'message':message, 
                                   'operation':'None'})
                
            else:
                cont_check.append({'cont_id':None,
                                   'cont_uuid':container['Id'],
                                   'node_name': names[1], 
                                   'cont_name':names[2],
                                   'status':container['State'],
                                   'message':'Orphan, Container is not in database', 
                                   'operation':'Orphan'})#Orphan Containers

    except:
        log_exception()
        pass

    db(~db.user_container_map.cont_id.belongs(db().select(db.container_data.id))).delete()
    db.commit()
    
    db_conts=db(db.container_data.status.belongs(VM_STATUS_RUNNING, VM_STATUS_SUSPENDED, VM_STATUS_SHUTDOWN)).select()
    for db_cont in db_conts:
        if(db_cont.name not in cont_list):
            cont_check.append({'cont_id'  : db_cont.id,
                               'cont_uuid': None,
                               'node_name': "-", 
                               'cont_name': db_cont.name,
                               'status'   : "-",
                               'message'  :'Container not present', 
                               'operation':'Undefined'})#Orphan Containers
            
    return cont_check
def check_cont_sanity():

    cont_check = []
    cont_list = []

    from container_create import get_node_to_deploy, list_container
    nodes = get_node_to_deploy()
    containers = list_container(showall=True)

    for node in nodes:
        ip_port = node['IP'].split(":")
        node_data = db(
            db.node_data.node_ip == str(ip_port[0])).select().first()
        if not node_data:
            db.node_data.insert(node_name=node['Name'],
                                node_ip=ip_port[0],
                                node_port=ip_port[1],
                                CPUs=node['Reserved CPUs'],
                                memory=node['Reserved Memory'],
                                version=node['ServerVersion'])

    try:
        for container in containers:
            names = container['Names'][0].split("/")
            cont_data = db(db.container_data.name == names[2]).select().first()
            cont_list.append(names[2])
            if cont_data:
                updated = False
                if cont_data.status != cont_state_to_status(
                        container['State']):
                    cont_data.update_record(
                        status=cont_state_to_status(container['State']))
                    updated = True
                node_name = cont_data.current_node.node_name if cont_data.current_node else None
                if names[1] != node_name:
                    new_node = db(
                        db.node_data.node_name == names[1]).select().first()
                    cont_data.update_record(current_node=new_node.id)

                message = 'Information updated' if updated else 'As expected'
                cont_check.append({
                    'cont_id': cont_data.id,
                    'cont_uuid': container['Id'],
                    'node_name': names[1],
                    'cont_name': names[2],
                    'status': container['State'],
                    'message': message,
                    'operation': 'None'
                })

            else:
                cont_check.append({
                    'cont_id': None,
                    'cont_uuid': container['Id'],
                    'node_name': names[1],
                    'cont_name': names[2],
                    'status': container['State'],
                    'message': 'Orphan, Container is not in database',
                    'operation': 'Orphan'
                })  #Orphan Containers

    except:
        log_exception()
        pass

    db(~db.user_container_map.cont_id.belongs(db().select(
        db.container_data.id))).delete()
    db.commit()

    db_conts = db(
        db.container_data.status.belongs(VM_STATUS_RUNNING,
                                         VM_STATUS_SUSPENDED,
                                         VM_STATUS_SHUTDOWN)).select()
    for db_cont in db_conts:
        if (db_cont.name not in cont_list):
            cont_check.append({
                'cont_id': db_cont.id,
                'cont_uuid': None,
                'node_name': "-",
                'cont_name': db_cont.name,
                'status': "-",
                'message': 'Container not present',
                'operation': 'Undefined'
            })  #Orphan Containers

    return cont_check
Beispiel #36
0
def check_vm_sanity(host_id=0):
    vmcheck = []
    vm_list = []

    if host_id == 0:
        hosts = db(db.host.status == HOST_STATUS_UP).select()
    else:
        hosts = db(db.host.id == host_id).select()

    for host in hosts:
        try:
            logger.info('Starting sanity check for host %s' % (host.host_name))
            #Get list of the domains(running and not running) on the hypervisor
            domains = get_host_domains(host.host_ip.private_ip)
            for dom in domains:
                try:
                    domain_name = dom.name()
                    vm = db((db.vm_data.vm_identity == domain_name)
                            & (db.vm_data.status.belongs(
                                VM_STATUS_RUNNING, VM_STATUS_SUSPENDED,
                                VM_STATUS_SHUTDOWN))).select().first()

                    vm_state = dom.info()[0]
                    status = vminfo_to_state(vm_state)
                    if (vm):
                        if (vm.host_id != host.id):
                            vmcheck.append({
                                'vm_id':
                                vm.id,
                                'host':
                                host.host_name,
                                'host_id':
                                host.id,
                                'vmname':
                                vm.vm_name,
                                'status':
                                status,
                                'message':
                                'Moved from ' + vm.host_id.host_name + ' to ' +
                                host.host_name,
                                'operation':
                                'None'
                            })  #Bad VMs
                            #If VM has been migrated to another host; Host information updated
                            db(db.vm_data.vm_identity == domain_name).update(
                                host_id=host.id)
                        else:
                            vmcheck.append({
                                'vm_id':
                                vm.id,
                                'host':
                                host.host_name,
                                'host_id':
                                host.id,
                                'vmname':
                                vm.vm_name,
                                'status':
                                status,
                                'message':
                                'VM is on expected host ' +
                                vm.host_id.host_name,
                                'operation':
                                'None'
                            })  #Good VMs
                        if vm_state_map[vm_state] != vm.status:
                            #If not in sync with actual state of VM; status of VM updated in DB
                            db(db.vm_data.vm_identity == domain_name).update(
                                status=vm_state_map[vm_state])

                            #Adding into vm_event_log about the vm details
                            db.vm_event_log.insert(vm_id=vm.id,
                                                   attribute='VM Status',
                                                   requester_id=SYSTEM_USER,
                                                   old_value=get_vm_status(
                                                       vm.status),
                                                   new_value=get_vm_status(
                                                       vm_state_map[vm_state]))

                        vm_list.append(vm.vm_identity)

                    elif vm_state != VIR_DOMAIN_CRASHED:
                        vmcheck.append({
                            'host': host.host_name,
                            'host_id': host.id,
                            'vmname': dom.name(),
                            'status': status,
                            'message': 'Orphan, VM is not in database',
                            'operation': 'Orphan'
                        })  #Orphan VMs

                except Exception:
                    log_exception()
                    if (vm):
                        vmcheck.append({
                            'vmname': vm.vm_name,
                            'host': 'Unknown',
                            'host_id': '0',
                            'status': 'Unknown',
                            'message': 'Some Error Occurred',
                            'operation': 'Error'
                        })

        except:
            pass
        db.commit()

    if host_id == 0:
        db_vms = db(
            db.vm_data.status.belongs(VM_STATUS_RUNNING, VM_STATUS_SUSPENDED,
                                      VM_STATUS_SHUTDOWN)).select()
        for db_vm in db_vms:
            if (db_vm.vm_identity not in vm_list):
                vmcheck.append({
                    'vmname': db_vm.vm_identity,
                    'host': db_vm.host_id.host_name,
                    'host_id': db_vm.host_id,
                    'status': 'Undefined',
                    'message': 'VM not found',
                    'operation': 'Undefined'
                })

    return vmcheck
Beispiel #37
0
def database_dependent_testing():
    print "database_dependent testing"
    import commands
    print request.vars
    email_id=request.vars['email_id']
    user_name=request.vars['user_name']
    name=request.vars['name']
    server_name=request.vars['server_name']
    print "server name is " + str(server_name)
    if name == None :
       print "inside name checking "
       ip_address=request.vars['ip_addr'] 
    else :
       print "else part of name checking"
       ip_address=name         
    print "ip address of the testing system is : "
    print ip_address
    form = FORM(  TABLE
        (  
           TR(INPUT(_name='testcases7', _type='checkbox', _value="7"),'My VMs'),
           TR(INPUT(_name='testcases8', _type='checkbox', _value="8"),'My Pending Tasks'),
           TR(INPUT(_name='testcases9', _type='checkbox', _value="9"),'My Completed Tasks'),
           TR(INPUT(_name='testcases10', _type='checkbox', _value="10"),'My Failed Tasks'),
           TR(INPUT(_name='testcases18', _type='checkbox', _value="18"),'All VMs'),
           TR(INPUT(_name='testcases19', _type='checkbox', _value="19"),'Host and VMs',),
           TR(INPUT(_name='testcases20', _type='checkbox', _value="20"),'Pending Tasks'),
           TR(INPUT(_name='testcases21', _type='checkbox', _value="21"),'Completed Tasks'),
           TR(INPUT(_name='testcases22', _type='checkbox', _value="22"),'Failed Tasks'),
           TR(INPUT(_name='testcases44', _type='checkbox', _value="44"),'Sanity Table'), 
           TR(INPUT(_name='testcases17', _type='checkbox', _value="17"),'List All Org-Level VMs',),
           TR(INPUT(_name='testcases45', _type='checkbox', _value="45"),'Pending User VM Requests(Install VM)'),
           TR(INPUT(_name='testcases46', _type='checkbox', _value="46"),'Pending User VM Requests(Clone VM)'),
           TR(INPUT(_name='testcases47', _type='checkbox', _value="47"),'Pending User VM Requests(Attach Disk)'), 
           TR(INPUT(_name='testcases11', _type='checkbox', _value="11"),'Pending Faculty-Level VM Approvals(Install VM)'),
           TR(INPUT(_name='testcases12', _type='checkbox', _value="12"),'Pending Faculty-Level VM Approvals(Clone VM)'),
           TR(INPUT(_name='testcases13', _type='checkbox', _value="13"),'Pending Faculty-Level VM Approvals(Attach Disk)'), 
           TR(INPUT(_name='testcases14', _type='checkbox', _value="14"),'Pending Org-Level VM Approvals(Install VM)'),
           TR(INPUT(_name='testcases15', _type='checkbox', _value="15"),'Pending Org-Level VM Approvals(Clone VM)'),
           TR(INPUT(_name='testcases16', _type='checkbox', _value="16"),'Pending Org-Level VM Approvals(Attach Disk)'),          
           BR(),
           TR(INPUT(_type='submit',_value='submit'))
          )
      )
    test_list={'7':'My VMs','8':'My Pending Tasks','9':'My Completed Tasks','10':'My Failed Tasks','11':'Pending Faculty-Level VM Approvals(Install VM)','12':'Pending Faculty-Level VM Approvals(Clone VM)','13':'Pending Faculty-Level VM Approvals(Attach Disk)','14':'Pending Org-Level VM Approvals(Install VM)','15':'Pending Org-Level VM Approvals(Clone VM)','16':'Pending Org-Level VM Approvals(Attach Disk)','17':'List All Org-Level VMs','18':'All VMs','19':'Host and VMs','20':'Pending Tasks','21':'Completed Tasks','22':'Failed Tasks','44':'Completed Tasks','22':'Sanity Table','47':'Pending User VM Requests(Attach Disk)','45':'Pending User VM Requests(Install VM)','46':'Pending User VM Requests(Clone VM)'}   
    if form.process().accepted:
        testcase_list=[]
        test_case_list=[]
        j=0
        for i in range(6,49): 
            print i
            test_case_no=request.vars['testcases'+str(i)]    
            print "test case no  : " +str(test_case_no)       
            if test_case_no==None:                
                	continue
            else:
                        testcase_list.insert(j,i)
                        test_case_list.append(test_list[str(i)])
            j+=1
        print "test case list : " + str(testcase_list)
        print test_case_list
        task_event_id = db.task_queue.insert(ip_addr=ip_address,task_type ='Database Dependent Testing',requester_type=testcase_list,email_id=email_id,user_name=user_name)
        db.commit()
        task_type='Database Dependent Testing'  
        schedule_task(task_type,task_event_id,email_id,user_name,server_name,test_case_list) 
   
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
Beispiel #38
0
def check_sanity():
    vmcheck = []
    vm_list = []
    hosts = db(db.host.status == HOST_STATUS_UP).select()
    for host in hosts:
        try:
            # Establish a read only remote connection to libvirtd
            # find out all domains running and not running
            # Since it might result in an error add an exception handler
            conn = libvirt.openReadOnly("qemu+ssh://root@" + host.host_ip + "/system")
            domains = []
            ids = conn.listDomainsID()
            for _id in ids:
                domains.append(conn.lookupByID(_id))
            names = conn.listDefinedDomains()
            for name in names:
                domains.append(conn.lookupByName(name))
            for dom in domains:
                try:
                    name = dom.name()
                    vm = db(db.vm_data.vm_name == name).select().first()
                    vm_state = dom.info()[0]
                    status = vminfo_to_state(vm_state)
                    if vm:
                        if vm.host_id != host.id:
                            vmcheck.append(
                                {
                                    "host": host.host_name,
                                    "host_id": host.id,
                                    "vmname": vm.vm_name,
                                    "status": status,
                                    "message": "Moved from " + vm.host_id.host_name + " to " + host.host_name,
                                    "operation": "None",
                                }
                            )  # Bad VMs
                            # If VM has been migrated to another host; Host information updated
                            db(db.vm_data.vm_name == name).update(host_id=host.id)
                        else:
                            vmcheck.append(
                                {
                                    "host": host.host_name,
                                    "host_id": host.id,
                                    "vmname": vm.vm_name,
                                    "status": status,
                                    "message": "VM is on expected host " + vm.host_id.host_name,
                                    "operation": "None",
                                }
                            )  # Good VMs
                        if vm_state_map[vm_state] != vm.status:
                            # If not in sync with actual state of VM; status of VM updated in DB
                            db(db.vm_data.vm_name == name).update(status=vm_state_map[vm_state])

                        vm_list.append(vm.vm_name)

                    else:
                        vmcheck.append(
                            {
                                "host": host.host_name,
                                "host_id": host.id,
                                "vmname": dom.name(),
                                "status": status,
                                "message": "Orphan, VM is not in database",
                                "operation": "Orphan",
                            }
                        )  # Orphan VMs

                except Exception as e:
                    logger.error(e)
                    if vm:
                        vmcheck.append(
                            {
                                "vmname": vm.vm_name,
                                "host": "Unknown",
                                "host_id": "0",
                                "status": "Unknown",
                                "message": "Some Error Occurred",
                                "operation": "Error",
                            }
                        )

            domains = []
            names = []
            conn.close()
        except:
            pass
        db.commit()
        db_vms = db(db.vm_data.status.belongs(VM_STATUS_RUNNING, VM_STATUS_SUSPENDED, VM_STATUS_SHUTDOWN)).select()

        for db_vm in db_vms:
            if db_vm.vm_name not in vm_list:
                vmcheck.append(
                    {
                        "vmname": db_vm.vm_name,
                        "host": db_vm.host_id.host_name,
                        "host_id": db_vm.host_id,
                        "status": "Undefined",
                        "message": "VM not found",
                        "operation": "Undefined",
                    }
                )

    return vmcheck
Beispiel #39
0
def unit_testing():
    print "inside unit testing"
    import commands
    print request.vars
    email_id = request.vars['email_id']
    user_name = request.vars['user_name']
    name = request.vars['name']
    server_name = request.vars['server_name']
    print "server name is " + str(server_name)
    if name == None:
        print "inside name checking "
        ip_address = request.vars['ip_addr']
    else:
        print "else part of name checking"
        ip_address = name
    print "ip address of the testing system is : "
    print ip_address
    form = FORM(
        TABLE(
            TR(INPUT(_name='testcase54', _type='checkbox', _value="54"),
               'All'),
            TR(INPUT(_name='testcase1', _type='checkbox', _value="1"),
               'Login'),
            TR(INPUT(_name='testcase2', _type='checkbox', _value="2"),
               'Configure System: Add Host'),
            TR(INPUT(_name='testcase3', _type='checkbox', _value="3"),
               'Configure System: Add Template'),
            TR(INPUT(_name='testcase4', _type='checkbox', _value="4"),
               'Configure System: Add Datastore'),
            TR(INPUT(_name='testcase6', _type='checkbox', _value="6"),
               'Request VM'),
            TR(INPUT(_name='testcase23', _type='checkbox', _value="23"),
               'Take VM snapshot(Running )'), BR(),
            TR(INPUT(_type='submit', _value='submit'))))
    #TR(INPUT(_name='testcases5', _type='checkbox', _value="5"),'Configure System:Add Security Domain'),
    #TR(INPUT(_name='testcase23', _type='checkbox', _value="23"),'Take VM snapshot(Running )'),
    #TR(INPUT(_name='testcase24', _type='checkbox', _value="24"),'Pause VM(Running )'),
    #TR(INPUT(_name='testcase25', _type='checkbox', _value="25"),'Add User to VM   (Running )'),
    #TR(INPUT(_name='testcase26', _type='checkbox', _value="26"),'Gracefully shut down VM    (Running )'),
    #TR(INPUT(_name='testcase27', _type='checkbox', _value="27"),'Forcefully power off VM   (Running )'),
    #TR(INPUT(_name='testcase28', _type='checkbox', _value="28"),'Migrate VM(Running)'),
    #TR(INPUT(_name='testcase29', _type='checkbox', _value="29"),'Delete VM    (Running)'),
    #TR(INPUT(_name='testcase30', _type='checkbox', _value="30"),'Take VM snapshot   (Paused )'),
    #TR(INPUT(_name='testcase32', _type='checkbox', _value="31"),'Migrate VM(Paused)'),
    #TR(INPUT(_name='testcase32', _type='checkbox', _value="32"),'Unpause VM   (Paused )'),
    # TR(INPUT(_name='testcase33', _type='checkbox', _value="33"),'Add User to VM  (Paused )'),
    # TR(INPUT(_name='testcase34', _type='checkbox', _value="34"),'Delete Addtional User   (Paused )'),
    #TR(INPUT(_name='testcase35', _type='checkbox', _value="35"),'Forcefully power off VM   (Paused)'),
    # TR(INPUT(_name='testcase36', _type='checkbox', _value="36"),'Delete Snapshot    (Paused )'),
    #TR(INPUT(_name='testcase37', _type='checkbox', _value="37"),'Revert Snapshot    (Paused )'),
    #TR(INPUT(_name='testcase38', _type='checkbox', _value="38"),'Delete VM   (Paused )'),
    # TR(INPUT(_name='testcase39', _type='checkbox', _value="39"),'Turn on VM   (Shutdown )'),
    #TR(INPUT(_name='testcase40', _type='checkbox', _value="40"),'Add User to VM  (Shutdown)'),
    # TR(INPUT(_name='testcase41', _type='checkbox', _value="41"),'Migrate VM(Shutdown)'),
    # TR(INPUT(_name='testcase42', _type='checkbox', _value="42"),'Take VM snapshot   (Shutdown )'),
    #TR(INPUT(_name='testcase43', _type='checkbox', _value="43"),'Delete VM   (Shutdown )'),
    #TR(INPUT(_name='testcase44', _type='checkbox', _value="44"),'Sanity Table'),
    # TR(INPUT(_name='testcase45', _type='checkbox', _value="45"),'Pending User VM Requests(Install VM)'),
    # TR(INPUT(_name='testcase46', _type='checkbox', _value="46"),'Pending User VM Requests(Clone VM)'),
    # TR(INPUT(_name='testcase47', _type='checkbox', _value="47"),'Pending User VM Requests(Attach Disk)'),

    test_list = {
        '54': 'All',
        '1': 'Login',
        '2': 'Configure System: Add Host',
        '3': 'Configure System: Add Template',
        '4': 'Configure System: Add Datastore',
        '5': 'Configure System:Add Security Domain',
        '6': 'Request VM',
        '23': 'Take VM snapshot(Running )',
        '24': 'Pause VM(Running )',
        '25': 'Add User to VM   (Running )',
        '26': 'Gracefully shut down VM(Running )',
        '4': 'Configure System: Add Datastore',
        '5': 'Configure System:Add Security Domain',
        '6': 'Request VM'
    }
    if form.process().accepted:
        testcase_list = []
        test_case_list = []
        j = 0
        for i in range(1, 95):
            test_case_no = request.vars['testcase' + str(i)]
            logger.debug(type(test_case_no))
            logger.debug("test case no is : " + str(test_case_no))
            if test_case_no == None or test_case_no == "":
                continue
            else:
                testcase_list.insert(j, i)
                test_case_list.append(test_list[str(i)])
            j += 1
        logger.debug(testcase_list)
        task_event_id = db.task_queue.insert(ip_addr=ip_address,
                                             task_type='Unit Testing',
                                             requester_type=testcase_list,
                                             email_id=email_id,
                                             user_name=user_name)
        db.commit()
        task_type = 'Unit Testing'
        print task_event_id
        schedule_task(task_type, task_event_id, email_id, user_name,
                      server_name, test_case_list)
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)