Openstack Rally测试方法

Rally是openstack的原生测试工具,用于性能测试,源代码中已经预设了大量的openstack经典测试场景,Rally可以将每次测试的结果从数据库中导出来,形成html或者json等格式,让结果一目了然。

测试方法:

1、由于需要使用源码中的测试用例,本环境中docker是使用二进制构建的,所以需要copy一份源码到rally容器中

[root@cloud ~]# docker cp rally/ rally:root/

2、进入rally容器,创建工作目录

[root@cloud ~]# docker exec -it -u root rally bash
(rally)[root@cloud /]# mkdir ‐p /workspace && cd /workspace
(rally)[root@cloud workspace]# 

3、创建deployment

deployment是rally测试的云环境,即在rally数据库中注册了待测试环境,之后的测试操作均在deployment空间中进行,创建方法如下:

(rally)[root@cloud workspace]# cp /root/rally/samples/deployments/existing-keystone-v3.json ./keystone‐v3.json
(rally)[root@cloud workspace]# ls
keystone‐v3.json

对应已有的环境变量修改keystone-v3.json文件

(rally)[root@cloud workspace]# cat keystone‐v3.json 
{
    "type": "ExistingCloud",
    "auth_url": "http://10.10.10.2:35357/v3/",
    "region_name": "RegionOne",
    "endpoint_type": "public",
    "admin": {
        "username": "admin",
        "password": "password",
        "user_domain_name": "default",
        "project_name": "admin",
        "project_domain_name": "default"
    },
    "https_insecure": false,
    "https_cacert": ""
}

创建rally数据库和注册测试环境

(rally)[root@cloud workspace]# rally-manage db create
(rally)[root@cloud workspace]# rally deployment create --filename keystone‐v3.json --name deployment
+--------------------------------------+---------------------+------------+------------------+--------+
| uuid                                 | created_at          | name       | status           | active |
+--------------------------------------+---------------------+------------+------------------+--------+
| 10c7b8e3-2015-419c-be68-0f0312217ab8 | 2017-11-17 07:15:50 | deployment | deploy->finished |        |
+--------------------------------------+---------------------+------------+------------------+--------+
Using deployment: 10c7b8e3-2015-419c-be68-0f0312217ab8
~/.rally/openrc was updated

HINTS:

* To use standard OpenStack clients, set up your env by running:
    source ~/.rally/openrc
  OpenStack clients are now configured, e.g run:
    openstack image list
(rally)[root@cloud workspace]# rally deployment list
+--------------------------------------+---------------------+------------+------------------+--------+
| uuid                                 | created_at          | name       | status           | active |
+--------------------------------------+---------------------+------------+------------------+--------+
| 10c7b8e3-2015-419c-be68-0f0312217ab8 | 2017-11-17 07:15:50 | deployment | deploy->finished | *      |
+--------------------------------------+---------------------+------------+------------------+--------+
(rally)[root@cloud workspace]# source ~/.rally/openrc

4、执行测试

rally源码中各组件的测试用例在如下目录

(rally)[root@cloud scenarios]# ls
authenticate  designate  glance  keystone  mistral  neutron  README.rst  senlin  watcher
ceilometer    dummy      heat    magnum    monasca  nova     requests    swift   workload
cinder        ec2        ironic  manila    murano   quotas   sahara      vm      zaqar
(rally)[root@cloud scenarios]# pwd
/root/rally/samples/tasks/scenarios

这里以nova的一个测试例为例:

原生的代码如下:

(rally)[root@cloud nova]# cat boot-and-list.json
{% set flavor_name = flavor_name or "m1.tiny" %}
{
    "NovaServers.boot_and_list_server": [
        {
            "args": {
                "flavor": {
                    "name": "{{flavor_name}}"
                },
                "image": {
                    "name": "^cirros.*-disk$"
                },
                "detailed": true
            },
            "runner": {
                "type": "constant",
                "times": 1,
                "concurrency": 1
            },
            "context": {
                "users": {
                    "tenants": 1,
                    "users_per_tenant": 1
                }
            },
            "sla": {
                "failure_rate": {
                    "max": 0
                }
            }
        }
    ]
}

为了对应我们的测试环境,需要对一些参数进行修改:

(rally)[root@cloud nova]# cat boot-and-list.json
{% set flavor_name = flavor_name or "m1.large" %}       <-----------修改云主机类型
{
    "NovaServers.boot_and_list_server": [
        {
            "args": {
                "flavor": {
                    "name": "{{flavor_name}}"
                },
                "image": {
                    "name": "centos7"                  <-----------修改镜像
                },
                "nics": [{
                    "net-id": "bf358074-4e27-4b97-8122-c64d8a3ac665"   <-------添加网络id
                }],
                "detailed": true
            },
            "runner": {
                "type": "constant",
                "times": 1,
                "concurrency": 1
            },
            "context": {
                "users": {
                    "tenants": 1,
                    "users_per_tenant": 1
                }
            },
            "sla": {
                "failure_rate": {
                    "max": 0
                }
            }
        }
    ]
}

