9 from decimal import Decimal
12 from locust import HttpLocust, TaskSet, task
15 class UserBehavior(TaskSet):
16 base = "/ecomp/mso/infra/e2eServiceInstances/v3"
17 headers = {"Accept":"application/json","Content-Type":"application/json","Authorization":"Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA=="}
18 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\" } } } ] } } }"
19 # following class variables to make them unique across all users
20 transaction_file= open("transaction.log", "w+")
21 operation_file = open("operation.log", "w+")
24 """ on_start is called when a Locust start before any task is scheduled """
30 def myconverter(self, o):
31 if isinstance(o, datetime.datetime):
35 def create_service(self):
36 # Post a E2E service instantiation request to SO
39 service_instance_name = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
40 data = self.service_creation_body % service_instance_name
42 t1 = datetime.datetime.now(tzlocal.get_localzone())
43 response = self.client.request(method, url, headers=self.headers, data=data)
44 t2 = datetime.datetime.now(tzlocal.get_localzone())
46 data = collections.OrderedDict()
47 data['datetime'] = datetime.datetime.now(tzlocal.get_localzone()).strftime("%Y-%m-%dT%H:%M:%S%Z")
48 data['method'] = method
50 data['status_code'] = response.status_code
51 data['transaction_time'] = (delta.seconds*10^6 + delta.microseconds)/1000
52 fcntl.flock(self.transaction_file, fcntl.LOCK_EX)
53 self.transaction_file.write(json.dumps(data, default = self.myconverter) + "\n")
54 self.transaction_file.flush()
55 os.fsync(self.transaction_file)
56 fcntl.flock(self.transaction_file, fcntl.LOCK_UN)
57 serviceId = response.json()['service']['serviceId']
58 operationId = response.json()['service']['operationId']
60 # Get the request status
62 url = self.base + "/" + serviceId + "/operations/" + operationId
63 url1 = "/ecomp/mso/infra/e2eServiceInstances/v3/{serviceId}/operations/{operationId}"
66 tt1 = datetime.datetime.now()
67 response = self.client.request(method, url, name=url1, headers=self.headers)
68 tt2 = datetime.datetime.now()
70 result = response.json()['operationStatus']['result']
71 progress = response.json()['operationStatus']['progress']
72 data = collections.OrderedDict()
73 data['datetime'] = datetime.datetime.now(tzlocal.get_localzone()).strftime("%Y-%m-%dT%H:%M:%S%Z")
74 data['method'] = method
76 data['status_code'] = response.status_code
78 data['result'] = result
79 data['progress'] = progress
80 data['transaction_time'] = (delta.seconds*10^6 + delta.microseconds)/1000
81 fcntl.flock(self.transaction_file, fcntl.LOCK_EX)
82 self.transaction_file.write(json.dumps(data, default = self.myconverter) + "\n")
83 self.transaction_file.flush()
84 os.fsync(self.transaction_file)
85 fcntl.flock(self.transaction_file, fcntl.LOCK_UN)
86 if result == "finished" or result == "error":
92 if result == "finished":
96 t3 = datetime.datetime.now(tzlocal.get_localzone())
98 data = collections.OrderedDict()
99 data['datetime'] = t1.strftime("%Y-%m-%dT%H:%M:%S%Z")
100 data['operation'] = "volte_create"
101 data['result'] = result
102 data['duration'] = round(delta.seconds + Decimal(delta.microseconds/1000000.0), 3)
103 fcntl.flock(self.operation_file, fcntl.LOCK_EX)
104 self.operation_file.write(json.dumps(data, default = self.myconverter) + "\n")
105 self.operation_file.flush()
106 os.fsync(self.operation_file)
107 fcntl.flock(self.operation_file, fcntl.LOCK_UN)
109 self.delete_service(serviceId)
111 def delete_service(self, serviceId):
113 url = self.base + "/" + serviceId
114 data = "{\"globalSubscriberId\":\"Demonstration\", \"serviceType\":\"vIMS\"}"
115 t1 = datetime.datetime.now(tzlocal.get_localzone())
116 response = self.client.request(method, url, name=self.base, headers=self.headers, data=data)
117 t2 = datetime.datetime.now(tzlocal.get_localzone())
119 data = collections.OrderedDict()
120 data['datetime'] = datetime.datetime.now(tzlocal.get_localzone()).strftime("%Y-%m-%dT%H:%M:%S%Z")
121 data['method'] = method
122 data['url'] = self.base
123 data['status_code'] = response.status_code
124 data['transaction_time'] = (delta.seconds*10^6 + delta.microseconds)/1000
125 fcntl.flock(self.transaction_file, fcntl.LOCK_EX)
126 self.transaction_file.write(json.dumps(data, default = self.myconverter) + "\n")
127 self.transaction_file.flush()
128 os.fsync(self.transaction_file)
129 fcntl.flock(self.transaction_file, fcntl.LOCK_UN)
130 operationId = response.json()['operationId']
132 # Get the request status
134 url = self.base + "/" + serviceId + "/operations/" + operationId
135 url1 = "/ecomp/mso/infra/e2eServiceInstances/v3/{serviceId}/operations/{operationId}"
138 tt1 = datetime.datetime.now(tzlocal.get_localzone())
139 response = self.client.request(method, url, name=url1, headers=self.headers)
140 tt2 = datetime.datetime.now(tzlocal.get_localzone())
142 result = response.json()['operationStatus']['result']
143 progress = response.json()['operationStatus']['progress']
144 data = collections.OrderedDict()
145 data['datetime'] = datetime.datetime.now(tzlocal.get_localzone()).strftime("%Y-%m-%dT%H:%M:%S%Z")
146 data['method'] = method
148 data['status_code'] = response.status_code
149 data['count'] = count
150 data['result'] = result
151 data['progress'] = progress
152 data['transaction_time'] = (delta.seconds*10^6 + delta.microseconds)/1000
153 fcntl.flock(self.transaction_file, fcntl.LOCK_EX)
154 self.transaction_file.write(json.dumps(data, default = self.myconverter) + "\n")
155 self.transaction_file.flush()
156 os.fsync(self.transaction_file)
157 fcntl.flock(self.transaction_file, fcntl.LOCK_UN)
158 if result == "finished" or result == "error":
164 if result == "finished":
168 t3 = datetime.datetime.now(tzlocal.get_localzone())
170 data = collections.OrderedDict()
171 data['datetime'] = t1.strftime("%Y-%m-%dT%H:%M:%S%Z")
172 data['operation'] = "volte_delete"
173 data['result'] = result
174 data['duration'] = round(delta.seconds + Decimal(delta.microseconds/1000000.0), 3)
175 fcntl.flock(self.operation_file, fcntl.LOCK_EX)
176 self.operation_file.write(json.dumps(data, default = self.myconverter) + "\n")
177 self.operation_file.flush()
178 os.fsync(self.operation_file)
179 fcntl.flock(self.operation_file, fcntl.LOCK_UN)
182 class WebsiteUser(HttpLocust):
183 task_set = UserBehavior