Add test folder to the smo package installation
[it/dep.git] / smo-install / test / enable-sim-fault-report / enable-network-sim-fault-reporting.sh
1 #!/usr/bin/env python3.8
2 ################################################################################
3 # Copyright 2021 highstreet technologies GmbH
4 ####################################################################
5 # Modifications Copyright (C) 2021 AT&T
6 ####################################################################
7 #
8 # Licensed under the Apache License, Version 2.0 (the 'License');
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #     http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an 'AS IS' BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 # importing the sys, json, requests library
22 import os
23 import sys
24 import json
25 import requests
26 import subprocess
27
28 dockerFilter = subprocess.check_output("kubectl get services -n network -o name | awk -F \"/\" '{print $2}'", shell=True)
29 containers = dockerFilter.splitlines()
30 dockerSdnc = subprocess.check_output("kubectl get services sdnc-web-service -n onap | grep sdnc-web-service |  awk '{print $3}'", shell=True)
31
32 mapping = dict({"ntsim-ng-o-ru": "o-ru", "ntsim-ng-o-du": "o-du"}) 
33 # base = 'https://sdnc-web:8453'
34 base = 'https://'+ dockerSdnc.decode("utf-8").strip() +':8443'
35 username = 'admin'
36 password = 'Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U'
37
38 # REST to set event settings
39 def configEventSettings(nfName, nfType):
40   file = os.path.dirname(os.path.abspath(__file__)) + '/data/' + 'event-settings-'+nfType+'.json'
41   print ("File name:" + file)
42   with open(file) as json_file:
43     body = json.load(json_file)
44     url = base + '/rests/data/network-topology:network-topology/topology=topology-netconf/node=' + nfName + '/yang-ext:mount/nts-network-function:simulation/network-function'
45     print ("url:"+url)
46     headers = {
47         'content-type': 'application/yang-data+json',
48         'accept': 'application/yang-data+json'
49     }
50     try:
51       response = requests.put(url, verify=False, auth=(username, password), json=body, headers=headers)
52       print("Response:" + str(response))
53     except requests.exceptions.Timeout:
54       sys.exit('HTTP request failed, please check you internet connection.')
55     except requests.exceptions.TooManyRedirects:
56       sys.exit('HTTP request failed, please check your proxy settings.')
57     except requests.exceptions.RequestException as e:
58       # catastrophic error. bail.
59       raise SystemExit(e)
60
61     return response.status_code >= 200 and response.status_code < 300
62
63 # main
64 print ("Container Lines:"+str(containers))
65 for container in containers:
66   name = container.decode("utf-8")
67   if "o-" in name:
68     if "o-ru" in name:
69       print("Set", name, configEventSettings(name, "ru"))
70     if "o-du" in name:
71       print("Set", name, configEventSettings(name, "du"))