1 # ============LICENSE_START=======================================================
2 # Copyright (c) 2021 AT&T Intellectual Property. All rights reserved.
3 # ================================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # ============LICENSE_END=========================================================
17 from aiohttp import web, WSMsgType
18 import json, pytest, re
19 from policysync.clients import PolicyClientV1 as PolicyClient
21 DECISION_ENDPOINT = 'policy/pdpx/v1/decision'
22 async def get_decision(request):
23 req_data = await request.json()
24 assert req_data['ONAPName'] == 'DCAE'
25 assert req_data['ONAPComponent'] == 'policy-sync'
26 assert req_data['action'] == 'configure'
27 assert req_data['resource'] == {
37 "onap.scaleout.tca": {
38 "type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
40 "metadata": {"policy-id": "onap.scaleout.tca"},
43 "domain": "measurementsForVfScaling",
44 "metricsPerEventName": [
46 "eventName": "vLoadBalancer",
47 "controlLoopSchemaType": "VNF",
48 "policyScope": "type=configuration",
49 "policyName": "onap.scaleout.tca",
50 "policyVersion": "v0.0.1",
53 "closedLoopControlName": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
54 "closedLoopEventStatus": "ONSET",
56 "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
57 "thresholdValue": 500,
58 "direction": "LESS_OR_EQUAL",
62 "closedLoopControlName": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
63 "closedLoopEventStatus": "ONSET",
65 "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
66 "thresholdValue": 5000,
67 "direction": "GREATER_OR_EQUAL",
68 "severity": "CRITICAL",
77 "type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
79 "metadata": {"policy-id": "onap.restart.tca", "policy-version": 1},
82 "domain": "measurementsForVfScaling",
83 "metricsPerEventName": [
85 "eventName": "Measurement_vGMUX",
86 "controlLoopSchemaType": "VNF",
87 "policyScope": "DCAE",
88 "policyName": "DCAE.Config_tca-hi-lo",
89 "policyVersion": "v0.0.1",
92 "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
94 "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value",
98 "closedLoopEventStatus": "ABATED",
101 "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
103 "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value",
105 "direction": "GREATER",
106 "severity": "CRITICAL",
107 "closedLoopEventStatus": "ONSET",
118 return web.json_response(j)
122 def policyclient(aiohttp_client, loop):
123 app = web.Application()
124 app.router.add_route("POST", "/" + DECISION_ENDPOINT, get_decision)
125 fake_client = loop.run_until_complete(aiohttp_client(app))
126 server = "{}://{}:{}".format("http", fake_client.host, fake_client.port)
127 return PolicyClient({}, server)
130 async def test_getconfig(policyclient):
131 j = await policyclient.get_config(ids=['onap.scaleout.tca', 'onap.restart.tca' ])
133 "type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
136 "policy-id": "onap.scaleout.tca"
138 "policyName": "onap.scaleout.tca.1-0-0.xml",
139 "policyVersion": "1.0.0",
142 "domain": "measurementsForVfScaling",
143 "metricsPerEventName": [{
144 "eventName": "vLoadBalancer",
145 "controlLoopSchemaType": "VNF",
146 "policyScope": "type=configuration",
147 "policyName": "onap.scaleout.tca",
148 "policyVersion": "v0.0.1",
150 "closedLoopControlName": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
151 "closedLoopEventStatus": "ONSET",
153 "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
154 "thresholdValue": 500,
155 "direction": "LESS_OR_EQUAL",
159 "closedLoopControlName": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
160 "closedLoopEventStatus": "ONSET",
162 "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
163 "thresholdValue": 5000,
164 "direction": "GREATER_OR_EQUAL",
165 "severity": "CRITICAL"
172 "type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
175 "policy-id": "onap.restart.tca",
178 "policyName": "onap.restart.tca.1-0-0.xml",
179 "policyVersion": "1.0.0",
182 "domain": "measurementsForVfScaling",
183 "metricsPerEventName": [{
184 "eventName": "Measurement_vGMUX",
185 "controlLoopSchemaType": "VNF",
186 "policyScope": "DCAE",
187 "policyName": "DCAE.Config_tca-hi-lo",
188 "policyVersion": "v0.0.1",
190 "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
192 "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value",
194 "direction": "EQUAL",
196 "closedLoopEventStatus": "ABATED"
199 "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
201 "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value",
203 "direction": "GREATER",
204 "severity": "CRITICAL",
205 "closedLoopEventStatus": "ONSET"
212 await policyclient.close()
215 async def test_supports_notifications(policyclient):
216 assert not policyclient.supports_notifications()