CN113315681B - Automatic testing method and system based on intelligent home gateway plug-in - Google Patents
Automatic testing method and system based on intelligent home gateway plug-in Download PDFInfo
- Publication number
- CN113315681B CN113315681B CN202110593981.5A CN202110593981A CN113315681B CN 113315681 B CN113315681 B CN 113315681B CN 202110593981 A CN202110593981 A CN 202110593981A CN 113315681 B CN113315681 B CN 113315681B
- Authority
- CN
- China
- Prior art keywords
- gateway
- plug
- request
- message body
- server
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Expired - Fee Related
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L43/00—Arrangements for monitoring or testing data switching networks
- H04L43/50—Testing arrangements
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/66—Arrangements for connecting between networks having differing types of switching systems, e.g. gateways
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L43/00—Arrangements for monitoring or testing data switching networks
- H04L43/10—Active monitoring, e.g. heartbeat, ping or trace-route
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Health & Medical Sciences (AREA)
- Cardiology (AREA)
- General Health & Medical Sciences (AREA)
- Computer And Data Communications (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
Description
技术领域technical field
本发明涉及一种网关测试技术,尤其涉及一种基于智能家庭网关插件的自动化测试方法及系统。The invention relates to a gateway testing technology, in particular to an automatic testing method and system based on an intelligent home gateway plug-in.
背景技术Background technique
当前中国移动智能家庭网关产品涉及到的插件模块业务测试比较多,也是重点核心的组成部分。在无环境及工具可测条件下,只能人工通过串口下发指令操作插件测试。At present, China Mobile's smart home gateway products involve many plug-in module business tests, which are also a key core component. Under the condition of no environment and tools to test, the plug-in test can only be operated manually by issuing instructions through the serial port.
该测试方法存在如下弊端:This test method has the following disadvantages:
(1)插件功能业务缺失工具可测性;(1) Tool testability for lack of plug-in function business;
(2)无法验证模拟真实环境场景插件业务安装、升级、缷载、停止、启动、升级、查询等操作测试;(2) Unable to verify operation tests such as plug-in business installation, upgrade, unloading, stop, start, upgrade, query, etc. in simulated real environment scenarios;
(3)产品质量随时出现风险;(3) Product quality risks at any time;
(4)人工通过串口下发指令操作插件测试,缺乏数据报文交互准确性验证。(4) Manually issue instructions through the serial port to operate the plug-in test, lacking verification of the accuracy of data message interaction.
因此,需要开发插件服务端工具提供接口与网关对接进行TCP协议网络通信,进而实现JSON数据传送、数据包解析并自动验证JSON数据包等一套插件自动化测试解决方案。Therefore, it is necessary to develop a plug-in server tool to provide an interface to connect with the gateway for TCP protocol network communication, and then realize a set of plug-in automated testing solutions such as JSON data transmission, data packet analysis, and automatic verification of JSON data packets.
发明内容Contents of the invention
为解决现有技术中的问题,本发明提供一种基于智能家庭网关插件的自动化测试方法及系统。In order to solve the problems in the prior art, the present invention provides an automated testing method and system based on an intelligent home gateway plug-in.
本发明基于智能家庭网关插件的自动化测试方法包括如下步骤:The present invention is based on the automated testing method of intelligent family gateway plug-in and comprises the following steps:
S1:初始化数据;S1: initialize data;
S2:注册认证被测试的网关,认证通过后,与网关建立通信;S2: Register and authenticate the gateway to be tested, and establish communication with the gateway after passing the authentication;
S3:获取操作指令,当所述操作指令为第二指令时,结束与网关通信,测试结束,当所述操作指令为第一指令时,执行下一步;S3: Obtain an operation instruction. When the operation instruction is the second instruction, end the communication with the gateway, and the test ends. When the operation instruction is the first instruction, execute the next step;
S4:根据测试用例数据迭代获取请求方法,直至请求方法获取完毕;S4: Obtain the request method iteratively according to the test case data until the request method is obtained;
S5:构造与请求方法匹配的消息体并发送给网关;S5: Construct a message body matching the request method and send it to the gateway;
S6:接收来自网关发送的响应消息;S6: receiving a response message sent from the gateway;
S7:根据响应消息判断测试结果并存储;S7: judge and store the test result according to the response message;
S8:生成测试报告,测试结束。S8: Generate a test report, and the test ends.
本发明作进一步改进,步骤S1中,所述基于智能家庭网关插件的自动化测试方法在插件服务器上实现,所述插件服务器设有config.ini配置文件,测试开始前,先配置有关数据。The present invention is further improved. In step S1, the automated test method based on the smart home gateway plug-in is implemented on a plug-in server, and the plug-in server is provided with a config.ini configuration file, and relevant data is configured before the test starts.
步骤S2中,注册认证被测试的网关的方法为:In step S2, the method for registering and authenticating the gateway under test is:
S21:网关注册认证启动;S21: gateway registration authentication start;
S22:创建接收线程,循环监听网关,接收网关请求消息;S22: Create a receiving thread, monitor the gateway in a loop, and receive the gateway request message;
S23:判断网关请求消息的类型及网关请求消息内的参数值;S23: judging the type of the gateway request message and the parameter values in the gateway request message;
S24:根据参数值与插件服务器内预设的值是否匹配,构造不同的响应消息体给网关;S24: Construct different response message bodies to the gateway according to whether the parameter value matches the preset value in the plug-in server;
S25:网关根据响应消息体的内容执行相应操作。S25: The gateway performs corresponding operations according to the content of the response message body.
本发明作进一步改进,步骤S22中,插件服务器与智能家庭网关通过socket监听IP和端口进行网络通信,并传送JSON数据,步骤S22中,单独创建接收消息线程,循环监听接收来自网关发来的请求JSON消息体。The present invention is further improved. In step S22, the plug-in server and the smart home gateway monitor the IP and port for network communication through the socket, and transmit JSON data. In step S22, a thread for receiving messages is created separately, and the request sent from the gateway is cyclically monitored. JSON message body.
本发明作进一步改进,步骤S23-25中,首先判断网关认证请求的JSON消息体RPCMethod键值是否为BootInitiation请求方法,如果是,再判断插件服务器平台INI配置文件MAC地址是否与JSON消息体MAC匹配,如果是,则构造认证响应JSON消息体的字段Result返回为0,结束;否则返回为-2,网关只能重启后连接重新进行网关注册认证。The present invention is further improved. In steps S23-25, first judge whether the JSON message body RPCMethod key value of the gateway authentication request is the BootInitiation request method, and if so, then judge whether the MAC address of the plug-in server platform INI configuration file matches the JSON message body MAC , if yes, the field Result of the constructed authentication response JSON message body returns 0, and ends; otherwise, it returns -2, and the gateway can only restart the connection and re-register and authenticate the gateway.
如果网关认证请求的JSON消息体RPCMethod键值不是BootInitiation请求方法,则判断网关认证请求JSON消息体RPCMethod键值是否为Register请求方法,如果是,再校验网关请求的JSON消息体CheckGateway的MD5值与预设的MD5拼接成字符计算得出的md5值匹配一致性,如果一致,则构造认证结果响应JSON消息体的字段Result返回为0,结束;否则返回为-5,网关静默等待设定时间后重新进行认证。If the RPCMethod key value of the JSON message body of the gateway authentication request is not the BootInitiation request method, then judge whether the RPCMethod key value of the JSON message body of the gateway authentication request is the Register request method, and if so, check the MD5 value of the CheckGateway JSON message body requested by the gateway and The preset MD5 is concatenated into characters and the calculated md5 value matches the consistency. If it is consistent, the field Result of the constructed authentication result response JSON message body returns 0, and ends; otherwise, it returns -5, and the gateway silently waits for the set time Re-authenticate.
如果网关认证请求的JSON消息体RPCMethod键值不是BootInitiation请求方法,则判断网关认证请求JSON消息体RPCMethod键值是否为Register请求方法,如果是,再校验网关请求的JSON消息体CheckGateway的MD5值与预设的MD5拼接成字符计算得出的md5值匹配一致性,如果一致,则构造认证结果响应JSON消息体的字段Result返回为0,结束;否则返回为-5,网关静默等待设定时间后重新进行认证。If the RPCMethod key value of the JSON message body of the gateway authentication request is not the BootInitiation request method, then judge whether the RPCMethod key value of the JSON message body of the gateway authentication request is the Register request method, and if so, check the MD5 value of the CheckGateway JSON message body requested by the gateway and The preset MD5 is concatenated into characters and the calculated md5 value matches the consistency. If it is consistent, the field Result of the constructed authentication result response JSON message body returns 0, and ends; otherwise, it returns -5, and the gateway silently waits for the set time Re-authenticate.
如果网关认证请求JSON消息体RPCMethod键值不是Register请求方法,判断网关认证请求JSON消息体RPCMethod键值是否为Hb请求方法,如果是,则构造心跳保活响应JSON消息体的字段Result返回为0,网关保持正常心跳周期,用于网关与插件服务器保持连接,插件服务器向智能家庭网关发起插件管理操作。If the RPCMethod key value of the gateway authentication request JSON message body is not the Register request method, judge whether the RPCMethod key value of the gateway authentication request JSON message body is the Hb request method, and if so, construct the field Result of the heartbeat keep-alive response JSON message body and return 0. The gateway maintains a normal heartbeat cycle, which is used to maintain the connection between the gateway and the plug-in server, and the plug-in server initiates a plug-in management operation to the smart home gateway.
如果认证请求JSON消息体RPCMethod没有找到请求方法,则抛出异常消息提示,认证失败。If the authentication request JSON message body RPCMethod does not find the request method, an exception message will be thrown to indicate that the authentication failed.
本发明作进一步改进,步骤S4中,所述请求方法包括安装、升级、查询、停止、启动、恢复和卸载请求,如果请求方法所在插件服务器不存在,则显示异常消息提示。The present invention is further improved. In step S4, the request method includes installation, upgrade, query, stop, start, recovery and uninstallation requests. If the plug-in server where the request method is located does not exist, an abnormal message prompt is displayed.
本发明作进一步改进,步骤S5中,其处理方法包括如下步骤:The present invention is further improved, in step S5, its processing method comprises the following steps:
S51:所述插件请求的消息ID字段统一调用封装好的函数id_code随机构造5位数字整型;S51: The message ID field requested by the plug-in uniformly calls the encapsulated function id_code e to randomly construct a 5-digit integer;
S52:构造请求方法JSON消息体后,使用json.dumps方法加载构造的JSON消息体并计算长度;S52: After constructing the request method JSON message body, use the json.dumps method to load the constructed JSON message body and calculate the length;
S53:通过struct.pack方法进行对JSON的消息体进行打包封装成网络字节流;S53: Pack and encapsulate the JSON message body into a network byte stream through the struct.pack method;
S54:统一调用socket的sendall方法向网关发送插件操作对应的请求消息。S54: uniformly calling the sendall method of the socket to send a request message corresponding to the plug-in operation to the gateway.
本发明还提供一种实现所述测试方法的测试系统,包括插件服务器、OLT设备、文件服务器,其中,所述插件服务器和文件服务器相连,所述待测试的网关通过OLT设备分别与插件服务器和文件服务器相连,所述OLT设备用于使待测网关接入网络,所述插件服务器运行基于智能家庭网关插件的自动化测试方法,用于对待测网关进行插件测试,所述文件服务器用于存储不同的插件版本文件,提供插件安装过程中进行远程下载对应的插件。The present invention also provides a test system for implementing the test method, including a plug-in server, an OLT device, and a file server, wherein the plug-in server is connected to the file server, and the gateway to be tested is connected to the plug-in server and the file server respectively through the OLT device The file server is connected, and the OLT device is used to enable the gateway to be tested to access the network. The plug-in server runs an automated test method based on the smart home gateway plug-in for plug-in testing of the gateway to be tested. The file server is used to store different The plug-in version file, which provides the corresponding plug-in for remote download during the plug-in installation process.
与现有技术相比,本发明的有益效果是:提供一套插件自动化测试解决方案,从而提升产品功能可测性,提高了测试效率,同时也避免了产品质量风险。Compared with the prior art, the invention has the beneficial effects of providing a set of plug-in automated testing solutions, thereby improving product function testability, improving testing efficiency, and simultaneously avoiding product quality risks.
附图说明Description of drawings
图1为本发明测试系统结构示意图;Fig. 1 is the structural representation of testing system of the present invention;
图2为智能家庭网关与插件服务器连接示意图;Fig. 2 is a schematic diagram of the connection between the smart home gateway and the plug-in server;
图3为智能家庭网关与插件服务器交互示意图Figure 3 is a schematic diagram of the interaction between the smart home gateway and the plug-in server
图4为本发明方法流程图;Fig. 4 is a flow chart of the method of the present invention;
图5为网关注册认证方法流程图;Fig. 5 is a flowchart of the gateway registration authentication method;
图6为本发明测试方法一实施例插件业务用例操作方法流程图。Fig. 6 is a flow chart of an operation method of a plug-in business use case in an embodiment of the testing method of the present invention.
具体实施方式Detailed ways
下面结合附图和实施例对本发明做进一步详细说明。The present invention will be described in further detail below in conjunction with the accompanying drawings and embodiments.
如图1所示,本发明测试系统包括插件服务器、OLT(光线路终端)设备、文件服务器和传送与承载网,各个设备的作用为:As shown in Figure 1, the test system of the present invention comprises plug-in server, OLT (optical line terminal) equipment, file server and transmission and bearer network, and the effect of each equipment is:
(1)待测的智能家庭网关光纤接口连接到OLT设备端口,提供注册认证、拨号服务。(1) The optical fiber interface of the smart home gateway to be tested is connected to the port of the OLT device to provide registration authentication and dial-up services.
(2)OLT设备接入到传送与承载网,插件服务器网口设置IP地址后,同样接入到传送与承载网。(2) The OLT device is connected to the transmission and bearer network. After the plug-in server network port is set with an IP address, it is also connected to the transmission and bearer network.
(3)智能家庭网关配置远程注册认证,并新建一条静态WAN连接IP地址,确保插件服务器能够与网关互相PING通。(3) The smart home gateway is configured with remote registration authentication, and creates a new static WAN connection IP address to ensure that the plug-in server and the gateway can ping each other.
(4)文件服务器使用HFS工具部署,使用http方式用于给网关提供URL地址下载插件文件安装操作测试。(4) The file server is deployed using the HFS tool, and the http method is used to provide the gateway with a URL address to download the plug-in file installation operation test.
本发明在插件服务器端设置插件服务器工具,该工具主要应用于中国移动智能家庭网关产品进行插件业务功能测试,支持对智能家庭网关上插件的安装、升级、卸载、启动、停止等业务管理操作,从而对智能家庭网关插件的自动化测试方法。The present invention sets a plug-in server tool at the plug-in server end, and the tool is mainly used for plug-in service function testing of China Mobile smart home gateway products, and supports business management operations such as installation, upgrade, uninstallation, startup, and stop of plug-ins on smart home gateways, Thereby an automated testing method for smart home gateway plug-ins.
插件服务端工具采用编程语言Python开发,实现的功能包括插件业务自动化测试和自动生成EXCEL测试报告,涉及的技术如下:The plug-in server tool is developed using the programming language Python. The functions realized include plug-in business automation testing and automatic generation of EXCEL test reports. The technologies involved are as follows:
一、自动执行插件业务用例自动化测试1. Automatically execute plug-in business use case automation test
(1)网络通信:使用socket实现TCP协议,绑定主机IP地址和端口号,实现监听网关并接收来自网关JSON消息结构体,引用json的dumps方法加载JSON消息结构体计算长度,通过struct.pack方法打包编译成网络字节流,使用socket的sendall向网关发送JSON消息结构体,解决与网关C语言编译的消息体实现跨语言通信交互及解析JSON数据。(1) Network communication: use socket to implement TCP protocol, bind the host IP address and port number, realize the monitoring gateway and receive the JSON message structure from the gateway, refer to the dumps method of json to load the JSON message structure to calculate the length, and use struct.pack The method is packaged and compiled into a network byte stream, and the sendall of the socket is used to send the JSON message structure to the gateway, so as to realize cross-language communication interaction with the message body compiled in C language of the gateway and parse JSON data.
(2)计算插件文件大小:引用第三方库os.path的getsize方法计算得出文件字节大小。(2) Calculate the plug-in file size: refer to the getsize method of the third-party library os.path to calculate the file size in bytes.
(3)MD5加密:引用第三方库hashlib的md5方法对拼接的字符串加密。(3) MD5 encryption: use the md5 method of the third-party library hashlib to encrypt the concatenated string.
(4)随机生成数字:对于JSON结构体的键名DeRND和ID数字引用第三方库random的choice方法分别随机生成字符型16字节和整型ID号。(4) Randomly generate numbers: For the key name DeRND and ID numbers of the JSON structure, refer to the choice method of the third-party library random to randomly generate 16-byte character-type and integer-type ID numbers respectively.
二、自动生成EXCEL测试报告2. Automatically generate EXCEL test report
(1)引用第三方库openpyxl的load_workbook方法加载指定的xlsx用例模板格式文件,通过内置的迭代器iter_rows逐行读取数据存储到列表里。(1) Refer to the load_workbook method of the third-party library openpyxl to load the specified xlsx use case template format file, and read the data line by line through the built-in iterator iter_rows and store them in the list.
(2)利用openpyxl定义对象sheet.cell方法把读取测试结果数据写进指定xlsx用例格式文件单元格,同时使用PatternFill方法进行针对PASS和FAIL状态值分别填充绿色和红色,最后保存文件。(2) Use the openpyxl definition object sheet.cell method to write the read test result data into the specified xlsx use case format file cell, and use the PatternFill method to fill green and red for PASS and FAIL status values respectively, and finally save the file.
如图2所示,插件服务器平台功能分三大类:用户管理、心跳维护、插件管理。所述插件服务器平台与智能家庭网关通过socket监听IP和端口进行网络通信,并传送JSON数据。通过用户管理接口:智能家庭网关向插件服务端平台访问请求认证;通过心跳维护接口:智能家庭网关向插件服务端平台之间的心跳维护;通过插件管理接口:支持插件服务器平台对智能家庭网关上插件的安装、升级、缷载、启动、停止、查询、升级等业务管理操作。As shown in Figure 2, the functions of the plug-in server platform are divided into three categories: user management, heartbeat maintenance, and plug-in management. The plug-in server platform communicates with the smart home gateway through the socket monitoring IP and port, and transmits JSON data. Through the user management interface: the smart home gateway requests authentication from the plug-in server platform; through the heartbeat maintenance interface: the heartbeat maintenance between the smart home gateway and the plug-in server platform; through the plug-in management interface: support the plug-in server platform to the smart home gateway Plug-in installation, upgrade, uninstall, start, stop, query, upgrade and other business management operations.
如图3所示,本例的采用TCP,智能家庭网关作为客户端向插件服务器平台发起TCP连接,前提条件下,注册认证通过后,才能进入心跳维链状态阶段,可通过心跳保活机制保持长连接。接下来就可以操作插件业务测试,插件管理提供操作方法有:插件安装、升级、查询、停止、启动、缷载、恢复等7种插件操作。整体业务流程交互过程如下:As shown in Figure 3, TCP is used in this example, and the smart home gateway acts as a client to initiate a TCP connection to the plug-in server platform. Under the premise, after the registration and authentication pass, it can enter the heartbeat dimension chain state stage, which can be kept alive through the heartbeat keep-alive mechanism. Long connection. Next, you can operate the plug-in business test. The plug-in management provides operation methods: plug-in installation, upgrade, query, stop, start, unload, restore, etc. 7 plug-in operations. The overall business process interaction process is as follows:
(1)智能家庭网关先向插件服务器发送认证请求消息,并上报:MAC、插件管理接口协议版本等信息;(1) The smart home gateway first sends an authentication request message to the plug-in server, and reports: MAC, plug-in management interface protocol version and other information;
(2)插件服务器记录相应信息,并根据MAC等信息进行认证,并返回认证结果;(2) The plug-in server records the corresponding information, performs authentication according to information such as MAC, and returns the authentication result;
(3)认证通过后,智能家庭网关周期性上报心跳到插件服务器;(3) After passing the authentication, the smart home gateway periodically reports the heartbeat to the plug-in server;
(4)插件服务器对心跳保活进行响应,默认心跳间隔为600秒;(4) The plug-in server responds to the heartbeat keep-alive, and the default heartbeat interval is 600 seconds;
(5)插件服务器向智能家庭网关发起插件管理操作;(5) The plug-in server initiates a plug-in management operation to the smart home gateway;
(6)智能家庭网关对插件管理操作进行响应,并返回操作结果。(6) The smart home gateway responds to the plug-in management operation and returns the operation result.
如图4所述,本发明测试工具的执行过程包括如下步骤:As shown in Figure 4, the execution process of the test tool of the present invention comprises the following steps:
S1:初始化数据;S1: initialize data;
S2:注册认证被测试的网关,认证通过后,与网关建立通信;S2: Register and authenticate the gateway to be tested, and establish communication with the gateway after passing the authentication;
S3:获取操作指令,当所述操作指令为第二指令时,结束与网关通信,测试结束,当所述操作指令为第一指令时,执行下一步;S3: Obtain an operation instruction. When the operation instruction is the second instruction, end the communication with the gateway, and the test ends. When the operation instruction is the first instruction, execute the next step;
S4:根据测试用例数据迭代获取请求方法,直至请求方法获取完毕;S4: Obtain the request method iteratively according to the test case data until the request method is obtained;
S5:构造与请求方法匹配的消息体并发送给网关;S5: Construct a message body matching the request method and send it to the gateway;
S6:接收来自网关发送的响应消息;S6: receiving a response message sent from the gateway;
S7:根据响应消息判断测试结果并存储;S7: judge and store the test result according to the response message;
S8:生成测试报告,测试结束。S8: Generate a test report, and the test ends.
以下对本发明的方法进行详细说明。插件服务器提供config.ini配置文件,测试前,先配置有关数据。配置HTTP文件服务器,可采用HFS文件服务器工具配置指定的存放插件文件目录即可。The method of the present invention will be described in detail below. The plug-in server provides the config.ini configuration file, and configures relevant data before testing. To configure the HTTP file server, you can use the HFS file server tool to configure the specified directory for storing plug-in files.
本例具体的操作如下:The specific operation in this example is as follows:
(1)首先,定义好服务端JSON消息结构体、Result消息状态码,config配置文件。(1) First, define the server-side JSON message structure, Result message status code, and config configuration file.
(2)其次,引入第三方库configparser,定义Config类,提供获取config.ini配置文件所有键名列表和键名值等方法;引入第三方库logging,定义Log类,提供封装方法有debug、info、warning、error等四个日志等级级别;引第三方库os、sys、random、hashlib、shutil、ctypes、openpyxl,定义公共类Common,提供方法有get_filesize(获取文件大小)、get_md5(获取MD5值)、challenge_code(随机16字节数字)、id_code(获取随机ID号)、read_excel(获取文件数据列表)、write_excel(写数据至文件)、cprint(打印颜色字体)等;引入第三方库socket、threading、time、struct、json、os、sys,定义PluginApi类文件,提供封装方法有socket_close(关闭socket通信)、recv_msg(接收消息)、recv_thread(接收线程)、send_msg(发送消息)。(2) Secondly, introduce the third-party library configparser, define the Config class, and provide methods to obtain all key name lists and key name values of the config.ini configuration file; introduce the third-party library logging, define the Log class, and provide encapsulation methods such as debug and info , warning, error and other four log levels; quote third-party libraries os, sys, random, hashlib, shutil, ctypes, openpyxl, define the common class Common, and provide methods such as get_filesize (get file size), get_md5 (get MD5 value) , challenge_code (random 16-byte number), id_code (get random ID number), read_excel (get file data list), write_excel (write data to file), cprint (print color font), etc.; introduce third-party libraries socket, threading, time, struct, json, os, sys, define the PluginApi class file, and provide encapsulation methods such as socket_close (close socket communication), recv_msg (receive message), recv_thread (receive thread), send_msg (send message).
(3)再次,更改网关插件中心信息数据,使用sidbg 1DB set MobileAppInfo0SpMgtURL命令修改为插件服务端的IP地址,sidbg 1DB set MobileAppInfo 0SpPort修改为服务端的端口号,再执行命令sidbg 1DB save保存当前配置网关插件中心数据。(3) Again, change the information data of the gateway plug-in center, use the sidbg 1DB set MobileAppInfo0SpMgtURL command to modify it to the IP address of the plug-in server, and sidbg 1DB set MobileAppInfo 0SpPort to modify it to the port number of the server, and then execute the command sidbg 1DB save to save the current configuration of the gateway plug-in center data.
如图5所示,作为本发明的一个实施例,本例的具体测试方法包括如下步骤:As shown in Figure 5, as an embodiment of the present invention, the concrete testing method of this example comprises the following steps:
1、初始化数据及socket实例化对象,启动网关注册认证请求、认证结果请求、心跳保活请求等三个阶段注册认证过程交互请求及插件服务器响应。1. Initialize data and socket instantiation objects, start gateway registration authentication request, authentication result request, heartbeat keep-alive request and other three stages of registration authentication process interaction request and plug-in server response.
所述网关注册认证业务逻辑处理流程如图4所示,具体处理方法为:The logic processing flow of the gateway registration and authentication business is shown in Figure 4, and the specific processing method is as follows:
(1)初始化数据,实例化socket对象,绑定服务器主机IP地址、端口号,建立最大连接数5个,使用socket的accept()函数等待接受客户端的请求。此时也可以设置为其他的最大连接数,对多个网关并行测试。(1) Initialize the data, instantiate the socket object, bind the IP address and port number of the server host, establish a maximum of 5 connections, and use the accept() function of the socket to wait for the client's request. At this time, it can also be set to other maximum connections to test multiple gateways in parallel.
(2)单独创建接收消息线程,循环监听接收来自网关发来的请求JSON消息。(2) Separately create a thread for receiving messages, and listen in a loop to receive request JSON messages from the gateway.
(3)判断网关认证请求的JSON消息体RPCMethod键值如果为BootInitiation请求方法,再判断插件服务器平台INI配置文件MAC地址与JSON消息体MAC匹配,则构造认证响应JSON消息体Result返回为0;否则Result返回为-2,网关只能重启后连接重新进行网关注册认证。(3) Determine if the RPCMethod key value of the JSON message body of the gateway authentication request is the BootInitiation request method, and then judge that the MAC address of the INI configuration file of the plug-in server platform matches the MAC address of the JSON message body, then construct the authentication response JSON message body Result and return 0; otherwise If the Result returns -2, the gateway can only be restarted and re-connected to the gateway for registration and authentication.
认证响应JSON消息体格式为:The format of the authentication response JSON message body is:
{{
“Result”:0|-2,"Result": 0|-2,
“ID”:数字,//事务ID对应与请求的事务ID保持一致"ID": number, //The transaction ID corresponds to the requested transaction ID
“ChallengeCode”:“十六字节随机数”"ChallengeCode": "Sixteen-byte random number"
}}
其中ChallengeCode字段,调用chalenge_code封装好的函数实现随机生成16字节数的字符,引用第三方库random的choice方法通过迭代16次拼接数字组成的16字节数的字符型。In the ChallengeCode field, call the function encapsulated by challenge_code to randomly generate 16-byte characters, and refer to the choice method of the third-party library random to iterate 16 times to form a 16-byte character type.
(4)判断网关认证请求JSON消息体RPCMethod键值如为Register请求方法,再校验网关请求的JSON消息体CheckGateway的MD5值与MD5(ChallengeCode+SN+SSID(后四位)+SSID初始密码(8位)+user初始密码(8位)+Password)拼接成字符计算得出的md5值匹配一致性,则构造认证结果响应JSON消息体Result返回为0;否则Result返回为-5,网关静默等待10分钟后重新进行认证。(4) Determine if the RPCMethod key value of the gateway authentication request JSON message body is the Register request method, and then verify the MD5 value of the JSON message body CheckGateway requested by the gateway and MD5 (ChallengeCode+SN+SSID (the last four digits)+SSID initial password ( 8 digits) + user initial password (8 digits) + Password) spliced into characters to calculate the md5 value matching consistency, then construct the authentication result response JSON message body Result and return 0; otherwise Result returns -5, and the gateway waits silently Re-authenticate after 10 minutes.
(5)判断网关认证请求JSON消息体RPCMethod键值如为Hb请求方法,则构造心跳保活响应JSON消息体Result返回为0,网关应保持正常心跳周期,默认心跳间隔时间为600秒。(5) Determine if the RPCMethod key value of the gateway authentication request JSON message body is the Hb request method, construct a heartbeat keep-alive response JSON message body Result and return 0, the gateway should maintain a normal heartbeat cycle, and the default heartbeat interval is 600 seconds.
(6)如果认证请求JSON消息体RPCMethod没有找到请求方法,则抛出异常消息提示。(6) If the authentication request JSON message body RPCMethod does not find the request method, an exception message will be thrown.
2、待注册认证通过后,才能进入心跳保活保持建立连接数据报文交互,接下来CMD窗口就可以显示主菜单选项,当选择编号为2时,退出程序,结束与网关通信。2. After the registration and authentication pass, you can enter the heartbeat keep alive to maintain the connection establishment data message interaction, and then the CMD window can display the main menu options. When the selection number is 2, exit the program and end the communication with the gateway.
3、当选择编号为1时,调用read_excel函数获取excel文件的测试用例数据并迭代获取请求方法,若请求方法为”Install”时自动触发构造Install安装插件JSON请求消息结构体;3. When the selection number is 1, call the read_excel function to obtain the test case data of the excel file and obtain the request method iteratively. If the request method is "Install", it will automatically trigger the construction of the JSON request message structure of the Install installation plug-in;
安装插件JSON请求消息格式如下:The JSON request message format for installing plugins is as follows:
{{
”RPCMethod”:”Install”,"RPCMethod": "Install",
“ID”:数字,//事务ID用于标识对应操作序号"ID": number, //transaction ID is used to identify the corresponding operation sequence number
”Plugin_Name”:“Plugin_ID”,//平台生成插件的唯一标示,生成规则为:“第三方插件名称”,插件名称应按照相应的OS的命名规则进行定义"Plugin_Name": "Plugin_ID", //The unique identifier of the platform generated plug-in, the generation rule is: "third-party plug-in name", the plug-in name should be defined according to the naming rules of the corresponding OS
“Version”:”插件版本号”,"Version": "Plugin version number",
”Download_url”:”插件下载URL地址”,"Download_url": "plug-in download URL address",
”Plugin_size”:”size”,//单位为Byte大小"Plugin_size": "size", //The unit is Byte size
”OS”:”插件类型”"OS":"plugin type"
}}
字段Plugin_size的值来源于调用get_filesize函数引用os.path.getsize方法计算得出插件文件字节大小。The value of the field Plugin_size comes from the byte size of the plug-in file calculated by calling the get_filesize function and referencing the os.path.getsize method.
4、本例使用threading线程调用recv_msg方法设置独立循环接收来自网关请求或响应消息线程,通过调用read_excel接口循环迭代读取用例数据列表来识别请求方法,并传参给JSON消息结构体,引用json.dumps方法加载JSON消息结构全,再得出消息结构体长度,使用struct.pack打包JSON消息结构体编译成网络字节流,再调用socket的sendall方法向网关发送消息请求。4. In this example, the threading thread is used to call the recv_msg method to set up an independent loop to receive the request or response message thread from the gateway. By calling the read_excel interface, iteratively reads the use case data list to identify the request method, and passes the parameters to the JSON message structure, citing json. The dumps method loads the entire JSON message structure, and then obtains the length of the message structure, uses struct.pack to pack the JSON message structure and compiles it into a network byte stream, and then calls the sendall method of the socket to send a message request to the gateway.
(1)若请求方法为”ListPlugin”时自动触发构造ListPlugin查询插件列表请求JSON消息体;(1) If the request method is "ListPlugin", the construction of the ListPlugin query plugin list request JSON message body is automatically triggered;
获取查询插件列表请求消息格式如下:The request message format for querying the plug-in list is as follows:
{{
”RPCMethod”:”Install_query”,"RPCMethod": "Install_query",
“ID”:数字,"ID": number,
”Plugin_Name”:“Plugin_ID”,"Plugin_Name": "Plugin_ID",
}}
(2)若请求方法为”Stop”时自动触发构造Stop停止插件请求JSON消息体;(2) If the request method is "Stop", it will automatically trigger the construction of the Stop plug-in to request the JSON message body;
停止插件请求消息格式如下:The stop plugin request message format is as follows:
{{
”RPCMethod”:”Stop,"RPCMethod": "Stop,
“ID”:数字,"ID": number,
”Plugin_Name”:“Plugin_ID”"Plugin_Name": "Plugin_ID"
}}
(3)若请求方法为”Run”时自动触发构造Run启用插件请求JSON消息体;(3) If the request method is "Run", it will automatically trigger the construction of Run to enable the plug-in to request the JSON message body;
启用插件请求消息格式如下:The enable plugin request message format is as follows:
{{
”RPCMethod”:”Run”,"RPCMethod": "Run",
“ID”:数字,"ID": number,
”Plugin_Name”:“Plugin_ID”"Plugin_Name": "Plugin_ID"
}}
(4)若请求方法为”UnInstall”时自动触发构造UnInstall缷载插件请求JSON消息体;(4) If the request method is "UnInstall", it will automatically trigger the construction of the UnInstall unloading plug-in request JSON message body;
缷载插件请求消息格式如下:The format of the unloading plugin request message is as follows:
{{
”RPCMethod”:”UnInstall”,"RPCMethod": "UnInstall",
“ID”:数字,"ID": number,
”Plugin_Name”:“Plugin_ID”,"Plugin_Name": "Plugin_ID",
}}
(5)若请求方法为”FactoryPlugin”时自动触发构造FactoryPlugin恢复插件请求JSON消息体;(5) If the request method is "FactoryPlugin", it will automatically trigger the construction of the FactoryPlugin recovery plugin to request the JSON message body;
恢复插件请求消息格式如下:The restore plugin request message format is as follows:
{{
”RPCMethod”:”FactoryPlugin”,"RPCMethod": "FactoryPlugin",
“ID”:数字,"ID": number,
”Plugin_Name”:“Plugin_ID”"Plugin_Name": "Plugin_ID"
}}
(6)若请求方法所在插件服务器不存在,则抛出异常消息提示”测试用例未找到请求方法,请检查测试用例文件”。(6) If the plug-in server where the request method is located does not exist, an exception message will be thrown to prompt "the test case did not find the request method, please check the test case file".
其中,插件请求的消息ID字段统一调用封装好的函数id_cod随机构造5位数字整型,构造请求方法JSON消息体后,统一调用socket的sendall方法向网关发送插件操作对应的请求消息。Among them, the message ID field of the plug-in request uniformly calls the encapsulated function id_cod to randomly construct a 5-digit integer, and after constructing the JSON message body of the request method, uniformly calls the sendall method of the socket to send the request message corresponding to the plug-in operation to the gateway.
5、由接收线程来接收来自网关发来的响应JSON消息体,并判断消息体的字段”Result”是否为0,如不为0,则添加”FAIL”到status列表存储,同时添加网关响应的消息体到gate_msg列表存储;否则,添加”PASS”到status列表存储,同时添加网关响应的消息体到gate_msg列表存储。把status和gate_msg两个列表传参给write_excel函数接口,并加载EXCEL测试用例文件并实例化对象sheet,根据列表的status和gate_msg数据迭代写进指定的单元格,然后根据status值如是”PASS”,填充颜色为绿色;如是”FAIL”,填充颜色为红色。最后使用wb.save方法保存并关闭当前文件,生成EXCEL测试报告文件。5. The receiving thread receives the response JSON message body sent from the gateway, and judges whether the field "Result" of the message body is 0. If it is not 0, add "FAIL" to the status list storage, and add the response of the gateway at the same time Store the message body in the gate_msg list; otherwise, add "PASS" to the status list and add the message body of the gateway response to the gate_msg list. Pass the two lists of status and gate_msg to the write_excel function interface, load the EXCEL test case file and instantiate the object sheet, write iteratively into the specified cell according to the status and gate_msg data in the list, and then according to the status value is "PASS", The fill color is green; if it is "FAIL", the fill color is red. Finally, use the wb.save method to save and close the current file to generate an EXCEL test report file.
本方案实现的创新点在于:The innovations achieved by this scheme are:
(1)定义菜单模板,提供了主菜单启动插件服务测试和结束程序两个选项功能,实现人机交互提供测试便利;(1) Define the menu template, provide the main menu to start the plug-in service test and end the program two option functions, realize human-computer interaction and provide test convenience;
(2)当插件服务端工具运行时,自动初始化环境接收来自网关发来的注册认证请求消息进行逻辑处理并响应消息给网关,当认证通过后,进入心跳保活阶段,然后程序自动输出主菜单,当选择编号1时,启动插件管理操作一体化代替人工操作,实现自动化用例执行测试;当选择编号2时,结束服务端与网关通信;(2) When the plug-in server tool is running, the automatic initialization environment receives the registration authentication request message from the gateway for logical processing and responds to the gateway. After the authentication is passed, it enters the heartbeat keep-alive stage, and then the program automatically outputs the main menu , when the
(3)当执行完用例,自动生成EXCEL测试报告文件。该服务端工具满足不同的插件业务自动化安装、缷载、查询、升级、停止、启动等操作。(3) When the use case is executed, an EXCEL test report file is automatically generated. This server-side tool satisfies different plug-in business automation installation, unloading, query, upgrade, stop, start and other operations.
本发明能够验证插件真实场景插件业务,并通过与网关的交互,能够提升产品功能可测性,提高了测试效率,同时也避免了产品质量风险。The present invention can verify the plug-in business of the real scene of the plug-in, and through the interaction with the gateway, can improve the testability of the product function, improve the test efficiency, and avoid the product quality risk at the same time.
以上所述之具体实施方式为本发明的较佳实施方式,并非以此限定本发明的具体实施范围,本发明的范围包括并不限于本具体实施方式,凡依照本发明所作的等效变化均在本发明的保护范围内。The specific implementation manners described above are preferred implementation modes of the present invention, and are not intended to limit the specific implementation scope of the present invention. The scope of the present invention includes but not limited to the specific implementation modes. All equivalent changes made according to the present invention are Within the protection scope of the present invention.
Claims (9)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110593981.5A CN113315681B (en) | 2021-05-28 | 2021-05-28 | Automatic testing method and system based on intelligent home gateway plug-in |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110593981.5A CN113315681B (en) | 2021-05-28 | 2021-05-28 | Automatic testing method and system based on intelligent home gateway plug-in |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN113315681A CN113315681A (en) | 2021-08-27 |
| CN113315681B true CN113315681B (en) | 2022-11-08 |
Family
ID=77376373
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202110593981.5A Expired - Fee Related CN113315681B (en) | 2021-05-28 | 2021-05-28 | Automatic testing method and system based on intelligent home gateway plug-in |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN113315681B (en) |
Families Citing this family (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115250197B (en) * | 2022-06-02 | 2024-04-12 | 苏州思萃工业互联网技术研究所有限公司 | Device for automatically creating container discovery service |
| CN116232951A (en) * | 2023-02-16 | 2023-06-06 | 南京国电南自软件工程有限公司 | A parallel detection method and system for multiple gateways based on instruction sequence set |
| CN116915875B (en) * | 2023-09-12 | 2023-12-05 | 深圳市天思智慧科技有限公司 | General method for analyzing modbus equipment by Internet of things and modbus system |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103259713A (en) * | 2013-04-15 | 2013-08-21 | 海信集团有限公司 | Message exchange system and method |
| CN109766278A (en) * | 2019-01-10 | 2019-05-17 | 中天宽带技术有限公司 | The backstage gateway WEB automatic test approach based on OSGI frame |
| CN111726607A (en) * | 2020-06-28 | 2020-09-29 | 深圳市友华通信技术有限公司 | Method and system for testing hardware of convergence gateway |
| CN112019405A (en) * | 2020-08-31 | 2020-12-01 | 深圳市吉祥腾达科技有限公司 | Automatic testing method and system |
| CN112350877A (en) * | 2019-08-07 | 2021-02-09 | 中国移动通信有限公司研究院 | Test method, test platform, intelligent gateway and test system |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US9354998B2 (en) * | 2012-05-04 | 2016-05-31 | Aegis.Net, Inc. | Automated conformance and interoperability test lab |
-
2021
- 2021-05-28 CN CN202110593981.5A patent/CN113315681B/en not_active Expired - Fee Related
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103259713A (en) * | 2013-04-15 | 2013-08-21 | 海信集团有限公司 | Message exchange system and method |
| CN109766278A (en) * | 2019-01-10 | 2019-05-17 | 中天宽带技术有限公司 | The backstage gateway WEB automatic test approach based on OSGI frame |
| CN112350877A (en) * | 2019-08-07 | 2021-02-09 | 中国移动通信有限公司研究院 | Test method, test platform, intelligent gateway and test system |
| CN111726607A (en) * | 2020-06-28 | 2020-09-29 | 深圳市友华通信技术有限公司 | Method and system for testing hardware of convergence gateway |
| CN112019405A (en) * | 2020-08-31 | 2020-12-01 | 深圳市吉祥腾达科技有限公司 | Automatic testing method and system |
Also Published As
| Publication number | Publication date |
|---|---|
| CN113315681A (en) | 2021-08-27 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN113315681B (en) | Automatic testing method and system based on intelligent home gateway plug-in | |
| CN110674027B (en) | SDN data plane software conformance testing system and method for P4 programming language | |
| CN107241315B (en) | Access method, device and computer-readable storage medium for bank gateway interface | |
| CN111159019B (en) | Application program testing method, testing control terminal and testing terminal | |
| CN110119350A (en) | Software Development Kit test method, device and equipment and computer storage medium | |
| CN111552568A (en) | Cloud service calling method and device | |
| WO2012022072A1 (en) | Method, device and system for triggering terminal operation | |
| US11709722B2 (en) | Extensible communication framework and communication method supporting multiple communication protocols | |
| CN112732231A (en) | System of computer-implemented microservice development platform and method of providing microservices | |
| CN102663298A (en) | Safety online detecting system facing to terminal computers | |
| CN106209515A (en) | Automatic test system for access network equipment | |
| WO2022257927A1 (en) | Key burning method and apparatus, electronic device board card, and storage medium | |
| CN115361327A (en) | A method, device, terminal and medium for automatically testing network card NCSI commands | |
| CN113852516A (en) | Method, system, terminal and storage medium for generating switch diagnostic program | |
| CN116056126B (en) | Simulation test method, simulation test device, computer equipment and computer readable storage medium | |
| CN114675876B (en) | Service processing method and device, electronic equipment and storage medium | |
| CN112688800B (en) | Remote maintenance method and system for intelligent power grid intelligent equipment based on script technology | |
| CN110955537B (en) | Method and device for containing pipes by physical machine | |
| CN118860799A (en) | Method and system for realizing automated operation and maintenance of OpenStack cloud computing | |
| CN118612128A (en) | Switch testing method, device, storage medium and electronic equipment | |
| CN109086200B (en) | An Effective Testing Framework Based on Android Virtual Machine Modification | |
| CN115391396A (en) | Interface-based query method and device and storage medium | |
| CN114629830A (en) | Method and system for automatically controlling TestCenter instrument test | |
| CN106997291A (en) | A kind of control method and master node, slave node | |
| CN114915549B (en) | Instruction query method, device, equipment and storage medium |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant | ||
| CF01 | Termination of patent right due to non-payment of annual fee | ||
| CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20221108 |