Exemplo n.º 1
0
    def create_soap_header(self, header_cwmp_id):
        """
        create soap header
        """
        log.debug_info("create_soap_header")

        # create sub element of soap header
        cwmp_id = Element('cwmp:ID', {'SOAP-ENV:mustUnderstand': '1'})
        cwmp_hold_requests = Element('cwmp:HoldRequests',
                                     {'SOAP-ENV:mustUnderstand': '1'})

        # set sub element's text
        # for cwmp:ID,create random num
        int_rand_num = random.randint(CWMP_ID_RANDOM_NUM_START,
                                      CWMP_ID_RANDOM_NUM_END)
        # element cwmp:ID's text need string type
        if header_cwmp_id:
            cwmp_id.text = header_cwmp_id
        else:
            cwmp_id.text = str(int_rand_num)

        # set cwmp:HoldRequests's text as 0 for default.maybe need to change later.
        cwmp_hold_requests.text = str(0)

        # add sub elments to soap_header
        self.soap_header.append(cwmp_id)
        self.soap_header.append(cwmp_hold_requests)

        return CONSTRUCT_SUC
Exemplo n.º 2
0
    def handle_close_wait_rpc_response_control(self,
                                               response_suc_flag=False,
                                               response_message=None):
        """
        关闭等待PRC执行结果控制,根据ACS返回结果进程处理,并将消息发送回RPC请求端
        """
        if not self.rpc_request_node_message:
            return

        #[step-0]
        tmp_request_msg = self.rpc_request_node_message[0]
        tmp_request_client_conn = self.rpc_request_node_message[1]

        #[step-1]
        if (True == response_suc_flag and None != response_message):
            # send rpc response message to client
            ResponseClientHandle.handle_send_response(response_message,
                                                      tmp_request_client_conn)
            log.debug_info("Agent send rpc response suc to client")

        else:
            # send rpc except message to client
            err_info = "ACS server's rpc response message type error"
            log.debug_err(err_info)
            ResponseClientHandle.handle_except(tmp_request_msg,
                                               tmp_request_client_conn,
                                               err_info)
            log.debug_info("Agent send rpc response error to client")

        #[step-2]
        #reset self.rpc_request_node_message value
        self.rpc_request_node_message = None
Exemplo n.º 3
0
    def set_worklist_execute_request_WLServer_check_response(
            self, response_type):
        """
        更新数据到发起工单执行的地方,表示工单执行check响应
        """
        if not (event.EV_WORKLIST_EXECUTE_RQST == self.msg_type):
            return

        if not self.dut_obj_handle:
            err_info = "dut_handle is None."
            log.debug_err(err_info)
            self.handle_request_except(self.msg, self.conn, err_info)
            return

        if not (isinstance(self.dut_obj_handle, DUTqueue.DUTQueue)):
            err_info = "dut_handle instance not DUTQueue object."
            log.debug_err(err_info)
            self.handle_request_except(self.msg, self.conn, err_info)
            return

        #send exec worklist event to WLserver response
        log.debug_info(
            "Set Worklist Server's response client request check suc")
        self.dut_obj_handle.set_worklist_execute_request_WLServer_check_response(
            response_type)
Exemplo n.º 4
0
    def handle_event_worklistserver2agent(self, msg_type, msg_priority_level,
                                          request, msg_key_sender):
        """
        分发从WorklistServer端来的消息,主要分为RPC请求和执行工单消息响应。
        """
        if not (event.KEY_SENDER_WORKLIST == msg_key_sender):
            return False

        msg_group = int(msg_type) & 0xFF00
        if (msg_group == event.EVENT_RPC_GROUP):

            #工单过程中的RPC方法,将它分发到 WLrpc_queue
            self.dispath_event_to_WLrpc(msg_type, request)

        elif (msg_group == event.EVENT_WORKLIST_GROUP):

            #工单执行的消息响应,工单执行结果
            # intercept worklist server response worklist execute data
            if msg_type == event.EV_WORKLIST_EXECUTE_RSP_RQST:

                #防止工单执行线程在服务器返回信息以后,由于处理时间差仍然超时的问题。
                #add by wangjun 20130627
                self.reset_check_WLexec_status_totalcount()
                log.debug_info("Reset check_WLexec_status_totalcount=%d" %
                               self.check_WLexec_status_totalcount)

                #[step-1] response EV_WORKLIST_EXECUTE_RSP_PSP to worklist server
                message = request[0]
                conn = request[1]
                ResponseClientHandle.handle_response_worklistserver_WLexec_response_post(
                    message, conn)

                #[step-2] response EV_WORKLIST_EXECUTE_PSP to acs server
                if not self.WLexec_request_node_message:
                    err_info = "DUTQueue not found running worklist request"
                    log.debug_err(err_info)
                    ResponseWLexecHandle.handle_WLexec_request_except(
                        message, err_info)
                    return True

                # set worklist exec response to ACS
                ResponseWLexecHandle.handle_WLexec_finish_request(
                    self.WLexec_request_node_message[0], message, conn)

                #[step-3]
                #reset self.WLexec_request_node_message value
                self.WLexec_request_node_message = None

            else:
                log.debug_err("DUTQueue not found event type request")
                return False

        else:
            return False

        return True
Exemplo n.º 5
0
    def handle_response_message_type_verify(self, msg_group, response_msg_type,
                                            message):
        """
        """
        # check response message type
        if (msg_group == event.EVENT_RPC_GROUP):

            if not DUTqueue.WAIT_RPC_RESPONSE_POST_FALG:
                if ((self.msg_type + 1) == response_msg_type
                        or (self.msg_type + 2) == response_msg_type):
                    return True

                else:
                    return False

            tmp_obj = message.get(event.KEY_OBJECT)
            strio = StringIO(tmp_obj)
            tmp_msg_key_obj = pickle.load(strio)

            if not (isinstance(tmp_msg_key_obj, event.MsgUserRpcCheck)):
                return False

            tmp_event_request = tmp_msg_key_obj.event_rqst

            #log.debug_info(response_msg_type)
            log.debug_info("request message=%s" %
                           event.get_event_desc(self.msg_type))
            log.debug_info("response message=%s" %
                           event.get_event_desc(tmp_event_request))

            if (response_msg_type == event.EV_RPC_CHECK_RSP):
                if (self.msg_type == tmp_event_request):
                    return True
                else:
                    return False

            elif (response_msg_type == event.EV_RPC_CHECK_FAIL):
                return False

            else:
                return False

        elif (msg_group == event.EVENT_QUERY_GROUP
              or msg_group == event.EVENT_CONFIGURE_GROUP
              or msg_group == event.EVENT_WORKLIST_GROUP):

            if ((self.msg_type + 1) == response_msg_type
                    or (self.msg_type + 2) == response_msg_type):
                return True

            else:
                return False

        return False
Exemplo n.º 6
0
    def send_event(self, queue_type, message, conn):
        """
        处理消息请求,并将消息分发到具体的功能服务器。
        """

        err_info = ("(Request from client %s)DUTQueue send_event message(%s)" %
                    (ResponseClientHandle.get_client_ipaddress(conn),
                     event.get_event_desc(message.get(event.KEY_MESSAGE))))
        log.debug_info(err_info)

        #查询消息队列查询消息节点
        if self.DUT_QUEUE_MODULE_TYPE_QUERY == queue_type:

            msg_type = message.get(event.KEY_MESSAGE)

            if msg_type == event.EV_WORKLIST_DOWNLOAD_RQST:
                RequestClientHandle.send_event_to_WLserver(self, message, conn)

            elif msg_type == event.EV_WORKLIST_EXEC_FINISH_RQST:
                RequestClientHandle.send_event_to_acsserver(
                    self, message, conn, True)

            else:
                RequestClientHandle.send_event_to_acsserver(
                    self, message, conn)

        #请求消息队列消息节点
        elif self.DUT_QUEUE_MODULE_TYPE_REQUEST == queue_type:

            if not WAIT_RPC_RESPONSE_POST_FALG:
                RequestClientHandle.send_event_to_acsserver(
                    self, message, conn, True)

            else:
                msg_group = int(message.get(event.KEY_MESSAGE)) & 0xFF00
                if msg_group == event.EVENT_RPC_GROUP:
                    self.send_event_rpc_methond(message, conn)
                else:
                    RequestClientHandle.send_event_to_acsserver(
                        self, message, conn, True)

        #工单RPC消息队列消息节点
        elif self.DUT_QUEUE_MODULE_TYPE_WL_REQUEST == queue_type:

            if not WAIT_RPC_RESPONSE_POST_FALG:
                RequestClientHandle.send_event_to_acsserver(
                    self, message, conn, True)
            else:
                self.send_event_rpc_methond(message, conn)
        else:
            pass

        return
Exemplo n.º 7
0
    def create_soap_envelope(self,
                             rpc_name,
                             cwmp_version="cwmp-1-0",
                             rpc_args="",
                             cwmp_id=""):
        """
        create soap envelope, and convert the structure to xml
        rpc_name: RPC name need to create
        cwmp_version: CPE supported cwmp version, default is cwmp-1-0
        rpc_args: RPC arguments, default is ""
        """

        log.debug_info("create_soap_envelope")

        try:
            dict_envelope_attrib = {
                'xmlns:SOAP-ENV': 'http://schemas.xmlsoap.org/soap/envelope/',
                'xmlns:SOAP-ENC': 'http://schemas.xmlsoap.org/soap/encoding/',
                'xmlns:xsd': 'http://www.w3.org/2001/XMLSchema',
                'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance'
            }

            dict_envelope_attrib[
                'xmlns:cwmp'] = '' + 'urn:dslforum-org:' + cwmp_version

            # create an element
            self.soap_envelope = Element('SOAP-ENV:Envelope',
                                         dict_envelope_attrib)

            # set root of tree
            self.soap._setroot(self.soap_envelope)

            # create sub elemnts of soap_envelop
            self.soap_header = Element('SOAP-ENV:Header')
            self.soap_body = Element('SOAP-ENV:Body')

            # add soap_header and soap_body to soap_envelope
            self.soap_envelope.append(self.soap_header)
            self.soap_envelope.append(self.soap_body)

            # create sub elements of soap header
            self.create_soap_header(cwmp_id)

            # create sub elements of soap body
            self.create_soap_body(rpc_name, rpc_args)

            # convert structure to xml
            self.str_xml = tostring(self.soap_envelope)

        except Exception, e:

            log.debug_err(e)
            return CONSTRUCT_FAIL, e
