Teuthology的使用与Ceph自动化测试用例的编写(一)

CentOS下搭建Teuthology Ceph自动化测试平台(一)
CentOS下搭建Teuthology Ceph自动化测试平台(二)
CentOS下搭建Teuthology Ceph自动化测试平台(三)
CentOS下搭建Teuthology Ceph自动化测试平台(四)
CentOS下搭建Teuthology Ceph自动化测试平台(五)
Teuthology节点的部署——Ceph自动化测试平台(六)
Teuthology的使用与Ceph自动化测试用例的编写(一)
Teuthology的使用与Ceph自动化测试用例的编写(二)

这里将简单介绍teuthology中自动化测试的用例的编写。Ceph的自动化测试使用yaml文件描述,如下的例子搭建了一个三节点的Ceph集群,终端在集群搭建好后停止在python的interactive上,允许测试着调用相关的函数与集群交互。

关于teuthology的介绍,其实官方是有文档的,比较隐藏。。。。
http://docs.ceph.com/teuthology/docs/

roles:
- [mon.0, mds.0, osd.0]
- [mon.1, osd.1]
- [mon.2, client.0]

tasks:
- install:
- ceph:
- ceph-fuse: [client.0]
- interactive:

targets:
  ubuntu@<host1>: ssh-rsa <host1 key>
  ubuntu@<host2>: ssh-rsa <host2 key>
  ubuntu@<host3>: ssh-rsa <host3 key>

基础模块介绍

roles

roles需要与targets下的节点相互对应,每一组对应targets中的一个人节点。书写形式可以如例子中的,一行一组,也可以使用- - 来区分组。例如:

roles:
-- mon.0
 - mds.0
 - osd.0
-- mon.1
 - osd.1
-- mon.2
 - client01

该部分描述了怎样去使用host,每一组表示了某一个host上的角色,例如上面这个说明了host1上将会包含一个mon.0、mds.0、osd.0。

tasks

tasks 只需要执行的任务,这里只简单介绍,后面将主要讲解tasks,给出支持的tasks与使用范例。 task是一个python的模块,它处于teuthology.task 的包中,另外task也包含了ceph/qa/tasks下的任务,如 ceph这个任务,teuthology运行到对应的tasks时候,会首先import本身目录下的tasks,也就是teuthology.task,如果没有则import ceph/qa/tasks,如果还没找到对应的任务模块则会报错。它包含两个参数分别是ctx、config,例如install这个task的函数定义为:

def task(ctx, config):

每一个任务的python代码中都有这样的一个函数,该定义位于 teuthology.task.install下
其中 参数的解释为:

ctx: a context that is available through the lifetime of the test run, and has useful attributes such as cluster, letting the task access the remote hosts. Tasks can also store their internal state here. (TODO beware of namespace collisions.)

config: the data structure after the colon in the config file, e.g. for the above ceph-fuse example, it would be a list like [“client.0”].

前面也说到,tasks将会从teuthology.task 和ceph/qa/tasks中寻找,所以teuthology所支持的任务类型都可以在这两个目录下找到,这里只是简单的说明下列子中的任务,更详细的将会在后面另外作为一个章节介绍。

示例yaml中的tasks包含四个任务:

  1. install 该任务是teuthology.task下的任务,它负责根据操作系统类型安装Ceph的包,CentOS则安装rpm包,ubuntu则安装deb包。teuthology.task.install下有一个packages.yaml,它描述了需要安装的软件包。
  2. ceph 该任务主要是 部署其一个ceph集群,它是ceph/qa/tasks 下的任务。Teuthology运行到ceph任务的时候就会调用 ceph/qa/tasks 下的ceph.py 文件。
  3. ceph-fuse 该任务表示使用ceph-fuse挂在文件系统,它包含了一个参数 client.0
  4. interactive 该任务是teuthology自身包含的任务,该任务很简单,直接调用python 的interactive模块调出 交互程序,给用户使用。 该任务的描述:
    The interactive task presents a prompt for you to interact with the teuthology configuration.
    This is also useful to pause the execution of the test between two tasks, either to perform ad hoc operations,or to examine the state of the cluster. Hit control-D to continue when done.

