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