Exemplo n.º 8
0
def start_service():
    """
    start service of useragent
    """

    log.debug_info("Start agent service...")

    # start SocketServer to wait for client connection
    try:
        ss_obj = agenthttpserver.start_http_server()

    except Exception, e:
        err_info = "Agent service occurs expection: %s" % e
        log.debug_err(err_info)
Exemplo n.º 9
0
def start_http_server():

    try:
        ip = agentcfg.AGENT_HTTP_SERVER_IP
        port = agentcfg.AGENT_HTTP_SERVER_PORT

        g_webserver = AgentHttpServer(port)

        log.debug_info("Agent (ip=%s, port=%s) start." % (ip, port))
        g_webserver.start()

    except Exception, e:
        err_info = "Agent http service occurs expection: %s" % e
        log.debug_info(err_info)
Exemplo n.º 10
0
 def get_children_value(self, element_object):
     """
     get value of  element_object's children_element recursively,
     return all children_element's [name,value] by list
     """
     tmp_list = []
     children_element_list = element_object.getchildren()
     if len(children_element_list) == 0:
         log.debug_info("element_object have no children")
         return None
     for element in children_element_list:
         sub_children_list = element.getchildren()
         if len(sub_children_list) == 0:
             tmp_list.append([element.tag, element.text, element.attrib])
         else:
             tmp_list.append([element.tag, get_children_value(element)])
     return tmp_list
Exemplo n.º 11
0
    def get_element_attribute(self, element_object, element_name):
        """
        get the attribute of element_name under element_object. if element_name is
        not existed or there are more than one element_name,return none
        """

        element_list = list(element_object.getiterator(tag=element_name))
        if len(element_list) == 1:
            return element_list[0].attrib
        elif len(element_list) > 1:
            log.debug_info("There are more then one", element_name, "under",
                           element_object)
            return None
        else:
            log.debug_info("There is no", element_name, "under",
                           element_object)
            return None
Exemplo n.º 12
0
    def parse_motive_xml_definition(self, xml_file):
        """
        parsed custom define motive xml file. return dict contain xml file's
        parameters' full name(keys) and parameters type(values)
        xml_file: be parsed xml file name
        """

        log.debug_info("parsing ", xml_file)

        dict_results = {}  # save current file parse parameter type results

        # parse xml file, and get the root object
        file_full_path = os.path.join(self.file_path, xml_file)
        root = ElementTree.parse(file_full_path).getroot()

        # get root children object
        list_root_children = root.getchildren()

        # go through all root children elements
        for root_children in list_root_children:

            # find dataModel node
            if root_children.tag == "dataModel":

                # find parameters node
                list_datamodel_children = root_children.getchildren()
                for datamodel_children in list_datamodel_children:
                    if datamodel_children.tag == "parameters":

                        # parse parameters's children node parameter
                        list_parameters_children = datamodel_children.getchildren(
                        )
                        for parameters_children in list_parameters_children:
                            tmp_dict_parameter = self.parse_motive_parameter(
                                parameters_children)
                            # save parsed result to dict_results
                            dict_results.update(tmp_dict_parameter)

                        # ignore the node not parameters
                        break

                # ignore the node not dataModel
                break

        return dict_results
Exemplo n.º 13
0
    def get_xmlschema_obj():
        """
        parse xmlschema xsd files, and return the object to verify xml file's validate
        """
        # get the xsd files path
        path = os.path.dirname(__file__) + '\\schema\\'
        # get all files name
        list_all_file = os.listdir(path)

        for filename in list_all_file:
            try:
                full_path = path + filename
                xmlschema_doc = ElementTree.parse(full_path).getroot()
                xmlschema = ElementTree.XMLSchema(xmlschema_doc)
                Parse.m_xmlschema_list.append(xmlschema)
            except Exception, e:
                err_info = "Parse xml schema files occures error:%s" % e
                log.debug_info(err_info)
Exemplo n.º 14
0
    def set_rpc_request_ACSServer_check_response(self, response_type):

        if not self.dut_obj_handle:
            err_info = "dut_handle is None."
            log.debug_err(err_info)
            self.handle_request_except(self.msg, self.conn, err_info)
            return

        if not (isinstance(self.dut_obj_handle, DUTqueue.DUTQueue)):
            err_info = "dut_handle instance not DUTQueue object."
            log.debug_err(err_info)
            self.handle_request_except(self.msg, self.conn, err_info)
            return

        #send exec worklist event to WLserver response
        log.debug_info("Set ACS Server's response client request check suc")
        self.dut_obj_handle.set_rpc_request_ACSServer_check_response(
            response_type)