该例子中,interactive是最后一个任务,当按下 control-D之后,teuthology将会认为任务完成,测试结束,然后开始清空节点的所有内容,卸载Ceph集群,恢复节点测试之前的状态。

targets

该模块表示测试将选择的节点,它每一行表示测试将要运行的节点的名字和秘钥,格式为:“[email protected]: ssh-rsa long_hostkey_here”,在使用teuthology运行的时候,需要将对应数量的节点lock住,给其使用。

运行该测试用例

将上面的列子稍微修改,然后保存为example.yaml。

锁住类型为plana的3台机器

teuthology-lock --lock-many 3 --machine-type plana

运行yaml文件

teuthology example.yaml --suite-path /home/foo/src/github.com_ceph_ceph_master/qa/

suite-path 后面的路径是ceph/qa/的路径,不指定也可以,teuthology将会自己根据配置文件寻找,并导入 os.path。

这一步是对前面整个平台的总体验证,其中可能会出现很多问题,但是其实都不难解决。另外这一块运行出错,百度或者谷歌其实都很难搜索得到。建议耐心去看输出的信息,然后去看看代码,也可以在代码中加log,输出更多的信息来观察分析,出错的地方。然后去解决它就行了,有时候会发现,就只是。。。。配置文件出错了而已。

Ceph中的suite测试

Suite测试指的是ceph-qa-suite下的测试,目前该项目整和到了Ceph项目下,ceph/qa/suite 下。每一个suite其实是一个directory ,下面又会包含子目录或者yam文件。这些yaml文件通过排列组合形成suite的job,一个suite包含很多的job,一个job就是一写yaml文件组合在一个的,一个job包含一些task。

Teuthology测试

Teuthology中包含很多的命令,teuthology-suite命令是用来跑suite测试的,而teuthology是用来跑自定义的测试的。这些都可以通过 #teuthology –help以及#teuthology-suite –help 来查看相关帮助。

teuthology-suite -s <suite> [-c <ceph>] [-k <kernel>] [-e email] [-f flavor] [-t <teuth>] [-m <mtype>]

其实很多参数不是必须的,因为其都有默认值,在help中都可以看的到。

• suite: the name of the suite (the directory in ceph-qa-suite).
• ceph: ceph branch to be used.
• kernel: version of the kernel to be used.
• email: email address to send the results to.
• flavor: the kernel flavor to run against
• teuth: version of teuthology to run
• mtype: machine type of the run
• templates: template file used for further modifying the suite (optional)

这里举一个例子,加入需要测试一个rbd/librbd的包含CentOS关键字的测试的JOB,也可以在猴米艾尼加一个过滤的参数。

#teuthology-suite -v -s rbd/librbd -c master -m plana -S 9106dcXXXXXXXXXXXXX --filter centos

其中 -v表示输出的日志会包含debug

-s 表示suite 这里是suite的目录,如果测整个rbd直接 -s rbd 就行
-c 表示ceph的branch
-m 表示跑测试使用的资源节点的类型
-S 表示该branch下的某一个commit ID
–filter 表示过滤,只运行那些描述包含centos的job

另外还包含了以下的命令,只列出一些,不再展开,可以查看–help
teuthology 运行ceph的集成测试
teuthology-suite 运行一系列(suite)的集成测试,一个suite是一个directory,下面有子目录和yaml文件
teuthology-kill 杀掉运行的teuthology的job,会清空队列,杀死正在跑的job,然后重置相关的机器
teuthology-queue 查看队列中的job
teuthology-nuke 重置测试的机器
teuthology-lock 解锁或者锁住机器等
…………………………………………………………………………………………………………………………………………………………………………………………………………..

猜你喜欢

转载自blog.csdn.net/csnd_pan/article/details/81181046