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