Exemplo n.º 15
0
    def intercept_client_worklist_execute_post(self, msg_type, request):
        """
        当接收到client请求执行工单消息,立即回工单check消息给client,后续工单的执行状态,由client自己负责查询
        """
        if msg_type == event.EV_WORKLIST_EXECUTE_RQST:
            log.debug_info("Agent response client exec worklist request event")

            #init data
            message = request[0]
            conn = request[1]
            tmp_WLexec_request_msg = message.copy()

            #response user exec worklist request event
            ResponseClientHandle.handle_response_client_WLexec_request(
                tmp_WLexec_request_msg, conn)

            #clear client connected handle
            request[1] = None

        return
Exemplo n.º 16
0
    def construct_agent_send_message_sequence_property(self):
        """
        更新从Agent发送出去消息的KEY_SEQUENCE属性
        """
        new_message = ResponseClientHandle.switch_msg_stream_type_str2dict(
            self.msg)

        #生成sequence_id
        in_sequence_id = MessageProcessing.construct_sequence_id(
            event.KEY_SENDER_AGENT)

        #更新sequence属性数据
        new_message[event.KEY_SEQUENCE] = in_sequence_id

        log_info = ("HttpClientToWorklistServer construct sequence id: %s" %
                    in_sequence_id)
        log.debug_info(log_info)

        self.msg = ResponseClientHandle.switch_msg_stream_type_dict2str(
            new_message)
Exemplo n.º 17
0
    def dispath_event_to_WLrpc(self, msg_type, request):
        """
        将工单RPC方法加入到WLrpc_queue队列
        """
        # dispatch
        try:
            if not self.WLexec_request_node_message:
                log.debug_err("DUTQueue not found running worklist request.")

            self.reset_check_WLexec_status_totalcount()
            log.debug_info("Reset check_WLexec_status_totalcount=%d" %
                           self.check_WLexec_status_totalcount)

            self.join_WLrpc_event_queue(request)

        except Exception, e:
            err_info = "DUTQueue dispath_event_to_WLrpc function occurs exception:%s" % e
            log.debug_err(err_info)
            message = request[0]
            conn = request[1]
            ResponseClientHandle.handle_except(message, conn, err_info)
Exemplo n.º 18
0
    def dispath_event(self, msg_type, msg_priority_level, request,
                      msg_key_sender):
        """
        分发消息总入口
        """
        log.debug_info(
            "(Request from client %s)DUTQueue dispath event key_sender=%s" %
            (ResponseClientHandle.get_client_ipaddress(
                request[1]), msg_key_sender))
        tmp_intercept_flag = False

        if (event.KEY_SENDER_USER == msg_key_sender
                or event.KEY_SENDER_AGENT == msg_key_sender):

            #处理AGENT自己构建的消息 #add by wangjun 20130717
            if event.KEY_SENDER_AGENT == msg_key_sender:
                msg_key_sender = event.KEY_SENDER_USER

            tmp_intercept_flag = self.handle_event_user2agent(
                msg_type, msg_priority_level, request, msg_key_sender)

        elif (event.KEY_SENDER_ACS == msg_key_sender):
            tmp_intercept_flag = self.handle_event_acsserver2agent(
                msg_type, msg_priority_level, request, msg_key_sender)

        elif (event.KEY_SENDER_WORKLIST == msg_key_sender):
            tmp_intercept_flag = self.handle_event_worklistserver2agent(
                msg_type, msg_priority_level, request, msg_key_sender)

        else:
            log.debug_info(
                "(Request from client %s)DUTQueue dispath event error,unsupport message key_sender"
                % ResponseClientHandle.get_client_ipaddress(request[1]))

        if not tmp_intercept_flag:
            err_info = "DUTQueue dispath event error"
            log.debug_err(err_info)
            message = request[0]
            conn = request[1]
            ResponseClientHandle.handle_except(message, conn, err_info)
Exemplo n.º 19
0
    def get_all_motive_parameters_type(self):
        """
        parse all files in motive directory, and save the parse result 
        in self.dict_parameters_type
        """

        try:

            # get all files name in self.file_path
            list_all_file = os.listdir(self.file_path)

            while list_all_file != []:

                # backup files name list
                tmp_list_all_file = list_all_file[:]

                for i in range(len(tmp_list_all_file)):
                    # ignore directory
                    if os.path.isdir(
                            os.path.join(self.file_path,
                                         tmp_list_all_file[i])):
                        list_all_file.remove(tmp_list_all_file[i])
                        continue

                    # parse each file in tmp_list_all_file
                    res = self.parse_motive_xml_definition(
                        tmp_list_all_file[i])
                    if res == PARSE_UNFINISH:
                        continue
                    else:
                        log.debug_info("parse suc:", tmp_list_all_file[i])
                        # remove the parsed successfully file
                        list_all_file.remove(tmp_list_all_file[i])
                        # update dict_parameters_type
                        self.dict_parameters_type.update(res)

            log.debug_info("parse end")

        except Exception, e:
            log.debug_err(e)
