1 ## Running automated test case and test suites
2 Test cases run a single test case and test suites run one or more test cases in a sequence.
4 ##Overall structure and setup
5 Test cases and test suites are written as bash scripts which call predefined functions in two other bash scripts
6 located in ../common dir.
7 The functions are described further below.
8 The integration repo is needed as well as docker.
9 If needed setup the ``DFC_LOCAL_IMAGE`` and ``DFC_REMOTE_IMAGE`` env var in test_env.sh to point to the dfc images (local registry image or next registry image) without the image tag.
10 The predefined images should be ok for current usage:
12 ``DFC_REMOTE_IMAGE=nexus3.onap.org:10001/onap/org.onap.dcaegen2.collectors.datafile.datafile-app-server``
14 ``DFC_LOCAL_IMAGE=onap/org.onap.dcaegen2.collectors.datafile.datafile-app-server``
16 If the test cases/suites in this dir are not executed in the auto-test dir in the integration repo, then the ``SIM_GROUP`` env var need to point to the ``simulator-group`` dir.
17 See instructions in the test_env.sh. The ../common dir is needed as well in the case. That is, it is possible to have auto-test dir (and the common dir) somewhere else
18 than in the integration repo but the simulator-group and common dir need to be available.
20 ##Test cases and test suites naming.
21 Each file filename should have the format ``<tc-id>.sh`` for test cases and ``<ts-id>.sh`` for test suite. The tc-id and ts-id are the
22 identify of the test case or test suite. Example FTC2.sh, FTC2 is the id of the test case. Just the contents of the files determines if
23 it is a test case or test suite so good to name the file so it is easy to see if it is a test case or a test suite.
24 A simple way to list all test cases/suite along with the description is to do ``grep ONELINE_DESCR *.sh`` in the shell.
26 ##Logs from containers and test cases
27 All logs from each test cases are stored under ``logs/<tc-id>/``.
28 The logs include the application.log and the container log from dfc, the container logs from each simulator and the test case log (same as the screen output).
29 In the test cases the logs are stored with a prefix so the logs can be stored at different steps during the test. All test cases contains an entry to save all logs with prefix 'END' at the end of each test case.
31 Test cases and test suites are executed by: `` [sudo] ./<tc-id or ts-id>.sh local | remote | remote-remove | manual-container | manual-app``</br>
32 **local** - uses the dfc image pointed out by ``DFC_LOCAL_IMAGE`` in the test_env, should be the dfc image built locally in your docker registry.</br>
33 **remote** - uses the dfc image pointed out by ``DFC_REMOTE_IMAGE`` in the test_env, should be the dfc nexus image in your docker registry.</br>
34 **remote-remove** - uses the dfc image pointed out by ``DFC_REMOTE_IMAGE`` in the test_env, should be the dfc nexus image in your docker registry. Removes the nexus image and pull from remote registry.</br>
35 **manual-container** - uses dfc in a manually started container. The script will prompt you for manual starting and stopping of the container.</br>
36 **manual-app** - uses dfc app started as an external process (from eclipse etc). The script will prompt you for manual start and stop of the process.</br>
38 When running dfc manually, either as a container or an app the ports need to be set to map the instance id of the dfc. Most test cases start dfc with index 0, then the test case expects the ports of dfc to be mapped to the standar port number.
39 However, if a higher instance id than 0 is used then the mapped ports need add that index to the port number (eg, if index 2 is used the dfc need to map port 8102 and 8435 instead of the standard 8100 and 8433).
42 A test case file contains a number of steps to verify a certain functionality.
43 A description of the test case should be given to the ``TC_ONELINE_DESCR`` var. The description will be printed in the test result.
45 The empty template for a test case files looks like this:
47 (Only the parts noted with < and > shall be changed.)
49 -----------------------------------------------------------
53 TC_ONELINE_DESCR="<test case description>"
55 . ../common/testcase_common.sh $1 $2
63 #### TEST COMPLETE ####
70 -----------------------------------------------------------
72 The ../common/testcase_common.sh contains all functions needed for the test case file.
74 The following is a list of the available functions in a test case file. Please see some of the defined test case for examples.
76 **log_sim_settings**</br>
77 Print the env variables needed for the simulators and their setup
79 **clean_containers**</br>
80 Stop and remove all containers including dfc apps and simulators
82 **start_simulators**</br>
83 Start all simulators in the simulator group
85 **start_dfc <dfc-instance-id>**</br>
86 Start the dfc application. The arg shall be an integer from 0 to 5 reprenting the dfc instance to start. DFC app will get a name like 'dfc_app0' to 'dfc_app4'.
88 **kill_dfc <dfc-instance-id> **</br>
89 Stop and remove the dfc app container with the instance id.
91 **consul_config_app <dfc-instance-id> <json-file-path>**</br>
92 Configure consul with json file with app config for a dfc instance using the dfc instance id and the json file.
94 **consul_config_dmaap <dfc-instance-id> <json-file-path>**</br>
95 Configure consul with json file with dmaap config for a dfc instance using the dfc instance id and the json file.
98 Stop and remove the DR simulator container
101 Stop and remove the DR redir simulator container
104 Stop and remove the MR simulator container
106 **kill_sftp <sftp-instance-id>**</br>
107 Stop and remove a SFTP container with the supplied instance id (0-5).
109 **stop_sftp <sftp-instance-id>**</br>
110 Stop a SFTP container with the supplied instance id (0-5).
112 **start_sftp <sftp-instance-id>**</br>
113 Start a previously stopped SFTP container with the supplied instance id (0-5).
115 **kill_ftps <ftps-instance-id>**</br>
116 Stop and remove a FTPS container with the supplied instance id (0-5).
118 **stop_ftps <ftps-instance-id>**</br>
119 Stop a FTPS container with the supplied instance id (0-5).
121 **start_ftps <ftps-instance-id>**</br>
122 Start a previously stopped FTPS container with the supplied instance id (0-5).
124 **mr_print <vaiable-name>**</br>
125 Print a variable value from the MR simulator.
127 **dr_print <vaiable-name>**</br>
128 Print a varialle value from the DR simulator.
130 **drr_print <vaiable-name>**</br>
131 Print a variable value from the DR redir simulator.
133 **dfc_print <dfc-instance-id> <vaiable-name>**</br>
134 Print a variable value from an dfc instance with the supplied instance id (0-5).
136 **mr_read <vaiable-name>**</br>
137 Read a variable value from MR sim and send to stdout
139 **dr_read <vaiable-name>**</br>
140 Read a variable value from DR sim and send to stdout
142 **drr_read <vaiable-name>**</br>
143 Read a variable value from DR redir sim and send to stdout
145 **sleep_wait <sleep-time-in-sec>**</br>
146 Sleep for a number of seconds
148 **sleep_heartbeat <sleep-time-in-sec>**</br>
149 Sleep for a number of seconds and prints dfc heartbeat output every 30 sec
151 **mr_equal <variable-name> <target-value> [<timeout-in-sec>]**</br>
152 Tests if a variable value in the MR simulator is equal to a target value and and optional timeout.
153 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
154 equal to the targer or not.
155 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>`` - This test waits up to the timeout seconds
156 before setting pass or fail depending on if the variable value becomes equal to the target
159 **mr_greater <variable-name> <target-value> [<timeout-in-sec>]**</br>
160 Tests if a variable value in the MR simulator is greater than a target value and and optional timeout.
161 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
162 greater the target or not.
163 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>`` - This test waits up to the timeout seconds
164 before setting pass or fail depending on if the variable value is greater than the target
167 **mr_less <variable-name> <target-value> [<timeout-in-sec>]**</br>
168 Tests if a variable value in the MR simulator is less than a target value and and optional timeout.
169 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
170 less than the target or not.
171 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>`` - This test waits up to the timeout seconds
172 before setting pass or fail depending on if the variable value is less than the target
175 **mr_contain_str <variable-name> <target-value> [<timeout-in-sec>]**</br>
176 Tests if a variable value in the MR simulator contains a substring target and and optional timeout.
177 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable contains
178 the target substring or not.
179 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>`` - This test waits up to the timeout seconds
180 before setting pass or fail depending on if the variable value contains the target
183 **dr_equal <variable-name> <target-value> [<timeout-in-sec>]**</br>
184 Tests if a variable value in the DR simulator is equal to a target value and and optional timeout.
185 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
186 equal to the target or not.
187 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>`` - This test waits up to the timeout seconds
188 before setting pass or fail depending on if the variable value becomes equal to the target
191 **dr_greater <variable-name> <target-value> [<timeout-in-sec>]**</br>
192 Tests if a variable value in the DR simulator is greater than a target value and and optional timeout.
193 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
194 greater the target or not.
195 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>`` - This test waits up to the timeout seconds
196 before setting pass or fail depending on if the variable value is greater than the target
199 **dr_less <variable-name> <target-value> [<timeout-in-sec>]**</br>
200 Tests if a variable value in the DR simulator is less than a target value and and optional timeout.
201 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
202 less than the target or not.
203 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>`` - This test waits up to the timeout seconds
204 before setting pass or fail depending on if the variable value is less than the target
207 **dr_contain_str <variable-name> <target-value> [<timeout-in-sec>]**</br>
208 Tests if a variable value in the DR simulator contains a substring target and and optional timeout.
209 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable contains
210 the target substring or not.
211 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>`` - This test waits up to the timeout seconds
212 before setting pass or fail depending on if the variable value contains the target
215 **drr_equal <variable-name> <target-value> [<timeout-in-sec>]**</br>
216 Tests if a variable value in the DR Redir simulator is equal to a target value and and optional timeout.
217 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
218 equal to the target or not.
219 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>`` - This test waits up to the timeout seconds
220 before setting pass or fail depending on if the variable value becomes equal to the target
223 **drr_greater <variable-name> <target-value> [<timeout-in-sec>]**</br>
224 Tests if a variable value in the DR Redir simulator is greater than a target value and and optional timeout.
225 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
226 greater the target or not.
227 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>`` - This test waits up to the timeout seconds
228 before setting pass or fail depending on if the variable value is greater than the target
231 **drr_less <variable-name> <target-value> [<timeout-in-sec>]**</br>
232 Tests if a variable value in the DR Redir simulator is less than a target value and and optional timeout.
233 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable is
234 less than the target or not.
235 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>`` - This test waits up to the timeout seconds
236 before setting pass or fail depending on if the variable value is less than the target
239 **drr_contain_str <variable-name> <target-value> [<timeout-in-sec>]**</br>
240 Tests if a variable value in the DR Redir simulator contains a substring target and and optional timeout.
241 </br>Arg: ``<variable-name> <target-value>`` - This test set pass or fail depending on if the variable contains
242 the target substring or not.
243 </br>Arg: ``<variable-name> <target-value> <timeout-in-sec>`` - This test waits up to the timeout seconds
244 before setting pass or fail depending on if the variable value contains the target
247 **dfc_contain_str <variable-name> <substring-in-quotes>**</br>
248 Test is a variable in the DFC contains a substring.
250 **store_logs <log-prefix>**</br>
251 Store all dfc app and simulators log to the test case log dir. All logs gets a prefix to
252 separate logs stored at different steps in the test script.
253 If logs need to be stored in several locations, use different prefix to easily identify the location
254 when the logs where taken.
256 **check_dfc_log**</br>
257 Check the dfc application log for WARN and ERR messages and print the count.
259 **print_result**</br>
260 Print the test result. Only once at the very end of the script.
263 Print all variables from the simulators and the dfc heartbeat.
265 In addition, comment in the file can be added using the normal comment sign in bash '#'.
266 Comments that shall be visible on the screen as well as in the test case log, use ``echo "<msg>"``.
269 A test suite file contains one or more test cases to run in sequence.
270 A description of the test case should be given to the ``TS_ONELINE_DESCR`` var. The description will be printed in the test result.
272 The empty template for a test suite files looks like this:
274 (Only the parts noted with ``<`` and ``>`` shall be changed.)
276 -----------------------------------------------------------
280 TS_ONELINE_DESCR="<test-suite-description>"
282 . ../common/testsuite_common.sh
286 ############# TEST CASES #################
288 run_tc <tc-id or ts-id>.sh $1 $2
292 ##########################################
298 -----------------------------------------------------------
300 The ../common/testsuite_common.sh contains all functions needed for a test suite file.
302 The following is a list of the available functions in a test case file. Please see a existing test suite for examples.
305 Sets up the test suite and print out a heading.
307 **run_tc <tc-script> <$1 from test suite script> <$2 from test suite script>**</br>
308 Execute a test case with arg from test suite script
310 **suite_complete**</br>
311 Print out the overall result of the executed test cases.