示例#1
0
文件: cmd.py 项目: newoo00/version-
    def insert_misson(self,
                      host,
                      action,
                      opt_obj_type,
                      opt_type,
                      param,
                      progress=0,
                      task_exe_stat='working',
                      username='******',
                      display=1):
        query = databases.DBQuery(host)

        mission_id = -1
        if query.get_mission_id_min() is not None:
            if query.get_mission_id_min() <= 0:
                mission_id = query.get_mission_id_min() - 1
        #avoid conflict with web counter

        keys = """(id, action, optobjtype, progress, task_execute_stat, 
        username, display, option_type, created_at, param, user_ip )"""
        #Wrong method, it's OK, all fake.
        create_time = datetime.datetime.now().strftime("%Y%m%d %H:%M:%S.%f")
        user_ip = base_utils.get_local_ip(host)
        values = (mission_id, action, opt_obj_type, progress, task_exe_stat,
                  username, display, opt_type, create_time, param, user_ip)

        query.insert('missions', keys, values)
        return mission_id
示例#2
0
文件: cmd.py 项目: newoo00/version-
    def wait_for_done(self, m_id, host, timeout=60):
        """
        wait action finished,
        m_id: the mission id for action
        host: which host the task is running
        timeout: wait timeout
        """
        query = databases.DBQuery(host)
        while True:
            try:
                msg = LISTENING_QUEUE.get(True, timeout)
                #logging.debug(msg)
            except Queue.Empty:
                raise error.OperationTimeoutException(timeout)
            else:
                if ((msg.has_key('action') or msg.has_key('option_result'))
                        and msg.has_key('id')):

                    if m_id == msg['id'] and 'actionResult' == msg['message']:
                        logging.debug(msg)
                        if 'failed' == query.get_mission_stat(m_id):
                            err_msg = query.get_mission_message(m_id)
                            raise error.TestError("Action Failed: %s" %
                                                  err_msg)

                        if msg.has_key('option_result'):
                            return msg['option_result']

                        return True
                    #Just put it back if mission id is not match, someone must need it
                    else:
                        #Every mission start from code has a negative id
                        if msg['id'] < 0 and msg[
                                'message'] != 'missionProgress':
                            LISTENING_QUEUE.put(msg, timeout=timeout)
示例#3
0
def get_storage_uuid(host, storage):
    qurey = databases.DBQuery(host)
    keyword = "description=\'" + storage + "\'"
    if not qurey.get_storagepath(keyword):
        raise error.CommonError("Storage not found")

    return qurey.get_storageUuid(keyword)
示例#4
0
 def initialize(self, host):
     self.host = vserver.create_vserver(host)
     self.query = databases.DBQuery(host, user="******")
示例#5
0
 def setUp(self):
     self.query = databases.DBQuery('10.10.51.220', 'postgres')
示例#6
0
文件: cmd.py 项目: newoo00/version-
 def get_host_uuid(self, host):
     qurey = databases.DBQuery(host)
     return qurey.get_hostUuid()
示例#7
0
文件: cmd.py 项目: newoo00/version-
 def get_img_path(self, host, storage, name):
     query = databases.DBQuery(host, user="******")
     keyword = "description=\'" + storage + "\'"
     path = os.path.join(query.get_storagepath(keyword), name)
     path = path.replace('\\', '/')
     return path
示例#8
0
文件: cmd.py 项目: newoo00/version-
 def is_name_dupliacted(self, name, host):
     query = databases.DBQuery(host)
     if name in query.query('vms', column='description'):
         return True
     else:
         return False