Exemplo n.º 20
0
    def handle_event_user2agent(self, msg_type, msg_priority_level, request,
                                msg_key_sender):
        """
        分发从USER端来的消息
        """
        if not (event.KEY_SENDER_USER == msg_key_sender):
            return False

        #特殊处理EV_RPC_GETRPCMETHODS_RQST方法
        #当有工单正在执行时,将该方法插入到工单RPC队列,等待马上执行
        #当无工单正在执行时,将该方法加入到RPC HIGH队列,优先执行
        if msg_type == event.EV_RPC_GETRPCMETHODS_RQST:

            if self.WLexec_request_node_message:
                log.debug_info(
                    "(Request from client %s)Insert EV_RPC_GETRPCMETHODS_RQST msg to worklist running rpc queue"
                    % ResponseClientHandle.get_client_ipaddress(request[1]))
                #dispath event to WLrpc_queue
                self.dispath_event_to_WLrpc(msg_type, request)
                return True

            else:
                #up request KEY_PRIORITY_LEVEL value
                request[0][event.KEY_PRIORITY_LEVEL] = event.PRIORITY_HIGH
                msg_priority_level = event.PRIORITY_HIGH

        #特殊处理从USER端来的请求执行工单消息
        elif msg_type == event.EV_WORKLIST_EXECUTE_RQST:
            log.debug_info(
                "(Request from client %s)Agent response user exec worklist request event"
                % ResponseClientHandle.get_client_ipaddress(request[1]))
            self.intercept_client_worklist_execute_post(msg_type, request)

        else:
            pass

        #将消息分发到具体的消息队列query_queue or request_queue
        self.dispath_event_to_normal(msg_type, msg_priority_level, request)

        return True
Exemplo n.º 21
0
    def hanale_worklistserver_response(self, message, conn):
        """
        check worklist server response data and call continue event
        """

        #检查消息的完整性
        tmp_msg_is_complete = ResponseClientHandle.check_message_complete(
            message)
        if False == tmp_msg_is_complete:
            log.debug_info(message)
            err_info = "Recv WorkList server's response incomplete"
            log.debug_info(err_info)
            self.handle_request_except(self.msg, self.conn, err_info)
            return

        else:
            response = ResponseClientHandle.switch_msg_stream_type_str2dict(
                message)

            msg_group = int(response.get(event.KEY_MESSAGE)) & 0xFF00
            if (msg_group == event.EVENT_WORKLIST_GROUP):

                #检查返回消息与请求消息的匹配关系
                if not self.handle_response_message_type_verify(
                        response.get(event.KEY_MESSAGE)):
                    err_info = "WorkList server's response message type error"
                    log.debug_info(err_info)
                    self.handle_request_except(self.msg, self.conn, err_info)
                    return

                #当请求消息是执行工单时,特殊处理,
                if (event.EV_WORKLIST_EXECUTE_RQST == self.msg_type):

                    #更新工单等待执行状态,表示发起工单成功
                    self.set_worklist_execute_request_WLServer_check_response(
                        "request_suc")

                else:  #worklist download

                    #其他消息正常处理
                    # send worklist down to user or ACS
                    ResponseClientHandle.handle_send_response(response, conn)

            else:
                err_info = "Unsupport msg event group:%d" % msg_group
                log.debug_info(err_info)
                self.handle_request_except(self.msg, self.conn, err_info)

        return
Exemplo n.º 22
0
    def get_all_parameters_type(self):
        """
        parse all files in self.file_path, and save the parse result 
        in self.dict_parameters_type
        """

        try:
            # parse custom xml file
            self.file_path = os.path.join(os.path.dirname(__file__),
                                          "customdatadef", "motive")
            self.get_all_motive_parameters_type()

            # parse datamodeldef
            self.file_path = os.path.join(os.path.dirname(__file__),
                                          "datamodeldef")

            # first parse "tr-106-1-0-0-types.xml"
            self.parse_data_type()

            # get all files name in self.file_path
            list_all_file = os.listdir(self.file_path)

            # removed the parsed file "tr-106-1-0-0-types.xml"
            list_all_file.remove("tr-106-1-0-0-types.xml")

            count = 0

            while list_all_file != []:
                count += 1
                log.debug_info("count:", str(count))

                # backup files name list
                tmp_list_all_file = list_all_file[:]

                for i in range(len(tmp_list_all_file)):
                    # ignore directory
                    if os.path.isdir(
                            os.path.join(self.file_path,
                                         tmp_list_all_file[i])):
                        list_all_file.remove(tmp_list_all_file[i])
                        continue

                    # parse each file in tmp_list_all_file
                    res = self.parse_tr069_parameters_definition(
                        tmp_list_all_file[i])
                    if res == PARSE_UNFINISH:
                        continue
                    else:
                        log.debug_info("parse suc:", tmp_list_all_file[i])
                        # remove the parsed successfully file
                        list_all_file.remove(tmp_list_all_file[i])
                        # update dict_parameters_type
                        self.dict_parameters_type.update(res)

            log.debug_info("parse motive xml file end")

        except Exception, e:
            log.debug_err(e)
