当前位置:网站首页>System of test development - create test virtual machine on demand
System of test development - create test virtual machine on demand
2022-06-24 05:43:00 【Chenqichan test】
First , Let's get to know KVM Several concepts and tools related to virtual machine .
- kvm: Virtual machine based on Kernel ( engine )
- qemu: Used to simulate virtual machines IO equipment
- qemu-img: Virtual machine disk management tool
- libvirt: Of virtualization services API Interface
- virsh: be based on libvirt Implementation of the command line tool
- qemu-manager: Graphical management tools
newly build KVM When virtual machines , You can specify another disk file as BackingFile.BackingFile Is a read-only virtual disk base image , It can be shared among multiple virtual machines . be based on BackingFile When creating and running a virtual machine , Only write files incrementally to your own disk file , To improve efficiency 、 Save disk and maintenance costs .
The virtual machine snapshot saves the state of the virtual machine at a specified point in time , When we encounter problems or errors in automated testing , Snapshots can be used to save 、 And restore to a certain point in time . With the help of BackingFile Mechanism , Virtual machines support multi-layer dependent snapshot chains like the following .
base image <-- vm01 <-- snap 1 <-- snap 2 <-- vm02(active)
You can use the following command , A virtual machine in the snapshot chain , Export to form a separate disk image file , It no longer depends on other images .
qemu-img convert -O qcow2 vm02.qcow2 vm-templ.img
Suppose we are in the user's working directory , The following directory has been established .
- kvm root directory
- iso Store CD image
- base Deposit BackingFile
- share Store the shared disk image , User storage test tool 、 Drive, etc
- image The disk image of the test machine xml Store exported virtual machine XML The configuration file
Here's an example , Introduce to you the method of quickly creating and testing virtual machines .
- according to Last article Step in , Create a Win10 virtual machine ;
- In virtual machine , Install the test software used in the work ;
- Use the following command , Create a new shared tool disk ;
qemu-img create -f qcow2 -o cluster_size=2M kvm/share/tools.qcow2 10G
- Mount the shared disk to the virtual machine , Copy tools and files to this disk ;
- Remove the virtual machine , In the confirmation dialog , Please choose not to delete the relevant disk files ;
- Move the primary disk file of the original virtual machine to the basic image directory , Such as kvm/base/windows/win10/x64-pro-zh_cn.qcow2
- Execute the following command , Take the above basic image as BackingFile, Create a new virtual machine disk ;
qemu-img create -f qcow2 -o cluster_size=2M,backing_file=kvm/base/windows/win10/x64-pro-zh_cn.qcow2 kvm/image/test-win10-x64-pro-zh_cn-01.qcow2 40G
- In the graphical interface , Create a new test virtual machine , Hang on the newly created virtual machine and shared disk .
In addition to using a graphical interface qemu-manager Software , A command line method is also provided here , You can use it in the code of the test platform .
- Export virtual machine XML The configuration file
virsh dumpxml test-win10-x64-pro-zh > kvm/xml/test-win10-x64-pro-zh.xml
- modify XML The following fields in the configuration file :
name uuid vcpu memory and currentMemory mac address The first 1 block disk Of source file
- In the 1 block disk Of Elemnt in , Add the following BackingFile About .
<backingStore type="file" index="2"> <format type="qcow2"/> <source file="/home/aaron/kvm/base/windows/win10/x64-pro-zh_cn.qcow2"/> <backingStore/>
- If necessary, use the page VNC Access the virtual desktop , find XML Of graphics Elements , Change it to the following .
<graphics type="vnc" port="-1" autoport="yes" listen="0.0.0.0" passwd="P2ssw0rd"> <listen type="address" address="0.0.0.0"/> </graphics>
- Use the following command to define the virtual machine .
virsh define kvm/xml/test-win10-x64-pro-zh.xml
- Start the virtual machine with the following command .
virsh start test-win10-x64-pro-zh
- Use the following command to get the name of the virtual machine VNC Port number , stay VNC Use... In software ”5900+ The number “ The port of , Access the virtual machine remote desktop .
virsh vncdisplay test-win10-x64-pro-zh
in addition , I use GO Language based on libvirt Functions related to virtual machine management of interface , This open source project aims to provide you with a platform based on KVM Virtual machine and Docker Container of 、 On demand test environment management platform , Please refer to the website for details https://github.com/easysoft/zagent .
Common commands :
# View virtual machine information qemu-img info --backing-chain kvm/image/test-win10-x64-pro-zh_cn-01.qcow2 # Modify the virtual machine disk size qemu-img resize x64-pro-zh_cn.qcow2 +10G # View the list in the virtual machine virsh list --all # View virtual machine VNC port virsh vncdisplay win10-test # Export virtual machine XML The configuration file virsh dumpxml win10-test > win10-test.xml # Create a virtual machine disk image qemu-img create -f qcow2 -o cluster_size=2M,backing_file=base.qcow2 win10-test.qcow2 40G # Definition 、 Undefine , start-up 、 Stop the virtual machine virsh define win10-test.xml virsh start win10-test virsh destroy win10-test virsh undefine win10-test
边栏推荐
- How enterprises overcome the data security barrier with the imminent implementation of the new law | interview with think tank on industrial security concept
- "Adobe international certified" graphic designer! How to break through the creative barrier and gain both fame and wealth?
- [Tencent cloud] enterprise micro marketing, private domain traffic value growth and operation efficiency improvement
- What is a domain name? How to use a domain name?
- How to apply for a website domain name and what problems should be paid attention to
- What is the learning path for model deployment optimization?
- Go's package management learning notes
- How should we learn cloud native in 2022?
- What is primary domain name? What are the divisions of domain names
- How do users purchase domain names? What should I pay attention to when buying a domain name?
猜你喜欢

How should we learn cloud native in 2022?

Answer questions! This article explains the automated testing framework in software testing from beginning to end
What cloud native knowledge should programmers master?
Easy to understand JDBC tutorial - absolutely suitable for zero Foundation
Learning routes and materials for cloud native O & M engineers
随机推荐
5g/4g data acquisition telemetry terminal
His secret script of hard technology investment
What are the advantages of building a private cloud platform?
"Adobe international certified" graphic designer! How to break through the creative barrier and gain both fame and wealth?
How to resolve Chinese domain names? What is domain name resolution?
[competition experience sharing] a problem-solving summary of the whole DFS (internal track)
Net domain name how to choose a domain name
What does it mean that the domain name is being walled? How to solve the problem of domain name by wall?
How to make a website with a domain name? What are the functions of the website?
Hacking with Golang
Fixed assets management software enables enterprises to realize intelligent management of fixed assets
What is the domain name system? What are the effects of domain names on Enterprises
How to resolve the domain name to IP? How long does it take for the domain name resolution to take effect?
What is primary domain name? What are the divisions of domain names
How to build a website with a domain name? What are the precautions for website construction?
What does it mean that the terminal displays escape character is'^]'after the telnet peer port?
It is necessary to do the industry of waiting insurance evaluation. Let's see if you are on the list
Explain thoroughly and learn thoroughly binary tree (6): written test of binary tree: flip | width | depth
Wang Wei, senior architect of coding Devops, was selected as the first batch of tutors in Mulan open source community
Establishment and basic use of vsftp server