Dashboard with Network and Platform NFVi metrics
[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 ======================
7 Yardstick Installation
8 ======================
9
10
11 Yardstick supports installation by Docker or directly in Ubuntu. The
12 installation procedure for Docker and direct installation are detailed in
13 the sections below.
14
15 To use Yardstick you should have access to an OpenStack environment, with at
16 least Nova, Neutron, Glance, Keystone and Heat installed.
17
18 The steps needed to run Yardstick are:
19
20 1. Install Yardstick.
21 2. Load OpenStack environment variables.
22 3. Create Yardstick flavor.
23 4. Build a guest image and load it into the OpenStack environment.
24 5. Create the test configuration ``.yaml`` file and run the test case/suite.
25
26
27 Prerequisites
28 -------------
29
30 The OPNFV deployment is out of the scope of this document and can be found in
31 `User Guide & Configuration Guide`_. The OPNFV platform is considered as the
32 System Under Test (SUT) in this document.
33
34 Several prerequisites are needed for Yardstick:
35
36 1. A Jumphost to run Yardstick on
37 2. A Docker daemon or a virtual environment installed on the Jumphost
38 3. A public/external network created on the SUT
39 4. 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 first consult `Proxy Support`_ section which is towards
52    the end of this document. That section details some tips/tricks which *may*
53    be of help in a proxified environment.
54
55
56 Install Yardstick using Docker (first option) (**recommended**)
57 ---------------------------------------------------------------
58
59 Yardstick has a Docker image. It is recommended to use this Docker image to run
60 Yardstick test.
61
62 Prepare the Yardstick container
63 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
64
65 Install docker on your guest system with the following command, if not done
66 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 in dockerhub_, with the following docker
72 command::
73
74    sudo -EH 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 \
86       -p 8888:5000 --name yardstick opnfv/yardstick:stable
87
88 Description of the parameters used with ``docker run`` command
89
90   +------------------------+--------------------------------------------------+
91   | Parameters             | Detail                                           |
92   +========================+==================================================+
93   | -itd                   |  -i: interactive, Keep STDIN open even if not    |
94   |                        |  attached                                        |
95   |                        +--------------------------------------------------+
96   |                        |  -t: allocate a pseudo-TTY detached mode, in the |
97   |                        |  background                                      |
98   +------------------------+--------------------------------------------------+
99   | --privileged           | If you want to build ``yardstick-image`` in      |
100   |                        | Yardstick container, this parameter is needed    |
101   +------------------------+--------------------------------------------------+
102   | -p 8888:5000           | Redirect the a host port (8888) to a container   |
103   |                        | port (5000)                                      |
104   +------------------------+--------------------------------------------------+
105   | -v /var/run/docker.sock| If you want to use yardstick env                 |
106   | :/var/run/docker.sock  | grafana/influxdb to create a grafana/influxdb    |
107   |                        | container out of Yardstick container             |
108   +------------------------+--------------------------------------------------+
109   | --name yardstick       | The name for this container                      |
110   +------------------------+--------------------------------------------------+
111
112
113 If the host is restarted
114 ^^^^^^^^^^^^^^^^^^^^^^^^
115
116 The yardstick container must be started if the host is rebooted::
117
118     docker start yardstick
119
120 Configure the Yardstick container environment
121 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
122
123 There are three ways to configure environments for running Yardstick, explained
124 in the following sections. Before that, access the Yardstick container::
125
126    docker exec -it yardstick /bin/bash
127
128 and then configure Yardstick environments in the Yardstick container.
129
130 Using the CLI command ``env prepare`` (first way) (**recommended**)
131 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132
133 In the Yardstick container, the Yardstick repository is located in the
134 ``/home/opnfv/repos`` directory. Yardstick provides a CLI to prepare OpenStack
135 environment variables and create Yardstick flavor and guest images
136 automatically::
137
138    yardstick env prepare
139
140 .. note:: Since Euphrates release, the above command will not be able to
141   automatically configure the ``/etc/yardstick/openstack.creds`` file. So before
142   running the above command, it is necessary to create the
143   ``/etc/yardstick/openstack.creds`` file and save OpenStack environment
144   variables into it manually. If you have the openstack credential file saved
145   outside the Yardstick Docker container, you can do this easily by mapping the
146   credential file into Yardstick container using::
147
148      '-v /path/to/credential_file:/etc/yardstick/openstack.creds'
149
150   when running the Yardstick container. For details of the required OpenStack
151   environment variables please refer to section `Export OpenStack environment
152   variables`_.
153
154 The ``env prepare`` command may take up to 6-8 minutes to finish building
155 yardstick-image and other environment preparation. Meanwhile if you wish to
156 monitor the env prepare process, you can enter the Yardstick container in a new
157 terminal window and execute the following command::
158
159   tail -f /var/log/yardstick/uwsgi.log
160
161
162 Manually exporting the env variables and initializing OpenStack (second way)
163 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164
165 Export OpenStack environment variables
166 ######################################
167
168 Before running Yardstick it is necessary to export OpenStack environment
169 variables::
170
171    source openrc
172
173 Environment variables in the ``openrc`` file have to include at least::
174
175    OS_AUTH_URL
176    OS_USERNAME
177    OS_PASSWORD
178    OS_PROJECT_NAME
179    EXTERNAL_NETWORK
180
181 A sample ``openrc`` file may look like this::
182
183   export OS_PASSWORD=console
184   export OS_PROJECT_NAME=admin
185   export OS_AUTH_URL=http://172.16.1.222:35357/v2.0
186   export OS_USERNAME=admin
187   export OS_VOLUME_API_VERSION=2
188   export EXTERNAL_NETWORK=net04_ext
189
190
191 Manual creation of Yardstick flavor and guest images
192 ####################################################
193
194 Before executing Yardstick test cases, make sure that Yardstick flavor and
195 guest image are available in OpenStack. Detailed steps about creating the
196 Yardstick flavor and building the Yardstick guest image can be found below.
197
198 Most of the sample test cases in Yardstick are using an OpenStack flavor called
199 ``yardstick-flavor`` which deviates from the OpenStack standard ``m1.tiny``
200 flavor by the disk size; instead of 1GB it has 3GB. Other parameters are the
201 same as in ``m1.tiny``.
202
203 Create ``yardstick-flavor``::
204
205    openstack flavor create --disk 3 --vcpus 1 --ram 512 --swap 100 \
206       yardstick-flavor
207
208 Most of the sample test cases in Yardstick are using a guest image called
209 ``yardstick-image`` which deviates from an Ubuntu Cloud Server image
210 containing all the required tools to run test cases supported by Yardstick.
211 Yardstick has a tool for building this custom image. It is necessary to have
212 ``sudo`` rights to use this tool.
213
214 Also you may need install several additional packages to use this tool, by
215 follwing the commands below::
216
217    sudo -EH apt-get update && sudo -EH apt-get install -y qemu-utils kpartx
218
219 This image can be built using the following command in the directory where
220 Yardstick is installed::
221
222    export YARD_IMG_ARCH='amd64'
223    echo "Defaults env_keep += \'YARD_IMG_ARCH\'" | sudo tee --append \
224       /etc/sudoers > /dev/null
225    sudo -EH tools/yardstick-img-modify tools/ubuntu-server-cloudimg-modify.sh
226
227 .. warning:: Before building the guest image inside the Yardstick container,
228   make sure the container is granted with privilege. The script will create files
229   by default in ``/tmp/workspace/yardstick`` and the files will be owned by root.
230
231 The created image can be added to OpenStack using the OpenStack client or via
232 the OpenStack Dashboard::
233
234    openstack image create --disk-format qcow2 --container-format bare \
235       --public --file /tmp/workspace/yardstick/yardstick-image.img \
236        yardstick-image
237
238
239 Some Yardstick test cases use a `Cirros 0.3.5`_ image and/or a `Ubuntu 16.04`_
240 image. Add Cirros and Ubuntu images to OpenStack::
241
242    openstack image create --disk-format qcow2 --container-format bare \
243       --public --file $cirros_image_file cirros-0.3.5
244    openstack image create --disk-format qcow2 --container-format bare \
245       --file $ubuntu_image_file Ubuntu-16.04
246
247
248 Automatic initialization of OpenStack (third way)
249 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
250
251 Similar to the second way, the first step is also to
252 `Export OpenStack environment variables`_. Then the following steps should be
253 done.
254
255 Automatic creation of Yardstick flavor and guest images
256 #######################################################
257
258 Yardstick has a script for automatically creating Yardstick flavor and building
259 Yardstick guest images. This script is mainly used for CI and can be also used
260 in the local environment::
261
262    source $YARDSTICK_REPO_DIR/tests/ci/load_images.sh
263
264
265 The Yardstick container GUI
266 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
267
268 In Euphrates release, Yardstick implemented a GUI for Yardstick Docker
269 container. After booting up Yardstick container, you can visit the GUI at
270 ``<container_host_ip>:8888/gui/index.html``.
271
272 For usage of Yardstick GUI, please watch our demo video at
273 `Yardstick GUI demo`_.
274
275 .. note:: The Yardstick GUI is still in development, the GUI layout and
276   features may change.
277
278 Delete the Yardstick container
279 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
280
281 If you want to uninstall Yardstick, just delete the Yardstick container::
282
283    sudo docker stop yardstick && docker rm yardstick
284
285
286
287 Install Yardstick directly in Ubuntu (second option)
288 ----------------------------------------------------
289
290 .. _install-framework:
291
292 Alternatively you can install Yardstick framework directly in Ubuntu or in an
293 Ubuntu Docker image. No matter which way you choose to install Yardstick, the
294 following installation steps are identical.
295
296 If you choose to use the Ubuntu Docker image, you can pull the Ubuntu
297 Docker image from Docker hub::
298
299    sudo -EH docker pull ubuntu:16.04
300
301
302 Install Yardstick
303 ^^^^^^^^^^^^^^^^^
304
305 Prerequisite preparation::
306
307    sudo -EH apt-get update && sudo -EH apt-get install -y \
308       git python-setuptools python-pip
309    sudo -EH easy_install -U setuptools==30.0.0
310    sudo -EH pip install appdirs==1.4.0
311    sudo -EH pip install virtualenv
312
313 Download the source code and install Yardstick from it::
314
315    git clone https://gerrit.opnfv.org/gerrit/yardstick
316    export YARDSTICK_REPO_DIR=~/yardstick
317    cd ~/yardstick
318    sudo -EH ./install.sh
319
320 If the host is ever restarted, nginx and uwsgi need to be restarted::
321
322    service nginx restart
323    uwsgi -i /etc/yardstick/yardstick.ini
324
325 Configure the Yardstick environment (**Todo**)
326 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
327
328 For installing Yardstick directly in Ubuntu, the ``yardstick env`` command is
329 not available. You need to prepare OpenStack environment variables and create
330 Yardstick flavor and guest images manually.
331
332
333 Uninstall Yardstick
334 ^^^^^^^^^^^^^^^^^^^
335
336 For uninstalling Yardstick, just delete the virtual environment::
337
338    rm -rf ~/yardstick_venv
339
340
341 Install Yardstick directly in OpenSUSE
342 --------------------------------------
343
344 .. _install-framework:
345
346 You can install Yardstick framework directly in OpenSUSE.
347
348
349 Install Yardstick
350 ^^^^^^^^^^^^^^^^^
351
352 Prerequisite preparation::
353
354    sudo -EH zypper -n install -y gcc \
355       wget \
356       git \
357       sshpass \
358       qemu-tools \
359       kpartx \
360       libffi-devel \
361       libopenssl-devel \
362       python \
363       python-devel \
364       python-virtualenv \
365       libxml2-devel \
366       libxslt-devel \
367       python-setuptools-git
368
369 Create a virtual environment::
370
371    virtualenv ~/yardstick_venv
372    export YARDSTICK_VENV=~/yardstick_venv
373    source ~/yardstick_venv/bin/activate
374    sudo -EH easy_install -U setuptools
375
376 Download the source code and install Yardstick from it::
377
378    git clone https://gerrit.opnfv.org/gerrit/yardstick
379    export YARDSTICK_REPO_DIR=~/yardstick
380    cd yardstick
381    sudo -EH python setup.py install
382    sudo -EH pip install -r requirements.txt
383
384 Install missing python modules::
385
386    sudo -EH pip install pyyaml \
387       oslo_utils \
388       oslo_serialization \
389       oslo_config \
390       paramiko \
391       python.heatclient \
392       python.novaclient \
393       python.glanceclient \
394       python.neutronclient \
395       scp \
396       jinja2
397
398
399 Configure the Yardstick environment
400 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
401
402 Source the OpenStack environment variables::
403
404    source DEVSTACK_DIRECTORY/openrc
405
406 Export the Openstack external network. The default installation of Devstack
407 names the external network public::
408
409    export EXTERNAL_NETWORK=public
410    export OS_USERNAME=demo
411
412 Change the API version used by Yardstick to v2.0 (the devstack openrc sets it
413 to v3)::
414
415    export OS_AUTH_URL=http://PUBLIC_IP_ADDRESS:5000/v2.0
416
417
418 Uninstall Yardstick
419 ^^^^^^^^^^^^^^^^^^^
420
421 For unistalling Yardstick, just delete the virtual environment::
422
423    rm -rf ~/yardstick_venv
424
425
426 Verify the installation
427 -----------------------
428
429 It is recommended to verify that Yardstick was installed successfully
430 by executing some simple commands and test samples. Before executing Yardstick
431 test cases make sure ``yardstick-flavor`` and ``yardstick-image`` can be found
432 in OpenStack and the ``openrc`` file is sourced. Below is an example invocation
433 of Yardstick ``help`` command and ``ping.py`` test sample::
434
435    yardstick -h
436    yardstick task start samples/ping.yaml
437
438 .. note:: The above commands could be run in both the Yardstick container and
439   the Ubuntu directly.
440
441 Each testing tool supported by Yardstick has a sample configuration file.
442 These configuration files can be found in the ``samples`` directory.
443
444 Default location for the output is ``/tmp/yardstick.out``.
445
446
447 Deploy InfluxDB and Grafana using Docker
448 ----------------------------------------
449
450 Without InfluxDB, Yardstick stores results for running test case in the file
451 ``/tmp/yardstick.out``. However, it's inconvenient to retrieve and display
452 test results. So we will show how to use InfluxDB to store data and use
453 Grafana to display data in the following sections.
454
455 Automatic deployment of InfluxDB and Grafana containers (**recommended**)
456 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
457
458 Firstly, enter the Yardstick container::
459
460    sudo -EH docker exec -it yardstick /bin/bash
461
462 Secondly, create InfluxDB container and configure with the following command::
463
464    yardstick env influxdb
465
466 Thirdly, create and configure Grafana container::
467
468    yardstick env grafana
469
470 Then you can run a test case and visit http://host_ip:1948
471 (``admin``/``admin``) to see the results.
472
473 .. note:: Executing ``yardstick env`` command to deploy InfluxDB and Grafana
474   requires Jumphost's docker API version => 1.24. Run the following command to
475   check the docker API version on the Jumphost::
476
477     docker version
478
479
480 Manual deployment of InfluxDB and Grafana containers
481 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
482
483 You can also deploy influxDB and Grafana containers manually on the Jumphost.
484 The following sections show how to do.
485
486 Pull docker images::
487
488    sudo -EH docker pull tutum/influxdb
489    sudo -EH docker pull grafana/grafana
490
491 Run influxDB::
492
493    sudo -EH docker run -d --name influxdb \
494       -p 8083:8083 -p 8086:8086 --expose 8090 --expose 8099 \
495       tutum/influxdb
496    docker exec -it influxdb bash
497
498 Configure influxDB::
499
500    influx
501       >CREATE USER root WITH PASSWORD 'root' WITH ALL PRIVILEGES
502       >CREATE DATABASE yardstick;
503       >use yardstick;
504       >show MEASUREMENTS;
505
506 Run Grafana::
507
508    sudo -EH docker run -d --name grafana -p 1948:3000 grafana/grafana
509
510 Log on http://{YOUR_IP_HERE}:1948 using ``admin``/``admin`` and configure
511 database resource to be ``{YOUR_IP_HERE}:8086``.
512
513 .. image:: images/Grafana_config.png
514    :width: 800px
515    :alt: Grafana data source configuration
516
517 Configure ``yardstick.conf``::
518
519    sudo -EH docker exec -it yardstick /bin/bash
520    sudo cp etc/yardstick/yardstick.conf.sample /etc/yardstick/yardstick.conf
521    sudo vi /etc/yardstick/yardstick.conf
522
523 Modify ``yardstick.conf``::
524
525    [DEFAULT]
526    debug = True
527    dispatcher = influxdb
528
529    [dispatcher_influxdb]
530    timeout = 5
531    target = http://{YOUR_IP_HERE}:8086
532    db_name = yardstick
533    username = root
534    password = root
535
536 Now you can run Yardstick test cases and store the results in influxDB.
537
538
539 Deploy InfluxDB and Grafana directly in Ubuntu (**Todo**)
540 ---------------------------------------------------------
541
542
543 Proxy Support
544 -------------
545
546 To configure the Jumphost to access Internet through a proxy its necessary to
547 export several variables to the environment, contained in the following
548 script::
549
550    #!/bin/sh
551    _proxy=<proxy_address>
552    _proxyport=<proxy_port>
553    _ip=$(hostname -I | awk '{print $1}')
554
555    export ftp_proxy=http://$_proxy:$_proxyport
556    export FTP_PROXY=http://$_proxy:$_proxyport
557    export http_proxy=http://$_proxy:$_proxyport
558    export HTTP_PROXY=http://$_proxy:$_proxyport
559    export https_proxy=http://$_proxy:$_proxyport
560    export HTTPS_PROXY=http://$_proxy:$_proxyport
561    export no_proxy=127.0.0.1,localhost,$_ip,$(hostname),<.localdomain>
562    export NO_PROXY=127.0.0.1,localhost,$_ip,$(hostname),<.localdomain>
563
564 To enable Internet access from a container using ``docker``, depends on the OS
565 version. On Ubuntu 14.04 LTS, which uses SysVinit, ``/etc/default/docker`` must
566 be modified::
567
568    .......
569    # If you need Docker to use an HTTP proxy, it can also be specified here.
570    export http_proxy="http://<proxy_address>:<proxy_port>/"
571    export https_proxy="https://<proxy_address>:<proxy_port>/"
572
573 Then its necessary to restart the ``docker`` service::
574
575    sudo -EH service docker restart
576
577 In Ubuntu 16.04 LTS, which uses Systemd, its necessary to create a drop-in
578 directory::
579
580    sudo mkdir /etc/systemd/system/docker.service.d
581
582 Then, the proxy configuration will be stored in the following file::
583
584    # cat /etc/systemd/system/docker.service.d/http-proxy.conf
585    [Service]
586    Environment="HTTP_PROXY=https://<proxy_address>:<proxy_port>/"
587    Environment="HTTPS_PROXY=https://<proxy_address>:<proxy_port>/"
588    Environment="NO_PROXY=localhost,127.0.0.1,<localaddress>,<.localdomain>"
589
590 The changes need to be flushed and the ``docker`` service restarted::
591
592    sudo systemctl daemon-reload
593    sudo systemctl restart docker
594
595 Any container is already created won't contain these modifications. If needed,
596 stop and delete the container::
597
598    sudo docker stop yardstick
599    sudo docker rm yardstick
600
601 .. warning:: Be careful, the above ``rm`` command will delete the container
602   completely. Everything on this container will be lost.
603
604 Then follow the previous instructions `Prepare the Yardstick container`_ to
605 rebuild the Yardstick container.
606
607
608 References
609 ----------
610
611 .. _`User Guide & Configuration Guide`: http://docs.opnfv.org/en/latest/release/userguide.introduction.html
612 .. _dockerhub: https://hub.docker.com/r/opnfv/yardstick/
613 .. _`Cirros 0.3.5`: http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
614 .. _`Ubuntu 16.04`: https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img
615 .. _`Yardstick GUI demo`: https://www.youtube.com/watch?v=M3qbJDp6QBk