当前位置: 首页 > 工具软件 > lmc-autotest > 使用案例 >

KVM Autotest client的使用

宋涵忍
2023-12-01

1. 安装

下载源代码

git clone git://github.com/autotest/autotest.git


安装其他的依赖

https://github.com/autotest/autotest/wiki/KVMAutotest-InstallPrerequesitePackagesClient


2. 快速配置

client/test/kvm/get_started.py

运行这个脚本,会使用一些默认的配置文件,并且设只好默认的路径。


3.查看配置

在运行之前,可以先查看一下当前的配置。 这样可以看到底有哪些测试会在本次测试中运行。

richard@richard:~/git/autotest$ cd client/tests/kvm
richard@richard:~/git/autotest/client/tests/kvm$ ../../common_lib/cartesian_config.py tests.cfg
dict    1:  smp2.CustomGuestLinux.uptime

加上-c选项,可以列出详细参数

richard@richard:~/git/autotest/client/tests/kvm$ ../../common_lib/cartesian_config.py -c tests.cfg
dict    1:  smp2.CustomGuestLinux.uptime
    backup_image = no
    backup_image_on_check_error = no

4. 运行简单的测试

richard@richard:~/git/autotest/client/tests/kvm$ ../../bin/autotest control


5. 查看测试结果

测试结果存放在 client/results/default

1. html 格式的   client/results/default/job_report.html

2. 文本格式的   在kvm 目录下运行  scan_results.py

richard@richard:~/git/autotest/client/tests/kvm$ ../../tools/scan_results.py
Test                                        Status     Seconds  Info
----                                        ------     -------  ----
        (Result file: ../../results/default/status)
smp2.CustomGuestLinux.uptime                FAIL       369      Unhandled VMIPAddressMissingError: Cannot find IP address for MAC address 9a:6b:f5:f9:0a:6f    [context: logging into 'vm1']
----                                        GOOD       372      

3. 每个test的log存放在  client/results/default/test_name/log


6。添加一个uptime测试用例

diff --git a/client/tests/kvm/subtests.cfg.sample b/client/tests/kvm/subtests.cfg.sample
index ccfd2f8..16ee7cc 100644
--- a/client/tests/kvm/subtests.cfg.sample
+++ b/client/tests/kvm/subtests.cfg.sample
@@ -1113,6 +1113,9 @@ variants:
                 dd_timeout = 900
                 check_cmd_timeout = 900
 
+    - uptime: install setup image_copy unattended_install.cdrom
+        type = uptime
+
     - cpu_hotplug_test:
         type = cpu_hotplug
         cpu_hotplug_timeout = 600
diff --git a/client/virt/tests/uptime.py b/client/virt/tests/uptime.py
new file mode 100644
index 0000000..dba62bc
--- /dev/null
+++ b/client/virt/tests/uptime.py
@@ -0,0 +1,13 @@
+import logging
+def run_uptime(test, params, env):
+    """
+    Docstring describing uptime.
+    """
+    print run_uptime.__doc__
+    vm = env.get_vm(params["main_vm"])
+    vm.verify_alive()
+    timeout = float(params.get("login_timeout", 240))
+    session = vm.wait_for_login(timeout=timeout)
+    uptime = session.cmd('uptime')
+    logging.info("Guest uptime result is: %s", uptime)

+    if session.get_command_status("touch /tmp/snapshot_test") != 0:
+        error.TestFail("can not touch file");
+    else:
+       logging.info("can touch")
+    session.close()

7。 遇到测试错误 就退出

默认配置下,autotest会将所有的测试用例全部运行完后才退出。

不过有时候我们会希望当测试遇到错误后就直接退出。

将 tests.cfg中 abort_on_error = yes 注释去掉


8.  进一步理解kvm autotest 的配置文件

https://github.com/autotest/autotest/wiki/CartesianConfig

就是个笛卡尔积。


 类似资料: