Skip to content

Commit 182685b

Browse files
Eduard RosertEduard Rosert
authored andcommitted
additional options added
1 parent 8ba5ffb commit 182685b

File tree

2 files changed

+61
-9
lines changed

2 files changed

+61
-9
lines changed

k8s-locust-wms-test.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ spec:
2828
value: "https://example.com/wms"
2929
#- name: WMS_ACCESS_KEY
3030
# value: "myauthkey=mysecretaccesstoken"
31+
#- name: WEIGHT_GET_CAPABILITIES
32+
# value: 1
33+
#- name: WEIGHT_GET_LEGEND_GRAPHIC
34+
# value: 2
35+
#- name: WEIGHT_GET_MAP
36+
# value: 10
37+
#- name: LOG_VERBOSE
38+
# value: 1
3139
command: ["/bin/bash", "-c"]
3240
args: [ "locust -f /app/wms-load-test/locustfile.py --host=$WMS_SERVICE_URL"]
3341
resources: {}

locustfile.py

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@
2525
parts = keyvalue.split("=")
2626
WMS_ACCESSS_KEY[parts[0]]=parts[1]
2727

28+
WEIGHT_GET_CAPABILITIES = int(os.getenv('WEIGHT_GET_CAPABILITIES', "1"))
29+
WEIGHT_GET_LEGEND_GRAPHIC = int(os.getenv('WEIGHT_GET_LEGEND_GRAPHIC', "2"))
30+
WEIGHT_GET_MAP = int(os.getenv('WEIGHT_GET_MAP', "10"))
31+
32+
verbose = os.getenv('LOG_VERBOSE', '0')
33+
VERBOSE = False
34+
if verbose.lower() == "1":
35+
VERBOSE = True
36+
37+
if VERBOSE:
38+
def vprint(*args, **kwargs):
39+
print(*args, **kwargs)
40+
else:
41+
vprint = lambda *a, **k: None # do-nothing function
42+
2843
WMS_VERSION_111 = "1.1.1"
2944
WMS_VERSION_130 = "1.3.0"
3045

@@ -146,7 +161,18 @@ def getLegendURL( style: xmltodict.OrderedDict):
146161
return legendUrl
147162

148163

149-
164+
def formatDateTime(ts:datetime):
165+
"""
166+
Formats the datetime according to D.2.1 of WMS Spec: ccyy-mm-ddThh:mm:ss.sssZ
167+
168+
A time zone suffix is mandatory if the hours field appears in the time string.
169+
All times should be expressed in Coordinated Universal Time (UTC), indicated
170+
by the suffix Z (for "zulu"). When a local time applies, a numeric time zone
171+
suffix as defined by ISO 8601:2004, 5.3.4.1 shall be used. The absence of any
172+
suffix at all means local time in an undefined zone, which shall not be
173+
used in the global network of map servers enabled by this International Standard.
174+
"""
175+
return ts.isoformat(timespec='milliseconds').replace("+00:00","Z")
150176

