Merge "Add clean_flag to test cases"
[functest.git] / docs / testing / developer / devguide / index.rst
1 ******************************
2 OPNFV FUNCTEST developer guide
3 ******************************
4
5 .. toctree::
6    :numbered:
7    :maxdepth: 2
8
9
10 ============
11 Introduction
12 ============
13
14 Functest is a project dealing with functional testing.
15 Functest produces its own internal test cases but can also be considered
16 as a framework to support feature and VNF onboarding project testing.
17 Functest developed a TestAPI and defined a test collection framework
18 that can be used by any OPNFV project.
19
20 Therefore there are many ways to contribute to Functest. You can:
21
22  * Develop new internal test cases
23  * Integrate the tests from your feature project
24  * Develop the framework to ease the integration of external test cases
25  * Develop the API / Test collection framework
26  * Develop dashboards or automatic reporting portals
27
28 This document describes how, as a developer, you may interact with the
29 Functest project. The first section details the main working areas of
30 the project. The Second part is a list of "How to" to help you to join
31 the Functest family whatever your field of interest is.
32
33
34 ========================
35 Functest developer areas
36 ========================
37
38
39 Functest High level architecture
40 ================================
41
42 Functest is project delivering a test container dedicated to OPNFV.
43 It includes the tools, the scripts and the test scenarios.
44
45 Functest can be described as follow::
46
47  +----------------------+
48  |                      |
49  |   +--------------+   |                  +-------------------+
50  |   |              |   |    Public        |                   |
51  |   | Tools        |   +------------------+      OPNFV        |
52  |   | Scripts      |   |                  | System Under Test |
53  |   | Scenarios    |   +------------------+                   |
54  |   |              |   |    Management    |                   |
55  |   +--------------+   |                  +-------------------+
56  |                      |
57  |    Functest Docker   |
58  |                      |
59  +----------------------+
60
61 Functest internal test cases
62 ============================
63 The internal test cases in Danube are:
64
65  * healthcheck
66  * connection_check
67  * api_check
68  * vping_ssh
69  * vping_userdata
70  * odl
71  * snaps_smoke
72  * tempest_smoke_serial
73  * rally_sanity
74  * tempest_full_parallel
75  * rally_full
76  * cloudify_ims
77
78 By internal, we mean that this particular test cases have been
79 developped and/or integrated by functest contributors and the associated
80 code is hosted in the Functest repository.
81 An internal case can be fully developped or a simple integration of
82 upstream suites (e.g. Tempest/Rally developped in OpenStack are just
83 integrated in Functest).
84 The structure of this repository is detailed in `[1]`_.
85 The main internal test cases are in the opnfv_tests subfolder of the
86 repository, the internal test cases are:
87
88  * sdn: odl, onos
89  * openstack: healthcheck, vping_ssh, vping_userdata, tempest_*, rally_*, connection_check, api_check, snaps_smoke
90  * vnf: cloudify_ims
91
92 If you want to create a new test case you will have to create a new
93 folder under the testcases directory.
94
95 Functest external test cases
96 ============================
97 The external test cases are inherited from other OPNFV projects,
98 especially the feature projects.
99
100 The external test cases are:
101
102  * promise
103  * doctor
104  * onos
105  * bgpvpn
106  * copper
107  * security_scan
108  * sfc-odl
109  * sfc-onos
110  * parser
111  * domino
112  * multisite
113  * opera_ims
114  * orchestra_ims
115
116
117 The code to run these test cases may be directly in the repository of
118 the project. We have also a **features** sub directory under opnfv_tests
119 directory that may be used (it can be usefull if you want to reuse
120 Functest library).
121
122 Functest framework
123 ==================
124
125 Functest can be considered as a framework.
126 Functest is release as a docker file, including tools, scripts and a CLI
127 to prepare the environement and run tests.
128 It simplifies the integration of external test suites in CI pipeline
129 and provide commodity tools to collect and display results.
130
131 Since Colorado, test categories also known as tiers have been created to
132 group similar tests, provide consistant sub-lists and at the end optimize
133 test duration for CI (see How To section).
134
135 The definition of the tiers has been agreed by the testing working group.
136
137 The tiers are:
138   * healthcheck
139   * smoke
140   * features
141   * components
142   * performance
143   * vnf
144   * stress
145
146 Functest abstraction classes
147 ============================
148
149 In order to harmonize test integration, 3 abstraction classes have been
150 introduced in Danube:
151
152  * testcase_base: base for any test case
153  * feature_base: abstraction for feature project
154  * vnf_base: abstraction for vnf onboarding
155
156 The goal is to unify the way to run test from Functest.
157
158 feature_base and vnf_base inherit from testcase_base.
159
160               +-----------------------------------------+
161               |                                         |
162               |         Testcase_base                   |
163               |                                         |
164               |         - init()                        |
165               |         - run()                         |
166               |         - publish_report()              |
167               |         - check_criteria()              |
168               |                                         |
169               +-----------------------------------------+
170                      |                       |
171                      V                       V
172          +--------------------+   +--------------------------+
173          |                    |   |                          |
174          |    feature_base    |   |      vnf_base            |
175          |                    |   |                          |
176          |  - prepare()       |   |  - prepare()             |
177          |  - post()          |   |  - deploy_orchestrator() |
178          |  - parse_results() |   |  - deploy_vnf()          |
179          |                    |   |  - test_vnf()            |
180          |                    |   |  - clean()               |
181          |                    |   |  - execute()             |
182          |                    |   |                          |
183          +--------------------+   +--------------------------+
184
185
186 Functest util classes
187 =====================
188
189 In order to simplify the creation of test cases, Functest develops some
190 functions that can be used by any feature or internal test cases.
191 Several features are supported such as logger, configuration management and
192 Openstack capabilities (snapshot, clean, tacker,..).
193 These functions can be found under <repo>/functest/utils and can be described as
194 follows:
195
196 functest/utils/
197 |-- config.py
198 |-- constants.py
199 |-- env.py
200 |-- functest_constants.py
201 |-- functest_logger.py
202 |-- functest_utils.py
203 |-- openstack_clean.py
204 |-- openstack_snapshot.py
205 |-- openstack_tacker.py
206 `-- openstack_utils.py
207
208 Note that for Openstack, keystone v3 is now deployed by default by compass,
209 fuel and joid in Danube. All installers still support keysone v2 (deprecated in
210 next version).
211
212 Test collection framework
213 =========================
214
215 The OPNFV testing group created a test collection database to collect
216 the test results from CI:
217
218
219  http://testresults.opnfv.org/test/swagger/spec.html
220
221  Authentication: opnfv/api@opnfv
222
223 Any test project running on any lab integrated in CI can push the
224 results to this database.
225 This database can be used to see the evolution of the tests and compare
226 the results versus the installers, the scenarios or the labs.
227
228
229 Overall Architecture
230 --------------------
231 The Test result management can be summarized as follows::
232
233   +-------------+    +-------------+    +-------------+
234   |             |    |             |    |             |
235   |   Test      |    |   Test      |    |   Test      |
236   | Project #1  |    | Project #2  |    | Project #N  |
237   |             |    |             |    |             |
238   +-------------+    +-------------+    +-------------+
239            |               |               |
240            V               V               V
241        +-----------------------------------------+
242        |                                         |
243        |         Test Rest API front end         |
244        |  http://testresults.opnfv.org/test      |
245        |                                         |
246        +-----------------------------------------+
247            A                |
248            |                V
249            |     +-------------------------+
250            |     |                         |
251            |     |    Test Results DB      |
252            |     |         Mongo DB        |
253            |     |                         |
254            |     +-------------------------+
255            |
256            |
257      +----------------------+
258      |                      |
259      |    test Dashboard    |
260      |                      |
261      +----------------------+
262
263 TestAPI description
264 -------------------
265 The TestAPI is used to declare pods, projects, test cases and test
266 results. Pods are the pods used to run the tests.
267 The results pushed in the database are related to pods, projects and
268 cases. If you try to push results of test done on non referenced pod,
269 the API will return an error message.
270
271 An additional method dashboard has been added to post-process
272 the raw results in release Brahmaputra (deprecated in Colorado).
273
274 The data model is very basic, 4 objects are created:
275
276   * Pods
277   * Projects
278   * Testcases
279   * Results
280
281 Pods::
282
283   {
284     "id": <ID>,
285     "details": <URL description of the POD>,
286     "creation_date": "YYYY-MM-DD HH:MM:SS",
287     "name": <The POD Name>,
288     "mode": <metal or virtual>,
289     "role": <ci-pod or community-pod or single-node>
290   },
291
292 Projects::
293
294   {
295     "id": <ID>,
296     "name": <Name of the Project>,
297     "creation_date": "YYYY-MM-DD HH:MM:SS",
298     "description": <Short description>
299   },
300
301 Testcases::
302
303   {
304     "id": <ID>,
305     "name":<Name of the test case>,
306     "project_name":<Name of belonged project>,
307     "creation_date": "YYYY-MM-DD HH:MM:SS",
308     "description": <short description>,
309     "url":<URL for longer description>
310   },
311
312 Results::
313
314   {
315     "_id": <ID>,
316     "case_name": <Reference to the test case>,
317     "project_name": <Reference to project>,
318     "pod_name": <Reference to POD where the test was executed>,
319     "installer": <Installer Apex or Compass or Fuel or Joid>,
320     "version": <master or Colorado or Brahmaputra>,
321     "start_date": "YYYY-MM-DD HH:MM:SS",
322     "stop_date": "YYYY-MM-DD HH:MM:SS",
323     "build_tag": <such as "jenkins-functest-fuel-baremetal-daily-master-108">,
324     "scenario": <Scenario on which the test was executed>,
325     "criteria": <PASS or FAILED>,
326     "trust_indicator": {
327                         "current": 0,
328                         "histories": []
329                        }
330   }
331
332 The API can described as follows. For detailed information, please go to
333
334  http://testresults.opnfv.org/test/swagger/spec.html
335
336  Authentication: opnfv/api@opnfv
337
338 Version:
339
340  +--------+--------------------------+-----------------------------------------+
341  | Method | Path                     | Description                             |
342  +========+==========================+=========================================+
343  | GET    | /versions                | Get all supported API versions          |
344  +--------+--------------------------+-----------------------------------------+
345
346
347 Pods:
348
349  +--------+----------------------------+-----------------------------------------+
350  | Method | Path                       | Description                             |
351  +========+============================+=========================================+
352  | GET    | /api/v1/pods               | Get the list of declared Labs (PODs)    |
353  +--------+----------------------------+-----------------------------------------+
354  | POST   | /api/v1/pods               | Declare a new POD                       |
355  |        |                            | Content-Type: application/json          |
356  |        |                            | {                                       |
357  |        |                            | "name": "pod_foo",                      |
358  |        |                            | "mode": "metal",                        |
359  |        |                            | "role": "ci-pod",                       |
360  |        |                            | "details": "it is a ci pod"             |
361  |        |                            | }                                       |
362  +--------+----------------------------+-----------------------------------------+
363  | GET    | /api/v1/pods/{pod_name}    | Get a declared POD                      |
364  +--------+----------------------------+-----------------------------------------+
365
366 Projects:
367
368  +--------+----------------------------+-----------------------------------------+
369  | Method | Path                       | Description                             |
370  +========+============================+=========================================+
371  | GET    | /api/v1/projects           | Get the list of declared projects       |
372  +--------+----------------------------+-----------------------------------------+
373  | POST   | /api/v1/projects           | Declare a new test project              |
374  |        |                            | Content-Type: application/json          |
375  |        |                            | {                                       |
376  |        |                            | "name": "project_foo",                  |
377  |        |                            | "description": "whatever you want"      |
378  |        |                            | }                                       |
379  +--------+----------------------------+-----------------------------------------+
380  | DELETE | /api/v1/projects/{project} | Delete a test project                   |
381  +--------+----------------------------+-----------------------------------------+
382  | GET    | /api/v1/projects/{project} | Get details on a {project}              |
383  |        |                            |                                         |
384  +--------+----------------------------+-----------------------------------------+
385  | PUT    | /api/v1/projects/{project} | Update a test project                   |
386  |        |                            |                                         |
387  |        |                            | Content-Type: application/json          |
388  |        |                            | {                                       |
389  |        |                            | <the field(s) you want to modify>       |
390  |        |                            | }                                       |
391  +--------+----------------------------+-----------------------------------------+
392
393
394 Testcases:
395
396  +--------+----------------------------+-----------------------------------------+
397  | Method | Path                       | Description                             |
398  +========+============================+=========================================+
399  | GET    | /api/v1/projects/{project}/| Get the list of testcases of {project}  |
400  |        | cases                      |                                         |
401  +--------+----------------------------+-----------------------------------------+
402  | POST   | /api/v1/projects/{project}/| Add a new test case to {project}        |
403  |        | cases                      | Content-Type: application/json          |
404  |        |                            | {                                       |
405  |        |                            | "name": "case_foo",                     |
406  |        |                            | "description": "whatever you want"      |
407  |        |                            | "url": "whatever you want"              |
408  |        |                            | }                                       |
409  +--------+----------------------------+-----------------------------------------+
410  | DELETE | /api/v1/projects/{project}/| Delete a test case                      |
411  |        | cases/{case}               |                                         |
412  +--------+----------------------------+-----------------------------------------+
413  | GET    | /api/v1/projects/{project}/| Get a declared test case                |
414  |        | cases/{case}               |                                         |
415  +--------+----------------------------+-----------------------------------------+
416  | PUT    | /api/v1/projects/{project}?| Modify a test case of {project}         |
417  |        | cases/{case}               |                                         |
418  |        |                            | Content-Type: application/json          |
419  |        |                            | {                                       |
420  |        |                            | <the field(s) you want to modify>       |
421  |        |                            | }                                       |
422  +--------+----------------------------+-----------------------------------------+
423
424 Results:
425
426  +--------+----------------------------+------------------------------------------+
427  | Method | Path                       | Description                              |
428  +========+============================+==========================================+
429  | GET    | /api/v1/results            | Get all the test results                 |
430  +--------+----------------------------+------------------------------------------+
431  | POST   | /api/v1/results            | Add a new test results                   |
432  |        |                            | Content-Type: application/json           |
433  |        |                            | {                                        |
434  |        |                            | "project_name": "project_foo",           |
435  |        |                            | "scenario": "odl-l2",                    |
436  |        |                            | "stop_date": "2016-05-28T14:42:58.384Z", |
437  |        |                            | "trust_indicator": 0.5,                  |
438  |        |                            | "case_name": "vPing",                    |
439  |        |                            | "build_tag": "",                         |
440  |        |                            | "version": "Colorado",                   |
441  |        |                            | "pod_name": "pod_foo",                   |
442  |        |                            | "criteria": "PASS",                      |
443  |        |                            | "installer": "fuel",                     |
444  |        |                            | "start_date": "2016-05-28T14:41:58.384Z",|
445  |        |                            | "details": <your results>                |
446  |        |                            | }                                        |
447  +--------+----------------------------+------------------------------------------+
448  | GET    | /api/v1/results?           | Get the test results of {case}           |
449  |        | case={case}                |                                          |
450  +--------+----------------------------+------------------------------------------+
451  | GET    | /api/v1/results?           | Get the test results of build_tag        |
452  |        | build_tag={tag}            | {tag}.                                   |
453  +--------+----------------------------+------------------------------------------+
454  | GET    | /api/v1/results?           | Get last {N} records of test results     |
455  |        | last={N}                   |                                          |
456  +--------+----------------------------+------------------------------------------+
457  | GET    | /api/v1/results?           | Get the test results of scenario         |
458  |        | scenario={scenario}        | {scenario}.                              |
459  +--------+----------------------------+------------------------------------------+
460  | GET    | /api/v1/results?           | Get the test results of trust_indicator  |
461  |        | trust_indicator={ind}      | {ind}.                                   |
462  +--------+----------------------------+------------------------------------------+
463  | GET    | /api/v1/results?           | Get the test results of last days        |
464  |        | period={period}            | {period}.                                |
465  +--------+----------------------------+------------------------------------------+
466  | GET    | /api/v1/results?           | Get the test results of {project}        |
467  |        | project={project}          |                                          |
468  +--------+----------------------------+------------------------------------------+
469  | GET    | /api/v1/results?           | Get the test results of version          |
470  |        | version={version}          | {version}.                               |
471  +--------+----------------------------+------------------------------------------+
472  | GET    | /api/v1/results?           | Get the test results of criteria         |
473  |        | criteria={criteria}        | {criteria}.                              |
474  +--------+----------------------------+------------------------------------------+
475  | GET    | /api/v1/results?           | get the results on pod {pod}             |
476  |        | pod={pod}                  |                                          |
477  +--------+----------------------------+------------------------------------------+
478  | GET    | /api/v1/results?           | Get the test results of installer {inst} |
479  |        | installer={inst}           |                                          |
480  +--------+----------------------------+------------------------------------------+
481  | GET    | /api/v1/results?           | Get the results according to combined    |
482  |        | <query conditions>         | query conditions supported above         |
483  +--------+----------------------------+------------------------------------------+
484  | GET    | /api/v1/results/{result_id}| Get the test result by result_id         |
485  +--------+----------------------------+------------------------------------------+
486
487 Scenarios:
488
489   +--------+----------------------------+-----------------------------------------+
490   | Method | Path                       | Description                             |
491   +========+============================+=========================================+
492   | GET    | /api/v1/scenarios          | Get the list of declared scenarios      |
493   +--------+----------------------------+-----------------------------------------+
494   | POST   | /api/v1/scenario           | Declare a new scenario                  |
495   +--------+----------------------------+-----------------------------------------+
496   | GET    | /api/v1/scenario?          | Get a declared scenario                 |
497   |        | <query conditions>         |                                         |
498   +--------+----------------------------+-----------------------------------------+
499
500
501 The code of the API is hosted in the releng repository `[6]`_.
502 The static documentation of the API can be found at `[17]`_.
503 The TestAPI has been dockerized and may be installed locally in your
504 lab. See `[15]`_ for details.
505
506 The deployment of the TestAPI has been automated.
507 A jenkins job manages:
508   * the unit tests of the TestAPI
509   * the creation of a new docker file
510   * the deployment of the new TestAPI
511   * the archive of the old TestAPI
512   * the backup of the Mongo DB
513
514 TestAPI Authorization
515 ~~~~~~~~~~~~~~~~~~~~~
516
517 PUT/DELETE/POST operations of the TestAPI now require token based authorization. The token needs
518 to be added in the request using a header 'X-Auth-Token' for access to the database.
519
520 e.g::
521     headers['X-Auth-Token']
522
523 The value of the header i.e the token can be accessed in the jenkins environment variable
524 *TestApiToken*. The token value is added as a masked password.
525
526 .. code-block:: python
527
528     headers['X-Auth-Token'] = os.environ.get('TestApiToken')
529
530 The above example is in Python. Token based authentication has been added so that only ci pods
531 jenkins job can have access to the database.
532
533 Please note that currently token authorization is implemented but is not yet enabled.
534
535   Automatic reporting
536   ===================
537
538   An automatic reporting page has been created in order to provide a
539   consistant view of the scenarios.
540   In this page, each scenario is evaluated according to test criteria.
541   The code for the automatic reporting is available at `[8]`_.
542
543   The results are collected from the centralized database every day and,
544   per scenario. A score is calculated based on the results from the last
545   10 days. This score is the addition of single test scores. Each test
546   case has a success criteria reflected in the criteria field from the
547   results.
548
549   Considering an instance of a scenario os-odl_l2-nofeature-ha, the
550   scoring is the addition of the scores of all the runnable tests from the
551   categories (tiers healthcheck, smoke and features)
552   corresponding to this scenario.
553
554
555    +---------------------+---------+---------+---------+---------+
556    | Test                | Apex    | Compass | Fuel    |  Joid   |
557    +=====================+=========+=========+=========+=========+
558    | vPing_ssh           |    X    |    X    |    X    |    X    |
559    +---------------------+---------+---------+---------+---------+
560    | vPing_userdata      |    X    |    X    |    X    |    X    |
561    +---------------------+---------+---------+---------+---------+
562    | tempest_smoke_serial|    X    |    X    |    X    |    X    |
563    +---------------------+---------+---------+---------+---------+
564    | rally_sanity        |    X    |    X    |    X    |    X    |
565    +---------------------+---------+---------+---------+---------+
566    | odl                 |    X    |    X    |    X    |    X    |
567    +---------------------+---------+---------+---------+---------+
568    | promise             |         |         |    X    |    X    |
569    +---------------------+---------+---------+---------+---------+
570    | doctor              |    X    |         |    X    |         |
571    +---------------------+---------+---------+---------+---------+
572    | security_scan       |    X    |         |         |         |
573    +---------------------+---------+---------+---------+---------+
574    | parser              |         |         |    X    |         |
575    +---------------------+---------+---------+---------+---------+
576    | copper              |    X    |         |         |    X    |
577    +---------------------+---------+---------+---------+---------+
578
579   All the testcases listed in the table are runnable on
580   os-odl_l2-nofeature scenarios.
581   If no result is available or if all the results are failed, the test
582   case get 0 point.
583   If it was succesfull at least once but not anymore during the 4 runs,
584   the case get 1 point (it worked once).
585   If at least 3 of the last 4 runs were successful, the case get 2 points.
586   If the last 4 runs of the test are successful, the test get 3 points.
587
588   In the example above, the target score for fuel/os-odl_l2-nofeature-ha
589   is 3x6 = 18 points.
590
591   The scenario is validated per installer when we got 3 points for all
592   individual test cases (e.g 18/18).
593   Please note that complex or long duration tests are not considered for
594   the scoring. The success criteria are not always easy to define and may
595   require specific hardware configuration. These results however provide
596   a good level of trust on the scenario.
597
598   A web page is automatically generated every day to display the status.
599   This page can be found at `[9]`_. For the status, click on Status menu,
600   you may also get feedback for vims and tempest_smoke_serial test cases.
601
602   Any validated scenario is stored in a local file on the web server. In
603   fact as we are using a sliding windows to get results, it may happen
604   that a successful scenarios is no more run (because considered as
605   stable) and then the number of iterations (4 needed) would not be
606   sufficient to get the green status.
607
608   Please note that other test cases (e.g. sfc_odl, bgpvpn) need also
609   ODL configuration addons and as a consequence specific scenario.
610   There are not considered as runnable on the generic odl_l2 scenario.
611
612 Dashboard
613 =========
614
615 Dashboard is used to provide a consistant view of the results collected
616 in CI.
617 The results showed on the dashboard are post processed from the Database,
618 which only contains raw results.
619
620 In Brahmaputra, we created a basic dashboard.
621 Since Colorado, it was decided to adopt ELK framework. Mongo DB results
622 are extracted to feed Elasticsearch database (`[7]`_).
623
624 A script was developed to build elasticsearch data set. This
625 script can be found in `[16]`_.
626
627 For next versions, it was decided to integrated bitergia dashboard.
628 Bitergia already provides a dashboard for code and infrastructure.
629 A new Test tab will be added. The dataset will be built by consuming
630 the TestAPI.
631
632
633 =======
634 How TOs
635 =======
636
637 How Functest works?
638 ===================
639
640 The installation and configuration of the Functest docker image is
641 described in `[1]`_.
642
643 The procedure to start tests is described  in `[2]`_
644
645
646 How can I contribute to Functest?
647 =================================
648
649 If you are already a contributor of any OPNFV project, you can
650 contribute to functest. If you are totally new to OPNFV, you must first
651 create your Linux Foundation account, then contact us in order to
652 declare you in the repository database.
653
654 We distinguish 2 levels of contributors:
655
656  * the standard contributor can push patch and vote +1/0/-1 on any Functest patch
657  * The commitor can vote -2/-1/0/+1/+2 and merge
658
659 Functest commitors are promoted by the Functest contributors.
660
661
662 Where can I find some help to start?
663 ====================================
664
665 This guide is made for you. You can also have a look at the project wiki
666 page `[10]`_.
667 There are references on documentation, video tutorials, tips...
668
669 You can also directly contact us by mail with [Functest] prefix in the
670 title at opnfv-tech-discuss@lists.opnfv.org or on the IRC chan
671 #opnfv-functest.
672
673
674 What kind of testing do you do in Functest?
675 ===========================================
676
677 Functest is focusing on Functional testing. The results must be PASS or
678 FAIL. We do not deal with performance and/or qualification tests.
679 We consider OPNFV as a black box and execute our tests from the jumphost
680 according to Pharos reference technical architecture.
681
682 Upstream test suites are integrated (Rally/Tempest/ODL/ONOS,...).
683 If needed Functest may bootstrap temporarily testing activities if they
684 are identified but not covered yet by an existing testing project (e.g
685 security_scan before the creation of the security repository)
686
687
688 How test constraints are defined?
689 =================================
690
691 Test constraints are defined according to 2 paramaters:
692
693  * The scenario (DEPLOY_SCENARIO env variable)
694  * The installer (INSTALLER_TYPE env variable)
695
696 A scenario is a formal description of the system under test.
697 The rules to define a scenario are described in `[4]`_
698
699 These 2 constraints are considered to determinate if the test is runnable
700 or not (e.g. no need to run onos suite on odl scenario).
701
702 In the test declaration for CI, the test owner shall indicate these 2
703 constraints. The file testcases.yaml `[5]`_ must be patched in git to
704 include new test cases. A more elaborated system based on template is
705 planned for next releases
706
707 For each dependency, it is possible to define a regex::
708
709     name: promise
710     criteria: 'success_rate == 100%'
711     description: >-
712         Test suite from Promise project.
713     dependencies:
714         installer: '(fuel)|(joid)'
715         scenario: ''
716
717 In the example above, it means that promise test will be runnable only
718 with joid or fuel installers on any scenario.
719
720 The vims criteria means any installer and exclude onos and odl with
721 bgpvpn scenarios::
722
723     name: vims
724     criteria: 'status == "PASS"'
725     description: >-
726         This test case deploys an OpenSource vIMS solution from Clearwater
727         using the Cloudify orchestrator. It also runs some signaling traffic.
728     dependencies:
729         installer: ''
730         scenario: '(ocl)|(nosdn)|^(os-odl)((?!bgpvpn).)*$'
731
732
733 How to write and check constaint regex?
734 =======================================
735
736 Regex are standard regex. You can have a look at  `[11]`_
737
738 You can also easily test your regex via an online regex checker such as `[12]`_.
739 Put your scenario in the TEST STRING window (e.g. os-odl_l3-ovs-ha), put
740 your regex in the REGULAR EXPRESSION window, then you can test your rule
741 .
742
743
744 How to know which test I can run?
745 =================================
746
747 You can use the API `[13]`_. The static declaration is in git `[5]`_
748
749 If you are in a Functest docker container (assuming that the
750 environement has been prepared): just use the CLI.
751
752 You can get the list per Test cases or by Tier::
753
754     # functest testcase list
755     healthcheck
756     vping_ssh
757     vping_userdata
758     tempest_smoke_serial
759     rally_sanity
760     odl
761     doctor
762     security_scan
763     tempest_full_parallel
764     rally_full
765     vims
766     # functest tier list
767     - 0. healthcheck:
768     ['healthcheck']
769     - 1. smoke:
770     ['vping_ssh', 'vping_userdata', 'tempest_smoke_serial', 'rally_sanity']
771     - 2. sdn_suites:
772     ['odl']
773     - 3. features:
774     ['doctor', 'security_scan']
775     - 4. openstack:
776     ['tempest_full_parallel', 'rally_full']
777     - 5. vnf:
778     ['vims']
779
780
781 How to manually start Functest tests?
782 =====================================
783
784 Assuming that you are connected on the jumphost and that the system is
785 "Pharos compliant", i.e the technical architecture is compatible with
786 the one defined in the Pharos project::
787
788     # docker pull opnfv/functest:latest
789     # envs="-e INSTALLER_TYPE=fuel -e INSTALLER_IP=10.20.0.2 -e DEPLOY_SCENARIO=os-odl_l2-nofeature-ha -e CI_DEBUG=true"
790     # sudo docker run --privileged=true -id ${envs} opnfv/functest:latest /bin/bash
791
792
793 Then you must connect to the docker container and source the
794 credentials::
795
796     # docker ps (copy the id)
797     # docker exec -ti <container_id> bash
798     # source $creds
799
800
801 You must first check if the environment is ready::
802
803     # functest env status
804     Functest environment ready to run tests.
805
806
807 If not ready, prepare the env by launching::
808
809     # functest env prepare
810     Functest environment ready to run tests.
811
812 Once the Functest env is ready, you can use the CLI to start tests.
813
814 You can run test cases per test case or per tier:
815  # functest testcase run <case name> or # functest tier run  <tier name>
816
817
818 e.g::
819
820     # functest testcase run tempest_smoke_serial
821     # functest tier run features
822
823
824 If you want to run all the tests you can type::
825
826     # functest testcase run all
827
828
829 If you want to run all the tiers (same at the end that running all the
830 test cases) you can type::
831
832     # functest tier run all
833
834
835 How to declare my tests in Functest?
836 ====================================
837
838 If you want to add new internal test cases, you can submit patch under
839 the testcases directory of Functest repository.
840
841 For feature test integration, the code can be kept into your own
842 repository. The Functest files to be modified are:
843
844  * functest/docker/Dockerfile: get your code in Functest container
845  * functest/ci/testcases.yaml: reference your test and its associated constraints
846
847
848 Dockerfile
849 ----------
850
851 This file lists the repositories (internal or external) to be cloned in
852 the Functest container. You can also add external packages::
853
854  RUN git clone https://gerrit.opnfv.org/gerrit/<your project> ${REPOS_DIR}/<your project>
855
856 testcases.yaml
857 --------------
858
859 All the test cases that must be run from CI / CLI must be declared in
860 ci/testcases.yaml.
861
862 This file is used to get the constraints related to the test::
863
864     name: <my_super_test_case>
865     criteria: <not used yet in Colorado, could be > 'PASS', 'rate > 90%'
866     description: >-
867         <the description of your super test suite>
868     dependencies:
869         installer: regex related to installer e.g. 'fuel', '(apex)||(joid)'
870         scenario: regex related to the scenario e.g. 'ovs*no-ha'
871
872
873 You must declare your test case in one of the category (tier).
874
875 If you are integrating test suites from a feature project, the default
876 category is **features**.
877
878
879 How to select my list of tests for CI?
880 ======================================
881
882 Functest can be run automatically from CI, a jenkins job is usually
883 called after an OPNFV fresh installation.
884 By default we try to run all the possible tests (see `[14]` called from
885 Functest jenkins job)::
886
887     cmd="python ${FUNCTEST_REPO_DIR}/ci/run_tests.py -t all ${flags}"
888
889
890 Each case can be configured as daily and/or weekly task.
891 Weekly tasks are used for long duration or experimental tests.
892 Daily tasks correspond to the minimum set of test suites to validate a scenario.
893
894 When executing run_tests.py, a check based on the jenkins build tag will
895 be considered to detect whether it is a daily and/or a weekly test.
896
897 in your CI you can customize the list of test you want to run by case or
898 by tier, just change the line::
899
900     cmd="python ${FUNCTEST_REPO_DIR}/ci/run_tests.py -t <whatever you want> ${flags}"
901
902 e.g.::
903
904     cmd="python ${FUNCTEST_REPO_DIR}/ci/run_tests.py -t healthcheck,smoke ${flags}"
905
906 This command will run all the test cases of the first 2 tiers, i.e.
907 healthcheck, connection_check, api_check, vping_ssh, vping_userdata,
908 snaps_somke, tempest_smoke_serial and rally_sanity.
909
910
911 How to push your results into the Test Database
912 ===============================================
913
914 The test database is used to collect test results. By default it is
915 enabled only for CI tests from Production CI pods.
916
917 The architecture and associated API is described in previous chapter.
918 If you want to push your results from CI, you just have to call the API
919 at the end of your script.
920
921 You can also reuse a python function defined in functest_utils.py::
922
923     def push_results_to_db(db_url, case_name, logger, pod_name,version, payload):
924       """
925       POST results to the Result target DB
926       """
927       url = db_url + "/results"
928       installer = get_installer_type(logger)
929       params = {"project_name": "functest", "case_name": case_name,
930                 "pod_name": pod_name, "installer": installer,
931                 "version": version, "details": payload}
932
933       headers = {'Content-Type': 'application/json'}
934       try:
935           r = requests.post(url, data=json.dumps(params), headers=headers)
936           if logger:
937               logger.debug(r)
938           return True
939       except Exception, e:
940           print "Error [push_results_to_db('%s', '%s', '%s', '%s', '%s')]:" \
941               % (db_url, case_name, pod_name, version, payload), e
942           return False
943
944
945 ==========
946 References
947 ==========
948
949 _`[1]`: http://artifacts.opnfv.org/functest/docs/configguide/index.html Functest configuration guide
950
951 _`[2]`: http://artifacts.opnfv.org/functest/docs/userguide/index.html functest user guide
952
953 _`[3]`: https://wiki.opnfv.org/opnfv_test_dashboard Brahmaputra dashboard
954
955 _`[4]`: https://wiki.opnfv.org/display/INF/CI+Scenario+Naming
956
957 _`[5]`: https://git.opnfv.org/cgit/functest/tree/ci/testcases.yaml
958
959 _`[6]`: https://git.opnfv.org/cgit/releng/tree/utils/test/result_collection_api
960
961 _`[7]`: https://git.opnfv.org/cgit/releng/tree/utils/test/scripts
962
963 _`[8]`: https://git.opnfv.org/cgit/releng/tree/utils/test/reporting/functest
964
965 _`[9]`: http://testresults.opnfv.org/reporting/
966
967 _`[10]`: https://wiki.opnfv.org/opnfv_functional_testing
968
969 _`[11]`: https://docs.python.org/2/howto/regex.html
970
971 _`[12]`: https://regex101.com/
972
973 _`[13]`: http://testresults.opnfv.org/test/api/v1/projects/functest/cases
974
975 _`[14]`: https://git.opnfv.org/cgit/releng/tree/jjb/functest/functest-daily.sh
976
977 _`[15]`: https://git.opnfv.org/cgit/releng/tree/utils/test/result_collection_api/README.rst
978
979 _`[16]`: https://git.opnfv.org/cgit/releng/tree/utils/test/scripts/mongo_to_elasticsearch.py
980
981 _`[17]`: http://artifacts.opnfv.org/releng/docs/testapi.html
982
983 OPNFV main site: http://www.opnfv.org
984
985 OPNFV functional test page: https://wiki.opnfv.org/opnfv_functional_testing
986
987 IRC support chan: #opnfv-functest
988
989 _`OpenRC`: http://docs.openstack.org/user-guide/common/cli_set_environment_variables_using_openstack_rc.html
990
991 _`Rally installation procedure`: https://rally.readthedocs.org/en/latest/tutorial/step_0_installation.html
992
993 _`config_functest.yaml` : https://git.opnfv.org/cgit/functest/tree/testcases/config_functest.yaml