KVM支持

如前所述,Autoserv 支持控制虚拟机。这个对象设计的可以支持虚拟机管理/hypervisors。一开始,只支持kvm,为了支持KVM,你需要做: 1.创建虚拟机,运行在虚拟层的机器 2.创建KVM对象,通过get()指定源,KVM InstallableObject安装到指定的虚拟机。 3.创建KVMGuest对象,需要指定做其他事情,KVM对象在上面已创建。 4.使用KVMGuest对象运行一些其他类型的虚拟机命令,如改变内核,运行autotest

可以通过查看server/kvm.py 和server/hosts/kvm_guest.py查看其他信息,尤其是KVM.install()的前面的函数和KVMGuest的函数构造。 下面给出一个Autoserv 控制文件的例子,第5行包括解析获取addresslist 列表,这个控制文件是由python实现。

remote_host = hosts.SSHHost("192.168.1.1")

kvm_on_remote_host = kvm.KVM(remote_host)
kvm_on_remote_host.get("/var/local/src/kvm-33.tar.gz")
addresses =[{"mac": "02:00:00:00:00:%02x" %(num,), "ip": "192.168.2.%d" % (num,)} for num in range(1, 32)]
kvm_on_remote_host.install(addreses)

qemu_options= "-m 256 -hda /var/local/vdisk.img -snapshot"
g = hosts.KVMGuest(kvm_on_remote_host, qemu_options)
g.wait_up()

print g.run("unme -a").stdout.strip()

Compiling qemu_options

你需要指定KVM的源码,需要从http://sourceforge.net/project/showfiles.phpgroup_id=180599获取。当KVM对象安装,需要控制2个选项:build(默认)和 insert_modules(默认为True). 如果build为true,Autoserv 会执行configure和make创建client和导入内核模块。 make install 永不会执行,否则会影响已经安装的系统。为了内核构建成功,需要将内核源码放到(/lib/modules/$(uname -r)/bulid. 如果build为flase,configure 和 make 已经执行了,二进制可以从源码文件夹中获取。还可以重新归档,如果你想让压缩包让get()获取。

如果insert_modules为True,Autoserv会移除kvm模块,包括编译的。如果KVM对象侦测到,它会移除内核中的模块。同时,Autoserv会检查内核合适的模块去插入。如果qemu或qemu-system-x86_64曾经用过,就不再检查,直接使用。如果 insert_modules为False,假设运行的内核已经拥有KVM支持,就不会再进行模块操作。

Kernel Considerations

下面介绍一些内核配置项,为定制自己的内核做参考。

Host Kernel

CONFIG_HPET_EMULATE_RTC, KVM常见问题,rtc中断丢失,客户端响应慢 KVM, KVM_AMD, KVM_INTEL, 让内核支持这部分

Guest Kernel

Guest kernel没有具体的需求,只要能保证在qumu运行。许多发行内核上使用IDE和ide_generic驱动程序,以便与那些不是较新的libata,避免从/dev/hda的到/dev/sda的设备名称更改。可以将它编译成模块,需要的时候插入。

Disk Image Coniderations

镜像需要作为qemu的一个选项,例如:

qemu_options= "-m 256 -hda /var/local/vdisk.img -snapshot"
g= hosts.KVMGuest(kvm_on_remote_host, qemu_options)

/var/local/vdisk.img 是磁盘镜像, -snapshot指定qumu不能修改image,更改会虚拟机关闭后取消。可以参考QEMU文档来了解QEMU信息。

IP Address Configuration

有一些要对diskimage做一些设置,在kvm.py:install()设置,虚拟机操作系统必须配置为与对应的Mac IP配置其网络。 Autoserv只能通过qemu的控制虚拟机的MAC地址,但是它将试图通过其IP联系它。你需要在install()实现map和IP的映射,还需要确保虚拟机启动后扔采用这个IP。如果你启动一个虚拟机,可以在image中设置IP。如果想启动多台虚拟机,可以通过DHCPserver分配或则选择和mac对应的IP。一种方式如debian系统下通过/etc/network/interfaces文件去设置:

auto eth0
mapping eth0
    script /usr/local/bin/get-mac-address.sh
    map 02:00:00:00:00:01 vhost1
    map 02:00:00:00:00:02 vhost2

iface vhost1 inet static
    address 10.0.2.1
    netmask 255.0.0.0
    geteway 10.0.0.1
iface vhost2 inet static
    address 10.0.2.2
    netmask 255.0.0.0
    geteway 10.0.0.1

/usr/local/bin/get-mac-address.sh :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#!/bin/sh

set -e
export LANG=C

iface="$1"
mac=$(/sbin/ifconfig "$iface" | sed -n -e '/^'.*HWaddr \([:[:xdigit:]]*\).*/{s//\1/;y/ABCDEF/abcdef/;p;q;}')
which=""

while read testmac scheme; do
    if ["$which" ]; then continue;fi
    if ["$mac" = "$(echo "$testmac" | sed -e 'y/ABCDEF/abcdef/')"]; then which="$scheme"; fi
done

if ["$which"]; then echo $which; exit 0; fi
exit 1

/etc/network/interfaces文件需要重复编写,替换,可以通过python脚本实现,调整map_entry, host_entry, first_value和 last_value:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python

header= """ #This file describes the network interfaces available on your system
# and how to activate them. For more infomation, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
mapping eth0
    script /usr/local/bin/get-mac-address.sh"""

map_entry="    map 00:1a:11:00:00:%02x vhost%d"

host_entry= """iface vhost%d inet static
    address 10.0.2.%d
    netmask 255.0.0.0
    gateway 10.0.0.1"""

print header

first_value= 1
last_value= 16

for i in range(first_value, last_value + 1):
    print map_entry % (i, i,)

print ""

for i in range(first_value, last_value + 1):
    print host_entry %(i, i,)

SSH Authentication

类似于SSHHost,也需要设置免密码登陆。

Serial Console

虽然对于Autoserv本身不是必要的,但对于启动qumu图形很重要,需要进行初始化。qemu的可以模拟来自视频卡的显示,也可以模拟一个串行端口。 * grub 配置文件(/boot/grub/menu.lst) serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1 terminal --timeout=3 serial console

  • kernel启动选项 console=tty0 console=ttyS0,9600

  • /etc/inittab T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100

Top^

上一篇Autotest: Autotest-Autotest Remote (Autoserv)(一)>> 下一篇Autotest:Autotest-Autotest Remote (Autoserv)(三)>>>

by 李鹏