当前位置:网站首页>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 to set the secondary domain name of the website? What should I pay attention to when setting the domain name?
- How to build a website with a domain name? Is the website domain name free to use?
- How to do reverse domain name resolution? What does reverse domain name resolution mean?
- How to apply for a website domain name and what problems should be paid attention to
- What are the stages from tradition to Tencent cloud
- How to file a personal domain name? What are the benefits of domain name filing?
- Error 0xc0000013, 0xc000007b, etc. due to the conflict between the CD-ROM drive letter and the drive letter in the business program path
- "Yi Jian Xing" was "Internet stormed". What countermeasures does the game company have other than "rather be broken jade"?
- PV and PVC analysis and use in kubernetes
- What is the subdomain name and how to register the domain name
猜你喜欢
Learning routes and materials for cloud native O & M engineers
Easy to understand JDBC tutorial - absolutely suitable for zero Foundation

Answer questions! This article explains the automated testing framework in software testing from beginning to end
What cloud native knowledge should programmers master?

How should we learn cloud native in 2022?
随机推荐
Enterprise image warehouse
"Yi Jian Xing" was "Internet stormed". What countermeasures does the game company have other than "rather be broken jade"?
How to buy a network domain name? Is the domain expensive
Tamp the foundation, step into the cloud and rise to the original cloud Devops
What is a domain name? How to use a domain name?
Bert series Roberta Albert erine detailed explanation and use learning notes
How about the online domain name? Is it easy to use from the current market
What does it mean that the domain name is being walled? How to solve the problem of domain name by wall?
What happened to the JVM locking on Tencent ECS?
2021, how to select a programming language?
What is the domain name of the website? What problems should be paid attention to when applying for a domain name
[performance test] 3 How to calculate the number of concurrent users
Tencent Anxin platform was officially released, and the "Anxin agricultural product plan" was launched at the same time, supporting the growth of 100 landmark agricultural product brands in three year
How to buy a domain name? What should I pay attention to when buying a domain name?
What kind of intelligent connection design do we need in an interconnected society?
What is the subdomain name and how to register the domain name
How to use a Chinese domain name? Would you prefer a Chinese domain name or an English domain name?
How to apply for web domain name what is the role of domain name
What is a domain name server? What are the types of domain name servers?
Oceanus practice consumption CMQ subject model data source