Merge "BugFix: Negative dropped packets in Prox tests"
[yardstick.git] / docs / testing / user / userguide / 04-installation.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International
2 .. License.
3 .. http://creativecommons.org/licenses/by/4.0
4 .. (c) OPNFV, Ericsson AB, Huawei Technologies Co.,Ltd and others.
5
6 Yardstick Installation
7 ======================
8
9
10 Abstract
11 --------
12
13 Yardstick supports installation by Docker or directly in Ubuntu. The
14 installation procedure for Docker and direct installation are detailed in
15 the sections below.
16
17 To use Yardstick you should have access to an OpenStack environment, with at
18 least Nova, Neutron, Glance, Keystone and Heat installed.
19
20 The steps needed to run Yardstick are:
21
22 1. Install Yardstick.
23 2. Load OpenStack environment variables.
24 #. Create Yardstick flavor.
25 #. Build a guest image and load it into the OpenStack environment.
26 #. Create the test configuration ``.yaml`` file and run the test case/suite.
27
28
29 Prerequisites
30 -------------
31
32 The OPNFV deployment is out of the scope of this document and can be found `here <http://artifacts.opnfv.org/opnfvdocs/colorado/docs/configguide/index.html>`_. The OPNFV platform is considered as the System Under Test (SUT) in this document.
33
34 Several prerequisites are needed for Yardstick:
35
36 #. A Jumphost to run Yardstick on
37 #. A Docker daemon or a virtual environment installed on the Jumphost
38 #. A public/external network created on the SUT
39 #. Connectivity from the Jumphost to the SUT public/external network
40
41 **NOTE:** *Jumphost* refers to any server which meets the previous
42 requirements. Normally it is the same server from where the OPNFV
43 deployment has been triggered.
44
45 **WARNING:** Connectivity from Jumphost is essential and it is of paramount
46 importance to make sure it is working before even considering to install
47 and run Yardstick. Make also sure you understand how your networking is
48 designed to work.
49
50 **NOTE:** If your Jumphost is operating behind a company http proxy and/or
51 Firewall, please consult first the section `Proxy Support (**Todo**)`_, towards
52 the end of this document. That section details some tips/tricks which
53 *may* be of help in a proxified environment.
54
55
56 Install Yardstick using Docker (**recommended**)
57 ---------------------------------------------------
58
59 Yardstick has a Docker image. It is recommended to use this Docker image to run Yardstick test.
60
61 Prepare the Yardstick container
62 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63
64 .. _dockerhub: https://hub.docker.com/r/opnfv/yardstick/
65
66 Install docker on your guest system with the following command, if not done yet::
67
68   wget -qO- https://get.docker.com/ | sh
69
70 Pull the Yardstick Docker image (``opnfv/yardstick``) from the public dockerhub
71 registry under the OPNFV account: dockerhub_, with the following docker
72 command::
73
74   docker pull opnfv/yardstick:stable
75
76 After pulling the Docker image, check that it is available with the
77 following docker command::
78
79   [yardsticker@jumphost ~]$ docker images
80   REPOSITORY         TAG       IMAGE ID        CREATED      SIZE
81   opnfv/yardstick    stable    a4501714757a    1 day ago    915.4 MB
82
83 Run the Docker image to get a Yardstick container::
84
85   docker run -itd --privileged -v /var/run/docker.sock:/var/run/docker.sock -p 8888:5000 --name yardstick opnfv/yardstick:stable
86
87 Note:
88
89 +----------------------------------------------+------------------------------+
90 | parameters                                   | Detail                       |
91 +==============================================+==============================+
92 | -itd                                         | -i: interactive, Keep STDIN  |
93 |                                              | open even if not attached.   |
94 |                                              | -t: allocate a pseudo-TTY.   |
95 |                                              | -d: run container in         |
96 |                                              | detached mode, in the        |
97 |                                              | background.                  |
98 +----------------------------------------------+------------------------------+
99 | --privileged                                 | If you want to build         |
100 |                                              | ``yardstick-image`` in       |
101 |                                              | Yardstick container, this    |
102 |                                              | parameter is needed.         |
103 +----------------------------------------------+------------------------------+
104 | -p 8888:5000                                 | If you want to call          |
105 |                                              | Yardstick API out of         |
106 |                                              | Yardstick container, this    |
107 |                                              | parameter is needed.         |
108 +----------------------------------------------+------------------------------+
109 | -v /var/run/docker.sock:/var/run/docker.sock | If you want to use yardstick |
110 |                                              | env grafana/influxdb to      |
111 |                                              | create a grafana/influxdb    |
112 |                                              | container out of Yardstick   |
113 |                                              | container, this parameter is |
114 |                                              | needed.                      |
115 +----------------------------------------------+------------------------------+
116 | --name yardstick                             | The name for this container, |
117 |                                              | not needed and can be        |
118 |                                              | defined by the user.         |
119 +----------------------------------------------+------------------------------+
120
121 Configure the Yardstick container environment
122 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
123
124 There are three ways to configure environments for running Yardstick, which will be shown in the following sections. Before that, enter the Yardstick container::
125
126   docker exec -it yardstick /bin/bash
127
128 and then configure Yardstick environments in the Yardstick container.
129
130 The first way (**recommended**)
131 ###################################
132
133 In the Yardstick container, the Yardstick repository is located in the ``/home/opnfv/repos`` directory. Yardstick provides a CLI to prepare OpenStack environment variables and create Yardstick flavor and guest images automatically::
134
135   yardstick env prepare
136
137 **NOTE**: Since Euphrates release, the above command will not able to automatically configure the /etc/yardstick/openstack.creds file.
138 So before running the above command, it is necessary to create the /etc/yardstick/openstack.creds file and save OpenStack environment variables into it manually.
139 If you have the openstack credential file saved outside the Yardstcik Docker container, you can do this easily by mapping the credential file into Yardstick container
140  using '-v /path/to/credential_file:/etc/yardstick/openstack.creds' when running the Yardstick container.
141 For details of the required OpenStack environment variables please refer to section **Export OpenStack environment variables**
142
143 The env prepare command may take up to 6-8 minutes to finish building
144 yardstick-image and other environment preparation. Meanwhile if you wish to
145 monitor the env prepare process, you can enter the Yardstick container in a new
146 terminal window and execute the following command::
147
148   tail -f /var/log/yardstick/uwsgi.log
149
150
151 The second way
152 ################
153
154 Export OpenStack environment variables
155 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
156
157 Before running Yardstick it is necessary to export OpenStack environment variables::
158
159   source openrc
160
161 Environment variables in the ``openrc`` file have to include at least:
162
163 * ``OS_AUTH_URL``
164 * ``OS_USERNAME``
165 * ``OS_PASSWORD``
166 * ``OS_TENANT_NAME``
167 * ``EXTERNAL_NETWORK``
168
169 A sample `openrc` file may look like this::
170
171   export OS_PASSWORD=console
172   export OS_TENANT_NAME=admin
173   export OS_AUTH_URL=http://172.16.1.222:35357/v2.0
174   export OS_USERNAME=admin
175   export OS_VOLUME_API_VERSION=2
176   export EXTERNAL_NETWORK=net04_ext
177
178 Manually create Yardstick falvor and guest images
179 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
180
181 Before executing Yardstick test cases, make sure that Yardstick flavor and guest image are available in OpenStack. Detailed steps about creating the Yardstick flavor and building the Yardstick guest image can be found below.
182
183 Most of the sample test cases in Yardstick are using an OpenStack flavor called
184 ``yardstick-flavor`` which deviates from the OpenStack standard ``m1.tiny`` flavor by the disk size - instead of 1GB it has 3GB. Other parameters are the same as in ``m1.tiny``.
185
186 Create ``yardstick-flavor``::
187
188   nova flavor-create yardstick-flavor 100 512 3 1
189
190 Most of the sample test cases in Yardstick are using a guest image called
191 ``yardstick-image`` which deviates from an Ubuntu Cloud Server image
192 containing all the required tools to run test cases supported by Yardstick.
193 Yardstick has a tool for building this custom image. It is necessary to have
194 ``sudo`` rights to use this tool.
195
196 Also you may need install several additional packages to use this tool, by
197 follwing the commands below::
198
199   sudo apt-get update && sudo apt-get install -y qemu-utils kpartx
200
201 This image can be built using the following command in the directory where Yardstick is installed::
202
203   export YARD_IMG_ARCH='amd64'
204   sudo echo "Defaults env_keep += \'YARD_IMG_ARCH\'" >> /etc/sudoers
205   sudo tools/yardstick-img-modify tools/ubuntu-server-cloudimg-modify.sh
206
207 **Warning:** Before building the guest image inside the Yardstick container, make sure the container is granted with privilege. The script will create files by default in ``/tmp/workspace/yardstick`` and the files will be owned by root!
208
209 The created image can be added to OpenStack using the ``glance image-create`` or via the OpenStack Dashboard. Example command is::
210
211   glance --os-image-api-version 1 image-create \
212   --name yardstick-image --is-public true \
213   --disk-format qcow2 --container-format bare \
214   --file /tmp/workspace/yardstick/yardstick-image.img
215
216 .. _`Cirros 0.3.5`: http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
217 .. _`Ubuntu 16.04`: https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img
218
219 Some Yardstick test cases use a `Cirros 0.3.5`_ image and/or a `Ubuntu 16.04`_ image. Add Cirros and Ubuntu images to OpenStack::
220
221   openstack image create \
222       --disk-format qcow2 \
223       --container-format bare \
224       --file $cirros_image_file \
225       cirros-0.3.5
226
227   openstack image create \
228       --disk-format qcow2 \
229       --container-format bare \
230       --file $ubuntu_image_file \
231       Ubuntu-16.04
232
233
234 The third way
235 ################
236
237 Similar to the second way, the first step is also to `Export OpenStack environment variables`_. Then the following steps should be done.
238
239 Automatically create Yardstcik flavor and guest images
240 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
241
242 Yardstick has a script for automatically creating Yardstick flavor and building
243 Yardstick guest images. This script is mainly used for CI and can be also used in the local environment::
244
245   source $YARDSTICK_REPO_DIR/tests/ci/load_images.sh
246
247
248 Delete the Yardstick container
249 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
250
251 If you want to uninstall Yardstick, just delete the Yardstick container::
252
253    docker stop yardstick && docker rm yardstick
254
255
256 Install Yardstick directly in Ubuntu
257 ---------------------------------------
258
259 .. _install-framework:
260
261 Alternatively you can install Yardstick framework directly in Ubuntu or in an Ubuntu Docker image. No matter which way you choose to install Yardstick, the following installation steps are identical.
262
263 If you choose to use the Ubuntu Docker image, you can pull the Ubuntu
264 Docker image from Docker hub::
265
266   docker pull ubuntu:16.04
267
268
269 Install Yardstick
270 ^^^^^^^^^^^^^^^^^^^^^
271
272 Prerequisite preparation::
273
274   apt-get update && apt-get install -y git python-setuptools python-pip
275   easy_install -U setuptools==30.0.0
276   pip install appdirs==1.4.0
277   pip install virtualenv
278
279 Create a virtual environment::
280
281   virtualenv ~/yardstick_venv
282   export YARDSTICK_VENV=~/yardstick_venv
283   source ~/yardstick_venv/bin/activate
284
285 Download the source code and install Yardstick from it::
286
287   git clone https://gerrit.opnfv.org/gerrit/yardstick
288   export YARDSTICK_REPO_DIR=~/yardstick
289   cd yardstick
290   ./install.sh
291
292
293 Configure the Yardstick environment (**Todo**)
294 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
295
296 For installing Yardstick directly in Ubuntu, the ``yardstick env`` command is not available. You need to prepare OpenStack environment variables and create Yardstick flavor and guest images manually.
297
298
299 Uninstall Yardstick
300 ^^^^^^^^^^^^^^^^^^^^^^
301
302 For unistalling Yardstick, just delete the virtual environment::
303
304   rm -rf ~/yardstick_venv
305
306
307 Verify the installation
308 -----------------------------
309
310 It is recommended to verify that Yardstick was installed successfully
311 by executing some simple commands and test samples. Before executing Yardstick
312 test cases make sure ``yardstick-flavor`` and ``yardstick-image`` can be found in OpenStack and the ``openrc`` file is sourced. Below is an example
313 invocation of Yardstick ``help`` command and ``ping.py`` test sample::
314
315   yardstick -h
316   yardstick task start samples/ping.yaml
317
318 **NOTE:** The above commands could be run in both the Yardstick container and the Ubuntu directly.
319
320 Each testing tool supported by Yardstick has a sample configuration file.
321 These configuration files can be found in the ``samples`` directory.
322
323 Default location for the output is ``/tmp/yardstick.out``.
324
325
326 Deploy InfluxDB and Grafana using Docker
327 -------------------------------------------
328
329 Without InfluxDB, Yardstick stores results for runnning test case in the file
330 ``/tmp/yardstick.out``. However, it's unconvenient to retrieve and display
331 test results. So we will show how to use InfluxDB to store data and use
332 Grafana to display data in the following sections.
333
334 Automatically deploy InfluxDB and Grafana containers (**recommended**)
335 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
336
337 Firstly, enter the Yardstick container::
338
339   docker exec -it yardstick /bin/bash
340
341 Secondly, create InfluxDB container and configure with the following command::
342
343   yardstick env influxdb
344
345 Thirdly, create and configure Grafana container::
346
347   yardstick env grafana
348
349 Then you can run a test case and visit http://host_ip:3000 (``admin``/``admin``) to see the results.
350
351 **NOTE:** Executing ``yardstick env`` command to deploy InfluxDB and Grafana requires Jumphost's docker API version => 1.24. Run the following command to check the docker API version on the Jumphost::
352
353   docker version
354
355 Manually deploy InfluxDB and Grafana containers
356 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
357
358 You could also deploy influxDB and Grafana containers manually on the Jumphost.
359 The following sections show how to do.
360
361 .. pull docker images
362
363 Pull docker images
364 ####################
365
366 ::
367
368   docker pull tutum/influxdb
369   docker pull grafana/grafana
370
371 Run and configure influxDB
372 ###############################
373
374 Run influxDB::
375
376   docker run -d --name influxdb \
377   -p 8083:8083 -p 8086:8086 --expose 8090 --expose 8099 \
378   tutum/influxdb
379   docker exec -it influxdb bash
380
381 Configure influxDB::
382
383   influx
384   >CREATE USER root WITH PASSWORD 'root' WITH ALL PRIVILEGES
385   >CREATE DATABASE yardstick;
386   >use yardstick;
387   >show MEASUREMENTS;
388
389 Run and configure Grafana
390 ###############################
391
392 Run Grafana::
393
394   docker run -d --name grafana -p 3000:3000 grafana/grafana
395
396 Log on http://{YOUR_IP_HERE}:3000 using ``admin``/``admin`` and configure database resource to be ``{YOUR_IP_HERE}:8086``.
397
398 .. image:: images/Grafana_config.png
399    :width: 800px
400    :alt: Grafana data source configration
401
402 Configure ``yardstick.conf``
403 ##############################
404
405 ::
406
407   docker exec -it yardstick /bin/bash
408   cp etc/yardstick/yardstick.conf.sample /etc/yardstick/yardstick.conf
409   vi /etc/yardstick/yardstick.conf
410
411 Modify ``yardstick.conf``::
412
413   [DEFAULT]
414   debug = True
415   dispatcher = influxdb
416
417   [dispatcher_influxdb]
418   timeout = 5
419   target = http://{YOUR_IP_HERE}:8086
420   db_name = yardstick
421   username = root
422   password = root
423
424 Now you can run Yardstick test cases and store the results in influxDB.
425
426
427 Deploy InfluxDB and Grafana directly in Ubuntu (**Todo**)
428 -----------------------------------------------------------
429
430
431 Yardstick common CLI
432 --------------------
433
434 list test cases
435 >>>>>>>>>>>>>>>
436 **yardstick testcase list**
437
438 This command line would list all test cases in yardstick.
439 It would show like below::
440
441   +---------------------------------------------------------------------------------------
442   | Testcase Name         | Description
443   +---------------------------------------------------------------------------------------
444   | opnfv_yardstick_tc001 | Measure network throughput using pktgen
445   | opnfv_yardstick_tc002 | measure network latency using ping
446   | opnfv_yardstick_tc005 | Measure Storage IOPS, throughput and latency using fio.
447   | opnfv_yardstick_tc006 | Measure volume storage IOPS, throughput and latency using fio.
448   | opnfv_yardstick_tc008 | Measure network throughput and packet loss using Pktgen
449   | opnfv_yardstick_tc009 | Measure network throughput and packet loss using pktgen
450   | opnfv_yardstick_tc010 | measure memory read latency using lmbench.
451   | opnfv_yardstick_tc011 | Measure packet delay variation (jitter) using iperf3.
452   | opnfv_yardstick_tc012 | Measure memory read and write bandwidth using lmbench.
453   | opnfv_yardstick_tc014 | Measure Processing speed using unixbench.
454   | opnfv_yardstick_tc019 | Sample test case for the HA of controller node service.
455   ...
456   +---------------------------------------------------------------------------------------
457 show a test case config file
458 >>>>>>>>>>>>>>>>>>>>>>>>>>>>
459 Take opnfv_yardstick_tc002 for an example. This test case measure network latency.
460 You just need to type in **yardstick testcase show opnfv_yardstick_tc002**, and the console
461 would show the config yaml of this test case::
462   ##############################################################################
463   # Copyright (c) 2017 kristian.hunt@gmail.com and others.
464   #
465   # All rights reserved. This program and the accompanying materials
466   # are made available under the terms of the Apache License, Version 2.0
467   # which accompanies this distribution, and is available at
468   # http://www.apache.org/licenses/LICENSE-2.0
469   ##############################################################################
470   ---
471
472   schema: "yardstick:task:0.1"
473   description: >
474       Yardstick TC002 config file;
475       measure network latency using ping;
476
477   {% set image = image or "cirros-0.3.5" %}
478
479   {% set provider = provider or none %}
480   {% set physical_network = physical_network or 'physnet1' %}
481   {% set segmentation_id = segmentation_id or none %}
482   {% set packetsize = packetsize or 100 %}
483
484   scenarios:
485   {% for i in range(2) %}
486   -
487     type: Ping
488     options:
489       packetsize: {{packetsize}}
490     host: athena.demo
491     target: ares.demo
492
493     runner:
494       type: Duration
495       duration: 60
496       interval: 10
497
498     sla:
499       max_rtt: 10
500       action: monitor
501   {% endfor %}
502
503   context:
504     name: demo
505     image: {{image}}
506     flavor: yardstick-flavor
507     user: cirros
508
509     placement_groups:
510       pgrp1:
511         policy: "availability"
512
513     servers:
514       athena:
515         floating_ip: true
516         placement: "pgrp1"
517       ares:
518         placement: "pgrp1"
519
520     networks:
521       test:
522         cidr: '10.0.1.0/24'
523         {% if provider == "vlan" %}
524         provider: {{provider}}
525         physical_network: {{physical_network}}å
526           {% if segmentation_id %}
527         segmentation_id: {{segmentation_id}}
528           {% endif %}
529         {% endif %}
530
531 start a task to run yardstick test case
532 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
533 If you want run a test case, then you need to use **yardstick task start <test_case_path>**
534 this command support some parameters as below:
535
536 +---------------------+--------------------------------------------------+
537 | Parameters          | Detail                                           |
538 +=====================+==================================================+
539 | -d                  | show debug log of yardstick running              |
540 |                     |                                                  |
541 +---------------------+--------------------------------------------------+
542 | --task-args         | If you want to customize test case parameters,   |
543 |                     | use "--task-args" to pass the value. The format  |
544 |                     | is a json string with parameter key-value pair.  |
545 |                     |                                                  |
546 +---------------------+--------------------------------------------------+
547 | --task-args-file    | If you want to use yardstick                     |
548 |                     | env prepare command(or                           |
549 |                     | related API) to load the                         |
550 +---------------------+--------------------------------------------------+
551 | --parse-only        |                                                  |
552 |                     |                                                  |
553 |                     |                                                  |
554 +---------------------+--------------------------------------------------+
555 | --output-file \     | Specify where to output the log. if not pass,    |
556 | OUTPUT_FILE_PATH    | the default value is                             |
557 |                     | "/tmp/yardstick/yardstick.log"                   |
558 |                     |                                                  |
559 +---------------------+--------------------------------------------------+
560 | --suite \           | run a test suite, TEST_SUITE_PATH speciy where   |
561 | TEST_SUITE_PATH     | the test suite locates                           |
562 |                     |                                                  |
563 +---------------------+--------------------------------------------------+
564
565
566 Run Yardstick in a local environment
567 ------------------------------------
568
569 We also have a guide about how to run Yardstick in a local environment.
570 This work is contributed by Tapio Tallgren.
571 You can find this guide at `here <https://wiki.opnfv.org/display/yardstick/How+to+run+Yardstick+in+a+local+environment>`_.
572
573
574 Create a test suite for Yardstick
575 ------------------------------------
576
577 A test suite in yardstick is a yaml file which include one or more test cases.
578 Yardstick is able to support running test suite task, so you can customize your
579 own test suite and run it in one task.
580
581 ``tests/opnfv/test_suites`` is the folder where Yardstick puts CI test suite. A typical test suite is like below (the ``fuel_test_suite.yaml`` example)::
582
583   ---
584   # Fuel integration test task suite
585
586   schema: "yardstick:suite:0.1"
587
588   name: "fuel_test_suite"
589   test_cases_dir: "samples/"
590   test_cases:
591   -
592     file_name: ping.yaml
593   -
594     file_name: iperf3.yaml
595
596 As you can see, there are two test cases in the ``fuel_test_suite.yaml``. The
597 ``schema`` and the ``name`` must be specified. The test cases should be listed
598 via the tag ``test_cases`` and their relative path is also marked via the tag
599 ``test_cases_dir``.
600
601 Yardstick test suite also supports constraints and task args for each test
602 case. Here is another sample (the ``os-nosdn-nofeature-ha.yaml`` example) to
603 show this, which is digested from one big test suite::
604
605  ---
606
607  schema: "yardstick:suite:0.1"
608
609  name: "os-nosdn-nofeature-ha"
610  test_cases_dir: "tests/opnfv/test_cases/"
611  test_cases:
612  -
613      file_name: opnfv_yardstick_tc002.yaml
614  -
615      file_name: opnfv_yardstick_tc005.yaml
616  -
617      file_name: opnfv_yardstick_tc043.yaml
618         constraint:
619            installer: compass
620            pod: huawei-pod1
621         task_args:
622            huawei-pod1: '{"pod_info": "etc/yardstick/.../pod.yaml",
623            "host": "node4.LF","target": "node5.LF"}'
624
625 As you can see in test case ``opnfv_yardstick_tc043.yaml``, there are two
626 tags, ``constraint`` and ``task_args``. ``constraint`` is to specify which
627 installer or pod it can be run in the CI environment. ``task_args`` is to
628 specify the task arguments for each pod.
629
630 All in all, to create a test suite in Yardstick, you just need to create a
631 yaml file and add test cases, constraint or task arguments if necessary.
632
633
634 Proxy Support (**Todo**)
635 ---------------------------
636