Add postman collections for smoke/pairwise testing
[policy/parent.git] / docs / development / devtools / policy-participant-smoke.rst
1 .. This work is licensed under a
2 .. Creative Commons Attribution 4.0 International License.
3 .. http://creativecommons.org/licenses/by/4.0
4
5 CLAMP Policy Participant Smoke Tests
6 ------------------------------------
7
8 1. Introduction
9 ***************
10 The Smoke testing of the policy participant is executed in a local CLAMP/Policy environment. The CLAMP-Controlloop interfaces interact with the Policy Framework to perform actions based on the state of the policy participant. The goal of the Smoke tests is the ensure that CLAMP Policy Participant and Policy Framework work together as expected.
11
12 2. Setup Guide
13 **************
14 This section will show the developer how to set up their environment to start testing in GUI with some instruction on how to carry out the tests. There are a number of prerequisites. Note that this guide is written by a Linux user - although the majority of the steps show will be exactly the same in Windows or other systems.
15
16 2.1 Prerequisites
17 =================
18 - Java 11
19 - Maven 3
20 - Git
21 - Refer to this guide for basic environment setup `Setting up dev environment <https://wiki.onap.org/display/DW/Setting+Up+Your+Development+Environment>`_
22
23 2.2 Assumptions
24 ===============
25 - You are accessing the policy repositories through gerrit
26 - You are using "git review".
27 The following repositories are required for development in this project. These repositories should be present on your machine and you should run "mvn clean install" on all of them so that the packages are present in your .m2 repository.
28 - policy/parent
29 - policy/common
30 - policy/models
31 - policy/clamp
32 - policy/docker
33 - policy/gui
34 - policy/api
35 In this setup guide, we will be setting up all the components technically required for a working convenient dev environment.
36
37 2.3 Setting up the components
38 =============================
39 2.3.1 MariaDB Setup
40 ^^^^^^^^^^^^^^^^^^^
41 We will be using Docker to run our mariadb instance. It will have a total of two databases running in it.
42 - controlloop: the runtime-controlloop db
43 - policyadmin: the policy-api db
44 The easiest way to do this is to perform a small alteration on an SQL script provided by the clamp backend in the file "runtime/extra/sql/bulkload/create-db.sql"
45 .. code-block:: mysql
46     CREATE DATABASE `controlloop`;
47     USE `controlloop`;
48     DROP USER 'policy';
49     CREATE USER 'policy';
50     GRANT ALL on controlloop.* to 'policy' identified by 'P01icY' with GRANT OPTION;
51     CREATE DATABASE `policyadmin`;
52     USE `policyadmin`;
53     DROP USER 'policy_user';
54     CREATE USER 'policy_user';
55     GRANT ALL on controlloop.* to 'policy_user' identified by 'policy_user' with GRANT OPTION;
56     FLUSH PRIVILEGES;
57 Once this has been done, we can run the bash script provided here: "runtime/extra/bin-for-dev/start-db.sh"
58 .. code-block:: bash
59     ./start-db.sh
60 This will setup the two databases needed. The database will be exposed locally on port 3306 and will be backed by an anonymous docker volume.
61
62 2.3.2 DMAAP Simulator
63 ^^^^^^^^^^^^^^^^^^^^^
64 For convenience, a dmaap simulator has been provided in the policy/models repository. To start the simulator, you can do the following:
65 1. Navigate to /models-sim/policy-models-simulators in the policy/models repository.
66 2. Add a configuration file to src/test/resources with the following contents:
67 .. code-block:: json
68     {
69        "dmaapProvider":{
70           "name":"DMaaP simulator",
71           "topicSweepSec":900
72        },
73        "restServers":[
74           {
75              "name":"DMaaP simulator",
76              "providerClass":"org.onap.policy.models.sim.dmaap.rest.DmaapSimRestControllerV1",
77              "host":"localhost",
78              "port":3904,
79              "https":false
80           }
81        ]
82     }
83 3. You can then start dmaap with:
84 .. code-block:: bash
85     mvn exec:java  -Dexec.mainClass=org.onap.policy.models.simulators.Main -Dexec.args="src/test/resources/YOUR_CONF_FILE.json"
86 At this stage the dmaap simulator should be running on your local machine on port 3904.
87
88 2.3.3 Policy API
89 ^^^^^^^^^^^^^^^^
90 In the policy-api repo, you should find the file "src/main/resources/etc/defaultConfig.json". This file must be altered slightly - as below with the restServerParameters and databaseProviderParameters shown. Note how the database parameters match-up with what you setup in Mariadb:
91 .. code-block:: json
92     {
93         "restServerParameters": {
94             "host": "0.0.0.0",
95             "port": 6970,
96             "userName": "healthcheck",
97             "password": "zb!XztG34",
98             "prometheus": true,
99             "https": false,
100             "aaf": false
101         },
102         "databaseProviderParameters": {
103             "name": "PolicyProviderParameterGroup",
104             "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
105             "databaseDriver": "org.mariadb.jdbc.Driver",
106             "databaseUrl": "jdbc:mariadb://mariadb:3306/policyadmin",
107             "databaseUser": "policy_user",
108             "databasePassword": "policy_user",
109             "persistenceUnit": "PolicyMariaDb"
110         },
111     }
112 Next, navigate to the "/main" directory. You can then run the following command to start the policy api:
113 .. code-block:: bash
114     mvn exec:java -Dexec.mainClass=org.onap.policy.api.main.startstop.Main -Dexec.args=" -c ../packages/policy-api-tarball/src/main/resources/etc/defaultConfig.json"
115
116 2.3.4 Policy PAP
117 ^^^^^^^^^^^^^^^^
118 In the policy-pap repo, you should find the file 'main/src/test/resources/parameters/PapConfigParameters.json'. This file may need to be altered slightly as below:
119 .. code-block:: json
120     {
121         "name": "PapGroup",
122         "restServerParameters": {
123             "host": "0.0.0.0",
124             "port": 6968,
125             "userName": "healthcheck",
126             "password": "zb!XztG34",
127             "https": false
128         },
129         "pdpParameters": {
130             "heartBeatMs": 60000,
131             "updateParameters": {
132                 "maxRetryCount": 1,
133                 "maxWaitMs": 30000
134             },
135             "stateChangeParameters": {
136                 "maxRetryCount": 1,
137                 "maxWaitMs": 30000
138             }
139         },
140         "databaseProviderParameters": {
141             "name": "PolicyProviderParameterGroup",
142             "implementation": "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl",
143             "databaseDriver": "org.mariadb.jdbc.Driver",
144             "databaseUrl": "jdbc:mariadb://localhost:3306/policyadmin",
145             "databaseUser": "policy_user",
146             "databasePassword": "policy_user",
147             "persistenceUnit": "PolicyMariaDb"
148         },
149         "topicParameterGroup": {
150             "topicSources" : [{
151                 "topic" : "POLICY-PDP-PAP",
152                 "servers" : [ "localhost:3904" ],
153                 "topicCommInfrastructure" : "dmaap"
154             }],
155             "topicSinks" : [{
156                 "topic" : "POLICY-PDP-PAP",
157                 "servers" : [ "localhost:3904" ],
158                 "topicCommInfrastructure" : "dmaap"
159             },{
160                 "topic" : "POLICY-NOTIFICATION",
161                 "servers" : [ "localhost:3904" ],
162                 "topicCommInfrastructure" : "dmaap"
163             }]
164         },
165         "healthCheckRestClientParameters":[{
166             "clientName": "api",
167             "hostname": "policy-api",
168             "port": 6968,
169             "userName": "healthcheck",
170             "password": "zb!XztG34",
171             "useHttps": false,
172             "basePath": "policy/api/v1/healthcheck"
173         },
174         {
175             "clientName": "distribution",
176             "hostname": "policy-distribution",
177             "port": 6970,
178             "userName": "healthcheck",
179             "password": "zb!XztG34",
180             "useHttps": false,
181             "basePath": "healthcheck"
182         }]
183     }
184 Next, navigate to the "/main" directory. You can then run the following command to start the policy pap
185 .. code-block:: bash
186     mvn -q -e clean compile exec:java -Dexec.mainClass="org.onap.policy.pap.main.startstop.Main" -Dexec.args="-c /src/test/resources/parameters/PapConfigParameters.json"
187
188 2.3.5 Controlloop Runtime
189 ^^^^^^^^^^^^^^^^^^^^^^^^^
190 To start the controlloop runtime we need to go the "runtime-controlloop" directory in the clamp repo. There is a config file that is used, by default, for the controlloop runtime. That config file is here: "src/main/resources/application.yaml". For development in your local environment, it shouldn't need any adjustment and we can just run the controlloop runtime with:
191 .. code-block:: bash
192     mvn spring-boot:run
193
194 2.3.6 Controlloop Policy Participant
195 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
196 To start the policy participant we need to go to the "participant-impl/participant-impl-policy" directory in the clamp repo. There is a config file under "src/main/resources/config/application.yaml". For development in your local environment, we will need to adjust this file slightly:
197 .. code-block:: yaml
198     server:
199         port: 8082
200
201     participant:
202       pdpGroup: defaultGroup
203       pdpType: apex
204       policyApiParameters:
205         clientName: api
206         hostname: localhost
207         port: 6970
208         userName: healthcheck
209         password: zb!XztG34
210         https: true
211         allowSelfSignedCerts: true
212       policyPapParameters:
213         clientName: pap
214         hostname: localhost
215         port: 6968
216         userName: healthcheck
217         password: zb!XztG34
218         https: true
219         allowSelfSignedCerts: true
220       intermediaryParameters:
221         reportingTimeIntervalMs: 120000
222         description: Participant Description
223         participantId:
224           name: org.onap.PM_Policy
225           version: 1.0.0
226         participantType:
227           name: org.onap.policy.controlloop.PolicyControlLoopParticipant
228           version: 2.3.1
229         clampControlLoopTopics:
230           topicSources:
231             -
232               topic: POLICY-CLRUNTIME-PARTICIPANT
233               servers:
234                 - ${topicServer:localhost}
235               topicCommInfrastructure: dmaap
236               fetchTimeout: 15000
237           topicSinks:
238             -
239               topic: POLICY-CLRUNTIME-PARTICIPANT
240               servers:
241                 - ${topicServer:localhost}
242               topicCommInfrastructure: dmaap
243 Navigate to the participant-impl/particpant-impl-policy/main directory. We can then run the policy-participant with the following command:
244 .. code-block:: bash
245     mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8082 --topicServer=localhost"
246
247 3. Testing Procedure
248 ====================
249 3.1 Testing Outline
250 ^^^^^^^^^^^^^^^^^^^
251 To perform the Smoke testing of the policy-participant we will be verifying the behaviours of the participant when the control loop changes state. The scenarios are:
252 - UNINITIALISED to PASSIVE: participant creates policies and policyTypes specified in the ToscaServiceTemplate using policy-api
253 - PASSIVE to RUNNING: participant deploys created policies specified in the ToscaServiceTemplate
254 - RUNNING to PASSIVE: participant undeploys policies which have been deployed
255 - PASSIVE to UNINITIALISED: participant deletes policies and policyTypes which has been created
256
257 3.2 Testing Steps
258 ^^^^^^^^^^^^^^^^^
259
260 Creation of Controlloop:
261 ************************
262 A Control Loop is created by commissioning a Tosca template with Control loop definitions and instantiating the Control Loop with the state "UNINITIALISED".
263 Using postman, commision a TOSCA template and instantiate using the following template:
264 :download:'Tosca Service Template <tosca/tosca_service_template_pptnt_smoke.yaml>'
265 :download:'Instantiate Controlloop <tosca/instantiation_pptnt_smoke.json>'
266 To verify this, we check that the Controlloop has been created and is in state UNINITIALISED.
267     .. image:: images/pol-part-controlloop-creation-ver.png
268
269 Creation of policies and policyTypes:
270 *************************************
271 The Controlloop STATE is changed from UNINITIALISED to PASSIVE using postman:
272 .. code-block::json
273     {
274         "orderedState": "PASSIVE",
275         "controlLoopIdentifierList": [
276             {
277                 "name": "PMSHInstance0",
278                 "version": "1.0.1"
279             }
280         ]
281     }
282 This state change will trigger the creation of policies and policyTypes using the policy-api. To verify this we will check, using policy-api endpoints, that the "Sirisha" policyType, which is specified in the service template, has been created.
283     .. image:: images/pol-part-controlloop-sirisha-ver.png
284 We can also check that the pm-control policy has been created.
285     .. image:: images/pol-part-controlloop-pmcontrol-ver.png
286
287 Deployment of policies:
288 ***********************
289 The Controlloop STATE is changed from PASSIVE to RUNNING using postman:
290 .. code-block::json
291     {
292         "orderedState": "RUNNING",
293         "controlLoopIdentifierList": [
294             {
295                 "name": "PMSHInstance0",
296                 "version": "1.0.1"
297             }
298         ]
299     }
300 This state change will trigger the deployment of the policies specified in the ToscaServiceTemplate. To verify this, we will check that the apex pmcontrol policy has been deployed to the defaultGroup. We check this using pap:
301     .. image:: images/pol-part-controlloop-pmcontrol-deploy-ver.png
302
303 Undeployment of policies:
304 *************************
305
306 The Controlloop STATE is changed from RUNNING to PASSIVE using postman:
307 .. code-block::json
308     {
309         "orderedState": "PASSIVE",
310         "controlLoopIdentifierList": [
311             {
312                 "name": "PMSHInstance0",
313                 "version": "1.0.1"
314             }
315         ]
316     }
317 This state change will trigger the undeployment of the pmcontrol policy which was deployed previously. To verifiy this we do a PdpGroup Query as before and check that the pmcontrol policy has been undeployed and removed from the defaultGroup:
318     .. image:: images/pol-part-controlloop-pmcontrol-undep-ver.png
319
320 Deletion of policies and policyTypes:
321 *************************************
322 The Controlloop STATE is changed from PASSIVE to UNINITIALISED using postman:
323 .. code-block::json
324     {
325         "orderedState": "UNINITIALISED",
326         "controlLoopIdentifierList": [
327             {
328                 "name": "PMSHInstance0",
329                 "version": "1.0.1"
330             }
331         ]
332     }
333 This state change will trigger the deletion of the previously created policies and policyTypes. To verify this, as before, we can check that the Sirisha policyType is not found this time and likewise for the pmcontrol policy:
334     .. image:: images/pol-part-controlloop-sirisha-nf.png
335     .. image:: images/pol-part-controlloop-pmcontrol-nf.png