Test case execution method and device based on three-power separation and storage medium
By determining the test mode and separating the control subject and executing subject in the test case execution, the difficulty of automated testing after the Kirin operating system is solved, and safe, flexible and efficient test case execution is achieved.
Patent Information
- Application Number
- CN202411756319.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-03-21
AI Technical Summary
After the Kirin operating system enables the secure three-rights mode, the automation test platform cannot execute the automation use cases normally, resulting in the script execution results being interfered with permission modifications, affecting the automation testing.
By receiving incoming test case parameters, determining the test mode according to the parameters, and determining the test control body and the test execution body according to the mode, generating and issuing test execution commands to receive the test results. This method disconnects the direct connection between the test platform and the test machine, avoiding the impact of separation of powers.
It effectively prevents potential security threats, improves the scalability and flexibility of the system, supports multiple testing environments, and significantly reduces the risk of data leakage when using dual-machine testing mode or Zen test mode.
Smart Images

Figure CN119669081A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of test cases, and in particular to a test case execution method, device and storage medium based on separation of powers. Background Art
[0002] In the process of automated testing and system management, the test platform usually needs to send commands to execute automated use cases to the test machine and receive the execution results. However, after the Kylin operating system turns on the security three-authority mode (strict), due to security restrictions, automated use cases cannot be executed through the platform, which brings many inconveniences to the testing work.
[0003] When executing through the automation platform, due to security permission issues, the platform must modify some system permissions to ensure that platform-related scripts can be executed normally on the test machine, and to achieve intercommunication between the platform and the test machine, which causes the script execution results to be disturbed due to permission modification, affecting automated testing. Summary of the invention
[0004] The embodiments of the present invention provide a test case execution method, device and storage medium based on the separation of powers to solve the technical problem in the prior art that there are security risks when a multi-core CPU runs multiple heterogeneous operating systems.
[0005] In a first aspect, an embodiment of the present invention provides a test case execution method based on separation of powers, including:
[0006] Receive the input test case parameters, and determine the test mode according to the test case parameters;
[0007] Determine a test control subject and a test execution subject according to the test mode;
[0008] Generate test execution commands based on the test script path and case ID;
[0009] Using the test control subject to send the test execution command to the test execution subject;
[0010] Receive the test result returned by the test execution entity.
[0011] In a second aspect, an embodiment of the present invention further provides a test case execution device based on separation of powers, including:
[0012] A receiving module, used to receive the incoming test case parameters and determine the test mode according to the test case parameters;
[0013] A determination module, used to determine a test control subject and a test execution subject according to the test mode;
[0014] The generation module is used to generate the test execution command according to the test script path and the case ID;
[0015] A sending module, used for sending the test execution command to the test execution subject by using the test control subject;
[0016] The test result receiving module is used to receive the test result returned by the test execution entity.
[0017] In a third aspect, an embodiment of the present invention further provides a storage medium comprising computer executable instructions, which, when executed by a computer processor, are used to execute a test case execution method based on separation of powers as provided in the above embodiment.
[0018] The test case execution method, device and storage medium based on the separation of powers provided in the embodiment of the present invention receive the incoming test case parameters, determine the test mode according to the test case parameters; determine the test control subject and the test execution subject according to the test mode; generate the test execution command according to the test script path and the case ID; use the test control subject to send the test execution command to the test execution subject; receive the test result returned by the test execution subject. The user can set the test case parameters according to the requirements, and the system can determine the corresponding test mode according to the parameters. And determine the control subject and the execution subject according to the test mode, and disconnect the connection with the test platform by setting the control subject and the execution subject separately, so as to avoid the influence of the separation of powers on the test. By physically or logically separating the control machine from the execution machine, potential security threats can be effectively prevented, and the scalability and flexibility of the system can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0020] Figure 1 It is a flowchart of a test case execution method based on separation of powers provided in the first embodiment of the present invention;
[0021] Figure 2 It is a flowchart of a test case execution method based on separation of powers provided in Embodiment 2 of the present invention;
[0022] Figure 3 It is a structural diagram of a test case execution device based on separation of powers provided in Embodiment 3 of the present invention. DETAILED DESCRIPTION
[0023] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0024] Embodiment 1
[0025] Figure 1 1 is a flow chart of a test case execution method based on separation of powers provided in the first embodiment of the present invention. This embodiment is applicable to the case where test cases are automatically executed in a scenario where separation of powers is enabled. The method can be executed by a test case execution device based on separation of powers, and specifically includes the following steps:
[0026] Step 110: Receive the incoming test case parameters and determine the test mode according to the test case parameters.
[0027] The "separation of powers" in Linux refers to users, groups, and permissions. In a Linux system, each file and directory has an owner, a group, and access rights. The separation of powers is to divide the traditional root permissions into three administrators for decentralized management. According to the principle of functional division and minimum authorization, they are granted the minimum permissions required to complete their respective tasks, and form a mutually restrictive relationship. The three administrators are: System administrator: responsible for the daily management of the system, such as user management, software management, service management, disk management, etc.; Security administrator: responsible for the system's security mechanism management (selinux and kysec), such as security status management, security tag management; Audit administrator: responsible for the system's audit management, such as audit services, audit rules, audit logs, etc.; In the process of automated testing and system management, the test platform is usually required to send execution automation use case commands to the test machine and receive execution results. However, after the Kylin operating system turns on the security three-power mode (strict), due to security restrictions, the automation platform often cannot connect to the test machine normally, resulting in the inability to execute automated use cases through the platform.
[0028] After the domestically produced Kylin server operating system turns on the security mode, there are several problems in executing automated scripts: When executing through the automated platform, due to security permission issues, the platform must modify some system permissions to ensure that platform-related scripts can be executed normally on the test machine, so that the platform and the test machine can communicate with each other, resulting in the script execution results being disturbed due to permission modification. When the test machine needs to enable some special permissions, such as the three-authority mode, the test machine will be disconnected from the platform. As a result, the automated use case cannot be executed through the platform.
[0029] Since various problems may occur after the automated test is used when the three-power mode is turned on, in this embodiment, multiple modes can be set to solve the above problems. The user can set multiple modes and input test case parameters. The system can determine the mode to be used according to the test case parameters.
[0030] Exemplarily, the modes may be respectively set as: direct execution mode in non-safe isolation mode, control machine-executor separation mode and offline mode.
[0031] Correspondingly, the test case parameters may include: test case ID, IP address, ZenTao test order ID, etc. When the test case parameter is the test case ID, it can be determined as the direct execution mode in the non-secure isolation mode; when the test case parameter is the IP address, it can be determined as the control machine-executor separation mode; when the test case parameter is the ZenTao test order ID, it can be determined as the offline mode.
[0032] Step 120: Determine a test control subject and a test execution subject according to the test mode.
[0033] In different modes, the test control subject and the test execution subject need to be separated to achieve the purpose of the test.
[0034] For example, the direct execution mode in the non-safe isolation mode, that is, the three-authority mode, does not affect the connection between the test platform and the test machine. In this case, in the single-machine test mode, the test control subject and the test execution subject are set to the same machine. The control machine is the execution machine, and the platform can be used directly to send test information to the control machine to realize automated case testing.
[0035] In the dual-machine test mode, due to the influence of the three-power mode, the execution machine cannot directly obtain the test instructions from the platform, so a control machine needs to be added. The control machine is used to send commands, and the execution machine is used to receive and execute commands and send the execution results back to the control machine. The control machine includes: a command sending module, which is used to send commands to be executed to the execution machine, and a result receiving module, which is used to receive the execution results returned by the execution machine. The execution machine includes: a receiving module, which is used to receive commands to be executed from the control machine; an execution module, which is used to execute the received commands; and a result sending module, which is used to send the execution results back to the control machine.
[0036] When the ZenTao test mode is used, it actually adopts the control machine-executor offline mode. In this mode, by integrating project management tools such as ZenTao, the test cases can be automatically synchronized and executed. ZenTao is an open source automated test management framework. It supports multiple unit test frameworks. It can be connected with the previous Jenkins continuous integration function. After the user initiates the task, ZenTao automatically executes the test script and sends the unit test results back to ZenTao. The cooperation between the two opens up the continuous integration closed loop and bridges the gap between project management tools and continuous integration tools. Due to the use of the three-power separation mode, it is impossible to directly obtain the parameters required to execute the automation case from the ZenTao platform, such as the script path and ID. Due to the large number of automation project files, it is very inconvenient to find the corresponding case file. Therefore, the control machine-executor offline mode can be used.
[0037] Step 130, generate a test execution command based on the test script path and the use case ID.
[0038] Exemplarily, in single-machine test mode or dual-machine test mode, a specific execution command can be generated according to the script path and use case ID provided by the platform. In ZenTao test mode, first use the ZenTao API interface to obtain relevant test case information according to the test order ID; parse the data returned by the ZenTao API to generate a list containing all relevant test case IDs; traverse the test case ID list, find the automation project file corresponding to each use case, and obtain its script path; generate a specific execution command according to the obtained script path and use case ID. Description: The control machine uses the ZenTao API interface to obtain relevant test case information according to the test order ID. Exemplarily, the control machine parses the data returned by the ZenTao API to generate a list containing all relevant test case IDs. According to the test case ID list, read in a loop and return the script path of the project file containing the test ID in the automation project. The control machine traverses the test case ID list, finds the automation project file corresponding to each use case, and obtains its script path. Generate a specific execution command according to the obtained script path and use case ID.
[0039] Step 140: Use the test control entity to send the test execution command to the test execution entity.
[0040] Exemplary, the test control subject can be used to use the paramiko module through the SSH protocol to issue the generated execution command to the specified test execution subject. Paramiko is a Python library, mainly used to perform remote operations in Python code, such as connecting to a remote server, executing commands, uploading and downloading files, etc. It supports two modes of password authentication and public key authentication, ensuring the safety of operation. Using the paramiko module is convenient to perform various test remote operations through the SSH protocol. It should be noted that since the single-machine test mode is that the test control subject and the test execution subject are the same machine, there is no need to use the paramiko module to issue through the SSH protocol.
[0041] Step 150: Receive the test result returned by the test execution entity.
[0042] The test execution subject executes the issued test command and obtains the test result. After the test execution subject completes the test case, the result data is transmitted back to the test control subject via the SSH protocol. Exemplarily, the test result can be first sent to the test control subject. Since the test has been completed at this time, the network connection can be restored and the test result obtained by the test control subject can be uploaded to the platform.
[0043] This embodiment receives the incoming test case parameters, determines the test mode according to the test case parameters; determines the test control subject and the test execution subject according to the test mode; generates a test execution command according to the test script path and the case ID; uses the test control subject to send the test execution command to the test execution subject; and receives the test result returned by the test execution subject. The user can set the test case parameters according to the requirements, and the system can determine the corresponding test mode according to the parameters. The control subject and the execution subject are determined according to the test mode, and the connection with the test platform is disconnected by setting the control subject and the execution subject separately, so as to avoid the influence of the separation of powers on the test. By physically or logically separating the control machine from the execution machine, potential security threats can be effectively prevented, and the scalability and flexibility of the system are also improved. Supports a variety of test environments, whether it is an open development environment or a highly secure production environment, and can provide corresponding solutions. When using the dual-machine test mode or the ZenTao test mode, the risk of data leakage is significantly reduced by physical or logical isolation. When using the ZenTao test mode, the whole process automation from the acquisition, execution to result feedback of the test case can be realized, which greatly saves human resources.
[0044] In a preferred implementation of this embodiment, the test result returned by the test execution subject can be specifically optimized as follows: the test control subject calls the update interface of the result of the ZenTao test single case test according to the returned result data to update the execution result of the case. When in ZenTao test mode, the update interface of the ZenTao system's test single case test can be called for the returned test result data, and the execution result can be uploaded and updated to ZenTao. The full process automation of result feedback can be achieved, which greatly saves human resources.
[0045] Embodiment 2
[0046] Figure 2 It is a flow chart of the test case execution method based on separation of powers provided in the second embodiment of the present invention. This embodiment is optimized on the basis of the above embodiment, and the test control subject and the test execution subject are determined according to the test mode. The specific optimization is as follows: according to the deployment information of the test execution subject, the test capability of each test execution subject is determined; the test execution subject is determined according to the test capability and the test mode; accordingly, the test execution command is sent to the test execution subject by using the test control subject, which is specifically optimized as follows: using the test control subject to allocate corresponding test execution commands according to the test capability of each test execution subject, and the allocated test execution commands are sent to the corresponding test execution subjects.
[0047] See also Figure 2 , the test case execution method based on separation of powers includes:
[0048] Step 210: receiving the input test case parameters, and determining the test mode according to the test case parameters.
[0049] Step 220: Determine the test capability of each test execution entity according to the deployment information of the test execution entity.
[0050] In this embodiment, there may be multiple test execution entities in order to process a large number of test execution commands. Therefore, it is necessary to obtain the test capability of each test execution entity in order to reasonably allocate them.
[0051] Step 230: determine each test execution subject according to the test capability and the test mode.
[0052] In this embodiment, it can be determined whether the test execution subject is separated from the test control subject according to the test mode. After the separation is determined, the test execution subject is determined according to the number of overall test execution commands. Optionally, a suitable number of test execution subjects can be selected from the test execution subjects according to the capability of each test execution subject and the number of overall test execution commands. The number of test execution subjects is reduced to avoid the impact of network connection.
[0053] Step 240, generate a test execution command based on the test script path and the use case ID.
[0054] Step 250: using the test control subject to allocate corresponding test execution commands according to the test capability of each test execution subject, and sending the allocated test execution commands to the corresponding test execution subjects.
[0055] The corresponding number of test execution commands is allocated according to the test capability, and the allocated results are allocated to the corresponding test execution subjects.
[0056] Step 260: Receive the test result returned by the test execution entity.
[0057] In this embodiment, the determination of the test control subject and the test execution subject according to the test mode is optimized as follows: the test capability of each test execution subject is determined according to the deployment information of the test execution subject; the test execution subject is determined according to the test capability and the test mode; accordingly, the use of the test control subject to send the test execution command to the test execution subject is optimized as follows: the test control subject is used to allocate the corresponding test execution command according to the test capability of each test execution subject, and the allocated test execution command is sent to the corresponding test execution subject. The test execution subject can be reasonably allocated according to the test task, and the impact of the network connection can be reduced while satisfying the test task.
[0058] Embodiment 3
[0059] Figure 3 is a schematic diagram of the structure of a test case execution device based on power separation provided in Embodiment 3 of the present invention, see Figure 3 , the test case execution device based on separation of powers comprises:
[0060] The receiving module 310 is used to receive the input test case parameters and determine the test mode according to the test case parameters;
[0061] A determination module 320, configured to determine a test control subject and a test execution subject according to the test mode;
[0062] A generation module 330 is used to generate a test execution command according to the test script path and the case ID;
[0063] The sending module 340 is used to send the test execution command to the test execution subject by using the test control subject;
[0064] The test result receiving module 350 is used to receive the test result returned by the test execution entity.
[0065] The test case execution device based on the separation of powers provided in this embodiment receives the incoming test case parameters, determines the test mode according to the test case parameters; determines the test control subject and the test execution subject according to the test mode; generates a test execution command according to the test script path and the case ID; uses the test control subject to send the test execution command to the test execution subject; and receives the test result returned by the test execution subject. The user can set the test case parameters according to the requirements, and the system can determine the corresponding test mode according to the parameters. The control subject and the execution subject are determined according to the test mode, and the connection with the test platform is disconnected by setting the control subject and the execution subject separately, so as to avoid the influence of the separation of powers on the test. By physically or logically separating the control machine from the execution machine, potential security threats can be effectively prevented, and the scalability and flexibility of the system can be improved.
[0066] Based on the above embodiments, the receiving module includes:
[0067] A first determining unit, configured to determine that the test mode is a single-machine test mode when the test case parameter is a test case ID;
[0068] Accordingly, the determination module includes:
[0069] The first setting unit is used to set the test control subject and the test execution subject to the same machine when the test mode is a single machine.
[0070] Based on the above embodiments, the receiving module includes:
[0071] A second determining unit, configured to determine that the test mode is a dual-machine test mode when the test case parameter is an IP address;
[0072] Accordingly, the determination module includes:
[0073] As a unit, it is used to use the machine with the IP address as the test execution subject when in a dual-machine test mode;
[0074] The receiving module comprises:
[0075] The first receiving unit is used to receive the test result forwarded by the test control subject.
[0076] Based on the above embodiments, the receiving module includes:
[0077] A second determining unit, configured to determine that the test mode is the ZenTao test mode when the test case parameter is a ZenTao test order ID;
[0078] Accordingly, the generating module includes:
[0079] Use unit, which is used to use ZenTao API to obtain relevant test case information according to the test order ID;
[0080] The parsing unit is used to parse the data returned by the ZenTao API and generate a list containing all relevant test case IDs;
[0081] The traversal unit is used to traverse the test case ID list, find the automation project file corresponding to each case, and obtain its script path;
[0082] The generation unit is used to generate a specific execution command according to the obtained script path and use case ID.
[0083] Based on the above embodiments, the receiving module includes:
[0084] The feedback unit is used to return the result data to the test control body through the SSH protocol after the test execution body completes the test case.
[0085] Based on the above embodiments, the receiving module includes:
[0086] The calling unit is used to use the test control subject to call the result call update interface of the ZenTao test single case test according to the returned result data, and update the execution result of the case.
[0087] Based on the above embodiments, the sending module includes:
[0088] The sending unit is used to use the test control subject to send the generated execution command to the specified test execution subject through the SSH protocol using the paramiko module.
[0089] Based on the above embodiments, the determining module further includes:
[0090] A capability determination unit, configured to determine the test capability of each test execution subject according to the deployment information of the test execution subject;
[0091] An execution subject determination unit, used to determine a test execution subject according to the test capability and the test mode;
[0092] Correspondingly, the sending module includes:
[0093] The allocating unit is used to allocate corresponding test execution commands according to the test capability of each test execution subject by using the test control subject, and send the allocated test execution commands to the corresponding test execution subjects.
[0094] The test case execution device based on separation of powers provided in the embodiment of the present invention can execute the test case execution method based on separation of powers provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0095] Embodiment 4
[0096] Embodiment 4 of the present invention further provides a storage medium comprising computer executable instructions, wherein the computer executable instructions, when executed by a computer processor, are used to execute any of the test case execution methods based on separation of powers provided in the above embodiments.
[0097] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0098] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0099] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0100] Computer program code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or device. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0101] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A test case execution method based on separation of powers, characterized in that: include: Receive the input test case parameters, and determine the test mode according to the test case parameters; Determine a test control subject and a test execution subject according to the test mode; Generate test execution commands based on the test script path and case ID; Using the test control subject to send the test execution command to the test execution subject; Receive the test result returned by the test execution entity.
2. The method according to claim 1, characterized in that Determining the test mode according to the test case parameters includes: When the test case parameter is a test case ID, determining that the test mode is a single-machine test mode; Accordingly, determining a test control subject and a test execution subject according to the test mode includes: In the single-machine test mode, the test control subject and the test execution subject are set to the same machine.
3. The method according to claim 1, characterized in that Determining the test mode according to the test case parameters includes: When the test case parameter is an IP address, determining that the test mode is a dual-machine test mode; Accordingly, determining a test control subject and a test execution subject according to the test mode includes: In the dual-machine test mode, the machine according to the IP address is used as the test execution subject; The receiving the test result returned by the test execution subject includes: Receive the test results forwarded by the test control subject.
4. The method according to claim 1, characterized in that: Determining the test mode according to the test case parameters includes: When the test case parameter is a ZenTao test order ID, determining that the test mode is a ZenTao test mode; Correspondingly, the generation of the test execution command according to the test script path and the case ID includes: Use the ZenTao API to obtain relevant test case information based on the test order ID; Parse the data returned by ZenTao API and generate a list containing all relevant test case IDs; Traverse the test case ID list, find the automation project file corresponding to each case, and obtain its script path; Generate specific execution commands based on the obtained script path and use case ID.
5. The method according to claim 4, characterized in that The receiving the test result returned by the test execution subject includes: After the test execution entity completes the test case, the result data is transmitted back to the test control entity via the SSH protocol.
6. The method according to claim 5, wherein the receiving the test result returned by the test execution subject further comprises: The test control subject is used to call the result call update interface of the ZenTao test single case test according to the returned result data to update the execution result of the case.
7. The method according to claim 3 or 4, characterized in that: The using the test control subject to send the test execution command to the test execution subject comprises: The test control subject uses the paramiko module through the SSH protocol to send the generated execution command to the specified test execution subject.
8. The method according to claim 7, characterized in that The step of determining a test control subject and a test execution subject according to the test mode includes: Determining the test capability of each test execution subject according to the deployment information of the test execution subject; Determine the test execution subject according to the test capability and the test mode; Correspondingly, the using the test control subject to send the test execution command to the test execution subject includes: The test control subject is utilized to allocate corresponding test execution commands according to the test capability of each test execution subject, and the allocated test execution commands are sent to the corresponding test execution subjects.
9. A test case execution device based on separation of powers, characterized in that: include: A receiving module, used to receive the incoming test case parameters and determine the test mode according to the test case parameters; A determination module, used to determine a test control subject and a test execution subject according to the test mode; The generation module is used to generate the test execution command according to the test script path and the case ID; A sending module, used for sending the test execution command to the test execution subject by using the test control subject; The test result receiving module is used to receive the test result returned by the test execution entity.
10. A storage medium containing computer executable instructions, characterized in that: The computer executable instructions are used to execute the test case execution method based on separation of powers as described in any one of claims 1 to 8 when executed by a computer processor.