Commit 1a2b1504 authored by Jérome Perrin's avatar Jérome Perrin

slaps.request: don't fetch schema for frontend software release

The frontend software URL is a virtual URL that does not have a
corresponding schema, so fetching the schema is just a waste of time.

Generally speaking, fetching the schema impact performance a lot, so it
would be nice to cache them. In practice most of the requests made
during instantiation are frontend request, so this is a first easy step
to fix the performance impact of fetching the schema.
parent 35a1ecde
Pipeline #24680 failed with stage
in 0 seconds
......@@ -4,6 +4,7 @@ Changes
1.8.4 (unreleased)
------------------
* service list, service info: output json
* request: don't fetch schema for frontend software release, speeding up slapos node instance
1.8.3 (2022-10-17)
------------------
......
......@@ -87,15 +87,24 @@ class SlapRequester(SlapDocument):
"""
Abstract class that allow to factor method for subclasses that use "request()"
"""
def _validateRequestParameters(self, software_release, software_type, parameter_dict):
"""Validate requests parameters.
def _requestComputerPartition(self, request_dict):
Default behavior is to fetch schema and warn using `warnings.warn` in case
of problems, with a special case for the magic git.erp5.org used as an alias
for frontend software release that does not have a software.cfg.json
"""
if software_release in (
# no corresponding schema
'http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg',
):
return
try:
SoftwareReleaseSchema(
request_dict['software_release'],
request_dict['software_type']
).validateInstanceParameterDict(
loads(request_dict['partition_parameter_xml']))
software_release,
software_type,
).validateInstanceParameterDict(parameter_dict)
except jsonschema.ValidationError as e:
warnings.warn(
"Request parameters do not validate against schema definition:\n{e}".format(e=e),
......@@ -115,6 +124,12 @@ class SlapRequester(SlapDocument):
UserWarning,
)
def _requestComputerPartition(self, request_dict):
self._validateRequestParameters(
request_dict['software_release'],
request_dict['software_type'],
loads(request_dict['partition_parameter_xml']),
)
try:
xml = self._connection_helper.POST('requestComputerPartition', data=request_dict)
except ResourceNotReady:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment