mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2026-09-17 13:20:12 +00:00
Share the Molecule homeserver stub between scenarios
Components here contact a homeserver while starting up and exit if it is
unreachable, so nearly every scenario will need one. Standing up a real
Synapse per role would dominate the run and drag in Postgres, and these
scenarios are not testing Synapse.
The stub answers the handful of endpoints components touch during startup
with the blandest plausible response, and is deliberately permissive: an
unrecognised path returns {} rather than 404, because the goal is to get the
component past its startup checks. It is not an authentication check or a
room state machine, and a scenario should not assert *about* it - if one
starts needing it to behave like a real homeserver, that scenario has
outgrown what these tests are for.
matrix-alertmanager-receiver now includes it instead of carrying its own
inline copy. Verified green afterwards.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
efe204829f
commit
81a0ee3d53
@@ -70,59 +70,12 @@
|
||||
- "'already exists' not in matrix_alertmanager_receiver_molecule_network.stderr"
|
||||
|
||||
# matrix-alertmanager-receiver contacts the homeserver while starting up -
|
||||
# it fetches /_matrix/client/v3/joined_rooms to resolve its room mapping -
|
||||
# and exits 1 if that fails. So a homeserver has to exist for the service
|
||||
# to come up at all. A stub is enough: the scenario is testing this role,
|
||||
# not Synapse, and it keeps the run offline and fast.
|
||||
- name: Ensure the Matrix homeserver stub script exists
|
||||
ansible.builtin.copy:
|
||||
dest: /root/matrix-homeserver-stub.py
|
||||
mode: "0755"
|
||||
content: |
|
||||
import json
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
ROOMS = {"joined_rooms": ["{{ matrix_alertmanager_receiver_config_matrix_room_mapping['molecule-room'] }}"]}
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def _send(self, payload):
|
||||
body = json.dumps(payload).encode()
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def do_GET(self):
|
||||
if self.path.endswith("/joined_rooms"):
|
||||
self._send(ROOMS)
|
||||
else:
|
||||
self._send({})
|
||||
|
||||
def do_POST(self):
|
||||
self._send({"event_id": "$molecule-event-id"})
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
HTTPServer(("0.0.0.0", 8008), Handler).serve_forever()
|
||||
|
||||
- name: Ensure the Matrix homeserver stub is running on the role's network
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- docker
|
||||
- run
|
||||
- --detach
|
||||
- --rm
|
||||
- --name=matrix-homeserver-stub
|
||||
- --network={{ matrix_alertmanager_receiver_container_network }}
|
||||
- --network-alias=matrix.molecule.local
|
||||
- --volume=/root/matrix-homeserver-stub.py:/stub.py:ro
|
||||
- "{{ molecule_shared_image_python }}"
|
||||
- python3
|
||||
- /stub.py
|
||||
register: matrix_alertmanager_receiver_molecule_stub
|
||||
changed_when: matrix_alertmanager_receiver_molecule_stub.rc == 0
|
||||
failed_when:
|
||||
- matrix_alertmanager_receiver_molecule_stub.rc != 0
|
||||
- "'already in use' not in matrix_alertmanager_receiver_molecule_stub.stderr"
|
||||
# it fetches /_matrix/client/v3/joined_rooms to resolve its room mapping and
|
||||
# exits 1 if that fails - so a homeserver has to exist for it to come up at
|
||||
# all. The shared stub is enough; see molecule-shared/homeserver-stub.py.
|
||||
- name: Ensure the homeserver stub is running
|
||||
ansible.builtin.include_tasks:
|
||||
file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/tasks/homeserver-stub.yml"
|
||||
vars:
|
||||
molecule_shared_stub_network: "{{ matrix_alertmanager_receiver_container_network }}"
|
||||
molecule_shared_stub_joined_rooms: "{{ matrix_alertmanager_receiver_config_matrix_room_mapping.values() | list }}"
|
||||
|
||||
Reference in New Issue
Block a user