Exemplo n.º 23
0
    def send_http_msg_notry(in_message,
                            in_timeout=300,
                            in_try_count=0,
                            in_url="127.0.0.1",
                            in_method="POST"):
        """
        send http request to WorkList Server Server or Worklist Server, and wait for response, if timeout, return time out,
        if response is not 200 OK, return errorno.
        """
        try:
            conn = httplib2.Http(timeout=in_timeout)
            res, content = conn.request(in_url,
                                        method=in_method,
                                        body=in_message)

        except Exception, e:
            if e.message == "timed out":
                log.debug_info("Wait for HTTP server's response timeout!")
                return ("error", "time out")
            else:
                err_info = "Send HTTP request occurs exception:%s" % e
                log.debug_err(err_info)
                return ("error", err_info)
Exemplo n.º 24
0
    def send_http_msg(in_message,
                      in_timeout=300,
                      in_try_count=0,
                      in_url="127.0.0.1",
                      in_method="POST"):
        """
        send http request to WorkList Server Server or Worklist Server, and wait for response, if timeout, return time out,
        if response is not 200 OK, return errorno.
        """

        tmp_try_count = 0
        if in_try_count >= 0:
            tmp_try_count = in_try_count

        while 1:  #in_try_count>0:

            conn = None

            try:
                conn = httplib2.Http(timeout=in_timeout)
                res, content = conn.request(in_url,
                                            method=in_method,
                                            body=in_message)

            except Exception, e:

                if e.message == "timed out":
                    log.debug_info("Wait for HTTP server's response timeout!")

                    if tmp_try_count > 0:
                        log.debug_info(
                            "Try(try_count=%d) send HTTP request event" %
                            tmp_try_count)
                        tmp_try_count -= 1
                        continue

                    else:
                        return ("error", "time out")
                else:
                    err_info = "Send HTTP request occurs exception:%s" % e
                    log.debug_err(err_info)
                    return ("error", err_info)
            else:

                #交互正常结束,客户端主动断开连接 #add by wangjun 20130726
                if conn:
                    conn.close()
                    log.debug_info(
                        "Close agent created to ACS Server's or WorkList Server's HTTP client connect"
                    )

                status = res.get('status')
                if status == "200":
                    return ("response", content)
                else:
                    return ("fail", status)
Exemplo n.º 25
0
    def parse_data_type(self):
        """
        parse "tr-106-1-0-0-types.xml", get TR-069 Data Model Data Types
        save all defined data type in data_type dict. 
        """

        log.debug_info("parsing tr-106-1-0-0-types.xml")
        # get file full path
        file_full_path = os.path.join(self.file_path, "tr-106-1-0-0-types.xml")

        # parse xml file, and get the root object
        root = ElementTree.parse(file_full_path).getroot()

        # get all "dataType" object iterator
        iter_data_type = root.getiterator(tag="dataType")

        for object in iter_data_type:

            # get attributes of object
            dict_object_attrib = object.attrib

            # get name attribute value
            object_name = dict_object_attrib['name']

            # if dataType have 'base' attribute, get data type from base dataType
            if 'base' in dict_object_attrib:

                object_base_name = dict_object_attrib['base']

                # check 'base' name whether save in self.data_type or not
                if object_base_name in self.data_type:

                    self.data_type[object_name] = self.data_type[
                        object_base_name]
                else:
                    log.debug_info(
                        object_name, "base", object_base_name,
                        "but the base type is not exist, something is wrong!")

            else:

                # get data type from the second child element of dataType,the first is description
                list_object_children = object.getchildren()
                if len(list_object_children) == 2:

                    # dataType have children object difined its data type
                    self.data_type[object_name] = list_object_children[1].tag

                else:
                    log.debug_info(
                        object_name, "dataType struct is error, \
                                   it have more than two children.")
