Method, device, electronic equipment and storage medium for testing virtual machine image
By automatically creating virtual machines and executing compatibility test commands, the problem of excessive manpower consumption in manual testing of virtual machine images is solved, thus realizing automated testing of virtual machine images.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
- Filing Date
- 2024-12-12
- Publication Date
- 2026-06-12
AI Technical Summary
In existing technologies, virtual machine image testing requires manual completion, resulting in a significant waste of human resources.
By reading the test configuration file, the system automatically creates virtual machines and executes compatibility test commands to generate compatibility test results, thus achieving automated testing of virtual machine images.
Automated testing of virtual machine images can be achieved without manual intervention, reducing the consumption of human resources.
Smart Images

Figure CN122195573A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, electronic device, and storage medium for testing virtual machine images. Background Technology
[0002] As various manufacturers' self-developed operating systems gradually improve and the pace of CPU (Central Processing Unit) chip updates accelerates significantly, the development of new machine models is becoming increasingly frequent. During iterative development, new operating system architectures need to be introduced as a second technology stack. To ensure product quality, compatibility testing of all currently online virtual machine images is required during the R&D self-testing phase. This ensures that the virtual machine images can function correctly on different platforms and environments, improving software quality and reliability, and avoiding potential vulnerabilities and malfunctions that could negatively impact user experience.
[0003] Currently, there are dozens of virtual machine images to be tested. In related technologies, the testing of virtual machine images still needs to be done manually. The manual testing process is tedious and highly repetitive, thus requiring a huge amount of human resources. Summary of the Invention
[0004] In view of this, in order to solve the technical problem of the large amount of human resources required for manual testing of virtual machine images in the prior art, this application provides a method, apparatus, electronic device and storage medium for testing virtual machine images.
[0005] In a first aspect, embodiments of this application provide a method for testing a virtual machine image, the method comprising:
[0006] Upon receiving an image test command, the test configuration file is read from the specified directory; wherein, the test configuration file includes virtual machine configuration information, a compatibility test command set, and at least one image information;
[0007] For each of the at least one image information, the following process is performed: obtain the number of virtual machine tests from the image information;
[0008] If the number of virtual machine tests is not a preset number, virtual machines are created based on the virtual machine configuration information and the image information; wherein, the number of virtual machines is the same as the number of virtual machine tests.
[0009] The virtual machine is used to execute compatibility test commands from the compatibility test command set to generate compatibility test results for the image information.
[0010] Optionally, as described above, creating a virtual machine based on the virtual machine configuration information and the image information includes:
[0011] Obtain the image download address from the image information;
[0012] Download the baseline image file from the aforementioned image download address:
[0013] Obtain the virtual machine XML template;
[0014] A virtual machine is created based on the baseline image file, the virtual machine configuration information, and the virtual machine XML template.
[0015] Optionally, as described above, creating a virtual machine based on the baseline image file, the virtual machine configuration information, and the virtual machine XML template includes:
[0016] A backup image file is created based on the baseline image file; wherein the number of backup image files is the same as the number of virtual machine tests.
[0017] Store the backup image file in the directory file of the specified virtual machine storage path;
[0018] Write the specified virtual machine storage path directory file and the virtual machine configuration information into the virtual machine XML template to obtain a virtual machine XML file;
[0019] A virtual machine is created based on the virtual machine XML file.
[0020] Optionally, as described above, the compatibility test command set includes multiple sub-compatibility test command sets corresponding to different operating systems, each sub-compatibility test command set includes multiple compatibility test commands with different compatibility test contents, and each sub-compatibility test command set corresponds to operating system identification information;
[0021] The step of generating compatibility test results for the image information by executing compatibility test commands from the compatibility test command set using the virtual machine includes:
[0022] Obtain operating system identification information and virtual machine login information from the image information;
[0023] The target sub-compatibility test command set is determined from the compatibility test command set based on the operating system identification information;
[0024] Log in to the virtual machine according to the virtual machine login information;
[0025] Determine whether the number of virtual machine tests is multiple:
[0026] If it is determined that there are multiple virtual machines to be tested, each of the compatibility test commands in the target sub-compatibility test command set is executed by each of the logged-in virtual machines to generate multiple compatibility test results for the image information;
[0027] If it is determined that the number of virtual machine tests is not multiple, the virtual machine after login executes each compatibility test command in the target sub-compatibility test command set to generate a compatibility test result for the image information.
[0028] Optionally, as described above, the method further includes:
[0029] The compatibility test results are written to the virtual machine runtime log; wherein, the compatibility test results include the execution information and compatibility status corresponding to each compatibility test command, the execution information is the execution result obtained by the virtual machine executing the compatibility test command, and the compatibility status is the result obtained by analyzing the execution information to indicate whether the virtual machine is compatible with the compatibility test command.
[0030] Optionally, as described above, the method further includes:
[0031] Obtain the virtual machine's runtime logs;
[0032] Extract the compatibility test results corresponding to the image information from the virtual machine runtime log, including the various compatibility test states and the real-time running status of the virtual machine;
[0033] In the case of multiple compatibility test results, the compatibility of the virtual machine image corresponding to the image information is determined based on the real-time running status and the compatibility status included in each of the compatibility test results.
[0034] If there is only one compatibility test result, the virtual machine image corresponding to the image information is determined to be compatible based on the real-time running status and each compatibility status included in the compatibility test result.
[0035] Optionally, as described above, determining whether the virtual machine image corresponding to the image information is compatible based on the real-time running status and the various compatibility states included in the various compatibility test results includes:
[0036] When the real-time running state is not a preset fault running state, and at least one of the compatibility test results includes each of the compatibility states as a compatibility pass state, the virtual machine image corresponding to the image information is determined to be compatible.
[0037] If the real-time running state is a preset fault running state and / or at least one of the compatibility states included in each of the compatibility test results is not a compatibility pass state, then the virtual machine image corresponding to the image information is determined to be incompatible.
[0038] Optionally, as described above, determining whether the virtual machine image corresponding to the image information is compatible based on the real-time running status and each of the compatibility states included in the compatibility test results includes:
[0039] When the real-time running state is not a preset fault running state, and all of the compatibility states are compatibility passed states, the virtual machine image corresponding to the image information is determined to be compatible.
[0040] When the real-time running state is a preset fault running state and / or at least one of the compatibility states is not a compatibility pass state, it is determined that the virtual machine image corresponding to the image information is incompatible.
[0041] Optionally, as described above, the method further includes:
[0042] When the virtual machine corresponding to the image information is detected to have completed the compatibility test, the baseline image file is deleted.
[0043] Secondly, embodiments of this application provide an apparatus for testing virtual machine images, the apparatus comprising:
[0044] The reading module is used to read the test configuration file from a specified directory when an image test command is received; wherein, the test configuration file includes virtual machine configuration information, a compatibility test command set, and at least one image information;
[0045] The acquisition module is configured to perform the following processing for each of the at least one image information: acquire the number of virtual machine tests from the image information;
[0046] A creation module is used to create virtual machines based on the virtual machine configuration information and the image information when the number of virtual machine tests is not a preset number; wherein the number of virtual machines is the same as the number of virtual machine tests.
[0047] The compatibility testing module is used to execute compatibility testing commands from the compatibility testing command set using the virtual machine to generate compatibility testing results for the image information.
[0048] Thirdly, embodiments of this application provide an electronic device, comprising: a processor and a memory, wherein the processor is configured to execute a program for testing a virtual machine image stored in the memory, so as to implement the above-described method for testing a virtual machine image.
[0049] Fourthly, embodiments of this application provide a storage medium that stores one or more programs, which can be executed by one or more processors to implement the above-described method for testing virtual machine images.
[0050] In this embodiment of the invention, upon receiving an image test command, a test configuration file is read from a specified directory. The test configuration file includes virtual machine configuration information, a compatibility test command set, and at least one image information. For each image information, the following processing is performed: the number of virtual machines to be tested is obtained from the image information; if the number of virtual machines to be tested is not a preset number, a virtual machine is created based on the virtual machine configuration information and the image information; and the virtual machine is used to execute compatibility test commands from the compatibility test command set to generate compatibility test results for the image information. This technical solution automatically creates the virtual machine corresponding to the image information using only the image information and virtual machine configuration information in the test configuration file, and uses the virtual machine to execute the adapted compatibility test commands. Automated testing of virtual machine images can be achieved without manual intervention. Compared to existing technologies that require manual testing of virtual machine images, this effectively overcomes the technical problem of consuming a large amount of human resources due to the need for manual testing of virtual machine images in existing technologies. Attached Figure Description
[0051] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0052] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0053] Figure 1 A flowchart illustrating an embodiment of a method for testing a virtual machine image provided in this application;
[0054] Figure 2 A flowchart illustrating an embodiment of another method for testing virtual machine images provided in this application;
[0055] Figure 3 A flowchart illustrating an embodiment of another method for testing virtual machine images provided in this application;
[0056] Figure 4 A flowchart illustrating an embodiment of another method for testing virtual machine images provided in this application;
[0057] Figure 5 A flowchart illustrating an embodiment of another method for testing virtual machine images provided in this application;
[0058] Figure 6 A block diagram illustrating an embodiment of a device for testing virtual machine images provided in this application.
[0059] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0060] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0061] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0062] To facilitate understanding of the embodiments of this application, the following will provide further explanation and description with reference to the accompanying drawings and specific embodiments. These embodiments do not constitute a limitation on the embodiments of this application.
[0063] According to one aspect of the embodiments of this application, a method for testing virtual machine images is provided. Optionally, in this embodiment, the above-described method for testing virtual machine images can be implemented by a physical machine that has a complete virtualization environment and can operate virtual machines using open-source software such as qemu (Quick Emulator) and libvirt (library virtualization library).
[0064] Based on the above description Figure 1A method for testing a virtual machine image, provided in this application embodiment and applied to the aforementioned physical machine, includes the following steps:
[0065] Step 101: Upon receiving the image test instruction, read the test configuration file from the specified directory;
[0066] When a physical machine adopts a new CPU or a new operating system, it is necessary to test whether there are any incompatibility issues among the various virtual machine images. In this case, it is necessary to input image test commands into the physical machine so that the physical machine can automatically test the virtual machine images.
[0067] The aforementioned test configuration file can be understood as a test-related information configuration for virtual machine image testing. This configuration file includes virtual machine configuration information, a compatibility test command set, and at least one image information. The virtual machine configuration information includes configurable information other than the virtual machine XML (Extensible Markup Language) template hard-coded in the source code, such as the number of CPUs, memory size, network card queue count, instruction set information, and image address. The aforementioned compatibility test command set is a collection of all compatibility test commands, including multiple compatibility test commands that need to perform different compatibility tests on the virtual machine image. The image information includes information about the virtual machine image, such as the image download address, virtual machine login information, number of virtual machines tested, and operating system identification information, which will be described below without further detail.
[0068] In practical applications, the virtual machine configuration information, compatibility test command set, and image information in the test configuration file can all be configured according to actual needs, greatly improving the flexibility of virtual machine image testing.
[0069] As described above, since the test configuration file is pre-written and configured, it needs to be stored in a specified directory on the physical machine before performing virtual machine image testing. This specified directory can be any disk directory on the physical machine, and there is no restriction here. Therefore, when performing virtual machine image testing on the physical machine, the test configuration file needs to be read from the specified directory to facilitate automatic testing of the virtual machine image.
[0070] Step 102: For each image in at least one image, perform the following processing: obtain the number of virtual machines tested from the image;
[0071] The number of virtual machine tests is used to represent the number of virtual machines required to perform virtual machine image testing. If the number of virtual machine tests is 1, it means that one virtual machine is started under this image information to test the virtual machine image. If the number of virtual machine tests is 2, it means that two virtual machines are started under this image information to test the virtual machine image. In special cases, if the number of virtual machine tests is less than 1, it means that the virtual machine image corresponding to this image information does not need to be tested, and the number of virtual machine tests in the next image information is directly obtained.
[0072] Step 103: If the number of virtual machine tests is not the preset number, create virtual machines based on the virtual machine configuration information and image information; wherein, the number of virtual machines is the same as the number of virtual machine tests.
[0073] If the preset number is less than 1, then if the number of virtual machines tested is not less than 1, it means that at least one virtual machine will be started under this image information to test the virtual machine image. Therefore, it is necessary to create the same number of virtual machines as the number of virtual machines tested.
[0074] Step 104: Use the virtual machine to execute the compatibility test commands in the compatibility test command set to generate compatibility test results for the image information.
[0075] It should be noted that if there are multiple virtual machines, compatibility test results will be generated for each virtual machine. For example, if there are two virtual machines created under the image information, executing the compatibility test command set for each virtual machine will generate a compatibility test result for the image information. Thus, two compatibility test results will be obtained for the image information. These compatibility test results can be used to explain whether the virtual machine image corresponding to the image information is compatible. That is, the compatibility test results can be used to analyze whether the virtual machine image corresponding to the image information can work normally on a physical machine that uses a new CPU or a new operating system.
[0076] The method in this embodiment can automatically create a virtual machine corresponding to the image information using only the image information and virtual machine configuration information in the test configuration file, and use the virtual machine to execute the adapted compatibility test commands. Automated testing of virtual machine images can be achieved without manual intervention. Compared with the existing technology, which requires manual testing of virtual machine images, this method effectively overcomes the technical problem of consuming a lot of human resources due to the need for manual testing of virtual machine images in the existing technology.
[0077] like Figure 2 As shown, as an optional implementation, the method described above, step 103 of creating a virtual machine based on virtual machine configuration information and image information includes the following steps:
[0078] Step 201: Obtain the image download address from the image information;
[0079] In practical applications, virtual machine images correspond to different operating systems. Therefore, the image information corresponding to each virtual machine image can be classified according to the different operating systems. For example, all virtual machine images corresponding to CentOS (Community Enterprise Operating System) 6 can be grouped into one category, all virtual machine images corresponding to CentOS 7 can be grouped into one category, and all virtual machine images corresponding to Ubuntu can be grouped into one category. These will not be elaborated on here.
[0080] It's important to note that different image information sets within the same operating system correspond to different system versions; there's a one-to-one correspondence between each image information set and each system version. Therefore, the image download addresses included in the image information sets within the same operating system will also be different. The image download address mentioned above indicates the address of the server where the virtual machine image file is located. For ease of understanding, for example, the CentOS 6 operating system includes CentOS 6.5_x86_64, CentOS 6.6_x86_64, and CentOS 6.7_x86_64 system versions. The image download address for the CentOS 6.5_x86_64 system version image information would be something like: "http: / / ce The image download address in the CentOS 6.6 x86 64 system image information is like "http: / / centos / 6.6 / x86_64 / img.base"; the image download address in the CentOS 6.7 x86 64 system image information is like "http: / / centos / 6.7 / x86_64 / img.base"; these are just examples, and the image download addresses in the image information can be any link set up by technical personnel, as long as the link can download the image file from the corresponding server. There are no restrictions on the image download address here.
[0081] In summary, the image download addresses included in different image information are different, so as to download the image file corresponding to the image download address to the local physical machine on different servers.
[0082] Step 202: Download the baseline image file from the image download address:
[0083] The base image file refers to the original base image file downloaded from the image download address. The base image file is an initial copy of the operating system, applications and their configurations. It is the environment used to create a virtual machine. It contains the complete operating system installer, drivers, file system and other necessary components, which are required to run a virtual machine.
[0084] Step 203: Obtain the virtual machine XML template;
[0085] A virtual machine XML template is a configuration file that uses XML format to describe a virtual machine. In this embodiment, this template file includes various configuration information for the virtual machine, excluding virtual machine configuration information and information about the base image file. Since the aforementioned virtual machine XML template is hardcoded into a specified source code on the physical machine, it can be obtained from the specified source code.
[0086] Step 204: Create a virtual machine based on the baseline image file, virtual machine configuration information, and virtual machine XML template.
[0087] Using the method in this embodiment, virtual machines of the same number as the number of virtual machines to be tested can be created based on the downloaded baseline image file, the virtual machine configuration information in the test configuration file, and the obtained virtual machine XML template, so as to perform automatic testing of virtual machine images.
[0088] In optional embodiments of this application, such as Figure 3 As shown in the aforementioned method, step 204, creating a virtual machine based on the baseline image file, virtual machine configuration information, and virtual machine XML template, includes the following steps:
[0089] Step 301: Create backup image files based on the baseline image file; wherein the number of backup image files is the same as the number of virtual machine tests;
[0090] Typically, a backup image file is an identical copy created based on a base image file. Its main purpose is to back up and restore data. By creating a backup image file, data can be quickly restored when the base image file is corrupted or needs to be restored to a specific state. In this embodiment, qemu-img create can be used to create a backup image file with the same number of virtual machines as the number of virtual machines to be tested, so as to use the backup image file to create virtual machines with the same number of virtual machines to be tested for automatic testing of virtual machine images.
[0091] Using backup image files for virtual machine creation is advantageous for two reasons. First, a base image file can be as large as 20GB, and saving multiple base image files simultaneously could lead to insufficient storage space on the physical machine. However, using backup image files only requires retaining the modified parts, thus requiring less storage space. Second, backup image files contain the complete state of the virtual machine, including the operating system, applications, and all configurations. This makes virtual machine creation faster and more convenient. In contrast, base image files typically only contain the initial installation state of the operating system, lacking subsequent configurations and application installations, making them less flexible in use than backup image files.
[0092] Step 302: Store the backup image file in the directory file of the specified virtual machine storage path;
[0093] The backup image file is stored in a directory file specified by the virtual machine storage path. It should be noted that when multiple backup image files are created for the same image information, each backup image file is stored in a different directory file specified by the virtual machine storage path to facilitate differentiation and storage.
[0094] Step 303: Write the specified virtual machine storage path directory file and virtual machine configuration information into the virtual machine XML template to obtain the virtual machine XML file;
[0095] The virtual machine XML template does not include information such as the specified virtual machine storage path directory file and virtual machine configuration information. In order to obtain a complete virtual machine XML file, the specified virtual machine storage path directory file and virtual machine configuration information need to be written into the corresponding positions in the virtual machine XML template. This is so that after the specified virtual machine storage path directory file is written into the virtual machine XML template, it can be clearly identified that the virtual machine was created based on the backup image file. After the virtual machine configuration information is written into the XML template, it can be clearly identified that the virtual machine is of what specification it is.
[0096] Step 304: Create a virtual machine based on the virtual machine XML file.
[0097] In practical applications, the libvirtd service's `virsh define XX.xml` directive can be used to create virtual machines. To ensure that the virtual machine can be tested with compatibility test commands, it is also necessary to use the `virsh start XX` directive after creating the virtual machine to start it and make it usable.
[0098] Since the virtual machine is created based on the backup image file, in order to save the storage space of the physical machine, when the virtual machine corresponding to the image information has completed the compatibility test, the base image file is deleted. If the physical machine adopts a new CPU or a new operating system and needs to re-perform the virtual machine image compatibility test, the base image file needs to be downloaded again through the image download address in the image information to create the virtual machine in steps 301 to 304.
[0099] The method in this embodiment enables the rapid creation of virtual machines using backup image files, thereby saving the overall testing time for virtual machine image testing.
[0100] As an optional implementation, the compatibility test command set includes multiple sub-compatibility test command sets corresponding to different operating systems. Each sub-compatibility test command set includes multiple compatibility test commands with different compatibility test contents, and each sub-compatibility test command set corresponds to operating system identification information.
[0101] The compatibility test commands for different compatibility test contents included in each sub-compatibility test command set are the same. This can be understood as follows: since the operating systems corresponding to each sub-compatibility test command set are different, the compatibility test commands with the same compatibility test contents in each sub-compatibility test command set corresponding to different operating systems are only different in code form.
[0102] For example, the sub-compatibility test command set for CentOS 6 includes compatibility test commands for different compatibility test content, such as whether the virtual machine can start normally, whether instruction set support is complete, whether the operating system can be used normally, whether network functions are normal, and whether disk read / write is normal. Similarly, the sub-compatibility test command sets for CentOS 7, Ubuntu, and OpenEuler all include compatibility test commands for different compatibility test content, only differing in code format. To facilitate differentiation between the various sub-compatibility test command sets, the operating system identification information can be used to distinguish between them. In practice, the operating system identification information can be represented by numbers, characters, or letters corresponding to the operating system; no specific restrictions are imposed here.
[0103] In this embodiment, when testing virtual machine images of different operating systems corresponding to the image information, the same compatibility test command with the same code format as that operating system must be used; otherwise, the created virtual machine cannot run compatibility test commands with different code formats corresponding to other operating systems. Based on the above description, as follows... Figure 4 As shown, as an optional implementation, the method described above, step 104, which uses a virtual machine to execute compatibility test commands from the compatibility test command set to generate compatibility test results for the image information, includes the following steps:
[0104] Step 401: Obtain operating system identification information and virtual machine login information from the image information;
[0105] The operating system identification information obtained from the image information is the operating system identification information described above, which is used to annotate each sub-compatibility test command set. The purpose of obtaining the operating system identification information from the image information is to determine which sub-compatibility test command set is used to automatically test the virtual machine image created by the image information.
[0106] The virtual machine login information includes the username and / or password of the virtual machine created under this image information, so that the virtual machine can be logged into and the virtual machine can perform remote compatibility test command execution.
[0107] Step 402: Determine the target sub-compatibility test command set from the compatibility test command set based on the operating system identification information;
[0108] The operating system identifier information obtained from the image information is compared one by one with the operating system identifier information corresponding to each sub-compatibility test command set. The sub-compatibility test command set corresponding to the matching operating system identifier is determined as the target sub-compatibility test command set, so that the virtual machine can execute each compatibility test command included in the target sub-compatibility test command set.
[0109] Step 403: Log in to the virtual machine based on the virtual machine login information;
[0110] Step 404: Determine if there are multiple virtual machines being tested.
[0111] If it is determined that there are multiple virtual machines being tested, proceed to step 405; if it is determined that there are not multiple virtual machines being tested, proceed to step 406.
[0112] Step 405: Execute each compatibility test command in the target sub-compatibility test command set on each logged-in virtual machine to generate multiple compatibility test results for the image information;
[0113] Step 406: Execute each compatibility test command in the target sub-compatibility test command set using the logged-in virtual machine to generate a compatibility test result for the image information.
[0114] This can be understood as follows: if several virtual machines are created under this image information, each virtual machine needs to execute each compatibility test command in the same target sub-compatibility test command set to obtain the compatibility test results of each virtual machine for the image information. For example, if two virtual machines are created under this image information, then two compatibility test results will be obtained for this image information, that is, one compatibility test result is generated for each virtual machine.
[0115] The method in this embodiment integrates compatibility testing commands for different operating systems to support testing virtual machine images of different operating systems.
[0116] This application provides another method for testing virtual machine images. Figure 1 Based on the above, see Figure 5 , Figure 5 A flowchart illustrating an embodiment of another method for testing virtual machine images provided in this application. Figure 5 The process shown may include the following steps:
[0117] Step 501: Upon receiving the image test instruction, read the test configuration file from the specified directory; wherein the test configuration file includes virtual machine configuration information, a compatibility test command set, and at least one image information;
[0118] Step 502: For each image in at least one image, perform the following processing: obtain the number of virtual machine tests from the image information;
[0119] Step 503: If the number of virtual machine tests is not the preset number, create virtual machines based on the virtual machine configuration information and image information; wherein, the number of virtual machines is the same as the number of virtual machine tests.
[0120] Step 504: Execute compatibility test commands from the compatibility test command set using the virtual machine to generate compatibility test results for the image information;
[0121] Specifically, the implementation process of steps 501 to 504 in this embodiment of the invention is the same as that of steps 101 to 104. For details, please refer to the following: Figure 1 The relevant descriptions in the Chinese method embodiments will not be repeated here.
[0122] Step 505: Write the compatibility test results into the virtual machine runtime log;
[0123] The compatibility test results include the execution information and compatibility status of each compatibility test command. The execution information is the execution result obtained by the virtual machine executing the compatibility test command, and the compatibility status is the result obtained by analyzing the execution information to indicate whether the virtual machine is compatible with the compatibility test command.
[0124] Each compatibility test command corresponds to an execution message and a compatibility status. Therefore, the number of execution messages and compatibility statuses corresponds to the number of compatibility test commands executed by the virtual machine. It can be understood that there is a one-to-one correspondence between compatibility test commands, execution messages, and compatibility statuses.
[0125] The execution information can be understood as the internal reaction of the virtual machine after executing the compatibility test command. The compatibility status is the result given by the physical machine after analyzing and judging the execution information. There are two compatibility statuses: compatibility passed and compatibility failed. The compatibility passed status indicates that there is no compatibility problem when the virtual machine executes the compatibility test command, and the compatibility failed status indicates that there is no compatibility problem when the virtual machine executes the compatibility test command.
[0126] To facilitate understanding, let's take the ifconfig compatibility test command as an example. When ifconfig is executed on a virtual machine, it displays network card information. The physical machine analyzes this information. If it determines that the displayed network card information contains IP (Internet Protocol) information, the compatibility test command is considered to have passed compatibility. If it determines that the displayed network card information does not contain IP (Internet Protocol) information, the compatibility test command is considered to have failed compatibility.
[0127] Step 506: Obtain the virtual machine runtime log;
[0128] Virtual machine runtime logs are typically located in the virtual machine's system log files. These files are usually stored in the default or custom paths of the virtual machine management software. Therefore, virtual machine runtime logs can be obtained from the default or custom paths of the virtual machine management software.
[0129] Step 507: Extract the compatibility test results corresponding to the image information from the virtual machine runtime log, including the various compatibility test states and the real-time running status of the virtual machine;
[0130] The real-time running status of a virtual machine indicates whether the virtual machine is experiencing lag, crashes, or printing errors during runtime. The virtual machine's running log records the real-time running status of the virtual machine when executing compatibility test commands.
[0131] Step 508: In the case of multiple compatibility test results, determine whether the virtual machine image corresponding to the image information is compatible based on the real-time running status and the compatibility status included in each compatibility test result.
[0132] If there are multiple compatibility test results, it means that multiple virtual machines were created under this image information. Therefore, the number of compatibility test results will be the number of virtual machines. Further, it is necessary to combine all the compatibility test results to determine whether the virtual machine image is compatible.
[0133] The specific process for determining virtual machine image compatibility is as follows: when the real-time running state is not a preset fault running state, and when at least one of the compatibility test results includes all compatibility states as passed, the virtual machine image corresponding to the image information is determined to be compatible.
[0134] A real-time running status that is not a preset fault running status means that the virtual machine does not experience any lag, crashes, or printing errors when running each compatibility test command in the target sub-compatibility test command set. Furthermore, if at least one compatibility test result contains all compatibility states that are considered to be in a compatibility pass state, then the virtual machine image and the physical machine are considered to be compatible. That is, if there are 3 compatibility test results, it is sufficient if the compatibility states corresponding to each compatibility test command in one compatibility test result are in a compatibility pass state. If the compatibility states corresponding to each compatibility test command in the other two compatibility test results are not in a compatibility pass state, then they are not considered.
[0135] The specific process for determining virtual machine image incompatibility is as follows: when the real-time running state is a preset fault running state and / or at least one of the compatibility states included in each compatibility test result is not a compatibility pass state, the virtual machine image corresponding to the image information is determined to be incompatible.
[0136] If the real-time running state is a preset fault running state, it means that the virtual machine experiences lag, crashes, or printing errors when running various compatibility test commands in the target sub-compatibility test command set, and is therefore considered incompatible with the physical machine. And / or, if in multiple compatibility test results, at least one compatibility state is not a compatibility pass state (i.e., a compatibility failure state), it is also determined that the virtual machine image corresponding to the image information is incompatible with the physical machine.
[0137] Step 509: If there is only one compatibility test result, determine whether the virtual machine image corresponding to the image information is compatible based on the real-time running status and the various compatibility states included in the compatibility test result.
[0138] If the compatibility test result is one, it means that a virtual machine has been created under this image information. Therefore, each virtual machine will generate a compatibility test result, and further, it is necessary to determine whether the virtual machine image is compatible based on this compatibility test result.
[0139] The specific process for determining virtual machine image compatibility is as follows: when the real-time running state is not a preset fault running state, and all compatibility states are in a compatibility pass state, the virtual machine image corresponding to the image information is determined to be compatible.
[0140] A real-time running status that is not a preset fault running status means that the virtual machine does not experience any lag, crashes, or printed errors when running any of the compatibility test commands in the target sub-compatibility test command set. Furthermore, if all compatibility states included in a compatibility test result are "compatibility passed," then the virtual machine image and the physical machine are considered compatible.
[0141] The specific process for determining virtual machine image incompatibility is as follows: when the real-time running state is a preset fault running state and / or at least one of the various compatibility states is not a compatibility pass state, the virtual machine image corresponding to the image information is determined to be incompatible.
[0142] A virtual machine image is considered incompatible with the physical machine if it is in a pre-defined fault running state during real-time operation, meaning that the virtual machine experiences lag, crashes, or print errors when running various compatibility test commands in the target sub-compatibility test command set. Alternatively, if at least one compatibility state in the compatibility test results is not a compatibility pass state (i.e., a compatibility failure state), the virtual machine image corresponding to the image information is also determined to be incompatible with the physical machine.
[0143] The method in this embodiment tests the compatibility of virtual machine images based on changes in the physical machine environment. It tests whether the virtual machine image has compatibility issues on the currently configured physical machine. It simulates user use of the functions in the virtual machine image by executing compatibility test commands on the created virtual machine. The compatibility test results and virtual machine operation logs are used to automatically detect whether the virtual machine image is compatible. This fully automatic virtual machine image testing method effectively overcomes the technical problem of consuming a lot of human resources due to the need for manual testing of virtual machine images in the prior art.
[0144] See Figure 6 This is a block diagram illustrating an embodiment of a virtual machine image testing apparatus provided in this application. Figure 6 As shown, the device includes:
[0145] The reading module 601 is used to read the test configuration file from the specified directory when the image test command is received; wherein the test configuration file includes virtual machine configuration information, compatibility test command set and at least one image information;
[0146] The acquisition module 602 is used to perform the following processing for each image information in at least one image information: obtain the number of virtual machine tests from the image information;
[0147] Module 603 is used to create virtual machines based on virtual machine configuration information and image information when the number of virtual machine tests is not the preset number; the number of virtual machines is the same as the number of virtual machine tests.
[0148] The compatibility test module 604 is used to generate compatibility test results for image information by executing compatibility test commands in the compatibility test command set using a virtual machine.
[0149] Specifically, the detailed process by which each module in the device of this invention implements its function can be found in the relevant description in the method embodiment, and will not be repeated here.
[0150] As an optional implementation, the above-mentioned creation module includes:
[0151] The first acquisition module is used to obtain the image download address from the image information;
[0152] The download module is used to download the base image file via the image download address:
[0153] The second acquisition module is used to acquire the virtual machine XML template;
[0154] The first creation module is used to create virtual machines based on the baseline image file, virtual machine configuration information, and virtual machine XML template.
[0155] Specifically, the detailed process by which each module in the device of this invention implements its function can be found in the relevant description in the method embodiment, and will not be repeated here.
[0156] As an optional implementation, the first creation module described above includes:
[0157] The second creation module is used to create backup image files based on the baseline image file; the number of backup image files is the same as the number of virtual machine tests.
[0158] The storage module is used to store the backup image file in the directory file of the specified virtual machine storage path;
[0159] The write module is used to write the specified virtual machine storage path directory file and virtual machine configuration information into the virtual machine XML template to obtain the virtual machine XML file;
[0160] The second creation module is used to create virtual machines based on virtual machine XML files.
[0161] Specifically, the detailed process by which each module in the device of this invention implements its function can be found in the relevant description in the method embodiment, and will not be repeated here.
[0162] As an optional implementation, the compatibility test command set includes multiple sub-compatibility test command sets corresponding to different operating systems. Each sub-compatibility test command set includes multiple compatibility test commands with different compatibility test contents, and each sub-compatibility test command set corresponds to operating system identification information.
[0163] The above compatibility testing modules include:
[0164] The third acquisition module is used to obtain operating system identification information and virtual machine login information from the image information;
[0165] The first determining module is used to determine the target sub-compatibility test command set from the compatibility test command set based on the operating system identification information;
[0166] The login module is used to log in to the virtual machine based on the virtual machine login information.
[0167] The determination module is used to determine whether there are multiple virtual machine tests:
[0168] The first generation module is used to generate multiple compatibility test results for the image information by executing each compatibility test command in the target sub-compatibility test command set on each logged-in virtual machine when the number of virtual machine tests is determined to be multiple.
[0169] The second generation module is used to generate a compatibility test result for the image information by executing various compatibility test commands in the target sub-compatibility test command set using the logged-in virtual machine when the number of virtual machine tests is not multiple.
[0170] Specifically, the detailed process by which each module in the device of this invention implements its function can be found in the relevant description in the method embodiment, and will not be repeated here.
[0171] As an optional implementation, the above-described apparatus further includes:
[0172] The result writing module is used to write the compatibility test results into the virtual machine runtime log. The compatibility test results include the execution information and compatibility status of each compatibility test command. The execution information is the execution result obtained by the virtual machine executing the compatibility test command, and the compatibility status is the result obtained by analyzing the execution information to indicate whether the virtual machine is compatible with the compatibility test command.
[0173] Specifically, the detailed process by which each module in the device of this invention implements its function can be found in the relevant description in the method embodiment, and will not be repeated here.
[0174] As an optional implementation, the above-described apparatus further includes:
[0175] The fourth acquisition module is used to acquire virtual machine runtime logs;
[0176] The extraction module is used to extract the compatibility test results corresponding to the image information from the virtual machine runtime log, including the various compatibility test states and the real-time running status of the virtual machine.
[0177] The first compatibility determination module is used to determine whether the virtual machine image corresponding to the image information is compatible based on the real-time running status and the compatibility status included in each compatibility test result when there are multiple compatibility test results.
[0178] The second compatibility determination module is used to determine whether the virtual machine image corresponding to the image information is compatible based on the real-time running status and the various compatibility states included in the compatibility test results when there is only one compatibility test result.
[0179] Specifically, the detailed process by which each module in the device of this invention implements its function can be found in the relevant description in the method embodiment, and will not be repeated here.
[0180] As an optional implementation, the first compatibility determination module includes:
[0181] The first compatibility determination module is used to determine the compatibility of the virtual machine image corresponding to the image information when the real-time running state is not a preset fault running state, and when at least one of the compatibility test results includes a compatibility pass state for each compatibility test result.
[0182] The first incompatibility determination module is used to determine that the virtual machine image corresponding to the image information is incompatible when the real-time running state is a preset fault running state and / or at least one of the compatibility states included in each compatibility test result is not a compatibility pass state.
[0183] Specifically, the detailed process by which each module in the device of this invention implements its function can be found in the relevant description in the method embodiment, and will not be repeated here.
[0184] As an optional implementation, the second compatibility determination module described above includes:
[0185] The second compatibility determination module is used to determine the compatibility of the virtual machine image corresponding to the image information when the real-time running state is not a preset fault running state and all compatibility states are compatibility passed states.
[0186] The second incompatibility determination module is used to determine that the virtual machine image corresponding to the image information is incompatible when the real-time running state is a preset fault running state and / or at least one of the various compatibility states is not a compatibility pass state.
[0187] Specifically, the detailed process by which each module in the device of this invention implements its function can be found in the relevant description in the method embodiment, and will not be repeated here.
[0188] As an optional implementation, the above-described apparatus further includes:
[0189] The deletion module is used to delete the baseline image file when the virtual machine corresponding to the image information has completed compatibility testing.
[0190] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 7 The illustrated electronic device 700 includes at least one processor 701, a memory 702, at least one network interface 704, and other user interfaces 703. The various components in the electronic device 700 are coupled together via a bus system 705. It is understood that the bus system 705 is used to implement communication between these components. In addition to a data bus, the bus system 705 also includes a power bus, a control bus, and a status signal bus. However, for clarity, ... Figure 7 The general labeled all buses as Bus System 705.
[0191] The user interface 703 may include a display, keyboard, or clicking device (e.g., mouse, trackball, touchpad, or touchscreen).
[0192] It is understood that the memory 702 in the embodiments of this application can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DRRAM). The memory 702 described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0193] In some implementations, memory 702 stores elements, executable units or data structures, or subsets thereof, or extended sets thereof: operating system 7021 and application program 7022.
[0194] The operating system 7021 includes various system programs, such as the framework layer, core library layer, and driver layer, used to implement various basic business functions and handle hardware-based tasks. The application program 7022 includes various applications, such as a media player and a browser, used to implement various application functions. The program implementing the method of the embodiments of this application can be included in the application program 7022.
[0195] In the embodiments of this application, the processor 701 executes the method steps provided in each method embodiment by calling the program or instructions stored in the memory 702, specifically the program or instructions stored in the application program 7022.
[0196] The methods disclosed in the embodiments of this application can be applied to or implemented by processor 701. Processor 701 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in processor 701 or by instructions in the form of software. The processor 701 may be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software units in the decoding processor. The software units may be located in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in memory 702. Processor 701 reads the information in memory 702 and, in conjunction with its hardware, completes the steps of the above method.
[0197] It is understood that the embodiments described herein can be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit can be implemented in one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described herein, or combinations thereof.
[0198] For software implementation, the techniques described herein can be implemented by units that perform the functions described herein. The software code can be stored in memory and executed by a processor. The memory can be implemented in the processor or external to the processor.
[0199] The electronic device provided in this embodiment may be as follows: Figure 7 The electronic device shown can perform the following: Figure 1-6 All steps of the method for testing virtual machine images in China, thereby achieving... Figure 1-6 For details on the technical effectiveness of the virtual machine image testing method shown, please refer to [link / reference]. Figure 1-6 The relevant descriptions are presented concisely and will not be elaborated upon here.
[0200] This application also provides a storage medium (computer-readable storage medium). This storage medium stores one or more programs. The storage medium may include volatile memory, such as random access memory; it may also include non-volatile memory, such as read-only memory, flash memory, hard disk, or solid-state drive; and it may also include combinations of the above types of memory.
[0201] The above method of testing virtual machine images is implemented when one or more programs in the storage medium can be executed by one or more processors.
[0202] The processor is used to execute a program for testing virtual machine images stored in memory to implement the steps of the following virtual machine image testing method.
[0203] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0204] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented in hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0205] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of this application. It should be understood that the above description is only a specific embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A method for testing virtual machine images, characterized in that, The method includes: Upon receiving an image test command, the test configuration file is read from the specified directory; wherein, the test configuration file includes virtual machine configuration information, a compatibility test command set, and at least one image information; For each of the at least one image information, the following process is performed: obtain the number of virtual machine tests from the image information; If the number of virtual machine tests is not a preset number, virtual machines are created based on the virtual machine configuration information and the image information; wherein, the number of virtual machines is the same as the number of virtual machine tests. The virtual machine is used to execute compatibility test commands from the compatibility test command set to generate compatibility test results for the image information.
2. The method according to claim 1, characterized in that, The process of creating a virtual machine based on the virtual machine configuration information and the image information includes: Obtain the image download address from the image information; Download the baseline image file from the aforementioned image download address: Obtain the virtual machine XML template; A virtual machine is created based on the baseline image file, the virtual machine configuration information, and the virtual machine XML template.
3. The method according to claim 2, characterized in that, The process of creating a virtual machine based on the baseline image file, the virtual machine configuration information, and the virtual machine XML template includes: A backup image file is created based on the baseline image file; wherein the number of backup image files is the same as the number of virtual machine tests. Store the backup image file in the directory file of the specified virtual machine storage path; Write the specified virtual machine storage path directory file and the virtual machine configuration information into the virtual machine XML template to obtain a virtual machine XML file; A virtual machine is created based on the virtual machine XML file.
4. The method according to claim 1, characterized in that, The compatibility test command set includes multiple sub-compatibility test command sets corresponding to different operating systems. Each sub-compatibility test command set includes multiple compatibility test commands with different compatibility test contents. Each sub-compatibility test command set corresponds to operating system identification information. The step of generating compatibility test results for the image information by executing compatibility test commands from the compatibility test command set using the virtual machine includes: Obtain operating system identification information and virtual machine login information from the image information; The target sub-compatibility test command set is determined from the compatibility test command set based on the operating system identification information; Log in to the virtual machine according to the virtual machine login information; Determine whether the number of virtual machine tests is multiple: If it is determined that there are multiple virtual machines to be tested, each of the compatibility test commands in the target sub-compatibility test command set is executed by each of the logged-in virtual machines to generate multiple compatibility test results for the image information; If it is determined that the number of virtual machine tests is not multiple, the virtual machine after login executes each compatibility test command in the target sub-compatibility test command set to generate a compatibility test result for the image information.
5. The method according to claim 4, characterized in that, The method further includes: The compatibility test results are written to the virtual machine runtime log; wherein, the compatibility test results include the execution information and compatibility status corresponding to each compatibility test command, the execution information is the execution result obtained by the virtual machine executing the compatibility test command, and the compatibility status is the result obtained by analyzing the execution information to indicate whether the virtual machine is compatible with the compatibility test command.
6. The method according to claim 5, characterized in that, The method further includes: Obtain the virtual machine's runtime logs; Extract the compatibility test results corresponding to the image information from the virtual machine runtime log, including the various compatibility test states and the real-time running status of the virtual machine; In the case of multiple compatibility test results, the compatibility of the virtual machine image corresponding to the image information is determined based on the real-time running status and the compatibility status included in each of the compatibility test results. If there is only one compatibility test result, the virtual machine image corresponding to the image information is determined to be compatible based on the real-time running status and each compatibility status included in the compatibility test result.
7. The method according to claim 6, characterized in that, The process of determining whether the virtual machine image corresponding to the image information is compatible based on the real-time running status and the various compatibility states included in the various compatibility test results includes: When the real-time running state is not a preset fault running state, and at least one of the compatibility test results includes each of the compatibility states as a compatibility pass state, the virtual machine image corresponding to the image information is determined to be compatible. If the real-time running state is a preset fault running state and / or at least one of the compatibility states included in each of the compatibility test results is not a compatibility pass state, then the virtual machine image corresponding to the image information is determined to be incompatible.
8. The method according to claim 6, characterized in that, The step of determining whether the virtual machine image corresponding to the image information is compatible based on the real-time running status and the various compatibility states included in the compatibility test results includes: When the real-time running state is not a preset fault running state, and all of the compatibility states are compatibility passed states, the virtual machine image corresponding to the image information is determined to be compatible. When the real-time running state is a preset fault running state and / or at least one of the compatibility states is not a compatibility pass state, it is determined that the virtual machine image corresponding to the image information is incompatible.
9. The method according to claim 2, characterized in that, The method further includes: When the virtual machine corresponding to the image information is detected to have completed the compatibility test, the baseline image file is deleted.
10. An apparatus for testing virtual machine images, characterized in that, The device includes: The reading module is used to read the test configuration file from a specified directory when an image test command is received; wherein, the test configuration file includes virtual machine configuration information, a compatibility test command set, and at least one image information; The acquisition module is configured to perform the following processing for each of the at least one image information: acquire the number of virtual machine tests from the image information; A creation module is used to create virtual machines based on the virtual machine configuration information and the image information when the number of virtual machine tests is not a preset number; wherein the number of virtual machines is the same as the number of virtual machine tests. The compatibility testing module is used to execute compatibility testing commands from the compatibility testing command set using the virtual machine to generate compatibility testing results for the image information.
11. An electronic device, characterized in that, include: A processor and a memory, the processor being configured to execute a program for testing a virtual machine image stored in the memory, to implement the method for testing a virtual machine image according to any one of claims 1 to 9.
12. A storage medium, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the virtual machine image testing method according to any one of claims 1 to 9.