3

Xen DomainU 自动测试脚本

 2 years ago
source link: https://blog.yxwang.me/2009/04/xen-test-script/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Xen DomainU 自动测试脚本

Tue, Apr 7, 2009 • Computer System

写完代码测试时重复的最多的步骤就是

  1. 编译,复制vmlinuz和xen.gz
  2. 重启VMware虚拟机
  3. 启动domainU xm create domU.conf 4. 开一个screen窗口attach到domainU的console xm console #domid 5. 在domainU中运行测试程序

于是写了个自动执行3 4 5的脚步,主要用到了熊熊推荐的pexpect,这东东很赞啊

为了提高用户体验,读取domainU的启动信息时我采用的方法是读一行输出一行,读到结尾登陆字符时通过超时设置退出循环,这样可能效率比较低,不过测试脚本也不care这个了

实际使用时碰到了另一个问题,domainU执行完自动命令后命令行会出现很严重的对齐问题,最后发现登陆后运行一次reset就可以了。

#!/usr/bin/python

# Automatic test script for Xen DomainU
# Author: zellux

import pexpect, os

conf = {
    'login_name'     : 'm2-vm2',
    'domainU_name'   : 'R900-DomU0',
    'domainU_conf'   : '/home/wyx/domU1',
    'domainU_id'     : '2',
    'domainU_user'   : 'wyx',
    'domainU_passwd' : 'wyx',
    }

# Command to be executed after domainU starts
cmd = """
cd m2
cd reg_test
./base_test -t affinity
"""

# Create domainU
print '[M2 Test] Starting domainU ...',
pexpect.run('xm create %(domainU_conf)s' % conf)
print 'done'

# Get domainU id
print '[M2 Test] SGetting domainU id ...',
ret = pexpect.run('xm list')
for line in ret.split('\n')[1:]:
    part = line.split()
    if part[0] == conf['domainU_name']:
        conf['domainU_id'] = part[1]
        break
print 'done'

# Run domainU commands
child = pexpect.spawn('xm console %(domainU_id)s' % conf)
print '[M2 Test] SReading from domainU console...'
try:
    while True:
        child.expect('\n', timeout=1, )
        print child.before.split['\n'][-1]
except:
    pass

child.expect('%(login_name)s login:' % conf)
child.sendline(conf['domainU_user'])
child.sendline(conf['domainU_passwd'])

for line in cmd.split('\n'):
    child.sendline(line)

try:
    child.expect(pexpect.EOF, timeout=1)
except:
    pass
print child.before
child.interact()

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK