1 .. This work is licensed under a
2 .. Creative Commons Attribution 4.0 International License.
3 .. http://creativecommons.org/licenses/by/4.0
5 CLAMP Policy Participant Smoke Tests
6 ------------------------------------
11 The Smoke testing of the policy participant is executed in a local CLAMP/Policy environment. The CLAMP-ACM 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.
12 All applications will be running by console, so they need to run with different ports. Configuration files should be changed accordingly.
14 +------------------------------+-------+
15 | Application | port |
16 +==============================+=======+
18 +------------------------------+-------+
20 +------------------------------+-------+
22 +------------------------------+-------+
24 +------------------------------+-------+
26 +------------------------------+-------+
27 | policy-clamp-runtime-acm | 6969 |
28 +------------------------------+-------+
29 | onap/policy-clamp-ac-pf-ppnt | 8085 |
30 +------------------------------+-------+
36 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 several 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.
44 - Refer to this guide for basic environment setup `Setting up dev environment <https://wiki.onap.org/display/DW/Setting+Up+Your+Development+Environment>`_
46 2.2 Cloning CLAMP automation composition and all dependency
47 ===========================================================
49 Run a script such as the script below to clone the required modules from the `ONAP git repository <https://gerrit.onap.org/r/admin/repos/q/filter:policy>`_. This script clones CLAMP automation composition and all dependency.
52 :caption: Typical ONAP Policy Framework Clone Script
57 ## script name for output
58 MOD_SCRIPT_NAME='basename $0'
60 ## the ONAP clone directory, defaults to "onap"
63 ## the ONAP repos to clone
70 ## Help screen and exit condition (i.e. too few arguments)
75 echo "$MOD_SCRIPT_NAME - clones all required ONAP git repositories"
77 echo " Usage: $MOD_SCRIPT_NAME [-options]"
80 echo " -d - the ONAP clone directory, defaults to '.'"
81 echo " -h - this help screen"
92 #-d ONAP clone directory
96 echo "$MOD_SCRIPT_NAME: no clone directory"
103 #-h prints help and exists
107 *) echo "$MOD_SCRIPT_NAME: undefined CLI option - $1"; exit 255;;
111 if [ -f "$clone_dir" ]; then
112 echo "$MOD_SCRIPT_NAME: requested clone directory '$clone_dir' exists as file"
115 if [ -d "$clone_dir" ]; then
116 echo "$MOD_SCRIPT_NAME: requested clone directory '$clone_dir' exists as directory"
123 echo cannot clone ONAP repositories, could not create directory '"'$clone_dir'"'
127 for repo in $onap_repos
129 repoDir=`dirname "$repo"`
130 repoName=`basename "$repo"`
134 mkdir "$clone_dir/$repoDir"
137 echo cannot clone ONAP repositories, could not create directory '"'$clone_dir/repoDir'"'
142 git clone https://gerrit.onap.org/r/${repo} $clone_dir/$repo
145 echo ONAP has been cloned into '"'$clone_dir'"'
148 Execution of the script above results in the following directory hierarchy in your *~/git* directory:
152 * ~/git/onap/policy/api
153 * ~/git/onap/policy/clamp
154 * ~/git/onap/policy/pap
157 2.3 Building CLAMP automation composition and all dependency
158 ============================================================
160 **Step 1:** Setting topicParameterGroup for kafka localhost in clamp and policy-participant.
161 It needs to set 'kafka' as topicCommInfrastructure and 'localhost:29092' as server.
162 In the clamp repo, you should find the file 'runtime-acm/src/main/resources/application.yaml'. This file (in the 'runtime' parameters section) may need to be altered as below:
164 .. literalinclude:: files/runtime-application.yaml
167 Setting topicParameterGroup for kafka localhost and api/pap http client (in the 'participant' parameters section) may need to be apply into the file 'participant/participant-impl/participant-impl-policy/src/main/resources/config/application.yaml'.
169 .. literalinclude:: files/participant-policy-application.yaml
173 **Step 2:** Setting datasource.url, hibernate.ddl-auto and server.port in policy-api.
174 In the api repo, you should find the file 'main/src/main/resources/application.yaml'. This file may need to be altered as below:
176 .. literalinclude:: files/api-application.yaml
180 **Step 3:** Setting datasource.url, server.port, and api http client in policy-pap.
181 In the pap repo, you should find the file 'main/src/main/resources/application.yaml'. This file may need to be altered as below:
183 .. literalinclude:: files/pap-application.yaml
187 **Step 4:** Optionally, for a completely clean build, remove the ONAP built modules from your local repository.
191 rm -fr ~/.m2/repository/org/onap
194 **Step 5:** A pom such as the one below can be used to build the ONAP Policy Framework modules. Create the *pom.xml* file in the directory *~/git/onap/policy*.
197 :caption: Typical pom.xml to build the ONAP Policy Framework
200 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
201 <modelVersion>4.0.0</modelVersion>
202 <groupId>org.onap</groupId>
203 <artifactId>onap-policy</artifactId>
204 <version>1.0.0-SNAPSHOT</version>
205 <packaging>pom</packaging>
206 <name>${project.artifactId}</name>
207 <inceptionYear>2024</inceptionYear>
214 <module>clamp</module>
220 **Step 6:** You can now build the Policy framework.
222 Build java artifacts only:
227 mvn clean install -DskipTests
229 Build with docker images:
233 cd ~/git/onap/policy/clamp/packages/
234 mvn clean install -P docker
236 cd ~/git/onap/policy/api/packages/
237 mvn clean install -P docker
239 cd ~/git/onap/policy/pap/packages/
240 mvn clean install -P docker
242 2.4 Setting up the components
243 =============================
245 2.4.1 MariaDB and Kafka Setup
246 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
248 We will be using Docker to run our mariadb instance`and Zookeeper/Kafka. It will have a total of two databases running in mariadb.
250 - clampacm: the policy-clamp-runtime-acm db
251 - policyadmin: the policy-api db
253 **Step 1:** Create the *mariadb.sql* file in a directory *~/git*.
257 create database clampacm;
258 CREATE USER 'policy'@'%' IDENTIFIED BY 'P01icY';
259 GRANT ALL PRIVILEGES ON clampacm.* TO 'policy'@'%';
260 CREATE DATABASE `policyadmin`;
261 CREATE USER 'policy_user'@'%' IDENTIFIED BY 'policy_user';
262 GRANT ALL PRIVILEGES ON policyadmin.* to 'policy_user'@'%';
263 CREATE DATABASE `migration`;
264 GRANT ALL PRIVILEGES ON migration.* to 'policy_user'@'%';
268 **Step 2:** Create the *init.sh* file in a directory *~/git* with execution permission.
274 export POLICY_HOME=/opt/app/policy
275 export SQL_USER=${MYSQL_USER}
276 export SQL_PASSWORD=${MYSQL_PASSWORD}
277 export SCRIPT_DIRECTORY=sql
279 /opt/app/policy/bin/prepare_upgrade.sh ${SQL_DB}
280 /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o report
281 /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o upgrade
283 /opt/app/policy/bin/db-migrator -s ${SQL_DB} -o report
288 **Step 3:** Create the *wait_for_port.sh* file in a directory *~/git* with execution permission.
295 echo args: [-t timeout] [-c command] hostname1 port1 hostname2 port2 ... >&2
300 while getopts c:t: opt
317 if [ $# -lt 2 ] || [ "$even_args" -ne 0 ]
327 echo "Waiting for $host port $port..."
329 while [ "$tmout" -gt 0 ]
331 if command -v docker > /dev/null 2>&1
333 docker ps --format "table {{ .Names }}\t{{ .Status }}"
335 nc -vz "$host" "$port"
347 echo "$host port $port cannot be reached"
355 **Step 4:** Create the '*docker-compose.yaml*' using following code:
357 .. literalinclude:: files/docker-compose-policy.yaml
361 **Step 5:** Run the docker composition:
372 In the policy-api repo, navigate to the "/main" directory. You can then run the following command to start the policy api:
382 In the policy-pap repo, navigate to the "/main" directory. You can then run the following command to start the policy pap:
391 To start the clampacm runtime we need to go the "runtime-acm" directory in the clamp repo. You can then run the following command to start the clampacm runtime:
397 2.4.5 ACM Policy Participant
398 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
400 To start the policy participant we need to go to the "participant/participant-impl/participant-impl-policy" directory in the clamp repo. You can then run the following command to start the policy-participant:
412 To perform the Smoke testing of the policy-participant we will be verifying the behaviours of the participant when the ACM changes state. The scenarios are:
414 - UNDEPLOYED to DEPLOYED: participant creates policies and policyTypes specified in the ToscaServiceTemplate using policy-api and deploys the policies using pap.
415 - LOCK to UNLOCK: participant changes lock state to UNLOCK. No operation performed.
416 - UNLOCK to LOCK: participant changes lock state to LOCK. No operation performed.
417 - DEPLOYED to UNDEPLOYED: participant undeploys deployed policies and deletes policies and policyTypes which have been created.
422 Creation of AC Definition:
423 **************************
424 An AC Definition is created by commissioning a Tosca template.
425 Using postman, commission a TOSCA template using the following template:
427 :download:`Tosca Service Template <tosca/tosca_service_template_pptnt_smoke.yaml>`
429 To verify this, we check that the AC Definition has been created and is in state COMMISSIONED.
431 .. image:: images/pol-part-clampacm-get-composition.png
433 Priming AC Definition:
434 **********************
435 The AC Definition state is changed from COMMISSIONED to PRIMED using postman:
440 "primeOrder": "PRIME"
444 To verify this, we check that the AC Definition has been primed.
446 .. image:: images/pol-part-clampacm-get-primed-composition.png
449 Creation of AC Instance:
450 ************************
451 Using postman, instance the AC definition using the following template:
453 :download:`Instantiate ACM <json/instantiation_pptnt_smoke.json>`
455 To verify this, we check that the AC Instance has been created and is in state UNDEPLOYED.
457 .. image:: images/pol-part-clampacm-creation-ver.png
459 Creation and deploy of policies and policyTypes:
460 ************************************************
461 The AC Instance deploy state is changed from UNDEPLOYED to DEPLOYED using postman:
466 "deployOrder": "DEPLOY"
469 This state change will trigger the creation of policies and policyTypes using the policy-api and the deployment of the policies specified in the ToscaServiceTemplate.
470 To verify this we will check, using policy-api endpoints, that the onap.policies.native.apex.ac.element policy, which is specified in the service template, has been created.
472 .. image:: images/pol-part-clampacm-ac-policy-ver.png
474 And we will check that the apex onap.policies.native.apex.ac.element policy has been deployed to the defaultGroup. We check this using pap:
476 .. image:: images/pol-part-clampacm-ac-deploy-ver.png
478 Undeployment and deletion of policies and policyTypes:
479 ******************************************************
480 The ACM STATE is changed from DEPLOYED to UNDEPLOYED using postman:
485 "deployOrder": "UNDEPLOY"
488 This state change will trigger the undeployment of the onap.policies.native.apex.ac.element policy which was deployed previously and the deletion of the previously created policies and policyTypes.
489 To verify this we do a PdpGroup Query as before and check that the onap.policies.native.apex.ac.element policy has been undeployed and removed from the defaultGroup:
491 .. image:: images/pol-part-clampacm-ac-undep-ver.png
494 As before, we can check that the Test Policy policyType is not found this time and likewise for the onap.policies.native.apex.ac.element policy:
496 .. image:: images/pol-part-clampacm-test-policy-nf.png