6f99638ce17db2e2e0f3a8e95eab755d4de354e8
[dcaegen2/platform.git] / oti / event-handler / tests / test_otihandler.py
1 # ============LICENSE_START=======================================================
2 # Copyright (c) 2020 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
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
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=========================================================
16 #
17
18 """test otihandler package of DCAE-Controller"""
19
20 import base64
21 import copy
22 import json
23 import logging
24 import os
25 import re
26 import sys
27 import time
28 import uuid
29 # from urlparse import urlparse, parse_qsl
30 from datetime import datetime
31
32 import pytest
33 import cherrypy
34 from cherrypy.test import helper
35
36 from otihandler.config import Config
37 from otihandler.consul_client import (ConsulClient,
38      ConsulClientConnectionError, ConsulClientServiceNotFoundError,
39      ConsulClientKVEntryNotFoundError)
40 from otihandler.onap.audit import (Audit, AuditHttpCode)
41 from otihandler.__main__ import LogWriter
42 from otihandler.web_server import _DTIWeb
43
44 OTIHANDLER_VERSION = "1.0.0"
45
46 false = False
47 true = True
48 null = None
49
50 class Settings(object):
51     """init all locals"""
52
53     logger = None
54     RUN_TS = datetime.utcnow().isoformat()[:-3] + 'Z'
55     discovered_config = None
56
57     @staticmethod
58     def init():
59         """init locals"""
60
61         os.environ["CLOUDIFY"] = '{"cloudify":{"protocol":"https","user":"XXXXX","password":"XXXX","address":"cloudify.bogus.com","port":"443"}}'
62         os.environ["CONSUL_URL"] = "http://consul:8500"
63         os.environ["OTI_HANDLER_URL"] = "https://oti_handler:8443"
64
65         Config.load_from_file()
66
67         with open("etc/config.json", 'r') as config_json:
68             Settings.discovered_config = json.load(config_json)
69
70         Config.load_from_file("etc/config.json")
71
72         Settings.logger = logging.getLogger("otihandler.unit_test")
73         sys.stdout = LogWriter(Settings.logger.info)
74         sys.stderr = LogWriter(Settings.logger.error)
75
76         print("print ========== run_otihandler ==========")
77         Settings.logger.info("========== run_otihandler ==========")
78         Audit.init(Config.get_system_name(), OTIHANDLER_VERSION, Config.LOGGER_CONFIG_FILE_PATH)
79
80         Settings.logger.info("starting otihandler with config:")
81         Settings.logger.info(Audit.log_json_dumps(Config.config))
82
83 Settings.init()
84
85
86 class MonkeyHttpResponse(object):
87     """Monkey http response"""
88
89     def __init__(self, headers):
90         """init locals"""
91
92         self.headers = headers or {}
93
94 class MonkeyRequestsResponse(object):
95     """Monkey response"""
96
97     def __init__(self, full_path, res_json, json_body=None, headers=None, status_code=200):
98         """init locals"""
99
100         self.full_path = full_path
101         self.req_json = json_body or {}
102         self.status_code = status_code
103         self.request = MonkeyHttpResponse(headers)
104         self.res = res_json
105         self.text = json.dumps(self.res)
106
107     def json(self):
108         """returns json of response"""
109
110         return self.res
111
112     def raise_for_status(self):
113         """ignoring"""
114
115         if self.status_code == 200:
116             return
117         else:
118             Settings.logger.warning("raise_for_status found status_code: {}".format(self.status_code))
119
120 def kv_encode(key, value):
121     """helper function to encode a consul key value"""
122
123     rtn = {
124         "LockIndex": 0,
125         "Key": key,
126         "Flags": 0,
127         "Value": base64.b64encode(bytes(value, "utf-8")).decode("utf-8"),
128         "CreateIndex": 19,
129         "ModifyIndex": 99999
130     }
131     return rtn
132
133 def monkey_consul_client_get(full_path, **kwargs):
134     """monkeypatch for GET from consul"""
135
136     rv = None
137     res_json = {}
138     if full_path == ConsulClient.CONSUL_SERVICE_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "cloudify_manager"):
139         res_json = [{
140             "ID": "048ec7c9-aa2e-bfad-34c7-6755e0007c9c",
141             "Node": "zldcdyh1adcc1orcl00.novalocal",
142             "Address": "192.168.1.13",
143             "Datacenter": "zldcdyh1adcc1",
144             "TaggedAddresses": {
145                 "lan": "192.168.1.13",
146                 "wan": "192.168.1.13"
147             },
148             "NodeMeta": {},
149             "ServiceID": "cloudify_manager",
150             "ServiceName": "cloudify_manager",
151             "ServiceTags": [],
152             "ServiceAddress": "1.1.1.1",
153             "ServicePort": 80,
154             "ServiceEnableTagOverride": false,
155             "CreateIndex": 1569262,
156             "ModifyIndex": 1569262
157         }]
158         rv = MonkeyRequestsResponse(full_path, res_json)
159
160     elif full_path == ConsulClient.CONSUL_SERVICE_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "oti_handler"):
161         res_json = [{
162             "ID": "476991b8-7f40-e3c2-9d5e-f936c2aeaf56",
163             "Node": "zldcdyh1adcc1dokr00",
164             "Address": "32.68.15.149",
165             "Datacenter": "zldcdyh1adcc1",
166             "TaggedAddresses": {
167                 "lan": "32.68.15.149",
168                 "wan": "32.68.15.149"
169             },
170             "NodeMeta": {
171                 "fqdn": "oti_handler"
172             },
173             "ServiceID": "58a417002f89:oti_handler:8443",
174             "ServiceName": "oti_handler",
175             "ServiceTags": [
176                 "oti_handler",
177                 "oti_handler"
178             ],
179             "ServiceAddress": "1.1.1.2",
180             "ServicePort": 8443,
181             "ServiceEnableTagOverride": false,
182             "CreateIndex": 1161355,
183             "ModifyIndex": 1161355
184         }]
185         rv = MonkeyRequestsResponse(full_path, res_json)
186
187     elif full_path == ConsulClient.CONSUL_SERVICE_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "deployment_handler"):
188         res_json = [{
189             "ID": "476991b8-7f40-e3c2-9d5e-f936c2aeaf56",
190             "Node": "zldcdyh1adcc1dokr00",
191             "Address": "32.68.15.149",
192             "Datacenter": "zldcdyh1adcc1",
193             "TaggedAddresses": {
194                 "lan": "32.68.15.149",
195                 "wan": "32.68.15.149"
196             },
197             "NodeMeta": {
198                 "fqdn": "deployment_handler:8188"
199             },
200             "ServiceID": "58a417002f89:deployment_handler:8188",
201             "ServiceName": "deployment_handler",
202             "ServiceTags": [
203                 "deployment_handler",
204                 "deployment_handler"
205             ],
206             "ServiceAddress": "1.1.1.2",
207             "ServicePort": 8188,
208             "ServiceEnableTagOverride": false,
209             "CreateIndex": 1502800,
210             "ModifyIndex": 1502800
211         }]
212         rv = MonkeyRequestsResponse(full_path, res_json)
213
214     elif full_path == ConsulClient.CONSUL_SERVICE_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "zldcdyh1adcc1-component-dockerhost-1"):
215         res_json = [{
216             "ID": "4ffed53d-7601-7d47-df93-c091ea66fb45",
217             "Node": "zldcdyh1adcc1dokr02",
218             "Address": "32.68.15.163",
219             "Datacenter": "zldcdyh1adcc1",
220             "TaggedAddresses": {
221                 "lan": "32.68.15.163",
222                 "wan": "32.68.15.163"
223             },
224             "NodeMeta": {
225                 "fqdn": "zldcdyh1adcc1dokr02.bogus.com"
226             },
227             "ServiceID": "zldcdyh1adcc1-component-dockerhost-1",
228             "ServiceName": "zldcdyh1adcc1-component-dockerhost-1",
229             "ServiceTags": [
230                 "LSLEILAA",
231                 "MDTWNJC1"
232             ],
233             "ServiceAddress": "1.1.1.5",
234             "ServicePort": 2376,
235             "ServiceEnableTagOverride": false,
236             "CreateIndex": 1704211,
237             "ModifyIndex": 1704211
238         }]
239         rv = MonkeyRequestsResponse(full_path, res_json)
240
241     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), Config.get_system_name()):
242         res_json = copy.deepcopy(Settings.discovered_config)
243         rv = MonkeyRequestsResponse(full_path, res_json)
244
245     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "cloudify_manager"):
246         res_json = [kv_encode("cloudify_manager", json.dumps(
247             {"cloudify":{"protocol" : "http", "user": "admin", "password":"XXXX"}}
248         ))]
249         rv = MonkeyRequestsResponse(full_path, res_json)
250
251     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "SCN_2:oti"):
252         res_json = [
253             kv_encode("SCN_2:oti", json.dumps(
254                 {
255                     "anot-her": {
256                         "another01ems003": {"dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.3", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_target_name": "another01ems003", "dcae_target_collection": "true", "event": {}, "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems003_2PMOBATTHSSEMS0165": {"serviceType": "MOB-VHSS", "nodeType": "VHSS", "description": "VHSS Data Collection", "priority": 1, "nodeSubtype": "", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroupId": "g1", "serverGroup": [{"isPrimary": "true", "remoteServerIp": "107.239.85.3", "remoteServerName": "another01ems003"}]}}, "protocol": "sftp", "collectionInterval": "300"}}}, "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_prov-status": "PROV"}
257                     }
258                 }
259             ))
260         ]
261         rv = MonkeyRequestsResponse(full_path, res_json)
262
263     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "docker_plugin/docker_logins"):
264         res_json = [
265             kv_encode("docker_plugin/docker_logins", json.dumps(
266                 [{"username": "fake_user", "password": "fake_password",
267                   "registry": "registry.bogus.com:5100" }]
268             ))
269         ]
270         rv = MonkeyRequestsResponse(full_path, res_json)
271
272     elif full_path == ConsulClient.CONSUL_KVS_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "oti_events/") \
273       or full_path == ConsulClient.CONSUL_KVS_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "oti_events/anot-her/"):
274         res_json = [
275             kv_encode("oti_events/anot-her/another01ems003", json.dumps(
276                 {"dcae_service_location": "LSLEILAA",
277                  "dcae_target_type": "ANOT-her",
278                  "dcae_service_action": "deploy",
279                  "dcae_service-instance_model-version-id": "1",
280                  "dcae_target_collection_ip": "107.239.85.3",
281                  "dcae_target_is-closed-loop-disabled": "false",
282                  "dcae_target_in-maint": "false",
283                  "dcae_target_name": "another01ems003",
284                  "dcae_target_collection": "true",
285                  "event": {},
286                  "dcae_snmp_version": "2c",
287                  "aai_additional_info": {"TasksItems": {"another01ems003_2PMOBATTHSSEMS0165": {"serviceType": "MOB-VHSS", "nodeType": "VHSS", "description": "VHSS Data Collection", "priority": 1, "nodeSubtype": "", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroupId": "g1", "serverGroup": [{"isPrimary": "true", "remoteServerIp": "107.239.85.3", "remoteServerName": "another01ems003"}]}}, "protocol": "sftp", "collectionInterval": "300"}}},
288                  "dcae_snmp_community_string": "my_first_community",
289                  "dcae_generic-vnf_model-version-id": "1",
290                  "dcae_target_prov-status": "PROV"
291                 }
292             )),
293             kv_encode("oti_events/anot-her/another01ems042", json.dumps(
294                 {"dcae_service_location": "LSLEILAA",
295                  "dcae_target_type": "ANOT-her",
296                  "dcae_service_action": "deploy",
297                  "dcae_service-instance_model-version-id": "1",
298                  "dcae_target_collection_ip": "107.239.85.42",
299                  "dcae_target_is-closed-loop-disabled": "false",
300                  "dcae_target_in-maint": "false",
301                  "dcae_target_name": "another01ems042",
302                  "dcae_target_collection": "true",
303                  "event": {},
304                  "dcae_snmp_version": "2c",
305                  "aai_additional_info": {"TasksItems": {"another01ems042_2PMOBATTHSSEMS0165": {"serviceType": "MOB-VHSS", "nodeType": "VHSS", "description": "VHSS Data Collection", "priority": 1, "nodeSubtype": "", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroupId": "g1", "serverGroup": [{"isPrimary": "true", "remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems042"}]}}, "protocol": "sftp", "collectionInterval": "300"}}},
306                  "dcae_snmp_community_string": "my_first_community",
307                  "dcae_generic-vnf_model-version-id": "1",
308                  "dcae_target_prov-status": "PROV"
309                 }
310             )),
311             kv_encode("oti_events/anot-her/another01ems044", json.dumps(
312                 {"dcae_service_location": "MDTWNJC1",
313                  "dcae_target_type": "ANOT-her",
314                  "dcae_service_action": "deploy",
315                  "dcae_service-instance_model-version-id": "1",
316                  "dcae_target_collection_ip": "107.239.85.42",
317                  "dcae_target_is-closed-loop-disabled": "false",
318                  "dcae_target_in-maint": "false",
319                  "dcae_target_name": "another01ems044",
320                  "dcae_target_collection": "true",
321                  "event": {},
322                  "dcae_snmp_version": "2c",
323                  "aai_additional_info": {"TasksItems": {"another01ems044_2PMOBATTHSSEMS0165": {"serviceType": "MOB-VHSS", "nodeType": "VHSS", "description": "VHSS Data Collection", "priority": 1, "nodeSubtype": "", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroupId": "g1", "serverGroup": [{"isPrimary": "true", "remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems044"}]}}, "protocol": "sftp", "collectionInterval": "300"}}},
324                  "dcae_snmp_community_string": "my_first_community",
325                  "dcae_generic-vnf_model-version-id": "1",
326                  "dcae_target_prov-status": "PROV"
327                 }
328             ))
329         ]
330         rv = MonkeyRequestsResponse(full_path, res_json)
331
332     elif full_path == ConsulClient.CONSUL_KVS_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "oti_events/birth-day/"):
333         res_json = [
334             kv_encode("oti_events/birth-day/birthdy01ems055", json.dumps(
335                 {"dcae_service_location": "LSLEILAA",
336                  "dcae_target_type": "birth-day",
337                  "dcae_service_action": "deploy",
338                  "dcae_service-instance_model-version-id": "1",
339                  "dcae_target_collection_ip": "107.239.85.3",
340                  "dcae_target_is-closed-loop-disabled": "false",
341                  "dcae_target_in-maint": "false",
342                  "dcae_target_name": "birthdy01ems055",
343                  "dcae_target_collection": "true",
344                  "event": {},
345                  "dcae_snmp_version": "2c",
346                  "aai_additional_info": {"TasksItems": {"birthdy01ems055_2PMOBATTHSSEMS0165": {"serviceType": "MOB-VHSS", "nodeType": "VHSS", "description": "VHSS Data Collection", "priority": 1, "nodeSubtype": "", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroupId": "g1", "serverGroup": [{"isPrimary": "true", "remoteServerIp": "107.239.85.3", "remoteServerName": "birthdy01ems055"}]}}, "protocol": "sftp", "collectionInterval": "300"}}},
347                  "dcae_snmp_community_string": "my_first_community",
348                  "dcae_generic-vnf_model-version-id": "1",
349                  "dcae_target_prov-status": "PROV"
350                 }
351             ))
352         ]
353         res_json = [
354         ]
355         rv = MonkeyRequestsResponse(full_path, res_json)
356
357     elif full_path == ConsulClient.CONSUL_KVS_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "oti_events/new-type/"):
358         res_json = [
359             kv_encode("oti_events/new-type/newtype01ems084", json.dumps(
360                 {"dcae_service_location": "LSLEILAA",
361                  "dcae_target_type": "new-type",
362                  "dcae_service_action": "deploy",
363                  "dcae_service-instance_model-version-id": "1",
364                  "dcae_target_collection_ip": "107.239.85.3",
365                  "dcae_target_is-closed-loop-disabled": "false",
366                  "dcae_target_in-maint": "false",
367                  "dcae_target_name": "newtype01ems084",
368                  "dcae_target_collection": "true",
369                  "event": {},
370                  "dcae_snmp_version": "2c",
371                  "aai_additional_info": {"TasksItems": {"newtype01ems084_2PMOBATTHSSEMS0165": {"serviceType": "MOB-VHSS", "nodeType": "VHSS", "description": "VHSS Data Collection", "priority": 1, "nodeSubtype": "", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroupId": "g1", "serverGroup": [{"isPrimary": "true", "remoteServerIp": "107.239.85.3", "remoteServerName": "newtype01ems084"}]}}, "protocol": "sftp", "collectionInterval": "300"}}},
372                  "dcae_snmp_community_string": "my_first_community",
373                  "dcae_generic-vnf_model-version-id": "1",
374                  "dcae_target_prov-status": "PROV"
375                 }
376             ))
377         ]
378         res_json = [
379         ]
380         rv = MonkeyRequestsResponse(full_path, res_json)
381
382     elif full_path == ConsulClient.CONSUL_KVS_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "oti_events/pcrf-oam/"):
383         res_json = [
384             kv_encode("oti_events/pcrf-oam/pcrfoam01ems009", json.dumps(
385                 {"dcae_service_location": "LSLEILAA",
386                  "dcae_target_type": "pcrf-oam",
387                  "dcae_service_action": "deploy",
388                  "dcae_service-instance_model-version-id": "1",
389                  "dcae_target_collection_ip": "107.239.85.3",
390                  "dcae_target_is-closed-loop-disabled": "false",
391                  "dcae_target_in-maint": "false",
392                  "dcae_target_name": "pcrfoam01ems009",
393                  "dcae_target_collection": "true",
394                  "event": {},
395                  "dcae_snmp_version": "2c",
396                  "aai_additional_info": {"TasksItems": {"pcrfoam01ems009_2PMOBATTHSSEMS0165": {"serviceType": "MOB-VHSS", "nodeType": "VHSS", "description": "VHSS Data Collection", "priority": 1, "nodeSubtype": "", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroupId": "g1", "serverGroup": [{"isPrimary": "true", "remoteServerIp": "107.239.85.3", "remoteServerName": "pcrfoam01ems009"}]}}, "protocol": "sftp", "collectionInterval": "300"}}},
397                  "dcae_snmp_community_string": "my_first_community",
398                  "dcae_generic-vnf_model-version-id": "1",
399                  "dcae_target_prov-status": "PROV"
400                 }
401             ))
402         ]
403         res_json = [
404         ]
405         rv = MonkeyRequestsResponse(full_path, res_json)
406
407     elif full_path == ConsulClient.CONSUL_KVS_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "oti_events/pnga-xxx/"):
408         res_json = [
409             kv_encode("oti_events/pnga-xxx/pngaxxx01ems007", json.dumps(
410                 {"dcae_service_location": "LSLEILAA",
411                  "dcae_target_type": "pnga-xxx",
412                  "dcae_service_action": "deploy",
413                  "dcae_service-instance_model-version-id": "1",
414                  "dcae_target_collection_ip": "107.239.85.3",
415                  "dcae_target_is-closed-loop-disabled": "false",
416                  "dcae_target_in-maint": "false",
417                  "dcae_target_name": "pngaxxx01ems007",
418                  "dcae_target_collection": "true",
419                  "event": {},
420                  "dcae_snmp_version": "2c",
421                  "aai_additional_info": {"TasksItems": {"pngaxxx01ems007_2PMOBATTHSSEMS0165": {"serviceType": "MOB-VHSS", "nodeType": "VHSS", "description": "VHSS Data Collection", "priority": 1, "nodeSubtype": "", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroupId": "g1", "serverGroup": [{"isPrimary": "true", "remoteServerIp": "107.239.85.3", "remoteServerName": "pngaxxx01ems007"}]}}, "protocol": "sftp", "collectionInterval": "300"}}},
422                  "dcae_snmp_community_string": "my_first_community",
423                  "dcae_generic-vnf_model-version-id": "1",
424                  "dcae_target_prov-status": "PROV"
425                 }
426             ))
427         ]
428         res_json = [
429         ]
430         rv = MonkeyRequestsResponse(full_path, res_json)
431
432     elif full_path == ConsulClient.CONSUL_KVS_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "oti_events/vhss-ems/"):
433         res_json = [
434             kv_encode("oti_events/vhss-ems/vhssems01ems019", json.dumps(
435                 {"dcae_service_location": "LSLEILAA",
436                  "dcae_target_type": "vhss-ems",
437                  "dcae_service_action": "deploy",
438                  "dcae_service-instance_model-version-id": "1",
439                  "dcae_target_collection_ip": "107.239.85.3",
440                  "dcae_target_is-closed-loop-disabled": "false",
441                  "dcae_target_in-maint": "false",
442                  "dcae_target_name": "vhssems01ems019",
443                  "dcae_target_collection": "true",
444                  "event": {},
445                  "dcae_snmp_version": "2c",
446                  "aai_additional_info": {"TasksItems": {"vhssems01ems019_2PMOBATTHSSEMS0165": {"serviceType": "MOB-VHSS", "nodeType": "VHSS", "description": "VHSS Data Collection", "priority": 1, "nodeSubtype": "", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroupId": "g1", "serverGroup": [{"isPrimary": "true", "remoteServerIp": "107.239.85.3", "remoteServerName": "vhssems01ems019"}]}}, "protocol": "sftp", "collectionInterval": "300"}}},
447                  "dcae_snmp_community_string": "my_first_community",
448                  "dcae_generic-vnf_model-version-id": "1",
449                  "dcae_target_prov-status": "PROV"
450                 }
451             ))
452         ]
453         res_json = [
454         ]
455         rv = MonkeyRequestsResponse(full_path, res_json)
456
457     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "oti_events/anot-her/another01ems003"):
458         res_json = [
459             kv_encode("oti_events/anot-her/another01ems003", json.dumps(
460                 {"dcae_service_location": "LSLEILAA",
461                  "dcae_target_type": "ANOT-her",
462                  "dcae_service_action": "deploy",
463                  "dcae_service-instance_model-version-id": "1",
464                  "dcae_target_collection_ip": "107.239.85.3",
465                  "dcae_target_is-closed-loop-disabled": "false",
466                  "dcae_target_in-maint": "false",
467                  "dcae_target_name": "another01ems003",
468                  "dcae_target_collection": "true",
469                  "event": {},
470                  "dcae_snmp_version": "2c",
471                  "aai_additional_info": {"TasksItems": {"another01ems003_2PMOBATTHSSEMS0165": {"serviceType": "MOB-VHSS", "nodeType": "VHSS", "description": "VHSS Data Collection", "priority": 1, "nodeSubtype": "", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroupId": "g1", "serverGroup": [{"isPrimary": "true", "remoteServerIp": "107.239.85.3", "remoteServerName": "another01ems003"}]}}, "protocol": "sftp", "collectionInterval": "300"}}},
472                  "dcae_snmp_community_string": "my_first_community",
473                  "dcae_generic-vnf_model-version-id": "1",
474                  "dcae_target_prov-status": "PROV"
475                 }
476             ))
477         ]
478         rv = MonkeyRequestsResponse(full_path, res_json)
479
480     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "oti_events/anot-her/another01ems042"):
481         res_json = [
482             kv_encode("oti_events/anot-her/another01ems042", json.dumps(
483                 {"dcae_service_location": "LSLEILAA",
484                  "dcae_target_type": "ANOT-her",
485                  "dcae_service_action": "deploy",
486                  "dcae_service-instance_model-version-id": "1",
487                  "dcae_target_collection_ip": "107.239.85.42",
488                  "dcae_target_is-closed-loop-disabled": "false",
489                  "dcae_target_in-maint": "false",
490                  "dcae_target_name": "another01ems042",
491                  "dcae_target_collection": "true",
492                  "event": {},
493                  "dcae_snmp_version": "2c",
494                  "aai_additional_info": {"TasksItems": {"another01ems042_2PMOBATTHSSEMS0165": {"serviceType": "MOB-VHSS", "nodeType": "VHSS", "description": "VHSS Data Collection", "priority": 1, "nodeSubtype": "", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroupId": "g1", "serverGroup": [{"isPrimary": "true", "remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems042"}]}}, "protocol": "sftp", "collectionInterval": "300"}}},
495                  "dcae_snmp_community_string": "my_first_community",
496                  "dcae_generic-vnf_model-version-id": "1",
497                  "dcae_target_prov-status": "PROV"
498                 }
499             ))
500         ]
501         rv = MonkeyRequestsResponse(full_path, res_json)
502
503     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "oti_events/anot-her/another01ems044"):
504         res_json = [
505             kv_encode("oti_events/anot-her/another01ems044", json.dumps(
506                 {"dcae_service_location": "MDTWNJC1",
507                  "dcae_target_type": "ANOT-her",
508                  "dcae_service_action": "deploy",
509                  "dcae_service-instance_model-version-id": "1",
510                  "dcae_target_collection_ip": "107.239.85.42",
511                  "dcae_target_is-closed-loop-disabled": "false",
512                  "dcae_target_in-maint": "false",
513                  "dcae_target_name": "another01ems044",
514                  "dcae_target_collection": "true",
515                  "event": {},
516                  "dcae_snmp_version": "2c",
517                  "aai_additional_info": {"TasksItems": {"another01ems044_2PMOBATTHSSEMS0165": {"serviceType": "MOB-VHSS", "nodeType": "VHSS", "description": "VHSS Data Collection", "priority": 1, "nodeSubtype": "", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroupId": "g1", "serverGroup": [{"isPrimary": "true", "remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems044"}]}}, "protocol": "sftp", "collectionInterval": "300"}}},
518                  "dcae_snmp_community_string": "my_first_community",
519                  "dcae_generic-vnf_model-version-id": "1",
520                  "dcae_target_prov-status": "PROV"
521                 }
522             ))
523         ]
524         rv = MonkeyRequestsResponse(full_path, res_json)
525
526     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "SCN_1"):
527         res_json = [
528             kv_encode("SCN_1", json.dumps(
529                 {"dcae_target_type": ["pnga-xxx"]}
530             ))
531         ]
532         rv = MonkeyRequestsResponse(full_path, res_json)
533
534     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "SCN_1:oti"):
535         res_json = [
536             kv_encode("SCN_1:oti", json.dumps(
537                 {"new-type": {}, "pnga-xxx": {}, "birth-day": {}, "anot-her": {}, "vhss-ems": {}, "pcrf-oam": {}}
538             ))
539         ]
540         rv = MonkeyRequestsResponse(full_path, res_json)
541
542     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "SCN_1:dmaap"):
543         res_json = [
544             kv_encode("SCN_1:dmaap", json.dumps(
545                 {"topic0": {
546                    "topic_url": "https://dcae-mrtr.bogus.com:3005/events/com.bogus.HelloWorld-PubTopic",
547                    "client_role": "com.bogus.member",
548                    "location": "loc-1",
549                    "client_id": "1575649224792"
550                  },
551                  "topic1": {
552                    "topic_url": "https://dcae-mrtr.bogus.com:3005/events/com.bogus.HelloWorld-PubTopic",
553                    "client_role": "com.bogus.member",
554                    "location": "loc-1",
555                    "client_id": "1575649221094"
556                  }
557                 }
558             ))
559         ]
560         rv = MonkeyRequestsResponse(full_path, res_json)
561
562     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "SCN_1:rel"):
563         res_json = [
564             kv_encode("SCN_1:rel", json.dumps(
565                 {"who-knows", "what this content might look like?"}
566             ))
567         ]
568         rv = MonkeyRequestsResponse(full_path, res_json)
569
570     elif full_path == ConsulClient.CONSUL_KVS_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "SCN_1"):
571         res_json = [
572             kv_encode("SCN_1", json.dumps(
573                 {"dcae_target_type": ["pnga-xxx"]}
574             )),
575             kv_encode("SCN_1:oti", json.dumps(
576                 {"new-type": {}, "pnga-xxx": {}, "birth-day": {}, "anot-her": {}, "vhss-ems": {}, "pcrf-oam": {}}
577             )),
578             kv_encode("SCN_1:policies/event", json.dumps(
579                 {"action": "updated", "timestamp": "2018-07-16T15:11:44.845Z", "update_id": "e6102aab-3079-435a-ae0d-0397a2cb3c4d", "policies_count": 3}
580             )),
581             kv_encode("SCN_1:policies/items/DCAE_FTL3B.Config_Green_Collectors", json.dumps(
582                 {"policyName": "DCAE_FTL3B.Config_Green_Collectors.1.xml", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyConfigStatus": "CONFIG_RETRIEVED", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "Green_Collectors"}, "type": "JSON", "property": null, "config": {"power_source": "lemmings", "conflicting_key": "green_collectors_wins", "package_type": "plastic", "polling_frequency": "30m"}, "policyVersion": "1"}
583             )),
584             kv_encode("SCN_1:policies/items/DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific", json.dumps(
585                 {"policyName": "DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific.5.xml", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyConfigStatus": "CONFIG_RETRIEVED", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "Green_Eggs_and_Ham_specific"}, "type": "JSON", "property": null, "config": {"conflicting_key": "green_eggs_and_ham_are_better", "dcae_target_type": ["pnga-xxx", "pcrf-oam", "vhss-ems", "anot-her", "new-type"], "bacon": "soft, not crispy", "preparation": "scrambled", "egg_color": "green", "bread": "pumpernickel"}, "policyVersion": "5"}
586             )),
587             kv_encode("SCN_1:policies/items/DCAE_FTL3B.Config_In_Service", json.dumps(
588                 {"policyName": "DCAE_FTL3B.Config_In_Service.1.xml", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyConfigStatus": "CONFIG_RETRIEVED", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "In_Service"}, "type": "JSON", "property": null, "config": {"conflicting_key": "in_service_trumps!", "in_service": true}, "policyVersion": "1"}
589             ))
590         ]
591         rv = MonkeyRequestsResponse(full_path, res_json)
592
593     elif full_path == ConsulClient.CONSUL_KVS_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "SCN_1:policies/items/"):
594         res_json = [
595             kv_encode("SCN_1:policies/items/DCAE_FTL3B.Config_Green_Collectors", json.dumps(
596                 {"policyName": "DCAE_FTL3B.Config_Green_Collectors.1.xml", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyConfigStatus": "CONFIG_RETRIEVED", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "Green_Collectors"}, "type": "JSON", "property": null, "config": {"power_source": "lemmings", "conflicting_key": "green_collectors_wins", "package_type": "plastic", "polling_frequency": "30m"}, "policyVersion": "1"}
597             )),
598             kv_encode("SCN_1:policies/items/DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific", json.dumps(
599                 {"policyName": "DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific.5.xml", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyConfigStatus": "CONFIG_RETRIEVED", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "Green_Eggs_and_Ham_specific"}, "type": "JSON", "property": null, "config": {"conflicting_key": "green_eggs_and_ham_are_better", "dcae_target_type": ["pnga-xxx", "pcrf-oam", "vhss-ems", "anot-her", "new-type"], "bacon": "soft, not crispy", "preparation": "scrambled", "egg_color": "green", "bread": "pumpernickel"}, "policyVersion": "5"}
600             )),
601             kv_encode("SCN_1:policies/items/DCAE_FTL3B.Config_In_Service", json.dumps(
602                 {"policyName": "DCAE_FTL3B.Config_In_Service.1.xml", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyConfigStatus": "CONFIG_RETRIEVED", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "In_Service"}, "type": "JSON", "property": null, "config": {"conflicting_key": "in_service_trumps!", "in_service": true}, "policyVersion": "1"}
603             ))
604         ]
605         rv = MonkeyRequestsResponse(full_path, res_json)
606
607     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "SCN_1:policies/items/DCAE_FTL3B.Config_Green_Collectors"):
608         res_json = [
609             kv_encode("SCN_1:policies/items/DCAE_FTL3B.Config_Green_Collectors", json.dumps(
610                 {"policyName": "DCAE_FTL3B.Config_Green_Collectors.1.xml", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyConfigStatus": "CONFIG_RETRIEVED", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "Green_Collectors"}, "type": "JSON", "property": null, "config": {"power_source": "lemmings", "conflicting_key": "green_collectors_wins", "package_type": "plastic", "polling_frequency": "30m"}, "policyVersion": "1"}
611             ))
612         ]
613         rv = MonkeyRequestsResponse(full_path, res_json)
614
615     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "SCN_1:policies/items/DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific"):
616         res_json = [
617             kv_encode("SCN_1:policies/items/DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific", json.dumps(
618                 {"policyName": "DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific.5.xml", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyConfigStatus": "CONFIG_RETRIEVED", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "Green_Eggs_and_Ham_specific"}, "type": "JSON", "property": null, "config": {"conflicting_key": "green_eggs_and_ham_are_better", "dcae_target_type": ["pnga-xxx", "pcrf-oam", "vhss-ems", "anot-her", "new-type"], "bacon": "soft, not crispy", "preparation": "scrambled", "egg_color": "green", "bread": "pumpernickel"}, "policyVersion": "5"}
619             ))
620         ]
621         rv = MonkeyRequestsResponse(full_path, res_json)
622
623     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "SCN_1:policies/items/DCAE_FTL3B.Config_In_Service"):
624         res_json = [
625             kv_encode("SCN_1:policies/items/DCAE_FTL3B.Config_In_Service", json.dumps(
626                 {"policyName": "DCAE_FTL3B.Config_In_Service.1.xml", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyConfigStatus": "CONFIG_RETRIEVED", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "In_Service"}, "type": "JSON", "property": null, "config": {"conflicting_key": "in_service_trumps!", "in_service": true}, "policyVersion": "1"}
627             ))
628         ]
629         rv = MonkeyRequestsResponse(full_path, res_json)
630
631     elif full_path == ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "bogus:oti"):
632         res_json = None
633         rv = MonkeyRequestsResponse(full_path, res_json)
634
635     elif full_path == "{}/v1/catalog/services".format(os.environ.get("CONSUL_URL").rstrip("/")):
636         res_json = {
637                 "OTITopologyVM": [],
638                 "apihandler": [],
639                 "cloudify_manager": [],
640                 "config_binding_service": [],
641                 "consul": [],
642                 "dashboard": [],
643                 "deployment_handler": [
644                     "deployment_handler"
645                 ],
646                 "dmaap_bus_controller": [],
647                 "dmrb": [],
648                 "oti_handler": [
649                     "oti_handler"
650                 ],
651                 "http_dmaap_bus_controller_api": [],
652                 "https_dmaap_bus_controller_api": [],
653                 "inventory": [
654                     "inventory"
655                 ],
656                 "pgda-readonly": [],
657                 "pgda-service": [],
658                 "pgda-write": [],
659                 "policy_handler": [
660                     "policy_handler"
661                 ],
662                 "pstg-readonly": [],
663                 "pstg-service": [],
664                 "pstg-write": [],
665                 "service-change-handler": [
666                     "service-change-handler"
667                 ],
668                 "zldcdyh1adcc1-component-dockerhost-1": [
669                     "LSLEILAA",
670                     "MDTWNJC1"
671                 ],
672                 "zldcdyh1adcc1-component-dockerhost-2": [
673                     "LSLEILAA",
674                     "MDTWNJC1"
675                 ],
676                 "zldcdyh1adcc1-component-dockerhost-3": [
677                     "LSLEILAA",
678                     "MDTWNJC1"
679                 ],
680                 "zldcdyh1adcc1-component-dockerhost-4": [
681                     "LSLEILAA",
682                     "MDTWNJC1"
683                 ],
684                 "zldcdyh1adcc1-platform-dockerhost-1": [
685                     "LSLEILAA",
686                     "MDTWNJC1"
687                 ],
688                 "zldcdyh1adcc1-platform-dockerhost-2": [
689                     "LSLEILAA",
690                     "MDTWNJC1"
691                 ],
692                 "zldcdyh1adce1-component-dockerhost-1": [
693                     "LSLEILAA",
694                     "MDTWNJC1"
695                 ],
696                 "zldcdyh1adce1-component-dockerhost-2": [
697                     "LSLEILAA",
698                     "MDTWNJC1"
699                 ],
700                 "zldcdyh1adce1-component-dockerhost-3": [
701                     "LSLEILAA",
702                     "MDTWNJC1"
703                 ],
704                 "zldcdyh1adce1-component-dockerhost-4": [
705                     "LSLEILAA",
706                     "MDTWNJC1"
707                 ],
708                 "zldcdyh1adce1-platform-dockerhost-1": [
709                     "LSLEILAA",
710                     "MDTWNJC1"
711                 ],
712                 "zldcdyh1adce1-platform-dockerhost-2": [
713                     "LSLEILAA",
714                     "MDTWNJC1"
715                 ]
716         }
717         rv = MonkeyRequestsResponse(full_path, res_json)
718
719     elif full_path == ConsulClient.CONSUL_SERVICE_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "SCN_1"):
720         res_json = [
721             {
722                 "ID": "966d0ef5-7ca2-1b25-d587-2f0541a6ef78",
723                 "Node": "node_1",
724                 "Address": "10.1.14.15",
725                 "Datacenter": "zldcdyh1adcc1",
726                 "TaggedAddresses": {
727                     "lan": "10.1.14.15",
728                     "wan": "10.1.14.15"
729                 },
730                 "NodeMeta": {
731                     "consul-network-segment": "",
732                     "fqdn": "kpma00.897658.bogus.com"
733                 },
734                 "ServiceKind": "",
735                 "ServiceID": "scn-1-service-301",
736                 "ServiceName": "scn-1-service",
737                 "ServiceTags": [
738                     "com-bogus-dcae-controller"
739                 ],
740                 "ServiceAddress": "scn-1.bogus.com",
741                 "ServiceWeights": {
742                     "Passing": 1,
743                     "Warning": 1
744                 },
745                 "ServiceMeta": {
746                     "proto": "http"
747                 },
748                 "ServicePort": 301,
749                 "ServiceEnableTagOverride": false,
750                 "ServiceProxyDestination": "",
751                 "ServiceProxy": {},
752                 "ServiceConnect": {},
753                 "CreateIndex": 30535167,
754                 "ModifyIndex": 30535167
755             }
756         ]
757         rv = MonkeyRequestsResponse(full_path, res_json)
758
759     elif full_path == ConsulClient.CONSUL_SERVICE_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), "bogus"):
760         res_json = [
761         ]
762         rv = MonkeyRequestsResponse(full_path, res_json)
763
764     elif full_path == "{}/v1/catalog/node/node_1".format(os.environ.get("CONSUL_URL").rstrip("/")):
765         res_json = {
766             "Node": {
767                 "ID": "966d0ef5-7ca2-1b25-d587-2f0541a6ef78",
768                 "Node": "node_1",
769                 "Address": "10.1.14.15",
770                 "Datacenter": "zldcdyh1adcc1",
771                 "TaggedAddresses": {
772                     "lan": "10.1.14.15",
773                     "wan": "10.1.14.15"
774                 },
775                 "Meta": {
776                     "consul-network-segment": "",
777                     "fqdn": "kpma00.897658.bogus.com"
778                 },
779                 "CreateIndex": 28443495,
780                 "ModifyIndex": 28443495
781             },
782             "Services": {
783                 "apple-320": {
784                     "ID": "apple-320",
785                     "Service": "apple",
786                     "Tags": [
787                         "com-bogus-controller-mgmt"
788                     ],
789                     "Address": "apple.bogus.com",
790                     "Meta": {
791                         "proto": ""
792                     },
793                     "Port": 320,
794                     "Weights": {
795                         "Passing": 1,
796                         "Warning": 1
797                     },
798                     "EnableTagOverride": false,
799                     "ProxyDestination": "",
800                     "Proxy": {},
801                     "Connect": {},
802                     "CreateIndex": 28598335,
803                     "ModifyIndex": 28598335
804                 },
805                 "banana-service-301": {
806                     "ID": "banana-service-301",
807                     "Service": "banana-service",
808                     "Tags": [
809                         "com-bogus-controller-dev"
810                     ],
811                     "Address": "banana.bogus.com",
812                     "Meta": {
813                         "proto": "http"
814                     },
815                     "Port": 301,
816                     "Weights": {
817                         "Passing": 1,
818                         "Warning": 1
819                     },
820                     "EnableTagOverride": false,
821                     "ProxyDestination": "",
822                     "Proxy": {},
823                     "Connect": {},
824                     "CreateIndex": 30535167,
825                     "ModifyIndex": 30535167
826                 },
827                 "d3_kp_platform_kubernetes_master": {
828                     "ID": "d3_kp_platform_kubernetes_master",
829                     "Service": "d3_kp_platform_kubernetes_master",
830                     "Tags": [
831                         "KGMTNC20"
832                     ],
833                     "Address": "10.1.14.15",
834                     "Meta": null,
835                     "Port": 6443,
836                     "Weights": {
837                         "Passing": 1,
838                         "Warning": 1
839                     },
840                     "EnableTagOverride": false,
841                     "ProxyDestination": "",
842                     "Proxy": {},
843                     "Connect": {},
844                     "CreateIndex": 28443495,
845                     "ModifyIndex": 28443495
846                 }
847             }
848         }
849         rv = MonkeyRequestsResponse(full_path, res_json)
850
851     else:
852         Settings.logger.error("monkey_consul_client_get had no mock for {}".format(full_path))
853         res_json = None
854         rv = MonkeyRequestsResponse(full_path, res_json, status_code=404)
855
856     return rv
857
858 def monkey_consul_client_put(full_path, **kwargs):
859     """monkeypatch for PUT from consul"""
860
861     Settings.logger.info("monkey_consul_client called with full_path={}, kwargs={}".format(full_path, kwargs))
862     rv = False
863     res_json = {}
864     if full_path == ConsulClient.CONSUL_TRANSACTION_URL.format(os.environ.get("CONSUL_URL").rstrip("/")):
865         txn = {}
866         if 'json' in kwargs:
867             Settings.logger.info("monkey_consul_client called with txn={}".format(str(kwargs.get('json'))))
868             txn = kwargs.get('json')[0]
869         r_dict = {
870             "Results": [
871               {
872                 "KV": {
873                   "LockIndex": 99999,
874                   "Key": txn.get('Key'),
875                   "Flags": 0,
876                   "Value": None,
877                   "CreateIndex": 99999,
878                   "ModifyIndex": 99999
879                 }
880               }
881             ],
882             "Errors": [
883             ]
884         }
885         status_code = 200
886         KV = txn.get('KV')
887         if KV and KV.get('Verb') == 'delete' and KV.get('Key') == 'oti_events/anot-her/bogus':
888             status_code = 409
889             r_dict["Errors"].append({
890                 "OpIndex": 99,
891                 "What": "That KV does not exist."
892             })
893         res_json = [ r_dict ]
894         Settings.logger.info("monkey_consul_client produced res_json={} with status_code={}".format(json.dumps(res_json), status_code))
895         rv = MonkeyRequestsResponse(full_path, res_json, status_code=status_code)
896
897     elif full_path.startswith(ConsulClient.CONSUL_KV_MASK.format(os.environ.get("CONSUL_URL").rstrip("/"), '')):  # wants to write
898         # parse_url = urlparse(url)
899         # query_dict = dict(parse_qsl(parse_url.query))
900
901         res_json = True
902         Settings.logger.info("monkey_consul_client produced res_json={}".format(json.dumps(res_json)))
903         rv = MonkeyRequestsResponse(full_path, res_json)
904
905     else:
906         Settings.logger.error("monkey_consul_client_put had no mock for {}".format(full_path))
907
908     return rv
909
910 class MonkeyCloudifyNode(object):
911     """fake cloudify node_instance"""
912
913     def __init__(self, **kwargs):
914         """init locals"""
915
916         self.runtime_properties = kwargs.get('runtime_properties', {})
917         self.deployment_id = kwargs.get('deployment_id')
918         self.node_id = kwargs.get('node_id')
919         self.id = kwargs.get('id')
920         self.state = kwargs.get('state')
921
922 class MonkeyCloudifyClient(object):
923     """monkeypatch for CloudifyClient"""
924
925     def __init__(self, **kwargs):
926         """init locals"""
927
928         Settings.logger.info("MonkeyCloudifyClient called with kwargs={}".format(json.dumps(kwargs)))
929         self._host = kwargs.get('host')
930         self._port = kwargs.get('port')
931         self._protocol = kwargs.get('protocol')
932         self._headers = kwargs.get('headers')
933
934         self.node_instances = self
935
936     def list(self, **kwargs):
937         """list node_instances"""
938
939         Settings.logger.info("MonkeyCloudifyClient.list() called with kwargs={}".format(json.dumps(kwargs)))
940         rval = []
941         deployment_id = kwargs.get('deployment_id')
942         sort_field = kwargs.get('_sort')
943         if deployment_id or sort_field:
944             rval = [
945                  MonkeyCloudifyNode(
946                      runtime_properties={
947                          "container_id": "container_1",
948                          "dti_reconfig_script": "dti_reconfig_script_1",
949                          "docker_config": {
950                              "reconfigs": {
951                                  "dti": "dti_reconfig_script_1",
952                                  "app": "app_reconfig_script_1",
953                                  "special": "special_reconfig_script_1"
954                              }
955                          },
956                          "service_component_name": "SCN_1",
957                          "selected_container_destination": "zldcdyh1adcc1-component-dockerhost-1",
958                          "service_component_type": "SCType_1"
959                      },
960                      deployment_id = 'deployment_id_1',
961                      node_id = 'node_id_1',
962                      id = 'id_1',
963                      state = 'state_1'
964                  ),
965                  MonkeyCloudifyNode(
966                      runtime_properties={
967                          "container_id": "container_2",
968                          "dti_reconfig_script": "dti_reconfig_script_2",
969                          "docker_config": {
970                              "reconfigs": {
971                                  "dti": "dti_reconfig_script_2",
972                                  "app": "app_reconfig_script_2",
973                                  "special": "special_reconfig_script_2"
974                              }
975                          },
976                          "service_component_name": "SCN_2",
977                          "selected_container_destination": "zldcdyh1adcc1-component-dockerhost-1",
978                          "service_component_type": "SCType_2"
979                      },
980                      deployment_id = 'deployment_id_2',
981                      node_id = 'node_id_2',
982                      id = 'id_2',
983                      state = 'state_2'
984                  )
985             ]
986
987         return rval
988
989 class MonkeyEventDbAccess(object):
990     """monkdypatch for otihandler.dbclient.apis.EventDbAccess()"""
991
992     def __init__(self, **kwargs):
993         """init locals"""
994         Settings.logger.info("MonkeyEventDbAccess called with kwargs={}".format(json.dumps(kwargs)))
995
996     def saveDomainObject(self, obj):
997         return None
998
999     def deleteDomainObject(self, obj):
1000         return None
1001
1002     def query_event_item(self, target_type, target_name):
1003         Settings.logger.info("MonkeyEventDbAccess.query_event_item({}, {})".format(target_type, target_name))
1004         return None
1005
1006     def query_event_data(self, target_type, target_name):
1007         Settings.logger.info("MonkeyEventDbAccess.query_event_data({}, {})".format(target_type, target_name))
1008         return []
1009
1010     def query_event_data_k8s(self, target_type, target_name):
1011         Settings.logger.info("MonkeyEventDbAccess.query_event_data_k8s({}, {})".format(target_type, target_name))
1012         return []
1013
1014     def query_event_info_docker(self, curr_evt, component_scn, deployment_id, container_id):
1015         Settings.logger.info("MonkeyEventDbAccess.query_event_info_docker({}, {}, {}, {})".format(curr_evt, component_scn, deployment_id, container_id))
1016         return None
1017
1018     def update_event_item(self, event, target_type, target_name):
1019         Settings.logger.info("MonkeyEventDbAccess.update_event_item({}, {}, {})".format(event, target_type, target_name))
1020         return None
1021
1022     def query_raw_k8_events(self, cluster, pod, namespace):
1023         Settings.logger.info("MonkeyEventDbAccess.query_raw_k8_events({}, {}, {})".format(cluster, pod, namespace))
1024         return []
1025
1026     def query_raw_docker_events(self, target_types, locations):
1027         Settings.logger.info("MonkeyEventDbAccess.query_raw_docker_events({}, {})".format(target_types, locations))
1028         return []
1029
1030     def query_event_data_k8s_pod(self, curr_evt, component_scn):
1031         Settings.logger.info("MonkeyEventDbAccess.query_event_k8s_pod({}, {})".format(curr_evt, component_scn))
1032         return None
1033
1034 class MonkeyDockerClient(object):
1035     """monkeypatch for docker.APIClient()"""
1036
1037     def __init__(self, **kwargs):
1038         """init locals"""
1039
1040         Settings.logger.info("MonkeyDockerClient called with kwargs={}".format(json.dumps(kwargs)))
1041         self._base_url = kwargs.get('base_url')
1042         self._timeout = kwargs.get('timeout')
1043
1044     def exec_create(self, **kwargs):
1045         """monkey exec_create"""
1046
1047         return {"Id": "fake_container_ID"}
1048
1049     def exec_start(self, **kwargs):
1050         """monkey exec_create"""
1051
1052         return "component reconfigured successfully"
1053
1054     def login(self, **kwargs):
1055         """monkey login"""
1056
1057         pass
1058
1059 @pytest.fixture()
1060 def fix_external_interfaces(monkeypatch):
1061     """monkey consul_client request.get"""
1062
1063     Settings.logger.info("setup fix_external_interfaces")
1064     monkeypatch.setattr('otihandler.consul_client.requests.get', monkey_consul_client_get)
1065     monkeypatch.setattr('otihandler.consul_client.requests.put', monkey_consul_client_put)
1066
1067     monkeypatch.setattr('otihandler.cfy_client.CloudifyClient', MonkeyCloudifyClient)
1068
1069     monkeypatch.setattr('otihandler.docker_client.docker.APIClient', MonkeyDockerClient)
1070
1071     monkeypatch.setattr('otihandler.dti_processor.EventDbAccess', MonkeyEventDbAccess)
1072
1073     yield fix_external_interfaces  # provide the fixture value
1074     Settings.logger.info("teardown fix_external_interfaces")
1075
1076
1077 def monkey_cherrypy_engine_exit():
1078     """monkeypatch for cherrypy exit"""
1079
1080     Settings.logger.info("monkey_cherrypy_engine_exit()")
1081
1082 @pytest.fixture()
1083 def fix_cherrypy_engine_exit(monkeypatch):
1084     """monkey cherrypy.engine.exit()"""
1085
1086     Settings.logger.info("setup fix_cherrypy_engine_exit")
1087     monkeypatch.setattr('otihandler.web_server.cherrypy.engine.exit',
1088                         monkey_cherrypy_engine_exit)
1089     yield fix_cherrypy_engine_exit  # provide the fixture value
1090     Settings.logger.info("teardown fix_cherrypy_engine_exit")
1091
1092
1093 #----- Tests ----------------------------------------------------------------------------
1094
1095 def test_healthcheck():
1096     """test /healthcheck"""
1097
1098     Settings.logger.info("=====> test_healthcheck")
1099     audit = Audit(req_message="get /healthcheck")
1100     audit.metrics_start("test /healthcheck")
1101     time.sleep(0.1)
1102
1103     audit.metrics("test /healthcheck")
1104     health = Audit.health() or {}
1105     audit.audit_done(result=json.dumps(health))
1106
1107     Settings.logger.info("healthcheck: %s", json.dumps(health))
1108     assert bool(health)
1109
1110 def test_healthcheck_with_error():
1111     """test /healthcheck"""
1112
1113     Settings.logger.info("=====> test_healthcheck_with_error")
1114     audit = Audit(req_message="get /healthcheck")
1115     audit.metrics_start("test /healthcheck")
1116     time.sleep(0.2)
1117     audit.error("error from test_healthcheck_with_error")
1118     audit.fatal("fatal from test_healthcheck_with_error")
1119     audit.debug("debug from test_healthcheck_with_error")
1120     audit.warn("warn from test_healthcheck_with_error")
1121     audit.info_requested("info_requested from test_healthcheck_with_error")
1122     if audit.is_success():
1123         audit.set_http_status_code(AuditHttpCode.DATA_NOT_FOUND_ERROR.value)
1124     audit.set_http_status_code(AuditHttpCode.SERVER_INTERNAL_ERROR.value)
1125     audit.metrics("test /healthcheck")
1126
1127     health = Audit.health() or {}
1128     audit.audit_done(result=json.dumps(health))
1129
1130     Settings.logger.info("healthcheck: %s", json.dumps(health))
1131     assert bool(health)
1132
1133 def test_consul_client_lookup_service_bogus():
1134     """test consul_client.lookup_service with bogus service_name"""
1135
1136     Settings.logger.info("=====> test_consul_client_lookup_service_bogus")
1137     with pytest.raises(ConsulClientConnectionError, match=r'lookup_service(.*) requests.get(.*)'):
1138         ConsulClient.lookup_service("bogus")
1139
1140 def test_consul_client_get_service_fqdn_port_none():
1141     """test consul_client.get_service_fqdn_port with no service_name"""
1142
1143     Settings.logger.info("=====> test_consul_client_get_service_fqdn_port_none")
1144     with pytest.raises(ConsulClientConnectionError):
1145         rv = ConsulClient.get_service_fqdn_port(None)
1146         assert (rv == None)
1147
1148 def test_consul_client_store_kvs_none():
1149     """test consul_client.store_kvs with no key"""
1150
1151     Settings.logger.info("=====> test_consul_client_store_kvs_none")
1152     rv = ConsulClient.store_kvs(None)
1153     assert (rv == None)
1154
1155 def test_consul_client_delete_key_none():
1156     """test consul_client.delete_key with no key"""
1157
1158     Settings.logger.info("=====> test_consul_client_delete_key_none")
1159     rv = ConsulClient.delete_key(None)
1160     assert (rv == None)
1161
1162 def test_consul_client_delete_kvs_none():
1163     """test consul_client.delete_kvs with no key"""
1164
1165     Settings.logger.info("=====> test_consul_client_delete_kvs_none")
1166     rv = ConsulClient.delete_kvs(None)
1167     assert (rv == None)
1168
1169 def test_consul_client_delete_kvs_bogus():
1170     """test consul_client.delete_kvs with bogus key"""
1171
1172     Settings.logger.info("=====> test_consul_client_delete_kvs_bogus")
1173     rv = ConsulClient.delete_kvs("bogus")
1174     assert (rv == None)
1175
1176 def test_consul_client_get_value_none():
1177     """test consul_client.get_value with no key"""
1178
1179     Settings.logger.info("=====> test_consul_client_get_value_none")
1180     with pytest.raises(ConsulClientConnectionError, match=r'get_value(.*) requests.get(.*)'):
1181         ConsulClient.get_value(None)
1182
1183 def test_consul_client_get_kvs_none():
1184     """test consul_client.get_kvs with no prefix"""
1185
1186     Settings.logger.info("=====> test_consul_client_get_kvs_none")
1187     with pytest.raises(ConsulClientConnectionError, match=r'get_kvs(.*) requests.get(.*)'):
1188         ConsulClient.get_kvs(None)
1189
1190 def test_consul_client_run_transaction_invalid():
1191     """test consul_client._run_transaction with invalid operation"""
1192
1193     Settings.logger.info("=====> test_consul_client_run_transaction_invalid")
1194     rv = ConsulClient._run_transaction("invalid", {"bogus": "bad"})
1195     assert (rv == None)
1196
1197 class TestsBase(helper.CPWebCase):
1198
1199     helper.CPWebCase.interactive = False
1200
1201 @pytest.mark.usefixtures("fix_external_interfaces")
1202 class WebServerTest(TestsBase):
1203     """testing the web-server - runs tests in alphabetical order of method names"""
1204
1205     def setup_server():
1206         """setup the web-server"""
1207
1208         cherrypy.tree.mount(_DTIWeb(), '/')
1209
1210     setup_server = staticmethod(setup_server)
1211
1212     def test_web_healthcheck(self):
1213         """test /healthcheck"""
1214
1215         Settings.logger.info("=====> test_web_healthcheck")
1216         result = self.getPage("/healthcheck")
1217         Settings.logger.info("got healthcheck: %s", self.body)
1218         self.assertStatus('200 OK')
1219
1220     def test_web_events_get(self):
1221         """test GET /events -- wrong method"""
1222
1223         Settings.logger.info("=====> test_web_events_get")
1224         result = self.getPage("/events")
1225         self.assertStatus(404)
1226
1227     def test_web_events_missing_dcae_service_action(self):
1228         """test POST /events < <dti_event>"""
1229
1230         Settings.logger.info("=====> test_web_events_missing_dcae_service_action")
1231         body = json.dumps({})
1232         expected_result = {"ERROR": "dcae_service_action is missing"}
1233         result = self.getPage("/events", method='POST', body=body,
1234                               headers=[
1235                                   ("Content-Type", "application/json"),
1236                                   ('Content-Length', str(len(body)))
1237                               ])
1238         self.assertStatus('400 Bad Request')
1239         assert ( json.loads(self.body) == expected_result )
1240
1241     def test_web_events_invalid_dcae_service_action(self):
1242         """test POST /events < <dti_event>"""
1243
1244         Settings.logger.info("=====> test_web_events_invalid_dcae_service_action")
1245         body = json.dumps({"dcae_service_action": "bogus"})
1246         expected_result = {"ERROR": "dcae_service_action is invalid"}
1247         result = self.getPage("/events", method='POST', body=body,
1248                               headers=[
1249                                   ("Content-Type", "application/json"),
1250                                   ('Content-Length', str(len(body)))
1251                               ])
1252         self.assertStatus('400 Bad Request')
1253         assert ( json.loads(self.body) == expected_result )
1254
1255     def test_web_events_missing_dcae_target_name(self):
1256         """test POST /events < <dti_event>"""
1257
1258         Settings.logger.info("=====> test_web_events_missing_dcae_target_name")
1259         body = json.dumps({"dcae_service_action": "deploy"})
1260         expected_result = {"ERROR": "dcae_target_name is missing"}
1261         result = self.getPage("/events", method='POST', body=body,
1262                               headers=[
1263                                   ("Content-Type", "application/json"),
1264                                   ('Content-Length', str(len(body)))
1265                               ])
1266         self.assertStatus('400 Bad Request')
1267         assert ( json.loads(self.body) == expected_result )
1268
1269     def test_web_events_missing_dcae_target_type(self):
1270         """test POST /events < <dti_event>"""
1271
1272         Settings.logger.info("=====> test_web_events_missing_dcae_target_type")
1273         body = json.dumps({"dcae_service_action": "deploy",
1274                            "dcae_target_name": "another01ems003"
1275                          })
1276         expected_result = {"ERROR": "dcae_target_type is missing"}
1277         result = self.getPage("/events", method='POST', body=body,
1278                               headers=[
1279                                   ("Content-Type", "application/json"),
1280                                   ('Content-Length', str(len(body)))
1281                               ])
1282         self.assertStatus('400 Bad Request')
1283         assert ( json.loads(self.body) == expected_result )
1284
1285     def test_web_events_deploy(self):
1286         """test POST /events < <dti_event>"""
1287
1288         Settings.logger.info("=====> test_web_events_deploy")
1289         body = json.dumps({"dcae_service_action": "deploy",
1290                            "dcae_target_name": "another01ems003",
1291                            "dcae_target_type": "ANOT-her"
1292                          })
1293         expected_result = {
1294             "SCN_1": "ran dti_reconfig_script_1 in docker container container_1 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_1 node node_id_1, got: component reconfigured successfully",
1295             "SCN_2": "ran dti_reconfig_script_2 in docker container container_2 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_2 node node_id_2, got: component reconfigured successfully"
1296         }
1297         expected_result = {
1298         }
1299         result = self.getPage("/events", method='POST', body=body,
1300                               headers=[
1301                                   ("Content-Type", "application/json"),
1302                                   ('Content-Length', str(len(body)))
1303                               ])
1304         self.assertStatus('200 OK')
1305         assert ( json.loads(self.body) == expected_result )
1306
1307     def test_web_events_undeploy(self):
1308         """test POST /events < <dti_event>"""
1309
1310         Settings.logger.info("=====> test_web_events_undeploy")
1311         body = json.dumps({"dcae_service_action": "undeploy",
1312                            "dcae_target_name": "another01ems003",
1313                            "dcae_target_type": "ANOT-her"
1314                          })
1315         expected_result = {
1316         }
1317         result = self.getPage("/events", method='POST', body=body,
1318                               headers=[
1319                                   ("Content-Type", "application/json"),
1320                                   ('Content-Length', str(len(body)))
1321                               ])
1322         self.assertStatus('200 OK')
1323         assert ( json.loads(self.body) == expected_result )
1324
1325     def test_web_events_add(self):
1326         """test POST /events < <dti_event>"""
1327
1328         Settings.logger.info("=====> test_web_events_add")
1329         body = json.dumps({"dcae_service_action": "add",
1330                            "dcae_target_name": "another01ems003",
1331                            "dcae_target_type": "ANOT-her"
1332                          })
1333         expected_result = {
1334             "SCN_1": "ran dti_reconfig_script_1 in docker container container_1 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_1 node node_id_1, got: component reconfigured successfully",
1335             "SCN_2": "ran dti_reconfig_script_2 in docker container container_2 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_2 node node_id_2, got: component reconfigured successfully"
1336         }
1337         result = self.getPage("/events", method='POST', body=body,
1338                               headers=[
1339                                   ("Content-Type", "application/json"),
1340                                   ('Content-Length', str(len(body)))
1341                               ])
1342         self.assertStatus('200 OK')
1343         assert ( json.loads(self.body) == expected_result )
1344
1345     def test_web_events_delete(self):
1346         """test POST /events < <dti_event>"""
1347
1348         Settings.logger.info("=====> test_web_events_delete")
1349         body = json.dumps({"dcae_service_action": "delete",
1350                            "dcae_target_name": "another01ems003",
1351                            "dcae_target_type": "ANOT-her"
1352                          })
1353         expected_result = {
1354             "SCN_1": "ran dti_reconfig_script_1 in docker container container_1 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_1 node node_id_1, got: component reconfigured successfully",
1355             "SCN_2": "ran dti_reconfig_script_2 in docker container container_2 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_2 node node_id_2, got: component reconfigured successfully"
1356         }
1357         result = self.getPage("/events", method='POST', body=body,
1358                               headers=[
1359                                   ("Content-Type", "application/json"),
1360                                   ('Content-Length', str(len(body)))
1361                               ])
1362         self.assertStatus('200 OK')
1363         assert ( json.loads(self.body) == expected_result )
1364
1365     def test_web_events_update(self):
1366         """test POST /events < <dti_event>"""
1367
1368         Settings.logger.info("=====> test_web_events_update")
1369         body = json.dumps({"dcae_service_action": "update",
1370                            "dcae_target_name": "another01ems003",
1371                            "dcae_target_type": "ANOT-her"
1372                          })
1373         expected_result = {
1374             "SCN_1": "ran dti_reconfig_script_1 in docker container container_1 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_1 node node_id_1, got: component reconfigured successfully",
1375             "SCN_2": "ran dti_reconfig_script_2 in docker container container_2 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_2 node node_id_2, got: component reconfigured successfully",
1376            "WARNING": "processing update event for anot-her/another01ems003, but current event info is not found in database, executing add event"
1377         }
1378         result = self.getPage("/events", method='POST', body=body,
1379                               headers=[
1380                                   ("Content-Type", "application/json"),
1381                                   ('Content-Length', str(len(body)))
1382                               ])
1383         self.assertStatus('200 OK')
1384         assert ( json.loads(self.body) == expected_result )
1385
1386     def test_web_events_notify(self):
1387         """test POST /events < <dti_event>"""
1388
1389         Settings.logger.info("=====> test_web_events_notify")
1390         body = json.dumps({"dcae_service_action": "notify",
1391                            "dcae_target_name": "another01ems003",
1392                            "dcae_target_type": "ANOT-her"
1393                          })
1394         expected_result = {
1395         }
1396         result = self.getPage("/events", method='POST', body=body,
1397                               headers=[
1398                                   ("Content-Type", "application/json"),
1399                                   ('Content-Length', str(len(body)))
1400                               ])
1401         self.assertStatus('200 OK')
1402         assert ( json.loads(self.body) == expected_result )
1403
1404     def test_web_events_location(self):
1405         """test POST /events < <dti_event>"""
1406
1407         Settings.logger.info("=====> test_web_events_location")
1408         body = json.dumps({"dcae_service_action": "deploy",
1409                            "dcae_target_name": "another01ems003",
1410                            "dcae_target_type": "ANOT-her",
1411                            "dcae_service_location": "LSLEILAA"
1412                          })
1413         expected_result = {
1414             "SCN_1": "ran dti_reconfig_script_1 in docker container container_1 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_1 node node_id_1, got: component reconfigured successfully",
1415             "SCN_2": "ran dti_reconfig_script_2 in docker container container_2 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_2 node node_id_2, got: component reconfigured successfully"
1416         }
1417         expected_result = {
1418         }
1419         result = self.getPage("/events", method='POST', body=body,
1420                               headers=[
1421                                   ("Content-Type", "application/json"),
1422                                   ('Content-Length', str(len(body)))
1423                               ])
1424         self.assertStatus('200 OK')
1425         Settings.logger.info("got result: %s", self.body)
1426         assert ( json.loads(self.body) == expected_result )
1427
1428     def test_web_events_undeploy_bad(self):
1429         """test POST /events < <dti_event> -- bad dcae_target_name"""
1430
1431         Settings.logger.info("=====> test_web_events_undeploy_bad")
1432         body = json.dumps({"dcae_service_action": "undeploy",
1433                            "dcae_target_name": "bogus",
1434                            "dcae_target_type": "ANOT-her"
1435                          })
1436         expected_result = {
1437             "SCN_1": "ran dti_reconfig_script_1 in docker container container_1 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_1 node node_id_1, got: component reconfigured successfully",
1438             "SCN_2": "ran dti_reconfig_script_2 in docker container container_2 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_2 node node_id_2, got: component reconfigured successfully",
1439             "WARNING": "VNF instance bogus was not in Consul oti_events historical folder"
1440         }
1441         expected_result = {
1442         }
1443         result = self.getPage("/events", method='POST', body=body,
1444                               headers=[
1445                                   ("Content-Type", "application/json"),
1446                                   ('Content-Length', str(len(body)))
1447                               ])
1448         self.assertStatus('200 OK')
1449         Settings.logger.info("got result: %s", self.body)
1450         assert ( json.loads(self.body) == expected_result )
1451
1452     def test_web_events_undeploy(self):
1453         """test POST /events < <dti_event>"""
1454
1455         Settings.logger.info("=====> test_web_events_undeploy")
1456         body = json.dumps({"dcae_service_action": "undeploy",
1457                            "dcae_target_name": "another01ems003",
1458                            "dcae_target_type": "ANOT-her"
1459                          })
1460         expected_result = {
1461             "SCN_1": "ran dti_reconfig_script_1 in docker container container_1 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_1 node node_id_1, got: component reconfigured successfully",
1462             "SCN_2": "ran dti_reconfig_script_2 in docker container container_2 on zldcdyh1adcc1-component-dockerhost-1 that was deployed by deployment_id_2 node node_id_2, got: component reconfigured successfully"
1463         }
1464         expected_result = {
1465         }
1466         result = self.getPage("/events", method='POST', body=body,
1467                               headers=[
1468                                   ("Content-Type", "application/json"),
1469                                   ('Content-Length', str(len(body)))
1470                               ])
1471         self.assertStatus('200 OK')
1472         Settings.logger.info("got result: %s", self.body)
1473         assert ( json.loads(self.body) == expected_result )
1474
1475     def test_web_mockevents(self):
1476         """test GET /mockevents"""
1477
1478         Settings.logger.info("=====> test_web_mockevents")
1479         expected_result = {"KubeNamespace":"com-my-dcae-test", "KubePod":"pod-0", "KubeServiceName":"pod-0.service.local", "KubeServicePort":"8880", "KubeClusterFqdn":"fqdn-1"}
1480         result = self.getPage("/mockevents")
1481         self.assertStatus('200 OK')
1482         Settings.logger.info("got result: %s", self.body)
1483         assert ( json.loads(self.body) == expected_result )
1484
1485     def test_web_dti_docker_events_put(self):
1486         """test PUT /dti_docker_events?service=SCN_1"""
1487
1488         Settings.logger.info("=====> test_web_dti_docker_events_put")
1489         result = self.getPage("/dti_docker_events?service=SCN_1", method='PUT')
1490         self.assertStatus(404)
1491
1492     def test_web_dti_docker_events_bad_service(self):
1493         """test GET /dti_docker_events?service=bogus"""
1494
1495         Settings.logger.info("=====> test_web_dti_docker_events_bad_service")
1496         expected_result = {}
1497         result = self.getPage("/dti_docker_events?service=bogus")
1498         self.assertStatus('200 OK')
1499         Settings.logger.info("got result: %s", self.body)
1500         assert ( json.loads(self.body) == expected_result )
1501
1502     def test_web_dti_docker_events(self):
1503         """test GET /dti_docker_events?service=SCN_1"""
1504
1505         Settings.logger.info("=====> test_web_dti_docker_events")
1506         expected_result = {}
1507         result = self.getPage("/dti_docker_events?service=SCN_1")
1508         self.assertStatus('200 OK')
1509         Settings.logger.info("got result: %s", self.body)
1510         assert ( json.loads(self.body) == expected_result )
1511
1512     def test_web_dti_docker_events_bad_location(self):
1513         """test GET /dti_docker_events?service=SCN_1&location=bogus"""
1514
1515         Settings.logger.info("=====> test_web_dti_docker_events_bad_location")
1516         expected_result = {}
1517         result = self.getPage("/dti_docker_events?service=SCN_1&location=bogus")
1518         self.assertStatus('200 OK')
1519         Settings.logger.info("got result: %s", self.body)
1520         assert ( json.loads(self.body) == expected_result )
1521
1522     def test_web_dti_docker_events_location(self):
1523         """test GET /dti_docker_events?service=SCN_1&location=LSLEILAA"""
1524
1525         Settings.logger.info("=====> test_web_dti_docker_events_location")
1526         expected_result = {}
1527         result = self.getPage("/dti_docker_events?service=SCN_1&location=LSLEILAA")
1528         self.assertStatus('200 OK')
1529         Settings.logger.info("got result: %s", self.body)
1530         assert ( json.loads(self.body) == expected_result )
1531
1532     def test_web_dti_docker_events_locations(self):
1533         """test GET /dti_docker_events?service=SCN_1&location=LSLEILAA,MDTWNJC1"""
1534
1535         Settings.logger.info("=====> test_web_dti_docker_events_locations")
1536         expected_result = {}
1537         result = self.getPage("/dti_docker_events?service=SCN_1&location=LSLEILAA,MDTWNJC1")
1538         self.assertStatus('200 OK')
1539         Settings.logger.info("got result: %s", self.body)
1540         assert ( json.loads(self.body) == expected_result )
1541
1542     def test_web_dti_docker_events_bad_locations(self):
1543         """test GET /dti_docker_events?service=SCN_1&location=LSLEILAA,bogus,MDTWNJC1"""
1544
1545         Settings.logger.info("=====> test_web_dti_docker_events_bad_locations")
1546         expected_result = {}
1547         result = self.getPage("/dti_docker_events?service=SCN_1&location=LSLEILAA,bogus,MDTWNJC1")
1548         self.assertStatus('200 OK')
1549         Settings.logger.info("got result: %s", self.body)
1550         assert ( json.loads(self.body) == expected_result )
1551
1552     def test_web_oti_docker_events_put(self):
1553         """test PUT /oti_docker_events?service=SCN_1"""
1554
1555         Settings.logger.info("=====> test_web_oti_docker_events_put")
1556         result = self.getPage("/oti_docker_events?service=SCN_1", method='PUT')
1557         self.assertStatus(404)
1558
1559     def test_web_oti_docker_events_bad_service(self):
1560         """test GET /oti_docker_events?service=bogus"""
1561
1562         Settings.logger.info("=====> test_web_oti_docker_events_bad_service")
1563         expected_result = {}
1564         result = self.getPage("/oti_docker_events?service=bogus")
1565         self.assertStatus('200 OK')
1566         Settings.logger.info("got result: %s", self.body)
1567         assert ( json.loads(self.body) == expected_result )
1568
1569     def test_web_oti_docker_events(self):
1570         """test GET /oti_docker_events?service=SCN_1"""
1571
1572         Settings.logger.info("=====> test_web_oti_docker_events")
1573         expected_result = {}
1574         result = self.getPage("/oti_docker_events?service=SCN_1")
1575         self.assertStatus('200 OK')
1576         Settings.logger.info("got result: %s", self.body)
1577         assert ( json.loads(self.body) == expected_result )
1578
1579     def test_web_oti_docker_events_bad_location(self):
1580         """test GET /oti_docker_events?service=SCN_1&location=bogus"""
1581
1582         Settings.logger.info("=====> test_web_oti_docker_events_bad_location")
1583         expected_result = {}
1584         result = self.getPage("/oti_docker_events?service=SCN_1&location=bogus")
1585         self.assertStatus('200 OK')
1586         Settings.logger.info("got result: %s", self.body)
1587         assert ( json.loads(self.body) == expected_result )
1588
1589     def test_web_oti_docker_events_location(self):
1590         """test GET /oti_docker_events?service=SCN_1&location=LSLEILAA"""
1591
1592         Settings.logger.info("=====> test_web_oti_docker_events_location")
1593         expected_result = {}
1594         result = self.getPage("/oti_docker_events?service=SCN_1&location=LSLEILAA")
1595         self.assertStatus('200 OK')
1596         Settings.logger.info("got result: %s", self.body)
1597         assert ( json.loads(self.body) == expected_result )
1598
1599     def test_web_oti_docker_events_locations(self):
1600         """test GET /oti_docker_events?service=SCN_1&location=LSLEILAA,MDTWNJC1"""
1601
1602         Settings.logger.info("=====> test_web_oti_docker_events_locations")
1603         expected_result = {}
1604         result = self.getPage("/oti_docker_events?service=SCN_1&location=LSLEILAA,MDTWNJC1")
1605         self.assertStatus('200 OK')
1606         Settings.logger.info("got result: %s", self.body)
1607         assert ( json.loads(self.body) == expected_result )
1608
1609     def test_web_oti_docker_events_bad_locations(self):
1610         """test GET /oti_docker_events?service=SCN_1&location=LSLEILAA,bogus,MDTWNJC1"""
1611
1612         Settings.logger.info("=====> test_web_oti_docker_events_bad_locations")
1613         expected_result = {}
1614         result = self.getPage("/oti_docker_events?service=SCN_1&location=LSLEILAA,bogus,MDTWNJC1")
1615         self.assertStatus('200 OK')
1616         Settings.logger.info("got result: %s", self.body)
1617         assert ( json.loads(self.body) == expected_result )
1618
1619     def test_web_reconfig_put(self):
1620         """test PUT /reconfig -- wrong method"""
1621
1622         Settings.logger.info("=====> test_web_reconfig_put")
1623         result = self.getPage("/reconfig/deployment_id_1", method='PUT')
1624         self.assertStatus(404)
1625
1626     def test_web_dti_put(self):
1627         """test PUT /dti -- wrong method"""
1628
1629         Settings.logger.info("=====> test_web_dti_put")
1630         result = self.getPage("/dti", method='PUT')
1631         self.assertStatus(404)
1632
1633     def test_web_dti(self):
1634         """test GET /dti"""
1635
1636         Settings.logger.info("=====> test_web_dti")
1637         result = self.getPage("/dti")
1638         Settings.logger.info("got dti: %s", self.body)
1639         self.assertStatus('200 OK')
1640
1641         expected_result = {
1642             "anot-her": {
1643                 "another01ems003": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems003", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.3", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems003_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.3", "remoteServerName": "another01ems003", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}},
1644                 "another01ems042": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems042", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.42", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems042_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems042", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}},
1645                 "another01ems044": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems044", "dcae_service_location": "MDTWNJC1", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.42", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems044_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems044", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}}
1646             }
1647         }
1648         assert ( json.loads(self.body) == expected_result )
1649
1650     def test_web_dti_SCN_bogus(self):
1651         """test GET /dti/<service_name> -- bogus SCN"""
1652
1653         Settings.logger.info("=====> test_web_dti_SCN_bogus")
1654         result = self.getPage("/dti/SCN_bogus")
1655         self.assertStatus(404)
1656
1657     def test_web_dti_SCN(self):
1658         """test GET /dti/<service_name>"""
1659
1660         Settings.logger.info("=====> test_web_dti_SCN")
1661         result = self.getPage("/dti/SCN_1")
1662         Settings.logger.info("got dti: %s", self.body)
1663         self.assertStatus('200 OK')
1664
1665         expected_result = {
1666             "anot-her": {
1667                 "another01ems003": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems003", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.3", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems003_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.3", "remoteServerName": "another01ems003", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}},
1668                 "another01ems042": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems042", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.42", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems042_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems042", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}},
1669                 "another01ems044": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems044", "dcae_service_location": "MDTWNJC1", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.42", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems044_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems044", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}}
1670             }
1671         }
1672         assert ( json.loads(self.body) == expected_result )
1673
1674     def test_web_dti_SCN_type(self):
1675         """test GET /dti/<service_name>?vnf_type=<vnf_type>"""
1676
1677         Settings.logger.info("=====> test_web_dti_SCN_type")
1678         result = self.getPage("/dti/SCN_1?vnf_type=ANOT-her")
1679         Settings.logger.info("got dti: %s", self.body)
1680         self.assertStatus('200 OK')
1681
1682         expected_result = {
1683             "another01ems003": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems003", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.3", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems003_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.3", "remoteServerName": "another01ems003", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}},
1684             "another01ems042": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems042", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.42", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems042_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems042", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}},
1685             "another01ems044": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems044", "dcae_service_location": "MDTWNJC1", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.42", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems044_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems044", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}}
1686         }
1687         assert ( json.loads(self.body) == expected_result )
1688
1689     def test_web_dti_types(self):
1690         """test GET /dti?vnf_type=<vnf_types>"""
1691
1692         Settings.logger.info("=====> test_web_dti_types")
1693         result = self.getPage("/dti?vnf_type=ANOT-her,new-type")
1694         Settings.logger.info("got dti: %s", self.body)
1695         self.assertStatus('200 OK')
1696
1697         expected_result = {
1698             "anot-her": {
1699                 "another01ems003": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems003", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.3", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems003_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.3", "remoteServerName": "another01ems003", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}},
1700                 "another01ems042": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems042", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.42", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems042_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems042", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}},
1701                 "another01ems044": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems044", "dcae_service_location": "MDTWNJC1", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.42", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems044_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems044", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}}
1702             }
1703         }
1704         assert ( json.loads(self.body) == expected_result )
1705
1706     def test_web_dti_SCN_type_miss(self):
1707         """test GET /dti/<service_name>?vnf_type=<vnf_type>"""
1708
1709         Settings.logger.info("=====> test_web_dti_SCN_type_miss")
1710         result = self.getPage("/dti/SCN_1?vnf_type=NO-match")
1711         Settings.logger.info("got dti: %s", self.body)
1712         self.assertStatus('200 OK')
1713
1714         expected_result = {}
1715         assert ( json.loads(self.body) == expected_result )
1716
1717     def test_web_dti_SCN_type_vnf_id(self):
1718         """test GET /dti/<service_name>?vnf_type=<vnf_type>;vnf_id=<vnf_id>"""
1719
1720         Settings.logger.info("=====> test_web_dti_SCN_type_vnf_id")
1721         result = self.getPage("/dti/SCN_1?vnf_type=ANOT-her;vnf_id=another01ems003")
1722         Settings.logger.info("got dti: %s", self.body)
1723         self.assertStatus('200 OK')
1724
1725         expected_result = {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems003", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.3", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems003_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.3", "remoteServerName": "another01ems003", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}}
1726         assert ( json.loads(self.body) == expected_result )
1727
1728     def test_web_dti_SCN_type_vnf_id_location(self):
1729         """test GET /dti/<service_name>?vnf_type=<vnf_type>;vnf_id=<vnf_id>;service_location=<service_location>"""
1730
1731         Settings.logger.info("=====> test_web_dti_SCN_type_vnf_id_location")
1732         result = self.getPage("/dti/SCN_1?vnf_type=ANOT-her;vnf_id=another01ems003;service_location=LSLEILAA")
1733         Settings.logger.info("got dti: %s", self.body)
1734         self.assertStatus('200 OK')
1735
1736         expected_result = {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems003", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.3", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems003_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.3", "remoteServerName": "another01ems003", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}}
1737         assert ( json.loads(self.body) == expected_result )
1738
1739     def test_web_dti_SCN_types_location(self):
1740         """test GET /dti/<service_name>?vnf_type=<vnf_types>;service_location=<service_location>"""
1741
1742         Settings.logger.info("=====> test_web_dti_SCN_types_location")
1743         result = self.getPage("/dti/SCN_1?vnf_type=ANOT-her,new-type;service_location=MDTWNJC1")
1744         Settings.logger.info("got dti: %s", self.body)
1745         self.assertStatus('200 OK')
1746
1747         expected_result = {
1748             "anot-her": {
1749                 "another01ems044": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems044", "dcae_service_location": "MDTWNJC1", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.42", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems044_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems044", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}}
1750             }
1751         }
1752         assert ( json.loads(self.body) == expected_result )
1753
1754     def test_web_dti_location(self):
1755         """test GET /dti?service_location=<service_location>"""
1756
1757         Settings.logger.info("=====> test_web_dti_location")
1758         result = self.getPage("/dti?service_location=LSLEILAA")
1759         Settings.logger.info("got dti: %s", self.body)
1760         self.assertStatus('200 OK')
1761
1762         expected_result = {
1763             "anot-her": {
1764                 "another01ems003": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems003", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.3", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems003_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.3", "remoteServerName": "another01ems003", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}},
1765                 "another01ems042": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems042", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.42", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems042_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems042", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}}
1766             }
1767         }
1768         assert ( json.loads(self.body) == expected_result )
1769
1770     def test_web_dti_type_location(self):
1771         """test GET /dti?vnf_type=<vnf_type>;service_location=<service_location>"""
1772
1773         Settings.logger.info("=====> test_web_dti_type_location")
1774         result = self.getPage("/dti?vnf_type=ANOT-her;service_location=LSLEILAA")
1775         Settings.logger.info("got dti: %s", self.body)
1776         self.assertStatus('200 OK')
1777
1778         expected_result = {
1779             "another01ems003": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems003", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.3", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems003_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.3", "remoteServerName": "another01ems003", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}},
1780             "another01ems042": {"dcae_service_action": "deploy", "dcae_service-instance_model-version-id": "1", "dcae_target_name": "another01ems042", "dcae_service_location": "LSLEILAA", "dcae_target_type": "ANOT-her", "dcae_target_collection": "true", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_in-maint": "false", "dcae_snmp_community_string": "my_first_community", "dcae_generic-vnf_model-version-id": "1", "dcae_target_collection_ip": "107.239.85.42", "dcae_snmp_version": "2c", "aai_additional_info": {"TasksItems": {"another01ems042_2PMOBATTHSSEMS0165": {"nodeType": "VHSS", "description": "VHSS Data Collection", "protocol": "sftp", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "priority": 1, "nodeSubtype": "", "collectionInterval": "300", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "remoteServerName": "another01ems042", "isPrimary": "true"}], "serverGroupId": "g1"}}}}}, "dcae_target_prov-status": "PROV", "event": {}}
1781         }
1782         assert ( json.loads(self.body) == expected_result )
1783
1784     def test_web_service_component_put(self):
1785         """test PUT /service_component -- wrong method"""
1786
1787         Settings.logger.info("=====> test_web_service_component_put")
1788         result = self.getPage("/service_component/SCN_1", method='PUT')
1789         self.assertStatus(404)
1790
1791     def test_web_service_component_bogus(self):
1792         """test GET /service_component/<service_name> -- bogus SCN"""
1793
1794         Settings.logger.info("=====> test_web_service_component_bogus")
1795         result = self.getPage("/service_component/SCN_bogus")
1796         self.assertStatus(404)
1797
1798     def test_web_service_component(self):
1799         """test GET /service_component/<service_name>"""
1800
1801         Settings.logger.info("=====> test_web_service_component")
1802         result = self.getPage("/service_component/SCN_1")
1803         Settings.logger.info("got service_component: %s", self.body)
1804         self.assertStatus('200 OK')
1805
1806         expected_result = {"dcae_target_type": ["pnga-xxx"]}
1807         assert ( json.loads(self.body) == expected_result )
1808
1809     def test_web_service_component_all_put(self):
1810         """test PUT /service_component_all -- wrong method"""
1811
1812         Settings.logger.info("=====> test_web_service_component_all_put")
1813         result = self.getPage("/service_component_all/SCN_1", method='PUT')
1814         self.assertStatus(404)
1815
1816     def test_web_service_component_all_bogus(self):
1817         """test GET /service_component_all/<service_name> -- bogus SCN"""
1818
1819         Settings.logger.info("=====> test_web_service_component_all_bogus")
1820         result = self.getPage("/service_component_all/SCN_bogus")
1821         self.assertStatus(404)
1822
1823     def test_web_service_component_all(self):
1824         """test GET /service_component_all/<service_name>"""
1825
1826         Settings.logger.info("=====> test_web_service_component_all")
1827         result = self.getPage("/service_component_all/SCN_1")
1828         Settings.logger.info("got service_component_all: %s", self.body)
1829         self.assertStatus('200 OK')
1830
1831         expected_result = {"oti": {"anot-her": {"another01ems003": {"dcae_target_name": "another01ems003", "dcae_target_collection_ip": "107.239.85.3", "event": {}, "dcae_service-instance_model-version-id": "1", "dcae_service_location": "LSLEILAA", "dcae_target_in-maint": "false", "dcae_service_action": "deploy", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_collection": "true", "aai_additional_info": {"TasksItems": {"another01ems003_2PMOBATTHSSEMS0165": {"collectionInterval": "300", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.3", "isPrimary": "true", "remoteServerName": "another01ems003"}], "serverGroupId": "g1"}}, "nodeType": "VHSS", "protocol": "sftp", "nodeSubtype": "", "priority": 1, "description": "VHSS Data Collection"}}}, "dcae_generic-vnf_model-version-id": "1", "dcae_target_prov-status": "PROV", "dcae_target_type": "ANOT-her", "dcae_snmp_community_string": "my_first_community", "dcae_snmp_version": "2c"}, "another01ems042": {"dcae_target_name": "another01ems042", "dcae_target_collection_ip": "107.239.85.42", "event": {}, "dcae_service-instance_model-version-id": "1", "dcae_service_location": "LSLEILAA", "dcae_target_in-maint": "false", "dcae_service_action": "deploy", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_collection": "true", "aai_additional_info": {"TasksItems": {"another01ems042_2PMOBATTHSSEMS0165": {"collectionInterval": "300", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "isPrimary": "true", "remoteServerName": "another01ems042"}], "serverGroupId": "g1"}}, "nodeType": "VHSS", "protocol": "sftp", "nodeSubtype": "", "priority": 1, "description": "VHSS Data Collection"}}}, "dcae_generic-vnf_model-version-id": "1", "dcae_target_prov-status": "PROV", "dcae_target_type": "ANOT-her", "dcae_snmp_community_string": "my_first_community", "dcae_snmp_version": "2c"}, "another01ems044": {"dcae_target_name": "another01ems044", "dcae_target_collection_ip": "107.239.85.42", "event": {}, "dcae_service-instance_model-version-id": "1", "dcae_service_location": "MDTWNJC1", "dcae_target_in-maint": "false", "dcae_service_action": "deploy", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_collection": "true", "aai_additional_info": {"TasksItems": {"another01ems044_2PMOBATTHSSEMS0165": {"collectionInterval": "300", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "isPrimary": "true", "remoteServerName": "another01ems044"}], "serverGroupId": "g1"}}, "nodeType": "VHSS", "protocol": "sftp", "nodeSubtype": "", "priority": 1, "description": "VHSS Data Collection"}}}, "dcae_generic-vnf_model-version-id": "1", "dcae_target_prov-status": "PROV", "dcae_target_type": "ANOT-her", "dcae_snmp_community_string": "my_first_community", "dcae_snmp_version": "2c"}}}, "policies": {"event": {"update_id": "e6102aab-3079-435a-ae0d-0397a2cb3c4d", "action": "updated", "timestamp": "2018-07-16T15:11:44.845Z", "policies_count": 3}, "items": {"DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific": {"property": null, "policyName": "DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific.5.xml", "policyConfigStatus": "CONFIG_RETRIEVED", "config": {"preparation": "scrambled", "egg_color": "green", "bread": "pumpernickel", "conflicting_key": "green_eggs_and_ham_are_better", "dcae_target_type": ["pnga-xxx", "pcrf-oam", "vhss-ems", "anot-her", "new-type"], "bacon": "soft, not crispy"}, "responseAttributes": {}, "type": "JSON", "policyVersion": "5", "policyConfigMessage": "Config Retrieved! ", "matchingConditions": {"ONAPName": "dcae", "ConfigName": "Green_Eggs_and_Ham_specific", "ECOMPName": "dcae"}}, "DCAE_FTL3B.Config_Green_Collectors": {"property": null, "policyName": "DCAE_FTL3B.Config_Green_Collectors.1.xml", "policyConfigStatus": "CONFIG_RETRIEVED", "config": {"power_source": "lemmings", "conflicting_key": "green_collectors_wins", "polling_frequency": "30m", "package_type": "plastic"}, "responseAttributes": {}, "type": "JSON", "policyVersion": "1", "policyConfigMessage": "Config Retrieved! ", "matchingConditions": {"ONAPName": "dcae", "ConfigName": "Green_Collectors", "ECOMPName": "dcae"}}, "DCAE_FTL3B.Config_In_Service": {"property": null, "policyName": "DCAE_FTL3B.Config_In_Service.1.xml", "policyConfigStatus": "CONFIG_RETRIEVED", "config": {"conflicting_key": "in_service_trumps!", "in_service": true}, "responseAttributes": {}, "type": "JSON", "policyVersion": "1", "policyConfigMessage": "Config Retrieved! ", "matchingConditions": {"ONAPName": "dcae", "ConfigName": "In_Service", "ECOMPName": "dcae"}}}}, "config": {"dcae_target_type": ["pnga-xxx"]}}
1832         assert ( json.loads(self.body) == expected_result )
1833
1834     def test_web_service_component_all_location(self):
1835         """test GET /service_component_all/<service_name>?service_location=<service_location>"""
1836
1837         Settings.logger.info("=====> test_web_service_component_all_location")
1838         result = self.getPage("/service_component_all/SCN_1?service_location=MDTWNJC1")
1839         Settings.logger.info("got service_component_all: %s", self.body)
1840         self.assertStatus('200 OK')
1841
1842         expected_result = {"oti": {"anot-her": {"another01ems044": {"dcae_target_name": "another01ems044", "dcae_target_collection_ip": "107.239.85.42", "event": {}, "dcae_service-instance_model-version-id": "1", "dcae_service_location": "MDTWNJC1", "dcae_target_in-maint": "false", "dcae_service_action": "deploy", "dcae_target_is-closed-loop-disabled": "false", "dcae_target_collection": "true", "aai_additional_info": {"TasksItems": {"another01ems044_2PMOBATTHSSEMS0165": {"collectionInterval": "300", "serviceType": "MOB-VHSS", "vnfType": "VHSS", "taskId": "2PMOBATTHSSEMS0165", "remoteServerGroups": {"g1": {"serverGroup": [{"remoteServerIp": "107.239.85.42", "isPrimary": "true", "remoteServerName": "another01ems044"}], "serverGroupId": "g1"}}, "nodeType": "VHSS", "protocol": "sftp", "nodeSubtype": "", "priority": 1, "description": "VHSS Data Collection"}}}, "dcae_generic-vnf_model-version-id": "1", "dcae_target_prov-status": "PROV", "dcae_target_type": "ANOT-her", "dcae_snmp_community_string": "my_first_community", "dcae_snmp_version": "2c"}}}, "policies": {"event": {"update_id": "e6102aab-3079-435a-ae0d-0397a2cb3c4d", "action": "updated", "timestamp": "2018-07-16T15:11:44.845Z", "policies_count": 3}, "items": {"DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific": {"property": null, "policyName": "DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific.5.xml", "policyConfigStatus": "CONFIG_RETRIEVED", "config": {"preparation": "scrambled", "egg_color": "green", "bread": "pumpernickel", "conflicting_key": "green_eggs_and_ham_are_better", "dcae_target_type": ["pnga-xxx", "pcrf-oam", "vhss-ems", "anot-her", "new-type"], "bacon": "soft, not crispy"}, "responseAttributes": {}, "type": "JSON", "policyVersion": "5", "policyConfigMessage": "Config Retrieved! ", "matchingConditions": {"ONAPName": "dcae", "ConfigName": "Green_Eggs_and_Ham_specific", "ECOMPName": "dcae"}}, "DCAE_FTL3B.Config_Green_Collectors": {"property": null, "policyName": "DCAE_FTL3B.Config_Green_Collectors.1.xml", "policyConfigStatus": "CONFIG_RETRIEVED", "config": {"power_source": "lemmings", "conflicting_key": "green_collectors_wins", "polling_frequency": "30m", "package_type": "plastic"}, "responseAttributes": {}, "type": "JSON", "policyVersion": "1", "policyConfigMessage": "Config Retrieved! ", "matchingConditions": {"ONAPName": "dcae", "ConfigName": "Green_Collectors", "ECOMPName": "dcae"}}, "DCAE_FTL3B.Config_In_Service": {"property": null, "policyName": "DCAE_FTL3B.Config_In_Service.1.xml", "policyConfigStatus": "CONFIG_RETRIEVED", "config": {"conflicting_key": "in_service_trumps!", "in_service": true}, "responseAttributes": {}, "type": "JSON", "policyVersion": "1", "policyConfigMessage": "Config Retrieved! ", "matchingConditions": {"ONAPName": "dcae", "ConfigName": "In_Service", "ECOMPName": "dcae"}}}}, "config": {"dcae_target_type": ["pnga-xxx"]}}
1843         assert ( json.loads(self.body) == expected_result )
1844
1845     def test_web_policies_put(self):
1846         """test PUT /policies/<service_name> -- wrong method"""
1847
1848         Settings.logger.info("=====> test_web_policies_put")
1849         result = self.getPage("/policies/SCN_1", method='PUT')
1850         self.assertStatus(404)
1851
1852     def test_web_policies_bogus(self):
1853         """test GET /policies/<service_name> -- bogus SCN"""
1854
1855         Settings.logger.info("=====> test_web_policies_bogus")
1856         result = self.getPage("/policies/SCN_bogus")
1857         self.assertStatus(404)
1858
1859     def test_web_policies(self):
1860         """test GET /policies/<service_name>"""
1861
1862         Settings.logger.info("=====> test_web_policies")
1863         result = self.getPage("/policies/SCN_1")
1864         Settings.logger.info("got policies: %s", self.body)
1865         self.assertStatus('200 OK')
1866
1867         expected_result = {"DCAE_FTL3B.Config_In_Service": {"type": "JSON", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyVersion": "1", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "In_Service"}, "policyConfigStatus": "CONFIG_RETRIEVED", "property": null, "config": {"conflicting_key": "in_service_trumps!", "in_service": true}, "policyName": "DCAE_FTL3B.Config_In_Service.1.xml"}, "DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific": {"type": "JSON", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyVersion": "5", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "Green_Eggs_and_Ham_specific"}, "policyConfigStatus": "CONFIG_RETRIEVED", "property": null, "config": {"preparation": "scrambled", "bread": "pumpernickel", "dcae_target_type": ["pnga-xxx", "pcrf-oam", "vhss-ems", "anot-her", "new-type"], "conflicting_key": "green_eggs_and_ham_are_better", "egg_color": "green", "bacon": "soft, not crispy"}, "policyName": "DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific.5.xml"}, "DCAE_FTL3B.Config_Green_Collectors": {"type": "JSON", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyVersion": "1", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "Green_Collectors"}, "policyConfigStatus": "CONFIG_RETRIEVED", "property": null, "config": {"conflicting_key": "green_collectors_wins", "package_type": "plastic", "power_source": "lemmings", "polling_frequency": "30m"}, "policyName": "DCAE_FTL3B.Config_Green_Collectors.1.xml"}}
1868         assert ( json.loads(self.body) == expected_result )
1869
1870     def test_web_policies_policy(self):
1871         """test GET /policies/<service_name>?policy_id=<policy_id>"""
1872
1873         Settings.logger.info("=====> test_web_policies_policy")
1874         result = self.getPage("/policies/SCN_1?policy_id=DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific")
1875         Settings.logger.info("got policies: %s", self.body)
1876         self.assertStatus('200 OK')
1877
1878         expected_result = {"type": "JSON", "policyConfigMessage": "Config Retrieved! ", "responseAttributes": {}, "policyVersion": "5", "matchingConditions": {"ONAPName": "dcae", "ECOMPName": "dcae", "ConfigName": "Green_Eggs_and_Ham_specific"}, "policyConfigStatus": "CONFIG_RETRIEVED", "property": null, "config": {"preparation": "scrambled", "bread": "pumpernickel", "dcae_target_type": ["pnga-xxx", "pcrf-oam", "vhss-ems", "anot-her", "new-type"], "conflicting_key": "green_eggs_and_ham_are_better", "egg_color": "green", "bacon": "soft, not crispy"}, "policyName": "DCAE_FTL3B.Config_Green_Eggs_and_Ham_specific.5.xml"}
1879         assert ( json.loads(self.body) == expected_result )
1880
1881     @pytest.mark.usefixtures("fix_cherrypy_engine_exit")
1882     def test_zzz_web_shutdown(self):
1883         """test /shutdown"""
1884
1885         Settings.logger.info("=====> test_zzz_web_shutdown")
1886         Settings.logger.info("sleep before shutdown...")
1887         time.sleep(1)
1888
1889         result = self.getPage("/shutdown")
1890         Settings.logger.info("shutdown result: %s", result)
1891         self.assertStatus('200 OK')
1892         Settings.logger.info("got shutdown: %s", self.body)
1893         self.assertInBody('goodbye! shutdown requested ')
1894         time.sleep(1)