Exemplo n.º 26
0
    def parse_tr069_parameters_definition(self, xml_file):
        """
        parsed tr069 parameters definition xml file. return dict contain xml file's
        parameters' full name(keys) and parameters type(values)
        xml_file: be parsed xml file name
        """

        log.debug_info("parsing ", xml_file)

        dict_results = {}  # save current file parse parameter type results
        dict_components = {}  # save current file parse components results

        # parse xml file, and get the root object
        file_full_path = os.path.join(self.file_path, xml_file)
        root = ElementTree.parse(file_full_path).getroot()

        # get root children object
        list_root_children = root.getchildren()

        # go through all root children elements
        for root_children in list_root_children:

            # get import components, save to dict_components
            if root_children.tag == "import":

                list_import_children = root_children.getchildren()

                if list_import_children != []:

                    import_file_name = root_children.attrib['file']

                    check_flag = 1  # whether need to check imported file parsed or not

                    for import_children in list_import_children:

                        if import_children.tag == "component":

                            if check_flag == 1:
                                check_flag = 0  # just check one times

                                if import_file_name not in self.dict_component:

                                    log.debug_info(
                                        "parse unfinish, need file ",
                                        import_file_name)
                                    return PARSE_UNFINISH

                            component_name = import_children.attrib['name']
                            # component is rename in this file, get component definition from 'ref'
                            if 'ref' in import_children.attrib:
                                ref_name = import_children.attrib['ref']
                                dict_components[component_name] = \
                                    self.dict_component[import_file_name][ref_name]
                            else:
                                dict_components[component_name] = \
                                    self.dict_component[import_file_name][component_name]

            elif root_children.tag == "component":

                component_name = root_children.attrib['name']

                # parse component's object-parameter struct
                dict_tmp_component = self.parse_parameter_struct(root_children)

                # get sub "component" defined in "component"
                list_children_component = root_children.getchildren()
                for children_component in list_children_component:

                    if children_component.tag == "component":
                        ref_name = children_component.attrib['ref']
                        dict_tmp_component.update(dict_components[ref_name])

                # save parsed result to dict_components, use component_name as key
                dict_components[component_name] = dict_tmp_component

            elif root_children.tag == "model":

                # parse model's object-parameter struct
                dict_tmp_model = self.parse_parameter_struct(root_children)
                # save parsed result to dict_results
                dict_results.update(dict_tmp_model)

                # parse model's component struct
                list_model_children = root_children.getchildren()

                for model_children in list_model_children:
                    if model_children.tag == "component":

                        path_name = model_children.attrib['path']
                        ref_name = model_children.attrib['ref']

                        # get ref component dict
                        dict_ref_component = dict_components[ref_name]

                        # add path_name prefix to each key of dict_ref_component
                        for key in dict_ref_component.keys():

                            full_name = path_name + key
                            # add full_name and key corresponding value to dict_results
                            dict_results[full_name] = dict_ref_component[key]

        # save all components of current file
        self.dict_component[xml_file] = dict_components

        return dict_results
Exemplo n.º 27
0
def test():
    get_all_parameters_type()
    list_values = g_object.dict_parameters_type.values()
    set_values = set(list_values)
    res2 = [(value, list_values.count(value)) for value in set_values]
    log.debug_info(res2)
Exemplo n.º 28
0
    def dispath_event_to_normal(self, msg_type, msg_priority_level, request):
        """
        将消息分发到默认的处理队列query_queue或request_queue
        """
        # dispatch
        try:
            msg_group = int(msg_type) & 0xFF00

            if (msg_group == event.EVENT_QUERY_GROUP
                    or msg_group == event.EVENT_CONFIGURE_GROUP):

                self.join_query_event_queue(msg_priority_level, request)

            elif (msg_group == event.EVENT_RPC_GROUP):

                self.join_request_event_queue(msg_priority_level, request)

            elif (msg_group == event.EVENT_WORKLIST_GROUP):

                #特殊处理工单消息,进入agent自己构建的工单执行逻辑模块。reserve->start->execute->finish
                if msg_type == event.EV_WORKLIST_EXECUTE_RQST:

                    #进入工单预约流程
                    log.debug_info(
                        "msg_type == event.EV_WORKLIST_RESERVE_RQST")
                    ResponseWLexecHandle.handle_WLreserve_request(request)

                elif msg_type == event.EV_WORKLIST_EXEC_START_RQST:

                    #进入工单开始流程,这里开始加入RPC队列等待执行。
                    log.debug_info(
                        "msg_type == event.EV_WORKLIST_EXEC_START_RQST")
                    self.join_request_event_queue(msg_priority_level, request)

                else:
                    # /********************************************************
                    #msg_type is:
                    # event.EV_WORKLIST_BUILD_RQST or
                    # event.EV_WORKLIST_BIND_PHISIC_RQST or
                    # event.EV_WORKLIST_BIND_LOGIC_RQST or
                    # event.EV_WORKLIST_RESERVE_RQST or
                    # event.EV_WORKLIST_EXEC_FINISH_RQST
                    # event.EV_WORKLIST_DOWNLOAD_RQST
                    # event.EV_WORKLIST_QUERY_RQST
                    # *********************************************************

                    self.join_query_event_queue(msg_priority_level, request)

            else:
                err_info = "DUTQueue dispath_event_to_normal: user message group(=%d) not support." % msg_group
                log.debug_err(err_info)
                message = request[0]
                conn = request[1]
                ResponseClientHandle.handle_except(message, conn, err_info)

        except Exception, e:
            err_info = "DUTQueue dispath_event_to_normal function occurs exception:%s" % e
            log.debug_err(err_info)
            message = request[0]
            conn = request[1]
            ResponseClientHandle.handle_except(message, conn, err_info)
