97c18a243216905c0ba05de25ffaabd3f2e76cf6
[ric-plt/a1.git] / docs / developer-guide.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
3
4 A1 Developer Guide
5 ==================
6
7 .. contents::
8    :depth: 3
9    :local:
10
11 Tech Stack
12 ----------
13
14 The A1 Mediator is implemented in Python, currently 3.8, and depends on these third-party packages
15 and technologies:
16
17 - OpenAPI3
18 - Connexion
19 - Flask with Gevent serving
20 - Swagger
21
22 Version bumping A1
23 ------------------
24
25 This project follows semver. When the version string changes, these files must be updated:
26
27 #. ``setup.py``
28 #. ``container-tag.yaml``
29 #. ``integration_tests/a1mediator/Chart.yaml``
30 #. ``docs/release-notes.rst``
31 #. ``a1/openapi.yaml`` But note this is an API version, not a software version; there's no need to bump on non-API changes.
32 #.  And over in the ric-plt/ric-dep repo that contains the A1 Mediator helm chart, files ``values.yaml`` and ``Chart.yaml``.
33
34 It's convenient to use the Python utility `bumpversion` to maintain the first three items.
35 After setup (``pip install bumpversion``) you can change the patch version like this::
36
37     bumpversion --verbose patch
38
39 Or change the minor version like this::
40
41     bumpversion --verbose minor
42
43 After the `bumpversion` utility has modified the files, update the release notes then commit.
44
45
46 Version bumping RMR
47 -------------------
48
49 A1 (Dockerfile), Dockerfile-Unit-Test, and all three integration test receivers use an Alpine
50 base image and install RMR from a base builder image.  Must update and rebuild all 5 containers
51 in the A1 repo (or just A1 itself for production usage).
52
53 In addition these items in this repo must be kept in sync:
54
55 #. ``rmr-version.yaml`` controls what rmr gets installed for unit testing in Jenkins
56 #. ``integration_tests/install_rmr.sh`` is a useful script for a variety of local testing.
57
58 Version bumping Python
59 ----------------------
60
61 If you want to update the version of python; for example this was recently done to move
62 from 3.7 to 3.8, update these files:
63
64 #. ``Dockerfile``
65 #. ``Dockerfile-Unit-Test``
66 #. ``tox.ini``
67
68 Unit Testing
69 ------------
70
71 Running the unit tests requires the python packages ``tox`` and ``pytest``.
72
73 The RMR library is also required during unit tests. If running directly from tox
74 (outside a Docker container), install RMR using the script in the integration_tests
75 directory: ``install_rmr.sh``.
76
77 Upon completion, view the test coverage like this:
78
79 ::
80
81    tox
82    open htmlcov/index.html
83
84 Alternatively, you can run the unit tests in Docker (this is somewhat
85 less nice because you don't get the pretty HTML)
86
87 ::
88
89    docker build  --no-cache -f Dockerfile-Unit-Test .
90
91 Integration testing
92 -------------------
93
94 This tests A1’s external API with three test receivers. This requires
95 docker, kubernetes and helm.
96
97 Build all the images:
98
99 ::
100
101     docker build  -t a1:latest .
102     cd integration_tests/testxappcode
103     docker build -t delayreceiver:latest -f Dockerfile-delay-receiver .
104     docker build -t queryreceiver:latest -f Dockerfile-query-receiver .
105     docker build -t testreceiver:latest  -f Dockerfile-test-receiver  .
106
107
108 Then, run all the tests from the root (this requires the python packages ``tox``, ``pytest``, and ``tavern``).
109
110 ::
111
112    tox -c tox-integration.ini
113
114 This script:
115
116 #. Deploys 3 helm charts (5 containers) into a local kubernetes installation
117 #. Port forwards a pod ClusterIP to localhost
118 #. Uses “tavern” to run some tests against the server
119 #. Barrages the server with Apache bench
120 #. Tears everything down