1- #!env/bin/python3
2-
1+ import argparse
32import datetime
43import random
54import threading
65import uuid
76
87import client
9- from locust import between , task
10-
11- from monitoring .monitorlib import rid_v1
12- from monitoring .monitorlib .testing import make_fake_url
8+ import locust
9+ from utils import format_time
1310
1411VERTICES = [
1512 {"lng" : 130.6205 , "lat" : - 23.6558 },
1916]
2017
2118
19+ @locust .events .init_command_line_parser .add_listener
20+ def init_parser (parser : argparse .ArgumentParser ):
21+ """Setup config params, populated by locust.conf."""
22+
23+ parser .add_argument (
24+ "--uss-base-url" ,
25+ type = str ,
26+ help = "Base URL of the USS" ,
27+ required = True ,
28+ )
29+
30+
2231class ISA (client .USS ):
23- wait_time = between (0.01 , 1 )
32+ wait_time = locust . between (0.01 , 1 )
2433 lock = threading .Lock ()
2534
26- @task (10 )
35+ @locust . task (10 )
2736 def create_isa (self ):
2837 time_start = datetime .datetime .now (datetime .UTC )
2938 time_end = time_start + datetime .timedelta (minutes = 60 )
3039 isa_uuid = str (uuid .uuid4 ())
3140
3241 resp = self .client .put (
33- f"/identification_service_areas/{ isa_uuid } " ,
42+ f"/rid/v2/dss/ identification_service_areas/{ isa_uuid } " ,
3443 json = {
3544 "extents" : {
36- "spatial_volume " : {
37- "footprint " : {
45+ "volume " : {
46+ "outline_polygon " : {
3847 "vertices" : VERTICES ,
3948 },
40- "altitude_lo" : 20 ,
41- "altitude_hi" : 400 ,
49+ "altitude_lower" : {
50+ "value" : 20 ,
51+ "reference" : "W84" ,
52+ "units" : "M" ,
53+ },
54+ "altitude_upper" : {
55+ "value" : 400 ,
56+ "reference" : "W84" ,
57+ "units" : "M" ,
58+ },
59+ },
60+ "time_start" : {
61+ "value" : format_time (time_start ),
62+ "format" : "RFC3339" ,
63+ },
64+ "time_end" : {
65+ "value" : format_time (time_end ),
66+ "format" : "RFC3339" ,
4267 },
43- "time_start" : time_start .strftime (rid_v1 .DATE_FORMAT ),
44- "time_end" : time_end .strftime (rid_v1 .DATE_FORMAT ),
4568 },
46- "flights_url " : make_fake_url () ,
69+ "uss_base_url " : self . uss_base_url ,
4770 },
4871 name = "/identification_service_areas/[isa_uuid]" ,
4972 )
5073 if resp .status_code == 200 :
51- self .isa_dict [isa_uuid ] = resp .json ()["service_area" ]["version" ]
74+ with self .lock :
75+ self .isa_dict [isa_uuid ] = resp .json ()["service_area" ]["version" ]
5276
53- @task (5 )
77+ @locust . task (5 )
5478 def update_isa (self ):
5579 target_isa , target_version = self .checkout_isa ()
5680 if not target_isa :
@@ -60,62 +84,77 @@ def update_isa(self):
6084 time_start = datetime .datetime .now (datetime .UTC )
6185 time_end = datetime .datetime .now (datetime .UTC ) + datetime .timedelta (minutes = 2 )
6286 resp = self .client .put (
63- f"/identification_service_areas/{ target_isa } /{ target_version } " ,
87+ f"/rid/v2/dss/ identification_service_areas/{ target_isa } /{ target_version } " ,
6488 json = {
6589 "extents" : {
66- "spatial_volume " : {
67- "footprint " : {
90+ "volume " : {
91+ "outline_polygon " : {
6892 "vertices" : VERTICES ,
6993 },
70- "altitude_lo" : 20 ,
71- "altitude_hi" : 400 ,
94+ "altitude_lower" : {
95+ "value" : 20 ,
96+ "reference" : "W84" ,
97+ "units" : "M" ,
98+ },
99+ "altitude_upper" : {
100+ "value" : 400 ,
101+ "reference" : "W84" ,
102+ "units" : "M" ,
103+ },
104+ },
105+ "time_start" : {
106+ "value" : format_time (time_start ),
107+ "format" : "RFC3339" ,
108+ },
109+ "time_end" : {
110+ "value" : format_time (time_end ),
111+ "format" : "RFC3339" ,
72112 },
73- "time_start" : time_start .strftime (rid_v1 .DATE_FORMAT ),
74- "time_end" : time_end .strftime (rid_v1 .DATE_FORMAT ),
75113 },
76- "flights_url " : make_fake_url () ,
114+ "uss_base_url " : self . uss_base_url ,
77115 },
78116 name = "/identification_service_areas/[target_isa]/[target_version]" ,
79117 )
80118 if resp .status_code == 200 :
81- self .isa_dict [target_isa ] = resp .json ()["service_area" ]["version" ]
119+ with self .lock :
120+ self .isa_dict [target_isa ] = resp .json ()["service_area" ]["version" ]
82121
83- @task (100 )
122+ @locust . task (100 )
84123 def get_isa (self ):
85- target_isa = (
86- random .choice (list (self .isa_dict .keys ())) if self .isa_dict else None
87- )
88- if not target_isa :
124+ if not self .isa_dict :
89125 print ("Nothing to pick from isa_dict for GET" )
90126 return
127+ with self .lock :
128+ target_isa = random .choice (list (self .isa_dict .keys ()))
91129 self .client .get (
92- f"/identification_service_areas/{ target_isa } " ,
130+ f"/rid/v2/dss/ identification_service_areas/{ target_isa } " ,
93131 name = "/identification_service_areas/[target_isa]" ,
94132 )
95133
96- @task (1 )
134+ @locust . task (1 )
97135 def delete_isa (self ):
98136 target_isa , target_version = self .checkout_isa ()
99137 if not target_isa :
100138 print ("Nothing to pick from isa_dict for DELETE" )
101139 return
102140 self .client .delete (
103- f"/identification_service_areas/{ target_isa } /{ target_version } " ,
141+ f"/rid/v2/dss/ identification_service_areas/{ target_isa } /{ target_version } " ,
104142 name = "/identification_service_areas/[target_isa]/[target_version]" ,
105143 )
106144
107145 def checkout_isa (self ):
108- self .lock .acquire ()
109- target_isa = (
110- random .choice (list (self .isa_dict .keys ())) if self .isa_dict else None
111- )
112- target_version = self .isa_dict .pop (target_isa , None )
113- self .lock .release ()
146+ with self .lock :
147+ if not self .isa_dict :
148+ return None , None
149+ target_isa = random .choice (list (self .isa_dict .keys ()))
150+ target_version = self .isa_dict .pop (target_isa , None )
114151 return target_isa , target_version
115152
116153 def on_start (self ):
154+ self .uss_base_url = self .environment .parsed_options .uss_base_url
117155 # insert atleast 1 ISA for update to not fail
118156 self .create_isa ()
119157
120158 def on_stop (self ):
121- self .isa_dict = {}
159+ while self .isa_dict : # Drain ISAs
160+ self .delete_isa ()
0 commit comments