151177
def enumerateAvailableTimes(text:str):
152178
"""
@@ -186,7 +212,7 @@ def enumerateAvailableTimes(text:str):
186212
except:
187213
raise Exception("Error parsing the step in time definition: '{}'".format(definition))
188214
while start <= end:
189-
values.append(datetime.strftime(start, TIME_FORMAT_ISO8601))
215+
values.append( formatDateTime(start))
190216
start = start + delta
191217
#values["beginning"] = beginning
192218
#values["end"] = end
@@ -415,8 +441,11 @@ def sendGetCapabilitiesRequest(client:locustclients.HttpSession, wmsversion:str)
415441
params = getGetCapabilitiesRequest(wmsversion=wmsversion)
416442

417443
with client.request("GET", "", params=params, name="WMS-{}-GetCapabilities".format(wmsversion), catch_response=True ) as response:
444+
url = urllib.parse.unquote(response.url)
418445
if not response.status_code == 200:
419-
response.failure("Request failed with HTTP status code: '{}'\nResponse-Content: '{}'".format(response.status_code, response.content ) )
446+
errormsg = "Request failed with HTTP status code: '{}'\n Request URL: {}\n Response-Content: '{}'".format(response.status_code, url, response.content )
447+
vprint( "Request failed:\n{}".format(errormsg) )
448+
response.failure(errormsg)
420449
return
421450

422451
if not hasValidGetCapabilitiesResponseType(response.headers['content-type']):
@@ -429,6 +458,7 @@ def sendGetCapabilitiesRequest(client:locustclients.HttpSession, wmsversion:str)
429458

430459
try:
431460
capabilities = xmltodict.parse(response.content)
461+
#vprint("Request successful: {}".format(url))
432462
return capabilities
433463
except:
434464
response.failure("Failed to parse GetCapabilities XML")
@@ -437,22 +467,36 @@ def sendGetCapabilitiesRequest(client:locustclients.HttpSession, wmsversion:str)
437467
def sendGetMapRequest(client:locustclients.HttpSession, params:dict, wmsversion:str):
438468
with client.request("GET", "", params=params, name="WMS-{}-GetMap".format(wmsversion), catch_response=True ) as response:
439469
if response.status_code == 200:
470+
url = urllib.parse.unquote(response.url)
440471
if response.headers['content-type'] != "image/png":
441-
response.failure("Expected format 'image/png' but got '{}' instead\n Request params: '{}'\nResponse: '{}'\n".format(response.headers['content-type'], params, response.text) )
472+
errormsg = "Expected format 'image/png' but got '{}' instead\n Request URL: {}\n Request params: '{}'\nResponse: '{}'\n".format(response.headers['content-type'], url, params, response.text)
473+
vprint( "Request failed:\n{}".format(errormsg) )
474+
response.failure(errormsg)
442475
else:
476+
#vprint("Request successful: {}".format(url))
443477
response.success()
444478

445479

446480
def sendGetLegendGraphicRequest(client:locustclients.HttpSession, params:dict, wmsversion:str):
447-
with client.request("GET", "", params=params, name="WMS-{}-GetLegendGraphic".format(wmsversion), catch_response=True ) as response:
481+
requestUrl = ""
482+
if "url" in params:
483+
# extract request url from params
484+
requestUrl = params["url"]
485+
params.pop("url")
486+
487+
with client.request("GET", requestUrl, params=params, name="WMS-{}-GetLegendGraphic".format(wmsversion), catch_response=True ) as response:
448488
#if response.history:
449489
# #Response was redirected
450490
# for resp in response.history:
451491
# print("Redirected with code '{}' to url '{}'".format(resp.status_code,resp.url))
452492
if response.status_code == 200:
493+
url = urllib.parse.unquote(response.url)
453494
if response.headers['content-type'] != "image/png":
454-
response.failure("Expected format 'image/png' but got '{}' instead\n Request params: '{}'\nResponse: '{}'\n".format(response.headers['content-type'], params, response.text) )
495+
errormsg = "Expected format 'image/png' but got '{}' instead\n Request URL: {}\n Request params: '{}'\nResponse: '{}'\n".format(response.headers['content-type'], url, params, response.text)
496+
vprint( "Request failed:\n{}".format(errormsg) )
497+
response.failure(errormsg)
455498
else:
499+
#vprint("Request successful: {}".format(url))
456500
response.success()
457501

458502
class WebsiteTasks(TaskSet):
@@ -469,7 +513,7 @@ class WebsiteTasks(TaskSet):
469513
#def index(self):
470514
# self.client.get("/")
471515

472-
@task(1)
516+
@task(WEIGHT_GET_CAPABILITIES)
473517
def get_capa(self):
474518
wmsversion = random.choice(WMS_SUPPORTED_VERSIONS)
475519
capabilities = sendGetCapabilitiesRequest(client=self.client, wmsversion=wmsversion)
@@ -482,7 +526,7 @@ def get_capa(self):
482526
# for each WMS version
483527
self.allLayers[wmsversion] = getAllLayers(capabilities=capabilities, wmsversion=wmsversion)
484528

485-
@task(2)
529+
@task(WEIGHT_GET_LEGEND_GRAPHIC)
486530
def get_legend_graphic(self):
487531
wmsversion = random.choice(WMS_SUPPORTED_VERSIONS)
488532
if not wmsversion in self.allLayers:
@@ -495,7 +539,7 @@ def get_legend_graphic(self):
495539
if not getLegendGraphicRequest is None:
496540
sendGetLegendGraphicRequest(client=self.client, params=getLegendGraphicRequest, wmsversion=wmsversion)
497541

498-
@task(10)
542+
@task(WEIGHT_GET_MAP)
499543
def get_map(self):
500544
wmsversion = random.choice(WMS_SUPPORTED_VERSIONS)
501545
if not wmsversion in self.allLayers:

0 commit comments

Comments
 (0)