A kind of integration test method based on Docker and system
Technical field
The present invention relates to field of computer technology, particularly based on integration test method and the system of Docker.
Background technology
Docker is an application container engine of increasing income, a lightweight, transplantable, self-centered container can be created easily for any application, allow developer can pack they application and rely on bag in a transplantable container, container uses sandbox mechanism completely, do not have any interface each other, almost there is no performance cost, can run in machine and data center easily.Developer can use the mirror image of a standard to build a set of exploitation container, and after having developed, operation maintenance personnel can directly use this container to dispose code.The start-up time of Docker container is level second, saves the time of exploitation, test, deployment in large quantities.
In the exploitation of cloud computing software, the service relating to exploitation is various and complicated, as network service, and stores service, all kinds of service such as virtualization services, be compare the key link in the later stage of exploitation as integration testing, in the link of integration testing, all kinds of cloud service will be deployed in different physical machine nodes or virtual machine node, account for many machine resources, therefore development efficiency is lower, and workload is large, and cost is higher.
Summary of the invention
The invention provides a kind of integration test method based on Docker and system, be intended to solve integration testing in existing cloud computing software development and take machine resources greatly, development efficiency is low, the problem that workload is large.
First aspect, the invention provides a kind of integration test method based on Docker, and described method comprises:
Adopt the integration mode of Docker container, by integration testing deployment of components inside Docker, form the integration testing environment of Docker;
Utilize script command line menu, call by RPC remote procedure call protocol the test that described integration testing assembly completes difference in functionality module.
Further, the integration mode of described employing Docker container, by integration testing deployment of components inside Docker, form Docker integration testing environment and specifically comprise: integration testing assembly and script, establishment Docker integration testing environment are provided and configure the integration testing environment of described Docker;
Described integration testing assembly and the script of providing specifically comprises: provide all component needed for integration testing and associated script, and offers the service of RPC remote procedure call protocol to described assembly;
Described establishment Docker integration testing environment specifically comprises: the first virtual machine is as the privately owned warehouse of Docker, second virtual machine is as Docker host, then Dockerfile rule is used to build the Docker mirror image of described integration testing assembly, described Docker mirror image is saved in the privately owned warehouse of described Docker, described Docker host downloads described Docker mirror image from the privately owned warehouse of described Docker, and the Docker container run based on described Docker mirror image, the integration testing environment of a set of Docker is made up of described Docker container;
Described configuration Docker integration testing environment specifically comprises: configure Docker container described in each, and be communicated with the communication of network between each Docker container, to guarantee the Docker container being called service end by the Docker of client.
Further, described associated script comprises: generate command menu and provide the script of RPC basic function, SQL script, data script and the script for various functional module.
Further, described two Docker hosts are divided into: a host runs main Docker test environment, and another host runs secondary Docker test environment.
Further, the integration mode of described employing Docker container, by integration testing deployment of components inside Docker, forms Docker integration testing environment, also comprises afterwards: increase Docker integration testing environment newly and/or copy Docker integration testing environment.
On the basis of above-mentioned steps, further, described newly-increased Docker integration testing environment specifically comprises: build a newly-increased Docker host; From the privately owned warehouse of described Docker, download described Docker mirror image, be placed in described newly-increased Docker host; The Docker container run based on described Docker mirror image forms Docker test environment.
Further, copy Docker integration testing environment described in comprise: build a newly-increased Docker host; The Docker container of Docker integration testing environment is derived tar structured file, and mobile described tar structured file is in described newly-increased Docker host; Importing described tar structured file is assembly mirror image, and the Docker container run based on described assembly mirror image forms Docker integration testing environment.
Preferably, the integration testing environment generation of described Docker upgrades automatically.
Further, describedly utilize script command line menu, the test that described integration testing assembly completes difference in functionality module is called by RPC remote procedure call protocol, be specially: recall command menu by associated script, select described command menu to the functional module in requisition for test, the submenu entering described command menu carries out correlation function test.
Second aspect, the present invention also provides a kind of integrated test system based on Docker, and described system comprises storer and processor, it is characterized in that, described processor is used for:
Adopt the integration mode of Docker container, by integration testing deployment of components inside Docker, form the integration testing environment of Docker;
Utilize script command line menu, call by RPC remote procedure call protocol the test that described integration testing assembly completes difference in functionality module.
Beneficial effect: the integration mode that have employed Docker container, by integration testing deployment of components inside Docker, form the integration testing environment of Docker, utilize script command line menu, described integration testing assembly is called to complete the test of difference in functionality module by RPC (RemoteProcedureCallProtocol, remote procedure call protocol).Because Docker container only occupies little CPU and the overhead of internal memory, toggle speed is fast, performance is close to the performance of primary system, and can in a physical machine or the multiple container of virtual machine deploy and performance is unaffected, this will greatly facilitate development phase integration testing and saves the hardware cost of test, this mode is well suited for promoting and is used as the exploitation of all departments of intra-company or the test environment of test organization, and can conveniently share in intra-company due to Docker mirror image, light realization migration and expansion, can fast based on the container of Docker mirror image operating component.
Accompanying drawing explanation
Fig. 1 is the integration test method process flow diagram based on Docker that the embodiment of the present invention provides;
The establishment Docker integration testing Environment Design figure that Fig. 2 embodiment of the present invention provides;
The newly-increased Docker integration testing Environment Design figure that Fig. 3 embodiment of the present invention provides;
What Fig. 4 embodiment of the present invention provided copies Docker integration testing Environment Design figure;
Docker integration testing figure is carried out in being called by script that Fig. 5 embodiment of the present invention provides;
The integrated test system based on Docker that Fig. 6 embodiment of the present invention provides.
Embodiment
In order to make object of the present invention, technical scheme and advantage clearly understand, below in conjunction with drawings and Examples, the present invention is further elaborated.
Fig. 1 shows the integration test method process flow diagram based on Docker that the embodiment of the present invention provides, and for convenience of explanation, illustrate only the part relevant to the embodiment of the present invention, as shown in Figure 1, the method comprises the following steps:
The integration mode of step 101, employing Docker container, by integration testing deployment of components inside Docker, forms Docker integration testing environment.
In this step, mainly utilize Docker feature, by integration testing deployment of components in Docker, comprise three parts particularly, be respectively: integration testing assembly and script, establishment Docker integration testing environment are provided and configure the integration testing environment of described Docker; In the process of disposing, first prepare required integration testing assembly and script, integration testing assembly refers to the whole software systems needing to do integration testing; Script comprises generation command menu script, provides the script of RPC basic function, SQL script, data script and the script for various functional module, and different scripts plays different functions.
Fig. 2 shows sets up Docker integration testing Environment Design process, set up Docker integration testing environment to be specially, first virtual machine is as the privately owned warehouse 20 of Docker, second virtual machine and the 3rd virtual machine are as Docker host, as Docker host 21 in Fig. 2 and Docker host 22, then Dockerfile rule is used to build the Docker mirror image 201 of integration testing assembly, Docker mirror image 201 comprises the mirror image of a lot of test suite, same components mirror image also has different versions, such as: mirror image 201 comprises multiple mirror image Image, corresponding different mirror image Image1, Image2 and Image3, wherein there are again a lot of versions in mirror image Image1, corresponding v1.0.0, v1.0.1 and v1.0.2, Docker mirror image 201 is saved in the privately owned warehouse 20 of described Docker, Docker host 21 or Docker host 22 download described Docker mirror image 201 from the privately owned warehouse of Docker 20, generate Docker mirror image 211 and the Docker mirror image 221 of host 21 or host 21, and the Docker container 212 run based on Docker mirror image 211, Docker container 212 comprises multiple container container (container1, container2, container3 ,), the corresponding mirror image of each container, or the Docker container 222 run based on Docker mirror image 221, is made up of the integration testing environment of a set of Docker, is called main Docker test environment Docker container 212, be made up of the integration testing environment of a set of Docker Docker container 222, be called secondary Docker test environment, the image release of initial main Docker test environment and assembly in secondary Docker test environment is number identical, main Docker test environment is used for the test in current software version performance history, use in secondary Docker test environment one in releasing software version assembly mirror image create container, composition test environment, Docker deposits in privately owned warehouse the mirror image of assembly in all versions of releasing software.
In addition, in order to increase test, the function of production environment and processing power of trooping, also comprise newly-increased Docker integration testing environment and copy Docker integration testing environment in this step.Increase Docker integration testing Environment Design newly as shown in Figure 3, when needing, for developer configures a set of new Docker integration testing environment, to build a newly-increased Docker host 31; From the privately owned warehouse 30 of Docker, download the test suite mirror image of Docker mirror image 301, Docker mirror image 301 version needed for test environment, be placed in newly-increased Docker host 31; By Docker-compose or manual run Docker container 312 based on Docker mirror image 311 and form Docker integration testing environment, very convenient for the environment starting the combination of multiple assembly.
Copy Docker integration testing Environment Design as shown in Figure 4, when needs for a set of already present test environment opens a Tiao Xin branch for integration testing, a newly-increased Docker host 42 can be built; Use Dockerexport order to export as tar structured file 401 in the Docker container 412 of Docker integration testing environment, mobile tar structured file 401 is in newly-increased Docker host 42; Host 42 use Dockerimport order tar structured file 401 is imported as Docker mirror image 421, by Docker-compose or manually run Docker container 422 based on assembly mirror image 421 and form Docker integration testing environment, very convenient for the environment starting the combination of multiple assembly.
Finally, forming Docker integration testing environment and also there is automatic Reconfigurations, by starting a self-verifying service, code release up-to-date in development environment being synchronized in integration testing environment and Reconfigurations etc.
Step 102, utilize script command line menu, call by RPC remote procedure call protocol the test that described integration testing assembly completes difference in functionality module.
The service of assembly is undertaken calling access by IP address and port, Docker container can by port mapping the port of the port mapping of internal tank to main frame, it is realized by the iptables rule of amendment host, the host having installed Docker can create the virtual bridge of a Docker0 by name, and the self-defining Docker chain of meeting each generation one during nat and filter of iptables shows, can define an access host designated port as nat at Docker chain when making port mapping is the IP of container and the rule of internal port.Therefore, the mapped port of accessing host just can access the service of internal tank testing component.In addition, can by the assigned catalogue of the file directory of carry internal tank to host, amendment host assigned catalogue is equal to the file directory of amendment internal tank, the library file like this needed for updated components, and amendment configuration file etc. are very convenient.
In this step, the concrete operations of calling as shown in Figure 5, enter in the environment of client Docker, because script environment is all placed in this Docker, then find following script in Fig. 5 to start to call, and the script crossing ./skyhot.sh calls out command menu; The test master menu that the command calls of ground floor goes out has 8, and wherein 1-7 item is test different functional module, the 8th menu that is used to exit command; When we will test one of them function, as tested a public network administration module (functional module PublicIPtesting in product, correspondence 2), we only need to input 2 in the order line of master menu and carriage return just can enter into the submenu (PublicIPtesting) testing public network administration module; In current submenu, have 12 Submenu Itemses, the 1st is return master menu, and remaining 11 Submenu Itemses are the correlation functions testing public network administration module respectively.
As can be seen from operation interface above and example explanation, the operation of whole integration testing is very simple in fact, the function package of a large amount of complexity is got up, when testing, only need input menu item numbering in command menu just passable, the work of the test greatly simplified.
Second aspect, corresponding to the method, present invention also offers a kind of integrated test system based on Docker, this system comprises storer 601 and processor 602, processor 602 is for the integration mode that adopts Docker container, by integration testing deployment of components inside Docker, form Docker integration testing environment; Utilize script command line menu, call by RPC remote procedure call protocol the test that described integration testing assembly completes difference in functionality module.
The integration test method based on Docker in system in the present embodiment and previous embodiment is based on the aspect of two under same inventive concept, detailed description is done to method implementation process above, so those skilled in the art can according to the structure of the aforementioned system understood with being described clearly in this enforcement and implementation process, succinct in order to instructions, just repeats no more at this.
The foregoing is only preferred embodiment of the present invention, not in order to limit the present invention, all any amendments done within the spirit and principles in the present invention, equivalent replacement and improvement etc., all should be included within protection scope of the present invention.