Exemplo n.º 29
0
                err_info = "The structure of recv message is invalid!"
                log.debug_err(err_info)
                return

        responseclient.g_http_client_count += 1
        log.app_info(
            "acceptConnection: Agent HTTP connected client count: %d" %
            responseclient.g_http_client_count)

        t = threading.Thread(target=root_dispath_evetn, args=(msg, conn))
        t.setDaemon(True)
        t.start()

    except Exception, e:
        err_info = "DUTQueueManagement dispath request event occurs exception:%s" % e
        log.debug_info(err_info)
        ResponseClientHandle.handle_except(msg, conn, err_info)


class AgentHandleRequest(http.Request):
    """
    """
    # 定义了路径映射功能
    dict_page_handlers = {
        agentcfg.AGENT_HTTP_SERVER_PATH: handle_dispath_request,
    }

    def process(self):
        """
        """
        self.setHeader("Content-Type", "text/html")
Exemplo n.º 30
0
    def parse_parameter_struct(self, element):
        """
        parse parameter struct and object-parameter struct, return dict contain
        parameters' full name and parameters type 
        element: the parents element of parameter or object
        """

        dict_results = {}

        # get all children object of element
        list_children_element = element.getchildren()

        for children_element in list_children_element:

            # when children_element is 'parameter'
            if children_element.tag == 'parameter':
                dict_para_attrib = children_element.attrib
                if "name" in dict_para_attrib:
                    parameter_name = dict_para_attrib['name']
                elif "base" in dict_para_attrib:
                    parameter_name = dict_para_attrib['base']
                else:
                    log.debug_info(
                        "This parameter have no name or base, unknown definition!"
                    )

                # get parameter children object
                list_para_children = children_element.getchildren()

                # if parameter have no children, don't need to save it, it have saved in base model
                if list_para_children == []:
                    continue
                else:

                    parameter_type = ""
                    for para_children in list_para_children:

                        # if parameter have 'syntax' element
                        if para_children.tag == 'syntax':
                            # get syntax's children list
                            list_syntax_children = para_children.getchildren()

                            # get parameter's type from syntax children element
                            for syntax_children in list_syntax_children:
                                if syntax_children.tag == "list":
                                    continue
                                elif syntax_children.tag == "default":
                                    continue
                                elif syntax_children.tag == "dataType":
                                    # get dataType's 'ref' attribute value
                                    data_type_ref = syntax_children.attrib[
                                        'ref']
                                    # find parameter_type from self.data_type dict
                                    parameter_type = self.data_type[
                                        data_type_ref]
                                else:
                                    parameter_type = syntax_children.tag

                            # add parameter and its type to dict
                            dict_results[parameter_name] = parameter_type

            elif children_element.tag == 'object':

                # get object name from object attribute 'name' or 'base'
                dict_object_attrib = children_element.attrib
                if "name" in dict_object_attrib:
                    object_name = dict_object_attrib['name']
                elif "base" in dict_object_attrib:
                    object_name = dict_object_attrib['base']
                else:
                    log.debug_info(
                        "The object have no name or base, unknown definition!")

                # get children of 'object'
                list_children_object = children_element.getchildren()

                # if object have no parameter sub element, ignore this object
                if list_children_object == []:
                    continue

                for children_object in list_children_object:
                    # ignore the others sub element,eg: 'uniqueKey', 'description'
                    # just parse 'parameter'
                    if children_object.tag == 'parameter':
                        # get parameter name from parameter attribute 'name' or 'base'
                        dict_para_attrib = children_object.attrib
                        if "name" in dict_para_attrib:
                            parameter_name = dict_para_attrib['name']
                        elif "base" in dict_para_attrib:
                            parameter_name = dict_para_attrib['base']
                        else:
                            log.debug_info(
                                "The parameter have no name or base, unknown definition!"
                            )

                        # get parameter children object
                        list_para_children = children_object.getchildren()

                        # if parameter have no children, don't need to save it, it have saved in base model
                        if list_para_children == []:
                            continue
                        else:
                            # build parameter's full name
                            full_name = object_name + parameter_name
                            parameter_type = ""
                            for para_children in list_para_children:

                                # if parameter have 'syntax' element
                                if para_children.tag == 'syntax':
                                    # get syntax's children list
                                    list_syntax_children = para_children.getchildren(
                                    )

                                    # get parameter's type from syntax children element
                                    for syntax_children in list_syntax_children:
                                        if syntax_children.tag == "list":
                                            continue
                                        elif syntax_children.tag == "default":
                                            continue
                                        elif syntax_children.tag == "dataType":
                                            # get dataType's 'ref' attribute value
                                            data_type_ref = syntax_children.attrib[
                                                'ref']
                                            # find parameter_type from self.data_type dict
                                            parameter_type = self.data_type[
                                                data_type_ref]
                                        else:
                                            parameter_type = syntax_children.tag

                                    # add parameter and its type to dict
                                    dict_results[full_name] = parameter_type
            else:
                pass

        return dict_results