MockSquadCast¶
- class lsst.ts.watcher.MockSquadCast(port: int = 80)¶
Bases:
objectA mock SquadCast service to support Watcher escalation in unit tests.
- Parameters:
- port
int The TCP/IP port for the service. 0 to choose a free port. The default is 80 because that is what SquadCast uses.
- port
- Raises:
RuntimeErrorIf env var
ESCALATION_KEYnot set.
Notes
To use:
async with MockSquadCast(port=...) as server: # ... use the server # Or if you prefer explicit start/stop: server = MockSquadCast(port=...) await server.start() # ... use the server await server.close()
Known limitations:
SquadCast supports having multiple incidents with the same event_id. This mock does not – it will reject creation of a new incident with a matching event ID.
SquadCast does not require the event_id field. This mock does, because it stores events by event_id.
SquadCast does not require the status field, based on tests, but the manual says nothing about it so I prefer to require it.
SquadCast does not require the “description” field when triggering an incident, but the manual says it is required. This emulates the manual.
The incidents dict is never purged, which is a memory leak, but emulates SquadCast. Thus this mock is intended for short-term unit tests, not long term emulation.
- Attributes:
- port
int The port. The port argument, except if that was 0 then this is updated to the chosen port when
startis run.- url
str The root URL of the service. “” until
starthas run.- endpoint_url
str The URL of the endpoint (including the secret API key). “” until
starthas run.- escalation_key
str The value of env var ESCALATION_KEY.
- incidents
dict[str,dict] Dict of event_id: incident data in SquadCast’s format, which has these keys:
event_id (str): unique identifier
status (str): one of “trigger” or “resolve”
message (str): summary of the problem
details (str): additional information
tags (dict[str, dict[str, str]]): a dict of tag_name: value.
These are keys that SquadCast uses. The first four are required and the mock does not check the rest of the data. Values for SquadCast “tags” can be str or dicts with a specific format, but Watcher only uses str values.
- reject_next_request
bool If the user sets this true then the mock will reject the next request with
web.HTTPInternalServerErrorand reset this flag. For unit tests.
- port
Methods Summary
close()Stop the service, if running.
incident_webhook(request)Request handler to trigger or resolve an incident.
make_app()Make an instance of the web application.
start()Start the service.
Methods Documentation
- async incident_webhook(request: Request) json_response¶
Request handler to trigger or resolve an incident.
- Parameters:
- request
aiohttp.web.Request Request.
- request
- Raises:
web.HTTPInternalServerErrorIf self.reject_next_request True.
web.HTTPRequestEntityTooLargeIf the request is too large.
- make_app() Application¶
Make an instance of the web application.
- async start() None¶
Start the service.
- Raises:
RuntimeErrorIf port = 0 and serving on more than one socket (in which case the served port cannot be determined), or if this method has already been called.