1- #!env/bin/python3
1+ import argparse
22import datetime
33import random
44import threading
55import uuid
66
77import client
8- from locust import between , task
8+ import locust
9+ from utils import format_time
910
10- from monitoring .monitorlib import rid_v1
11- from monitoring .monitorlib .testing import make_fake_url
11+
12+ @locust .events .init_command_line_parser .add_listener
13+ def init_parser (parser : argparse .ArgumentParser ):
14+ """Setup config params, populated by locust.conf."""
15+
16+ parser .add_argument (
17+ "--uss-base-url" ,
18+ type = str ,
19+ help = "Base URL of the USS" ,
20+ required = True ,
21+ )
1222
1323
1424class Sub (client .USS ):
15- wait_time = between (0.01 , 1 )
25+ wait_time = locust . between (0.01 , 1 )
1626 lock = threading .Lock ()
1727
1828 def gen_vertices (self ):
@@ -25,47 +35,61 @@ def gen_vertices(self):
2535 {"lng" : base_lng + 0.6466 , "lat" : base_lat + 0.6407 },
2636 ]
2737
28- @task (100 )
38+ @locust . task (100 )
2939 def create_sub (self ):
3040 time_start = datetime .datetime .now (datetime .UTC )
3141 time_end = time_start + datetime .timedelta (minutes = 60 )
3242 sub_uuid = str (uuid .uuid4 ())
3343
3444 resp = self .client .put (
35- f"/subscriptions/{ sub_uuid } " ,
45+ f"/rid/v2/dss/ subscriptions/{ sub_uuid } " ,
3646 json = {
3747 "extents" : {
38- "spatial_volume " : {
39- "footprint " : {
48+ "volume " : {
49+ "outline_polygon " : {
4050 "vertices" : self .gen_vertices (),
4151 },
42- "altitude_lo" : 20 ,
43- "altitude_hi" : 400 ,
52+ "altitude_lower" : {
53+ "value" : 20 ,
54+ "reference" : "W84" ,
55+ "units" : "M" ,
56+ },
57+ "altitude_upper" : {
58+ "value" : 400 ,
59+ "reference" : "W84" ,
60+ "units" : "M" ,
61+ },
62+ },
63+ "time_start" : {
64+ "value" : format_time (time_start ),
65+ "format" : "RFC3339" ,
66+ },
67+ "time_end" : {
68+ "value" : format_time (time_end ),
69+ "format" : "RFC3339" ,
4470 },
45- "time_start" : time_start .strftime (rid_v1 .DATE_FORMAT ),
46- "time_end" : time_end .strftime (rid_v1 .DATE_FORMAT ),
4771 },
48- "callbacks " : { "identification_service_area_url" : make_fake_url ()} ,
72+ "uss_base_url " : self . uss_base_url ,
4973 },
5074 name = "/subscriptions/[sub_uuid]" ,
5175 )
5276 if resp .status_code == 200 :
53- self .sub_dict [sub_uuid ] = resp .json ()["subscription" ]["version" ]
77+ with self .lock :
78+ self .sub_dict [sub_uuid ] = resp .json ()["subscription" ]["version" ]
5479
55- @task (20 )
80+ @locust . task (20 )
5681 def get_sub (self ):
57- target_sub = (
58- random .choice (list (self .sub_dict .keys ())) if self .sub_dict else None
59- )
60- if not target_sub :
61- print ("Nothing to pick from sub_dict for GET" )
62- return
82+ with self .lock :
83+ if not self .sub_dict :
84+ print ("Nothing to pick from sub_dict for GET" )
85+ return
86+ target_sub = random .choice (list (self .sub_dict .keys ()))
6387 self .client .get (
64- f"/subscriptions/{ target_sub } " ,
88+ f"/rid/v2/dss/ subscriptions/{ target_sub } " ,
6589 name = "/subscriptions/[target_sub]" ,
6690 )
6791
68- @task (50 )
92+ @locust . task (50 )
6993 def update_sub (self ):
7094 target_sub , target_version = self .checkout_sub ()
7195 if not target_sub :
@@ -75,49 +99,65 @@ def update_sub(self):
7599 time_start = datetime .datetime .now (datetime .UTC )
76100 time_end = datetime .datetime .now (datetime .UTC ) + datetime .timedelta (minutes = 2 )
77101 resp = self .client .put (
78- f"/subscriptions/{ target_sub } /{ target_version } " ,
102+ f"/rid/v2/dss/ subscriptions/{ target_sub } /{ target_version } " ,
79103 json = {
80104 "extents" : {
81- "spatial_volume " : {
82- "footprint " : {
105+ "volume " : {
106+ "outline_polygon " : {
83107 "vertices" : self .gen_vertices (),
84108 },
85- "altitude_lo" : 20 ,
86- "altitude_hi" : 400 ,
109+ "altitude_lower" : {
110+ "value" : 20 ,
111+ "reference" : "W84" ,
112+ "units" : "M" ,
113+ },
114+ "altitude_upper" : {
115+ "value" : 400 ,
116+ "reference" : "W84" ,
117+ "units" : "M" ,
118+ },
119+ },
120+ "time_start" : {
121+ "value" : format_time (time_start ),
122+ "format" : "RFC3339" ,
123+ },
124+ "time_end" : {
125+ "value" : format_time (time_end ),
126+ "format" : "RFC3339" ,
87127 },
88- "time_start" : time_start .strftime (rid_v1 .DATE_FORMAT ),
89- "time_end" : time_end .strftime (rid_v1 .DATE_FORMAT ),
90128 },
91- "callbacks " : { "identification_service_area_url" : make_fake_url ()} ,
129+ "uss_base_url " : self . uss_base_url ,
92130 },
93131 name = "/subscriptions/[target_sub]/[target_version]" ,
94132 )
95133 if resp .status_code == 200 :
96- self .sub_dict [target_sub ] = resp .json ()["subscription" ]["version" ]
134+ with self .lock :
135+ self .sub_dict [target_sub ] = resp .json ()["subscription" ]["version" ]
97136
98- @task (5 )
137+ @locust . task (5 )
99138 def delete_sub (self ):
100139 target_sub , target_version = self .checkout_sub ()
101140 if not target_sub :
102141 print ("Nothing to pick from sub_dict for DELETE" )
103142 return
104143 self .client .delete (
105- f"/subscriptions/{ target_sub } /{ target_version } " ,
144+ f"/rid/v2/dss/ subscriptions/{ target_sub } /{ target_version } " ,
106145 name = "/subscriptions/[target_sub]/[target_version]" ,
107146 )
108147
109148 def checkout_sub (self ):
110- self .lock .acquire ()
111- target_sub = (
112- random .choice (list (self .sub_dict .keys ())) if self .sub_dict else None
113- )
114- target_version = self .sub_dict .pop (target_sub , None )
115- self .lock .release ()
149+ with self .lock :
150+ if not self .sub_dict :
151+ return None , None
152+ target_sub = random .choice (list (self .sub_dict .keys ()))
153+ target_version = self .sub_dict .pop (target_sub , None )
116154 return target_sub , target_version
117155
118156 def on_start (self ):
157+ self .uss_base_url = self .environment .parsed_options .uss_base_url
119158 # Insert atleast 1 Sub for update to not fail
120159 self .create_sub ()
121160
122161 def on_stop (self ):
123- self .sub_dict = {}
162+ while self .sub_dict : # Drain subscriptions
163+ self .delete_sub ()
0 commit comments