X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=solution%2Fdev%2Fves-test-collector%2Fclient-scripts-ves-v7%2FglobalVesEventEmitter.py;fp=solution%2Fdev%2Fves-test-collector%2Fclient-scripts-ves-v7%2FglobalVesEventEmitter.py;h=0000000000000000000000000000000000000000;hb=86b92e82e31a1c948dbc7c78517978aaee31a0b8;hp=a0be6844f39f636bdb381fe197bab23c2733143a;hpb=aca16f72ab8e1dfa3ef53c213e453d654c15c0ad;p=oam.git diff --git a/solution/dev/ves-test-collector/client-scripts-ves-v7/globalVesEventEmitter.py b/solution/dev/ves-test-collector/client-scripts-ves-v7/globalVesEventEmitter.py deleted file mode 100644 index a0be684..0000000 --- a/solution/dev/ves-test-collector/client-scripts-ves-v7/globalVesEventEmitter.py +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env python -################################################################################ -# Copyright 2021 highstreet technologies GmbH -# -# Licensed under the Apache License, Version 2.0 (the 'License'); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an 'AS IS' BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -################################################################################ -# A selection of common methods - -import datetime -import json -import requests -import os -import socket -import sys -import yaml -from pathlib import Path - -def sendVesEvent(data): - url = data['config']['vesEndpoint']['url'] - username = data['config']['vesEndpoint']['username'] - password = data['config']['vesEndpoint']['password'] - headers = {'content-type': 'application/json'} - verify = data['config']['vesEndpoint']['verify'] - try: - response = requests.post(url, json=data['body'], auth=( - username, password), headers=headers, verify=verify) - except requests.exceptions.Timeout: - sys.exit('HTTP request failed, please check you internet connection.') - except requests.exceptions.TooManyRedirects: - sys.exit('HTTP request failed, please check your proxy settings.') - except requests.exceptions.RequestException as e: - # catastrophic error. bail. - raise SystemExit(e) - - if response.status_code >= 200 and response.status_code < 300: - print(response) - else: - sys.exit('Reading VES "stndDefined" message template failed.') - -def sendHttpGet(url): - try: - response = requests.get(url) - except requests.exceptions.Timeout: - sys.exit('HTTP request failed, please check you internet connection.') - except requests.exceptions.TooManyRedirects: - sys.exit('HTTP request failed, please check your proxy settings.') - except requests.exceptions.RequestException as e: - # catastrophic error. bail. - raise SystemExit(e) - - if response.status_code >= 200 and response.status_code < 300: - return response.json() - else: - sys.exit('Reading VES "stndDefined" message template failed.') - -def getInitData(domain, stndBody=''): - currentTime = datetime.datetime.utcnow() - dir = os.path.dirname(os.path.realpath(__file__)) - - result = {} - result['domain']= domain - result['directory']= dir - result['outdir']= dir + '/json/examples' - result['fqdn']= socket.getfqdn() - result['timestamp']= int(currentTime.timestamp()*1000000) - result['eventTime']= currentTime.isoformat() + 'Z' - result['interface']= "urn:ietf:params:xml:ns:yang:ietf-interfaces:interfaces/interface/name='O-RAN-SC-OAM'" - - # Read config - with open('config.yml', 'r') as stream: - try: - result['config']= yaml.safe_load(stream) - except yaml.YAMLError as exc: - print(exc) - - # Read template body - if domain == 'stndDefined': - url = 'https://raw.githubusercontent.com/onap/testsuite/master/robot/assets/dcae/ves_stdnDefined_' + stndBody + '.json' - result['body']= sendHttpGet(url) - else: - templateFileName = dir + '/json/templates/' + domain + '.json' - with open(templateFileName) as f: - result['body']= json.load(f) - - Path(result["outdir"]).mkdir(parents=True, exist_ok=True) - return result - -def saveExample(data): - if 'directory' in data and 'domain' in data and 'body' in data: - name = data['domain'] - if 'pnfId' in data: name = '-'.join( (data['pnfId'], data['domain']) ) - outputFileName = data['directory'] + '/json/examples/' + name + '.json' - with open(outputFileName, 'w') as f: - json.dump(data['body'], f, indent=2, sort_keys=True) - else: - print("Example could not been saved:\n" + json.dump(data, f, indent=2, sort_keys=True)) - \ No newline at end of file