Merge "Add a new monitor type: MultiMonitor that can run any number of other monitors...
[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 -e INSTALLER_IP=192.168.200.2 -e INSTALLER_TYPE=compass --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 | -e INSTALLER_IP=192.168.200.2                | If you want to use yardstick |
105 |                                              | env prepare command(or       |
106 | -e INSTALLER_TYPE=compass                    | related API) to load the     |
107 |                                              | images that Yardstick needs, |
108 |                                              | these parameters should be   |
109 |                                              | provided.                    |
110 |                                              | The INSTALLER_IP and         |
111 |                                              | INSTALLER_TYPE are depending |
112 |                                              | on your OpenStack installer. |
113 |                                              | Currently Apex, Compass,     |
114 |                                              | Fuel and Joid are supported. |
115 |                                              | If you use other installers, |
116 |                                              | such as devstack, these      |
117 |                                              | parameters can be ignores.   |
118 +----------------------------------------------+------------------------------+
119 | -p 8888:5000                                 | If you want to call          |
120 |                                              | Yardstick API out of         |
121 |                                              | Yardstick container, this    |
122 |                                              | parameter is needed.         |
123 +----------------------------------------------+------------------------------+
124 | -v /var/run/docker.sock:/var/run/docker.sock | If you want to use yardstick |
125 |                                              | env grafana/influxdb to      |
126 |                                              | create a grafana/influxdb    |
127 |                                              | container out of Yardstick   |
128 |                                              | container, this parameter is |
129 |                                              | needed.                      |
130 +----------------------------------------------+------------------------------+
131 | --name yardstick                             | The name for this container, |
132 |                                              | not needed and can be        |
133 |                                              | defined by the user.         |
134 +----------------------------------------------+------------------------------+
135
136 Configure the Yardstick container environment
137 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
138
139 There are three ways to configure environments for running Yardstick, which will be shown in the following sections. Before that, enter the Yardstick container::
140
141   docker exec -it yardstick /bin/bash
142
143 and then configure Yardstick environments in the Yardstick container.
144
145 The first way (**recommended**)
146 ###################################
147
148 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::
149
150   yardstick env prepare
151
152 **NOTE**: The above command just works for four OPNFV installers -- **Apex**, **Compass**, **Fuel** and **Joid**.
153 The env prepare command may take up to 6-8 minutes to finish building
154 yardstick-image and other environment preparation. Meanwhile if you wish to
155 monitor the env prepare process, you can enter the Yardstick container in a new
156 terminal window and execute the following command::
157
158   tail -f /var/log/yardstick/uwsgi.log
159
160
161 The second way
162 ################
163
164 Export OpenStack environment variables
165 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
166
167 Before running Yardstick it is necessary to export OpenStack environment variables::
168
169   source openrc
170
171 Environment variables in the ``openrc`` file have to include at least:
172
173 * ``OS_AUTH_URL``
174 * ``OS_USERNAME``
175 * ``OS_PASSWORD``
176 * ``OS_TENANT_NAME``
177 * ``EXTERNAL_NETWORK``
178
179 A sample `openrc` file may look like this::
180
181   export OS_PASSWORD=console
182   export OS_TENANT_NAME=admin
183   export OS_AUTH_URL=http://172.16.1.222:35357/v2.0
184   export OS_USERNAME=admin
185   export OS_VOLUME_API_VERSION=2
186   export EXTERNAL_NETWORK=net04_ext
187
188 Manually create Yardstick falvor and guest images
189 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
190
191 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.
192
193 Most of the sample test cases in Yardstick are using an OpenStack flavor called
194 ``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``.
195
196 Create ``yardstick-flavor``::
197
198   nova flavor-create yardstick-flavor 100 512 3 1
199
200 Most of the sample test cases in Yardstick are using a guest image called
201 ``yardstick-image`` which deviates from an Ubuntu Cloud Server image
202 containing all the required tools to run test cases supported by Yardstick.
203 Yardstick has a tool for building this custom image. It is necessary to have
204 ``sudo`` rights to use this tool.
205
206 Also you may need install several additional packages to use this tool, by
207 follwing the commands below::
208
209   sudo apt-get update && sudo apt-get install -y qemu-utils kpartx
210
211 This image can be built using the following command in the directory where Yardstick is installed::
212
213   sudo tools/yardstick-img-modify tools/ubuntu-server-cloudimg-modify.sh
214
215 **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!
216
217 The created image can be added to OpenStack using the ``glance image-create`` or via the OpenStack Dashboard. Example command is::
218
219   glance --os-image-api-version 1 image-create \
220   --name yardstick-image --is-public true \
221   --disk-format qcow2 --container-format bare \
222   --file /tmp/workspace/yardstick/yardstick-image.img
223
224 .. _`Cirros 0.3.5`: http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
225 .. _`Ubuntu 16.04`: https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img
226
227 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::
228
229   openstack image create \
230       --disk-format qcow2 \
231       --container-format bare \
232       --file $cirros_image_file \
233       cirros-0.3.5
234
235   openstack image create \
236       --disk-format qcow2 \
237       --container-format bare \
238       --file $ubuntu_image_file \
239       Ubuntu-16.04
240
241
242 The third way
243 ################
244
245 Similar to the second way, the first step is also to `Export OpenStack environment variables`_. Then the following steps should be done.
246
247 Automatically create Yardstcik flavor and guest images
248 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
249
250 Yardstick has a script for automatically creating Yardstick flavor and building
251 Yardstick guest images. This script is mainly used for CI and can be also used in the local environment::
252
253   source $YARDSTICK_REPO_DIR/tests/ci/load_images.sh
254
255
256 Delete the Yardstick container
257 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
258
259 If you want to uninstall Yardstick, just delete the Yardstick container::
260
261    docker stop yardstick && docker rm yardstick
262
263
264 Install Yardstick directly in Ubuntu
265 ---------------------------------------
266
267 .. _install-framework:
268
269 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.
270
271 If you choose to use the Ubuntu Docker image, you can pull the Ubuntu
272 Docker image from Docker hub::
273
274   docker pull ubuntu:16.04
275
276
277 Install Yardstick
278 ^^^^^^^^^^^^^^^^^^^^^
279
280 Prerequisite preparation::
281
282   apt-get update && apt-get install -y git python-setuptools python-pip
283   easy_install -U setuptools==30.0.0
284   pip install appdirs==1.4.0
285   pip install virtualenv
286
287 Create a virtual environment::
288
289   virtualenv ~/yardstick_venv
290   export YARDSTICK_VENV=~/yardstick_venv
291   source ~/yardstick_venv/bin/activate
292
293 Download the source code and install Yardstick from it::
294
295   git clone https://gerrit.opnfv.org/gerrit/yardstick
296   export YARDSTICK_REPO_DIR=~/yardstick
297   cd yardstick
298   ./install.sh
299
300
301 Configure the Yardstick environment (**Todo**)
302 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
303
304 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.
305
306
307 Uninstall Yardstick
308 ^^^^^^^^^^^^^^^^^^^^^^
309
310 For unistalling Yardstick, just delete the virtual environment::
311
312   rm -rf ~/yardstick_venv
313
314
315 Verify the installation
316 -----------------------------
317
318 It is recommended to verify that Yardstick was installed successfully
319 by executing some simple commands and test samples. Before executing Yardstick
320 test cases make sure ``yardstick-flavor`` and ``yardstick-image`` can be found in OpenStack and the ``openrc`` file is sourced. Below is an example
321 invocation of Yardstick ``help`` command and ``ping.py`` test sample::
322
323   yardstick -h
324   yardstick task start samples/ping.yaml
325
326 **NOTE:** The above commands could be run in both the Yardstick container and the Ubuntu directly.
327
328 Each testing tool supported by Yardstick has a sample configuration file.
329 These configuration files can be found in the ``samples`` directory.
330
331 Default location for the output is ``/tmp/yardstick.out``.
332
333
334 Deploy InfluxDB and Grafana using Docker
335 -------------------------------------------
336
337 Without InfluxDB, Yardstick stores results for runnning test case in the file
338 ``/tmp/yardstick.out``. However, it's unconvenient to retrieve and display
339 test results. So we will show how to use InfluxDB to store data and use
340 Grafana to display data in the following sections.
341
342 Automatically deploy InfluxDB and Grafana containers (**recommended**)
343 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
344
345 Firstly, enter the Yardstick container::
346
347   docker exec -it yardstick /bin/bash
348
349 Secondly, create InfluxDB container and configure with the following command::
350
351   yardstick env influxdb
352
353 Thirdly, create and configure Grafana container::
354
355   yardstick env grafana
356
357 Then you can run a test case and visit http://host_ip:3000 (``admin``/``admin``) to see the results.
358
359 **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::
360
361   docker version
362
363 Manually deploy InfluxDB and Grafana containers
364 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
365
366 You could also deploy influxDB and Grafana containers manually on the Jumphost.
367 The following sections show how to do.
368
369 .. pull docker images
370
371 Pull docker images
372 ####################
373
374 ::
375
376   docker pull tutum/influxdb
377   docker pull grafana/grafana
378
379 Run and configure influxDB
380 ###############################
381
382 Run influxDB::
383
384   docker run -d --name influxdb \
385   -p 8083:8083 -p 8086:8086 --expose 8090 --expose 8099 \
386   tutum/influxdb
387   docker exec -it influxdb bash
388
389 Configure influxDB::
390
391   influx
392   >CREATE USER root WITH PASSWORD 'root' WITH ALL PRIVILEGES
393   >CREATE DATABASE yardstick;
394   >use yardstick;
395   >show MEASUREMENTS;
396
397 Run and configure Grafana
398 ###############################
399
400 Run Grafana::
401
402   docker run -d --name grafana -p 3000:3000 grafana/grafana
403
404 Log on http://{YOUR_IP_HERE}:3000 using ``admin``/``admin`` and configure database resource to be ``{YOUR_IP_HERE}:8086``.
405
406 .. image:: images/Grafana_config.png
407    :width: 800px
408    :alt: Grafana data source configration
409
410 Configure ``yardstick.conf``
411 ##############################
412
413 ::
414
415   docker exec -it yardstick /bin/bash
416   cp etc/yardstick/yardstick.conf.sample /etc/yardstick/yardstick.conf
417   vi /etc/yardstick/yardstick.conf
418
419 Modify ``yardstick.conf``::
420
421   [DEFAULT]
422   debug = True
423   dispatcher = influxdb
424
425   [dispatcher_influxdb]
426   timeout = 5
427   target = http://{YOUR_IP_HERE}:8086
428   db_name = yardstick
429   username = root
430   password = root
431
432 Now you can run Yardstick test cases and store the results in influxDB.
433
434
435 Deploy InfluxDB and Grafana directly in Ubuntu (**Todo**)
436 -----------------------------------------------------------
437
438
439 Run Yardstick in a local environment
440 ------------------------------------
441
442 We also have a guide about how to run Yardstick in a local environment.
443 This work is contributed by Tapio Tallgren.
444 You can find this guide at `here <https://wiki.opnfv.org/display/yardstick/How+to+run+Yardstick+in+a+local+environment>`_.
445
446
447 Create a test suite for Yardstick
448 ------------------------------------
449
450 A test suite in yardstick is a yaml file which include one or more test cases.
451 Yardstick is able to support running test suite task, so you can customize your
452 own test suite and run it in one task.
453
454 ``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)::
455
456   ---
457   # Fuel integration test task suite
458
459   schema: "yardstick:suite:0.1"
460
461   name: "fuel_test_suite"
462   test_cases_dir: "samples/"
463   test_cases:
464   -
465     file_name: ping.yaml
466   -
467     file_name: iperf3.yaml
468
469 As you can see, there are two test cases in the ``fuel_test_suite.yaml``. The
470 ``schema`` and the ``name`` must be specified. The test cases should be listed
471 via the tag ``test_cases`` and their relative path is also marked via the tag
472 ``test_cases_dir``.
473
474 Yardstick test suite also supports constraints and task args for each test
475 case. Here is another sample (the ``os-nosdn-nofeature-ha.yaml`` example) to
476 show this, which is digested from one big test suite::
477
478  ---
479
480  schema: "yardstick:suite:0.1"
481
482  name: "os-nosdn-nofeature-ha"
483  test_cases_dir: "tests/opnfv/test_cases/"
484  test_cases:
485  -
486      file_name: opnfv_yardstick_tc002.yaml
487  -
488      file_name: opnfv_yardstick_tc005.yaml
489  -
490      file_name: opnfv_yardstick_tc043.yaml
491         constraint:
492            installer: compass
493            pod: huawei-pod1
494         task_args:
495            huawei-pod1: '{"pod_info": "etc/yardstick/.../pod.yaml",
496            "host": "node4.LF","target": "node5.LF"}'
497
498 As you can see in test case ``opnfv_yardstick_tc043.yaml``, there are two
499 tags, ``constraint`` and ``task_args``. ``constraint`` is to specify which
500 installer or pod it can be run in the CI environment. ``task_args`` is to
501 specify the task arguments for each pod.
502
503 All in all, to create a test suite in Yardstick, you just need to create a
504 yaml file and add test cases, constraint or task arguments if necessary.
505
506
507 Proxy Support (**Todo**)
508 ---------------------------