这里需要添加网络id,因为环境中有2个以上的网络,如果不指明网络id会报以下错误:

Conflict: Multiple possible networks found, use a Network ID to be more specific. (HTTP 409) (Request-ID: req-f3cca91e-a12f-49b7-ab2b-660ac21b7008)

执行测试脚本

(rally)[root@cloud nova]rally task start --deployment 10c7b8e3-2015-419c-be68-0f0312217ab8 --task boot-and-list.json
Running Rally version 0.8.1
--------------------------------------------------------------------------------
Preparing input task
--------------------------------------------------------------------------------

Input task is:

{
    "NovaServers.boot_and_list_server": [
        {
            "args": {
                "flavor": {
                    "name": "m1.large"
                },
                "image": {
                    "name": "centos7"
                },
                "nics": [{
                    "net-id": "bf358074-4e27-4b97-8122-c64d8a3ac665"
                }],
                "detailed": true
            },
            "runner": {
                "type": "constant",
                "times": 1,
                "concurrency": 1
            },
            "context": {
                "users": {
                    "tenants": 1,
                    "users_per_tenant": 1
                }
            },
            "sla": {
                "failure_rate": {
                    "max": 0
                }
            }
        }
    ]
}


Task syntax is correct :)
Task config is valid :)
--------------------------------------------------------------------------------
Task  96cdeeaf-af41-4018-ae26-1fa0b22a547c: started
--------------------------------------------------------------------------------

Benchmarking... This can take a while...

To track task status use:

    rally task status
    or
    rally task detailed

Using task: 96cdeeaf-af41-4018-ae26-1fa0b22a547c

--------------------------------------------------------------------------------
Task 96cdeeaf-af41-4018-ae26-1fa0b22a547c: finished
--------------------------------------------------------------------------------

test scenario NovaServers.boot_and_list_server
args position 0
args values:
{
  "runner": {
    "type": "constant", 
    "concurrency": 1, 
    "times": 1
  }, 
  "hooks": [], 
  "args": {
    "detailed": true, 
    "nics": [
      {
        "net-id": "bf358074-4e27-4b97-8122-c64d8a3ac665"
      }
    ], 
    "flavor": {
      "name": "m1.large"
    }, 
    "image": {
      "name": "centos7"
    }
  }, 
  "sla": {
    "failure_rate": {
      "max": 0
    }
  }, 
  "context": {
    "users": {
      "users_per_tenant": 1, 
      "tenants": 1
    }
  }
}

--------------------------------------------------------------------------------
Task 96cdeeaf-af41-4018-ae26-1fa0b22a547c has 0 error(s)
--------------------------------------------------------------------------------

+----------------------------------------------------------------------------------------------------------------------+
|                                                 Response Times (sec)                                                 |
+-------------------+-----------+--------------+--------------+--------------+-----------+-----------+---------+-------+
| Action            | Min (sec) | Median (sec) | 90%ile (sec) | 95%ile (sec) | Max (sec) | Avg (sec) | Success | Count |
+-------------------+-----------+--------------+--------------+--------------+-----------+-----------+---------+-------+
| nova.boot_server  | 15.383    | 15.383       | 15.383       | 15.383       | 15.383    | 15.383    | 100.0%  | 1     |
| nova.list_servers | 0.331     | 0.331        | 0.331        | 0.331        | 0.331     | 0.331     | 100.0%  | 1     |
| total             | 14.714    | 14.714       | 14.714       | 14.714       | 14.714    | 14.714    | 100.0%  | 1     |
+-------------------+-----------+--------------+--------------+--------------+-----------+-----------+---------+-------+

Load duration: 14.7144
Full duration: 24.0348

HINTS:
* To plot HTML graphics with this data, run:
    rally task report 96cdeeaf-af41-4018-ae26-1fa0b22a547c --out output.html

* To generate a JUnit report, run:
    rally task report 96cdeeaf-af41-4018-ae26-1fa0b22a547c --junit --out output.xml

* To get raw JSON output of task results, run:
    rally task results 96cdeeaf-af41-4018-ae26-1fa0b22a547c

5、查看测试结果

测试成功后,会有HINTS,这里我们将测试结果以html形式输出

(rally)[root@cloud workspace]# rally task report 96cdeeaf-af41-4018-ae26-1fa0b22a547c --out output.html
(rally)[root@cloud workspace]# ls
keystone‐v3.json  output.html

将测试结果拷出容器:

[root@cloud ~]# docker cp rally:/workspace/output.html .

将测试结果拷到本地电脑上,使用浏览器打开:

这里写图片描述

如需自己添加测试例,可以模仿原生代码进行编写,至此,使用rally进行测试的方法就介绍完毕了。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值