Refine documentation
[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 Pull the Yardstick Docker image (``opnfv/yardstick``) from the public dockerhub
67 registry under the OPNFV account: dockerhub_, with the following docker
68 command::
69
70   docker pull opnfv/yardstick:stable
71
72 After pulling the Docker image, check that it is available with the
73 following docker command::
74
75   [yardsticker@jumphost ~]$ docker images
76   REPOSITORY         TAG       IMAGE ID        CREATED      SIZE
77   opnfv/yardstick    stable    a4501714757a    1 day ago    915.4 MB
78
79 Run the Docker image to get a Yardstick container::
80
81   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
82
83 Note:
84
85 +----------------------------------------------+------------------------------+
86 | parameters                                   | Detail                       |
87 +==============================================+==============================+
88 | -itd                                         | -i: interactive, Keep STDIN  |
89 |                                              | open even if not attached.   |
90 |                                              | -t: allocate a pseudo-TTY.   |
91 |                                              | -d: run container in         |
92 |                                              | detached mode, in the        |
93 |                                              | background.                  |
94 +----------------------------------------------+------------------------------+
95 | --privileged                                 | If you want to build         |
96 |                                              | ``yardstick-image`` in       |
97 |                                              | Yardstick container, this    |
98 |                                              | parameter is needed.         |
99 +----------------------------------------------+------------------------------+
100 | -e INSTALLER_IP=192.168.200.2                | If you want to use yardstick |
101 |                                              | env prepare command(or       |
102 | -e INSTALLER_TYPE=compass                    | related API) to load the     |
103 |                                              | images that Yardstick needs, |
104 |                                              | these parameters should be   |
105 |                                              | provided.                    |
106 |                                              | The INSTALLER_IP and         |
107 |                                              | INSTALLER_TYPE are depending |
108 |                                              | on your OpenStack installer. |
109 |                                              | Currently Apex, Compass,     |
110 |                                              | Fuel and Joid are supported. |
111 |                                              | If you use other installers, |
112 |                                              | such as devstack, these      |
113 |                                              | parameters can be ignores.   |
114 +----------------------------------------------+------------------------------+
115 | -p 8888:5000                                 | If you want to call          |
116 |                                              | Yardstick API out of         |
117 |                                              | Yardstick container, this    |
118 |                                              | parameter is needed.         |
119 +----------------------------------------------+------------------------------+
120 | -v /var/run/docker.sock:/var/run/docker.sock | If you want to use yardstick |
121 |                                              | env grafana/influxdb to      |
122 |                                              | create a grafana/influxdb    |
123 |                                              | container out of Yardstick   |
124 |                                              | container, this parameter is |
125 |                                              | needed.                      |
126 +----------------------------------------------+------------------------------+
127 | --name yardstick                             | The name for this container, |
128 |                                              | not needed and can be        |
129 |                                              | defined by the user.         |
130 +----------------------------------------------+------------------------------+
131
132 Configure the Yardstick container environment
133 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
134
135 There are three ways to configure environments for running Yardstick, which will be shown in the following sections. Before that, enter the Yardstick container::
136
137   docker exec -it yardstick /bin/bash
138
139 and then configure Yardstick environments in the Yardstick container.
140
141 The first way (**recommended**)
142 ###################################
143
144 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::
145
146   yardstick env prepare
147
148 **NOTE**: The above command just works for four OPNFV installers -- **Apex**, **Compass**, **Fuel** and **Joid**.
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   sudo tools/yardstick-img-modify tools/ubuntu-server-cloudimg-modify.sh
204
205 **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!
206
207 The created image can be added to OpenStack using the ``glance image-create`` or via the OpenStack Dashboard. Example command is::
208
209   glance --os-image-api-version 1 image-create \
210   --name yardstick-image --is-public true \
211   --disk-format qcow2 --container-format bare \
212   --file /tmp/workspace/yardstick/yardstick-image.img
213
214 .. _`Cirros 0.3.5`: http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
215 .. _`Ubuntu 14.04`: https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
216
217 Some Yardstick test cases use a `Cirros 0.3.5`_ image and/or a `Ubuntu 14.04`_ image. Add Cirros and Ubuntu images to OpenStack::
218
219   openstack image create \
220       --disk-format qcow2 \
221       --container-format bare \
222       --file $cirros_image_file \
223       cirros-0.3.5
224
225   openstack image create \
226       --disk-format qcow2 \
227       --container-format bare \
228       --file $ubuntu_image_file \
229       Ubuntu-14.04
230
231
232 The third way
233 ################
234
235 Similar to the second way, the first step is also to `Export OpenStack environment variables`_. Then the following steps should be done.
236
237 Automatically create Yardstcik flavor and guest images
238 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
239
240 Yardstick has a script for automatically creating Yardstick flavor and building
241 Yardstick guest images. This script is mainly used for CI and can be also used in the local environment::
242
243   source $YARDSTICK_REPO_DIR/tests/ci/load_images.sh
244
245
246 Delete the Yardstick container
247 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
248
249 If you want to uninstall Yardstick, just delete the Yardstick container::
250
251    docker stop yardstick && docker rm yardstick
252
253
254 Install Yardstick directly in Ubuntu
255 ---------------------------------------
256
257 .. _install-framework:
258
259 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.
260
261 If you choose to use the Ubuntu Docker image, you can pull the Ubuntu
262 Docker image from Docker hub::
263
264   docker pull ubuntu:16.04
265
266
267 Install Yardstick
268 ^^^^^^^^^^^^^^^^^^^^^
269
270 Create a virtual environment::
271
272   virtualenv ~/yardstick_venv
273   source ~/yardstick_venv/bin/activate
274
275 Download the source code and install Yardstick from it::
276
277   git clone https://gerrit.opnfv.org/gerrit/yardstick
278   cd yardstick
279   ./install.sh
280
281
282 Configure the Yardstick environment (**Todo**)
283 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
284
285 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.
286
287
288 Uninstall Yardstick
289 ^^^^^^^^^^^^^^^^^^^^^^
290
291 For unistalling Yardstick, just delete the virtual environment::
292
293   rm -rf ~/yardstick_venv
294
295
296 Verify the installation
297 -----------------------------
298
299 It is recommended to verify that Yardstick was installed successfully
300 by executing some simple commands and test samples. Before executing Yardstick
301 test cases make sure ``yardstick-flavor`` and ``yardstick-image`` can be found in OpenStack and the ``openrc`` file is sourced. Below is an example
302 invocation of Yardstick ``help`` command and ``ping.py`` test sample::
303
304   yardstick -h
305   yardstick task start samples/ping.yaml
306
307 **NOTE:** The above commands could be run in both the Yardstick container and the Ubuntu directly.
308
309 Each testing tool supported by Yardstick has a sample configuration file.
310 These configuration files can be found in the ``samples`` directory.
311
312 Default location for the output is ``/tmp/yardstick.out``.
313
314
315 Deploy InfluxDB and Grafana using Docker
316 -------------------------------------------
317
318 Without InfluxDB, Yardstick stores results for runnning test case in the file
319 ``/tmp/yardstick.out``. However, it's unconvenient to retrieve and display
320 test results. So we will show how to use InfluxDB to store data and use
321 Grafana to display data in the following sections.
322
323 Automatically deploy InfluxDB and Grafana containers (**recommended**)
324 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
325
326 Firstly, enter the Yardstick container::
327
328   docker exec -it yardstick /bin/bash
329
330 Secondly, create InfluxDB container and configure with the following command::
331
332   yardstick env influxdb
333
334 Thirdly, create and configure Grafana container::
335
336   yardstick env grafana
337
338 Then you can run a test case and visit http://host_ip:3000 (``admin``/``admin``) to see the results.
339
340 **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::
341
342   docker version
343
344 Manually deploy InfluxDB and Grafana containers
345 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
346
347 You could also deploy influxDB and Grafana containers manually on the Jumphost.
348 The following sections show how to do.
349
350 .. pull docker images
351
352 Pull docker images
353 ####################
354
355 ::
356
357   docker pull tutum/influxdb
358   docker pull grafana/grafana
359
360 Run and configure influxDB
361 ###############################
362
363 Run influxDB::
364
365   docker run -d --name influxdb \
366   -p 8083:8083 -p 8086:8086 --expose 8090 --expose 8099 \
367   tutum/influxdb
368   docker exec -it influxdb bash
369
370 Configure influxDB::
371
372   influx
373   >CREATE USER root WITH PASSWORD 'root' WITH ALL PRIVILEGES
374   >CREATE DATABASE yardstick;
375   >use yardstick;
376   >show MEASUREMENTS;
377
378 Run and configure Grafana
379 ###############################
380
381 Run Grafana::
382
383   docker run -d --name grafana -p 3000:3000 grafana/grafana
384
385 Log on http://{YOUR_IP_HERE}:3000 using ``admin``/``admin`` and configure database resource to be ``{YOUR_IP_HERE}:8086``.
386
387 .. image:: images/Grafana_config.png
388    :width: 800px
389    :alt: Grafana data source configration
390
391 Configure ``yardstick.conf``
392 ##############################
393
394 ::
395
396   docker exec -it yardstick /bin/bash
397   cp etc/yardstick/yardstick.conf.sample /etc/yardstick/yardstick.conf
398   vi /etc/yardstick/yardstick.conf
399
400 Modify ``yardstick.conf``::
401
402   [DEFAULT]
403   debug = True
404   dispatcher = influxdb
405
406   [dispatcher_influxdb]
407   timeout = 5
408   target = http://{YOUR_IP_HERE}:8086
409   db_name = yardstick
410   username = root
411   password = root
412
413 Now you can run Yardstick test cases and store the results in influxDB.
414
415
416 Deploy InfluxDB and Grafana directly in Ubuntu (**Todo**)
417 -----------------------------------------------------------
418
419
420 Run Yardstick in a local environment
421 ------------------------------------
422
423 We also have a guide about how to run Yardstick in a local environment.
424 This work is contributed by Tapio Tallgren.
425 You can find this guide at `here <https://wiki.opnfv.org/display/yardstick/How+to+run+Yardstick+in+a+local+environment>`_.
426
427
428 Create a test suite for Yardstick
429 ------------------------------------
430
431 A test suite in yardstick is a yaml file which include one or more test cases.
432 Yardstick is able to support running test suite task, so you can customize your
433 own test suite and run it in one task.
434
435 ``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)::
436
437   ---
438   # Fuel integration test task suite
439
440   schema: "yardstick:suite:0.1"
441
442   name: "fuel_test_suite"
443   test_cases_dir: "samples/"
444   test_cases:
445   -
446     file_name: ping.yaml
447   -
448     file_name: iperf3.yaml
449
450 As you can see, there are two test cases in the ``fuel_test_suite.yaml``. The
451 ``schema`` and the ``name`` must be specified. The test cases should be listed
452 via the tag ``test_cases`` and their relative path is also marked via the tag
453 ``test_cases_dir``.
454
455 Yardstick test suite also supports constraints and task args for each test
456 case. Here is another sample (the ``os-nosdn-nofeature-ha.yaml`` example) to
457 show this, which is digested from one big test suite::
458
459  ---
460
461  schema: "yardstick:suite:0.1"
462
463  name: "os-nosdn-nofeature-ha"
464  test_cases_dir: "tests/opnfv/test_cases/"
465  test_cases:
466  -
467      file_name: opnfv_yardstick_tc002.yaml
468  -
469      file_name: opnfv_yardstick_tc005.yaml
470  -
471      file_name: opnfv_yardstick_tc043.yaml
472         constraint:
473            installer: compass
474            pod: huawei-pod1
475         task_args:
476            huawei-pod1: '{"pod_info": "etc/yardstick/.../pod.yaml",
477            "host": "node4.LF","target": "node5.LF"}'
478
479 As you can see in test case ``opnfv_yardstick_tc043.yaml``, there are two
480 tags, ``constraint`` and ``task_args``. ``constraint`` is to specify which
481 installer or pod it can be run in the CI environment. ``task_args`` is to
482 specify the task arguments for each pod.
483
484 All in all, to create a test suite in Yardstick, you just need to create a
485 yaml file and add test cases, constraint or task arguments if necessary.
486
487
488 Proxy Support (**Todo**)
489 ---------------------------
490