Functional Test Updates for I Release
[nonrtric.git] / test / auto-test / README.md
1 #  ============LICENSE_START===============================================
2 #  Copyright (C) 2020-2023 Nordix Foundation. All rights reserved.
3 #  Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved.
4 #  ========================================================================
5 #  Licensed under the Apache License, Version 2.0 (the "License");
6 #  you may not use this file except in compliance with the License.
7 #  You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #  Unless required by applicable law or agreed to in writing, software
12 #  distributed under the License is distributed on an "AS IS" BASIS,
13 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #  See the License for the specific language governing permissions and
15 #  limitations under the License.
16 #  ============LICENSE_END=================================================
17
18 # Overview
19
20 The bash scripts in this dir are intended for function test of the Non-RT RIC in different configurations, using simulators when needed for the external interfaces.
21 A few of the bash scripts are so called 'suites', These suite scripts calls a sequence of the other bash test scripts.
22
23 ## Automated test scripts
24
25 There are two types of scripts, filenames in the format FTCXXX.sh test one or more components of the Non-RT RIC. Filenames in the format SuiteZZZZ.sh tests a number of FTCXXX.sh script as one suite. (XXX is an integer selected from the categories described further below).
26 FTC is short for Function Test Case. In addition, there are also other test scripts with other naming format used for demo setup etc (e.g PM_DEMO.sh).
27
28 To list all test case files with a s short description, do `grep TC_ONELINE_DESCR *.sh` for a complete list.
29
30 The requirements, in terms of the execution environment, to run a script or a suite is to have docker, docker-compose (v2+) and python3 installed (the scripts warns if not installed). As an option, the scripts can also be executed in a Minikube or Kubernetes installation. The additional requirement is to have a clean minikube/kubernetes installation, preferably with the kube dashboard installed.
31 The scripts have been tested to work on both MacOS and Ubuntu using docker. They should work also in git-bash on windows (for docker) but only partly verified. Running using minikube has only been verified on Ubuntu and running on kubernetes has been verified on MacOS and Ubuntu. Successful sample tests has been made on google cloud.
32
33 ## Configuration
34
35 The test scripts uses configuration from a single profile file, found in `../common/test_env-*.sh`, which contains all needed configuration in terms of image names, image tags, ports, file paths, passwords etc. There is one profile file for system (ORAN/ONAP) and release.
36 If temporary changes are needed to the settings in a profile file, use an override file containing only the variable to override.
37
38 ## How to run
39
40 A test script, for example FTC1, is executed from the cmd line using the script filename and one or more parameters:
41
42  >```./FTC1.sh remote docker --env-file ../common/test_env-oran-i-release.sh```
43
44 Note that this script will use the staging images. Once the release images are available,add the parameter "release" to run with released images.
45
46 See the README.md in  `../common/` for all details about available parameters and their meaning.
47
48 Each test script prints out the overall result of the tests in the end of the execution.
49
50 The test scripts produce quite a number of logs; all container logs, a log of all http/https calls from the test scripts including the payload, some configuration created during test and also a test case log (same as what is printed on the screen during execution). All these logs are stored in `logs/FTCXXX/` - basically in a dir with the same name as the script. So each test script is using its own log directory. If the same test is started again, any existing logs will be moved to a subdirectory called `previous`.
51
52 To test all components on a very basic level, run the demo test script(s) for the desired release.
53 Note that oran tests only include components from oran (exception is the onap sdnc).
54 Note that onap test uses components from onap combined with released oran components available at that onap release (e.g. Montreal contains onap images from Montreal and oran images (released images from i-release).
55
56 In general, the test scripts support the current ongoing release as well as two previous releases.
57
58
59 ORAN G-RELEASE
60 =========
61 >```./PM_EI_DEMO.sh remote-remove  docker  release  --env-file ../common/test_env-oran-g-release.sh  --use-release-image SDNC```
62
63 >```./PM_EI_DEMO.sh remote-remove  kube  release  --env-file ../common/test_env-oran-g-release.sh  --use-release-image SDNC```
64
65 ORAN H-RELEASE
66 =========
67 >```./PM_EI_DEMO.sh remote-remove  docker  release  --env-file ../common/test_env-oran-h-release.sh  --use-release-image SDNC```
68
69 >```./PM_EI_DEMO.sh remote-remove  kube  release  --env-file ../common/test_env-oran-h-release.sh  --use-release-image SDNC```
70
71 ORAN I-RELEASE
72 =========
73 >```./PM_EI_DEMO.sh remote-remove  docker  --env-file ../common/test_env-oran-i-release.sh --use-release-image SDNC```
74
75 >```./PM_EI_DEMO.sh remote-remove  kube  --env-file ../common/test_env-oran-i-release.sh --use-release-image SDNC```
76
77
78 ONAP KOHN
79 =============
80 >```./PM_EI_DEMO.sh remote-remove  docker  release  --env-file ../common/test_env-onap-kohn.sh```
81
82 >```./PM_EI_DEMO.sh remote-remove  kube  release  --env-file ../common/test_env-onap-kohn.sh```
83
84
85 ONAP LONDON
86 =============
87 >```./PM_EI_DEMO.sh remote-remove  docker  release  --env-file ../common/test_env-onap-london.sh```
88
89 >```./PM_EI_DEMO.sh remote-remove  kube  release  --env-file ../common/test_env-onap-london.sh```
90
91
92 ONAP MONTREAL
93 =============
94 >```./PM_EI_DEMO.sh remote-remove  docker  --env-file ../common/test_env-onap-montreal.sh```
95
96 >```./PM_EI_DEMO.sh remote-remove  kube  --env-file ../common/test_env-onap-montreal.sh```
97
98
99 ## Useful features
100
101 There are a fair amount of additional flags that can be used to configure the test setup. See a detailed descriptions of all flags in `test/common/README.md`.
102
103
104 ### Stop at first error
105 In general, the test script will continue to try to make all tests even if there are failures. For debugging it might be needed to stop when the first test fails. In this case, add the flag below to stop test execution at the first failed test:
106 `--stop-at-error`
107
108 ### Test released images
109
110 Tests are normally carried out on staging images. However, for testing the released images (when the images are available in the nexus report) the flag `release` shall be added to command. See also the below section to further tailor which image version (local/staging/snapshot) to use.
111
112 ### Use other image builds
113 As default, all tests of the project images are carried out on the staging images (unless the `release` flag is given -  then released versions of the project images are used).
114 In some cases, for example a locally built image or a snapshot image for one or more components can be used for testing together with staging or released images.
115
116 The following flags can be used to switch image for one more individual components to use local image, remote snapshot image, remote staging image or or remote release image.
117
118 `--use-local-image`
119 `--use-snapshot-image`
120 `--use-staging-image`
121 `--use-release-image`
122
123 The flag shall be followed by a space separated list of app names.
124 Example of using a local image for A1 Policy Management Service :
125 `--use-local-image A1PMS`
126
127 The app names that can use other image are listed in the test engine configuration, see env var `AVAILABLE_IMAGES_OVERRIDE`in file `test/common/testengine-config.sh`
128
129 ### Temporary overriding env vars in a testprofile
130
131 Each release has its own test profile, see files `common/test_env-<release-name>.sh`
132 For debugging it is possible to override one or more settings in the profile given to the test script.
133 Add the flag and file with env vars to override: `--override <override-environment-filename>`. The desired env vars shall be specified in the same way as in the test profile.
134
135 ### Use other image builds from external repo for A1PMS or other app
136 It is possible to replace images with images from other external repos (other than oran and onap nexus repos).
137 Modify the file `common/override_external_a1pms.sh` with the desired values. A login to the image repo may be required prior to running the test.
138 Add the flag and the file: `--override common/override_external_a1pms.sh` to the command.
139 In addition, tell the test script to use the overridden env vars by adding the flag `--use-external-image A1PMS`
140
141 Example of running a1pms from external image repo using a test suite (a set of testscripts) and create endpoint statistics.
142
143 `./Suite-short-alternative-a1pms.sh remote-remove  docker  --env-file ../common/test_env-onap-london.sh --override common/override_external_a1pms.sh --use-external-image A1PMS --print-stats --endpoint-stats`
144
145 When the test suite is executed and all test are "PASS", a test report can be created with the following command - (only A1PMS is currently supported).
146 The list of IDs shall be same as used in the test suite - in this case: `FTC1 FTC10 FTC100 FTC110 FTC2001`
147
148 `./format_endpoint_stats.sh log A1PMS <overall test description> <space separated list of TC-IDs>`
149
150 The report is printed to standard out in plain text (can be piped to a file)
151
152 ## Running test with external or multi node kubernetes
153 The test script manages the images to use in each test run. When running locally using docker desktop etc, the image registry reside on the local machine and the test script can then pull the configured images to that registry which is then used by the test script.
154 However, for external or multi node kubernetes clusters then each node in the cluster pull the external (nexus) images directly from the external repos. Images built locally cannot be used since the local registry is not accessible.
155 The solution is to use another external registry as a temporary registry.
156 Basically, the test script pulls the images, re-tag them and pushes them to the temporary registry. Locally built images are also pushed to the same report.
157 All pods started by the script will then pull correct images from the temporary registry (a docker hub registry works fine - requires login to push images though). In this way, the test script has full control over which images are actually used and it is also guaranteed that multiple pod using the same image version actually use the same image.
158
159 In addition, the kubernetes config file shall be downloaded from the master node of the cluster prior to the test - the config file is used by the command kubectl to access the cluster.
160
161 The following flags shall be added to the command: `--kubeconfig <config-file> --image-repo <repo-address> --repo-policy local\|remote`
162 The image repo flag shall be the name of the repo (in case of docker hub -  e.g. "myprivateregistry") and repo policy shall be set to `remote` indicating that all images shall use the temporary registry.
163
164
165 ### Print test stats
166 A test script will normally run all test even if there are failures. Detailed info about total test time, number of test, number of failed test etc the flag `--print-stats` can be added. Then the detailed info is printed for each test.
167
168
169 ## Test case categories
170
171 The test script are number using these basic categories where 0-999 are related to the policy management and 1000-1999 are related to information management. 2000-2999 are for southbound http proxy. There are also demo test cases that test more or less all components. These test scripts does not use the numbering scheme below.
172
173 The numbering in each series corresponds to the following groupings
174 1-99 - Basic sanity tests, A1PMS
175
176 100-199 - API tests, A1PMS
177
178 300-399 - Config changes and sync, A1PMS
179
180 800-899 - Stability and capacity test, A1PMS
181
182 900-999 - Misc test, A1PMS
183
184 11XX - ICS API Tests
185
186 18XX - ICS Stability and capacity test
187
188 20XX - Southbound http proxy tests
189
190 30XX - rApp tests
191
192 40XX - Helm Manager tests
193
194 Suites
195
196 To get an overview of the available test scripts, use the following command to print the test script description:
197 'grep ONELINE *.sh' in the dir of the test scripts.
198
199
200
201 ## Test case file - template
202
203 A test script contains a number of steps to verify a certain functionality.
204 The empty template for a test case file looks like this.
205 Only the parts noted with < and > shall be changed.
206 It is strongly suggested to look at the existing test scripts, it is probably easier to copy an existing test script instead of creating one from scratch. The README.md in  `../common/` describes the functions available in the test script in detail.
207
208 -----------------------------------------------------------
209
210 ```
211 #!/bin/bash
212
213 <license text>
214
215 TC_ONELINE_DESCR="<test case description>"
216
217 DOCKER_INCLUDED_IMAGES=<list of used apps in this test case - for docker>
218
219 KUBE_INCLUDED_IMAGES=<list of used apps (started by the script) in this test case - for kube>
220 KUBE_PRESTARTED_IMAGES=<list of used apps (pre-started - i.e. not started by the script) in this test case - for kube>
221
222 SUPPORTED_PROFILES=<list of supported profile names>
223
224 SUPPORTED_RUNMODES=<List of runmodes, DOCKER and/or KUBE>
225
226 CONDITIONALLY_IGNORED_IMAGES=<list of images to exclude if it does not exist in the profile file>
227
228 . ../common/testcase_common.sh $@
229
230 setup_testenvironment
231
232 #### TEST BEGIN ####
233
234
235 <tests here>
236
237
238 #### TEST COMPLETE ####
239
240 print_result
241
242 store_logs          END
243
244 ```