From 5c53ab23008ee73ad2e137aab3acbe1b5d64cc8a Mon Sep 17 00:00:00 2001 From: Yang Xu Date: Sun, 15 Apr 2018 18:07:13 +0000 Subject: Init cut for s3p Issue-ID: INT-451 Change-Id: Ifd0f17f85d51e49eea45af6115e01287cceb0d92 Signed-off-by: Yang Xu --- test/s3p/collector/get_resource_stats.py | 87 +++++++++++ test/s3p/generator/locustfile.py | 186 +++++++++++++++++++++++ test/s3p/mock/set_expectation.sh | 249 +++++++++++++++++++++++++++++++ 3 files changed, 522 insertions(+) create mode 100755 test/s3p/collector/get_resource_stats.py create mode 100644 test/s3p/generator/locustfile.py create mode 100755 test/s3p/mock/set_expectation.sh (limited to 'test') diff --git a/test/s3p/collector/get_resource_stats.py b/test/s3p/collector/get_resource_stats.py new file mode 100755 index 000000000..8ad22c575 --- /dev/null +++ b/test/s3p/collector/get_resource_stats.py @@ -0,0 +1,87 @@ +#!/usr/bin/python +import subprocess +import sys +import json +import datetime +import collections +import re +import tzlocal +from decimal import Decimal + +sys.path.append('../util') +import docker_util + +AAI1_NAME = "AAI1" +AAI2_NAME = "AAI2" +SO_NAME = "SO" +SDNC_NAME = "SDNC" +AAI1_IP = "10.0.1.1" +AAI2_IP = "10.0.1.2" +SO_IP = "10.0.5.1" +SDNC_IP = "10.0.7.1" + +def aai1(): + containers = docker_util.get_container_list(AAI1_IP) + run(AAI1_NAME, AAI1_IP, containers) + +def aai2(): + containers = docker_util.get_container_list(AAI2_IP) + run(AAI2_NAME, AAI2_IP, containers) + +def so(): + containers = docker_util.get_container_list(SO_IP) + run(SO_NAME, SO_IP, containers) + +def sdnc(): + containers = docker_util.get_container_list(SDNC_IP) + run(SDNC_NAME, SDNC_IP, containers) + +def run(component, ip, containers): + cmd = ["ssh", "-i", "onap_dev"] + cmd.append("ubuntu@" + ip) + cmd.append("sudo docker stats --no-stream") + for c in containers: + cmd.append(c) + ssh = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + result = ssh.stdout.readlines() + if result == []: + error = ssh.stderr.readlines() + print(error) + else: + result.pop(0) + for line in result: + token = line.decode('ascii').strip().split() + data = collections.OrderedDict() + data['datetime'] = datetime.datetime.now(tzlocal.get_localzone()).strftime("%Y-%m-%dT%H:%M:%S%Z") + data['component'] = component + data['container'] = token[0] + data['cpu'] = get_percent_number(token[1]) + data['memory'] = get_memory_number(token[2]) + data['physical'] = get_memory_number(token[4]) + data['mem_percent'] = get_percent_number(token[5]) + size = docker_util.get_container_volume_size(ip, data['container']) + if size is not None: + data['volume'] = size + file.write(json.dumps(data, default = myconverter) + "\n") + file.flush() + +def myconverter(o): + if isinstance(o, datetime.datetime): + return o.__str__() + +def get_percent_number(s): + return float(re.sub('[^0-9\.]', '', s)) + +def get_memory_number(s): + f = float(re.sub('[^0-9\.]', '', s)) + if s.endswith("GiB"): + f = f*1000 + return f + +file = open("resource.log", "w+") +while True: + so() + sdnc() + aai1() + aai2() diff --git a/test/s3p/generator/locustfile.py b/test/s3p/generator/locustfile.py new file mode 100644 index 000000000..63031cd78 --- /dev/null +++ b/test/s3p/generator/locustfile.py @@ -0,0 +1,186 @@ +import random +import string +import time +import datetime +import sys +import collections +import json +import tzlocal +import os +import fcntl +import logging +from locust import HttpLocust, TaskSet, task +from decimal import Decimal + + +class UserBehavior(TaskSet): + base = "/ecomp/mso/infra/e2eServiceInstances/v3" + headers = {"Accept":"application/json","Content-Type":"application/json","Authorization":"Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA=="} + service_creation_body = "{\"service\": {\"name\": \"E2E_volte_%s\", \"description\": \"E2E_volte_ONAP_deploy\", \"serviceDefId\": \"a16eb184-4a81-4c8c-89df-c287d390315a\", \"templateId\": \"012c3446-51db-4a2a-9e64-a936f10a5e3c\", \"parameters\": { \"globalSubscriberId\": \"Demonstration\", \"subscriberName\": \"Demonstration\", \"serviceType\": \"vIMS\", \"templateName\": \"VoLTE e2e Service:null\", \"resources\": [ { \"resourceName\": \"VL OVERLAYTUNNEL\", \"resourceDefId\": \"671d4757-b018-47ab-9df3-351c3bda0a98\", \"resourceId\": \"e859b0fd-d928-4cc8-969e-0fee7795d623\", \"nsParameters\": { \"locationConstraints\": [], \"additionalParamForNs\": { \"site2_vni\": \"5010\", \"site1_localNetworkAll\": \"false\", \"site1_vni\": \"5010\", \"site1_exportRT1\": \"11:1\", \"description\": \"overlay\", \"site2_localNetworkAll\": \"false\", \"site1_routerId\": \"9.9.9.9\", \"site1_fireWallEnable\": \"false\", \"site1_networkName\": \"network1\", \"site2_description\": \"overlay\", \"site1_importRT1\": \"11:1\", \"site1_description\": \"overlay\", \"site2_networkName\": \"network3\", \"name\": \"overlay\", \"site2_fireWallEnable\": \"false\", \"site2_id\": \"ZTE-DCI-Controller\", \"site2_routerId\": \"9.9.9.9\", \"site2_importRT1\": \"11:1\", \"site2_exportRT1\": \"11:1\", \"site2_fireWallId\": \"false\", \"site1_id\": \"DCI-Controller-1\", \"tunnelType\": \"L3-DCI\" } } },{\"resourceName\": \"VL UNDERLAYVPN\", \"resourceDefId\": \"4f5d692b-4022-43ab-b878-a93deb5b2061\", \"resourceId\": \"b977ec47-45b2-41f6-aa03-bf6554dc9620\", \"nsParameters\": { \"locationConstraints\": [], \"additionalParamForNs\": { \"topology\": \"full-mesh\", \"site2_name\": \"site2\", \"sna2_name\": \"site2_sna\", \"description\": \"underlay\", \"sna1_name\": \"site1_sna\", \"ac1_route\": \"3.3.3.12/30:dc84ce88-99f7\", \"ac2_peer_ip\": \"3.3.3.20/30\", \"technology\": \"mpls\", \"ac2_route\": \"3.3.3.20/30:98928302-3287\", \"ac2_id\": \"84d937a4-b227-375f-a744-2b778f36e04e\", \"ac1_protocol\": \"STATIC\", \"ac2_svlan\": \"4004\", \"serviceType\": \"l3vpn-ipwan\", \"ac2_ip\": \"3.3.3.21/30\", \"pe2_id\": \"4412d3f0-c296-314d-9284-b72fc5d485e8\", \"ac1_id\": \"b4f01ac0-c1e1-3e58-a8be-325e4372c960\", \"af_type\": \"ipv4\", \"ac1_svlan\": \"4002\", \"ac1_peer_ip\": \"3.3.3.12/30\", \"ac1_ip\": \"3.3.3.13/30\", \"version\": \"1.0\", \"name\": \"testunderlay\", \"id\": \"123124141\", \"pe1_id\": \"2ef788f0-407c-3070-b756-3a5cd71fde18\", \"ac2_protocol\": \"STATIC\", \"site1_name\": \"stie1\" } } } ] } } }" + # following class variables to make them unique across all users + transaction_file= open("transaction.log", "w+") + operation_file = open("operation.log", "w+") + + def on_start(self): + """ on_start is called when a Locust start before any task is scheduled """ + self.init() + + def init(self): + pass + + def myconverter(self, o): + if isinstance(o, datetime.datetime): + return o.__str__() + + @task(1) + def create_service(self): + # Post a E2E service instantiation request to SO + method = "POST" + url = self.base + service_instance_name = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) + data = self.service_creation_body % service_instance_name + + t1 = datetime.datetime.now(tzlocal.get_localzone()) + response = self.client.request(method, url, headers=self.headers, data=data) + t2 = datetime.datetime.now(tzlocal.get_localzone()) + delta = t2 - t1 + data = collections.OrderedDict() + data['datetime'] = datetime.datetime.now(tzlocal.get_localzone()).strftime("%Y-%m-%dT%H:%M:%S%Z") + data['method'] = method + data['url'] = url + data['status_code'] = response.status_code + data['transaction_time'] = (delta.seconds*10^6 + delta.microseconds)/1000 + fcntl.flock(self.transaction_file, fcntl.LOCK_EX) + self.transaction_file.write(json.dumps(data, default = self.myconverter) + "\n") + self.transaction_file.flush() + os.fsync(self.transaction_file) + fcntl.flock(self.transaction_file, fcntl.LOCK_UN) + serviceId = response.json()['service']['serviceId'] + operationId = response.json()['service']['operationId'] + + # Get the request status + method = "GET" + url = self.base + "/" + serviceId + "/operations/" + operationId + url1 = "/ecomp/mso/infra/e2eServiceInstances/v3/{serviceId}/operations/{operationId}" + count = 1 + while count < 50: + tt1 = datetime.datetime.now() + response = self.client.request(method, url, name=url1, headers=self.headers) + tt2 = datetime.datetime.now() + delta = tt2 - tt1 + result = response.json()['operationStatus']['result'] + progress = response.json()['operationStatus']['progress'] + data = collections.OrderedDict() + data['datetime'] = datetime.datetime.now(tzlocal.get_localzone()).strftime("%Y-%m-%dT%H:%M:%S%Z") + data['method'] = method + data['url'] = url1 + data['status_code'] = response.status_code + data['count'] = count + data['result'] = result + data['progress'] = progress + data['transaction_time'] = (delta.seconds*10^6 + delta.microseconds)/1000 + fcntl.flock(self.transaction_file, fcntl.LOCK_EX) + self.transaction_file.write(json.dumps(data, default = self.myconverter) + "\n") + self.transaction_file.flush() + os.fsync(self.transaction_file) + fcntl.flock(self.transaction_file, fcntl.LOCK_UN) + if result == "finished" or result == "error": + break + else: + time.sleep(1) + count = count + 1 + + if result == "finished": + result = "success" + else: + result = "failure" + t3 = datetime.datetime.now(tzlocal.get_localzone()) + delta = t3 - t1 + data = collections.OrderedDict() + data['datetime'] = t1.strftime("%Y-%m-%dT%H:%M:%S%Z") + data['operation'] = "volte_create" + data['result'] = result + data['duration'] = round(delta.seconds + Decimal(delta.microseconds/1000000.0), 3) + fcntl.flock(self.operation_file, fcntl.LOCK_EX) + self.operation_file.write(json.dumps(data, default = self.myconverter) + "\n") + self.operation_file.flush() + os.fsync(self.operation_file) + fcntl.flock(self.operation_file, fcntl.LOCK_UN) + + self.delete_service(serviceId) + + def delete_service(self, serviceId): + method = "DELETE" + url = self.base + "/" + serviceId + data = "{\"globalSubscriberId\":\"Demonstration\", \"serviceType\":\"vIMS\"}" + t1 = datetime.datetime.now(tzlocal.get_localzone()) + response = self.client.request(method, url, name=self.base, headers=self.headers, data=data) + t2 = datetime.datetime.now(tzlocal.get_localzone()) + delta = t2 - t1 + data = collections.OrderedDict() + data['datetime'] = datetime.datetime.now(tzlocal.get_localzone()).strftime("%Y-%m-%dT%H:%M:%S%Z") + data['method'] = method + data['url'] = self.base + data['status_code'] = response.status_code + data['transaction_time'] = (delta.seconds*10^6 + delta.microseconds)/1000 + fcntl.flock(self.transaction_file, fcntl.LOCK_EX) + self.transaction_file.write(json.dumps(data, default = self.myconverter) + "\n") + self.transaction_file.flush() + os.fsync(self.transaction_file) + fcntl.flock(self.transaction_file, fcntl.LOCK_UN) + operationId = response.json()['operationId'] + + # Get the request status + method = "GET" + url = self.base + "/" + serviceId + "/operations/" + operationId + url1 = "/ecomp/mso/infra/e2eServiceInstances/v3/{serviceId}/operations/{operationId}" + count = 1 + while count < 50: + tt1 = datetime.datetime.now(tzlocal.get_localzone()) + response = self.client.request(method, url, name=url1, headers=self.headers) + tt2 = datetime.datetime.now(tzlocal.get_localzone()) + delta = tt2 - tt1 + result = response.json()['operationStatus']['result'] + progress = response.json()['operationStatus']['progress'] + data = collections.OrderedDict() + data['datetime'] = datetime.datetime.now(tzlocal.get_localzone()).strftime("%Y-%m-%dT%H:%M:%S%Z") + data['method'] = method + data['url'] = url1 + data['status_code'] = response.status_code + data['count'] = count + data['result'] = result + data['progress'] = progress + data['transaction_time'] = (delta.seconds*10^6 + delta.microseconds)/1000 + fcntl.flock(self.transaction_file, fcntl.LOCK_EX) + self.transaction_file.write(json.dumps(data, default = self.myconverter) + "\n") + self.transaction_file.flush() + os.fsync(self.transaction_file) + fcntl.flock(self.transaction_file, fcntl.LOCK_UN) + if result == "finished" or result == "error": + break + else: + time.sleep(1) + count = count + 1 + + if result == "finished": + result = "success" + else: + result = "failure" + t3 = datetime.datetime.now(tzlocal.get_localzone()) + delta = t3 - t1 + data = collections.OrderedDict() + data['datetime'] = t1.strftime("%Y-%m-%dT%H:%M:%S%Z") + data['operation'] = "volte_delete" + data['result'] = result + data['duration'] = round(delta.seconds + Decimal(delta.microseconds/1000000.0), 3) + fcntl.flock(self.operation_file, fcntl.LOCK_EX) + self.operation_file.write(json.dumps(data, default = self.myconverter) + "\n") + self.operation_file.flush() + os.fsync(self.operation_file) + fcntl.flock(self.operation_file, fcntl.LOCK_UN) + + +class WebsiteUser(HttpLocust): + task_set = UserBehavior + min_wait = 1000 + max_wait = 3000 diff --git a/test/s3p/mock/set_expectation.sh b/test/s3p/mock/set_expectation.sh new file mode 100755 index 000000000..e8c2c24b4 --- /dev/null +++ b/test/s3p/mock/set_expectation.sh @@ -0,0 +1,249 @@ +curl -v -X PUT "http://localhost:1080/expectation" -d '{ + "httpRequest": { + "method": "GET", + "path": "/api/huaweivnfmdriver/v1/swagger.json" + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "content-type": ["application/json"] + }, + "body": { + "not": false, + "type": "JSON", + "json": "{\"errcode\":\"0\",\"errmsg\":\"get token successfully.\",\"data\":{\"expiredDate\":\"2018-11-10 10:03:33\"}}" + } + }, + "times" : { + "unlimited" : true + }, + "timeToLive" : { + "unlimited" : true + } +}' + +curl -v -X PUT "http://localhost:1080/expectation" -d '{ + "httpRequest": { + "method": "POST", + "path": "/controller/v2/tokens" + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "content-type": ["application/json"] + }, + "body": { + "not": false, + "type": "JSON", + "json": "{\"errcode\":\"0\",\"errmsg\":\"get token successfully.\",\"data\":{\"expiredDate\":\"2018-11-10 10:03:33\",\"token_id\":\"7F06BFDDAC33A989:77DAD6058B1BB81EF1A557745E4D9C78399B31C4DB509704ED8A7DF05A362A59\"}}" + } + }, + "times" : { + "unlimited" : true + }, + "timeToLive" : { + "unlimited" : true + } +}' + +curl -v -X PUT "http://localhost:1080/expectation" -d '{ + "httpRequest": { + "method": "POST", + "path": "/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services" + }, + "httpResponse": { + "statusCode": 201 + }, + "times" : { + "unlimited" : true + }, + "timeToLive" : { + "unlimited" : true + } +}' + +curl -v -X PUT "http://localhost:1080/expectation" -d '{ + "httpRequest": { + "method": "PUT", + "path": "/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/huawei-ac-net-l3vpn-svc-vfi:vrf-attributes" + }, + "httpResponse": { + "statusCode": 204 + }, + "times" : { + "unlimited" : true + }, + "timeToLive" : { + "unlimited" : true + } +}' + +curl -v -X PUT "http://localhost:1080/expectation" -d '{ + "httpRequest": { + "method": "POST", + "path": "/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites" + }, + "httpResponse": { + "statusCode": 201 + }, + "times" : { + "unlimited" : true + }, + "timeToLive" : { + "unlimited" : true + } +}' + +# ZTE DCI +curl -v -X PUT "http://localhost:1080/expectation" -d '{ + "httpRequest": { + "method": "POST", + "path": "/v2.0/l3-dci-connects" + }, + "httpResponse": { + "statusCode": 201 + }, + "times" : { + "unlimited" : true + }, + "timeToLive" : { + "unlimited" : true + } +}' + +# huaweivnfmdriver +curl -v -X PUT "http://localhost:1080/expectation" -d '{ + "httpRequest": { + "method": "POST", + "path": "/api/huaweivnfmdriver/v1/a0400010-11d7-4875-b4ae-5f42ed5d3a85/vnfs" + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "content-type": ["application/json"] + }, + "body": { + "not": false, + "type": "JSON", + "json": "{\"vnfInstanceId\":\"fa3dca847b054f4eb9d3bc8bb9e5eec9\",\"jobId\":\"fa3dca847b054f4eb9d3bc8bb9e5eec9_post\"}" + } + }, + "times" : { + "unlimited" : true + }, + "timeToLive" : { + "unlimited" : true + } +}' + +# huaweivnfmdriver +curl -v -X PUT "http://localhost:1080/expectation" -d '{ + "httpRequest": { + "method": "GET", + "path": "/api/huaweivnfmdriver/v1/a0400010-11d7-4875-b4ae-5f42ed5d3a85/jobs/fa3dca847b054f4eb9d3bc8bb9e5eec9_post", + "queryStringParameters": { + "responseId": ["0"] + } + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "content-type": ["application/json"] + }, + "body": { + "not": false, + "type": "JSON", + "json": "{\"jobId\":\"fa3dca847b054f4eb9d3bc8bb9e5eec9\",\"responsedescriptor\":{\"progress\":\"50\",\"status\":\"processing\",\"errorCode\":null,\"responseId\":\"0\"}}" + } + }, + "times" : { + "unlimited" : false + }, + "timeToLive" : { + "unlimited" : true + } +}' + +# huaweivnfmdriver +curl -v -X PUT "http://localhost:1080/expectation" -d '{ + "httpRequest": { + "method": "GET", + "path": "/api/huaweivnfmdriver/v1/a0400010-11d7-4875-b4ae-5f42ed5d3a85/jobs/fa3dca847b054f4eb9d3bc8bb9e5eec9_post", + "queryStringParameters": { + "responseId": ["0"] + } + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "content-type": ["application/json"] + }, + "body": { + "not": false, + "type": "JSON", + "json": "{\"jobId\":\"fa3dca847b054f4eb9d3bc8bb9e5eec9\",\"responsedescriptor\":{\"progress\":\"100\",\"status\":\"processing\",\"errorCode\":null,\"responseId\":\"0\"}}" + } + }, + "times" : { + "unlimited" : true + }, + "timeToLive" : { + "unlimited" : true + } +}' + +curl -v -X PUT "http://localhost:1080/expectation" -d '{ + "httpRequest": { + "method": "GET", + "path": "/api/huaweivnfmdriver/v1/a0400010-11d7-4875-b4ae-5f42ed5d3a85/jobs/fa3dca847b054f4eb9d3bc8bb9e5eec9_post", + "queryStringParameters": { + "responseId": ["50"] + } + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "content-type": ["application/json"] + }, + "body": { + "not": false, + "type": "JSON", + "json": "{\"jobId\":\"fa3dca847b054f4eb9d3bc8bb9e5eec9\",\"responsedescriptor\":{\"progress\":\"100\",\"status\":\"processing\",\"errorCode\":null,\"responseId\":\"50\"}}" + } + }, + "times" : { + "unlimited" : true + }, + "timeToLive" : { + "unlimited" : true + } +}' + + +curl -v -X PUT "http://localhost:1080/expectation" -d '{ + "httpRequest": { + "method": "GET", + "path": "/api/huaweivnfmdriver/v1/a0400010-11d7-4875-b4ae-5f42ed5d3a85/jobs/fa3dca847b054f4eb9d3bc8bb9e5eec9_post", + "queryStringParameters": { + "responseId": ["2"] + } + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "content-type": ["application/json"] + }, + "body": { + "not": false, + "type": "JSON", + "json": "{\"jobId\":\"fa3dca847b054f4eb9d3bc8bb9e5eec9\",\"responsedescriptor\":{\"progress\":\"100\",\"status\":\"processing\",\"errorCode\":null,\"responseId\":\"2\"}}" + } + }, + "times" : { + "unlimited" : true + }, + "timeToLive" : { + "unlimited" : true + } +}' + -- cgit 1.2.3-korg