소스 검색

Test matrix-element-call with Molecule

pull/5555/merge
Slavi Pantaleev 1 일 전
부모
커밋
9dc72e45a8
6개의 변경된 파일497개의 추가작업 그리고 0개의 파일을 삭제
  1. +2
    -0
      .github/renovate.json
  2. +41
    -0
      roles/custom/matrix-element-call/molecule/default/converge.yml
  3. +79
    -0
      roles/custom/matrix-element-call/molecule/default/molecule.yml
  4. +56
    -0
      roles/custom/matrix-element-call/molecule/default/prepare.yml
  5. +1
    -0
      roles/custom/matrix-element-call/molecule/default/requirements.yml
  6. +318
    -0
      roles/custom/matrix-element-call/molecule/default/verify.yml

+ 2
- 0
.github/renovate.json 파일 보기

@@ -150,6 +150,7 @@
"roles/custom/matrix-client-element/defaults/main.yml",
"roles/custom/matrix-client-fluffychat/defaults/main.yml",
"roles/custom/matrix-element-admin/defaults/main.yml",
"roles/custom/matrix-element-call/defaults/main.yml",
"roles/custom/matrix-ketesa/defaults/main.yml",
"roles/custom/matrix-livekit-jwt-service/defaults/main.yml",
"roles/custom/matrix-static-files/defaults/main.yml",
@@ -178,6 +179,7 @@
"roles/custom/matrix-bridge-steam/defaults/main.yml",
"roles/custom/matrix-client-fluffychat/defaults/main.yml",
"roles/custom/matrix-element-admin/defaults/main.yml",
"roles/custom/matrix-element-call/defaults/main.yml",
"roles/custom/matrix-livekit-jwt-service/defaults/main.yml",
"roles/custom/matrix-static-files/defaults/main.yml",
"roles/custom/matrix-synapse-auto-compressor/defaults/main.yml"


+ 41
- 0
roles/custom/matrix-element-call/molecule/default/converge.yml 파일 보기

@@ -0,0 +1,41 @@
# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
#
# SPDX-License-Identifier: AGPL-3.0-or-later

---
- name: Include roles for matrix-element-call Molecule tests
hosts: all
become: true
vars_files:
- "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/playbook-context.yml"
gather_facts: true
tasks:
- name: Include base roles for matrix-element-call Molecule tests
ansible.builtin.include_role:
name: "{{ role_name }}"
public: true
loop:
- com.devture.ansible.role.playbook_help
- com.devture.ansible.role.systemd_docker_base
loop_control:
loop_var: role_name

- name: Include matrix-element-call
ansible.builtin.include_role:
name: "custom/{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
public: true

# The role installs the unit; the full playbook's systemd service manager starts it.
- name: Ensure matrix-element-call is started
hosts: all
become: true
gather_facts: false
tasks:
- name: Ensure systemd daemon is reloaded
ansible.builtin.systemd_service:
daemon_reload: true

- name: Ensure the matrix-element-call systemd service is started
ansible.builtin.systemd_service:
name: matrix-element-call.service
state: started

+ 79
- 0
roles/custom/matrix-element-call/molecule/default/molecule.yml 파일 보기

@@ -0,0 +1,79 @@
# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
#
# SPDX-License-Identifier: AGPL-3.0-or-later

---
dependency:
name: galaxy
options:
requirements-file: requirements.yml
force: true
driver:
name: docker
platforms:
- name: matrix-element-call-${MOLECULE_DISTRO:-ubuntu2604}-default
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2604}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
provisioner:
name: ansible
config_options:
defaults:
callback_result_format: yaml
inventory:
group_vars:
all:
matrix_element_call_enabled: true
matrix_element_call_architecture: amd64

# Keep the role's files away from its matrix_base_data_path-derived default,
# proving that both the renderer and the systemd unit honor this contract.
matrix_element_call_base_path: /matrix/molecule-element-call

matrix_element_call_container_network: matrix-element-call-molecule

# Both values differ from the role and application defaults. The live
# /config.json response proves they reached the browser application.
matrix_element_call_config_default_server_config_m_homeserver_base_url: https://homeserver.call.molecule.local
matrix_element_call_config_default_server_config_m_homeserver_server_name: call-molecule.local
matrix_element_call_config_livekit_livekit_service_url: https://livekit-jwt.call.molecule.local

# Exercise the generated public routing and response-header labels.
matrix_element_call_hostname: call.molecule.local
matrix_element_call_container_labels_traefik_enabled: true
matrix_element_call_container_labels_traefik_priority: 827
matrix_element_call_container_labels_traefik_entrypoints: web
matrix_element_call_container_labels_traefik_tls: false
matrix_element_call_http_header_xss_protection: "0"
matrix_element_call_http_header_content_type_options: molecule-nosniff
matrix_element_call_http_header_content_security_policy: "frame-ancestors https://embed.call.molecule.local"
matrix_element_call_http_header_content_permission_policy: "camera=(self), microphone=(self)"
matrix_element_call_container_labels_additional_labels: |
molecule.element-call.coverage=enabled

# Make the generic Docker-argument escape hatch observable.
matrix_element_call_container_extra_arguments:
- --hostname=element-call-molecule-runtime
- --label=molecule.element-call.extra-argument=reached
env:
# Workaround for https://github.com/ansible/molecule/issues/4391
ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/../..:/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:${ANSIBLE_HOME:-~/.ansible}/roles
scenario:
test_sequence:
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
- idempotence
- verify
- cleanup
- destroy
verifier:
name: ansible

+ 56
- 0
roles/custom/matrix-element-call/molecule/default/prepare.yml 파일 보기

@@ -0,0 +1,56 @@
# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
#
# SPDX-License-Identifier: AGPL-3.0-or-later

---
- name: Prepare matrix-element-call Molecule tests
hosts: all
become: true
vars_files:
- "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/playbook-context.yml"
gather_facts: true
tasks:
- name: Ensure apt cache is updated
ansible.builtin.apt:
update_cache: true
cache_valid_time: 600
when: ansible_facts['os_family'] == 'Debian'

- name: Ensure required packages are installed
ansible.builtin.package:
name:
- python3-requests
- fuse-overlayfs
state: present

- name: Ensure Docker is installed
ansible.builtin.include_role:
name: ansible-role-docker
vars:
docker_daemon_options:
storage-driver: fuse-overlayfs

# matrix-base creates this identity in a full deployment. The role's file tasks
# resolve owner and group by name, so the role-scoped test provides it directly.
- name: Ensure the matrix group exists
ansible.builtin.group:
name: "{{ matrix_group_name }}"
gid: "{{ matrix_user_gid }}"
state: present

- name: Ensure the matrix user exists
ansible.builtin.user:
name: "{{ matrix_user_name }}"
uid: "{{ matrix_user_uid }}"
group: "{{ matrix_group_name }}"
create_home: false
system: true
state: present

- name: Ensure the base data path exists
ansible.builtin.file:
path: "{{ matrix_base_data_path }}"
state: directory
owner: "{{ matrix_user_name }}"
group: "{{ matrix_group_name }}"
mode: "0750"

+ 1
- 0
roles/custom/matrix-element-call/molecule/default/requirements.yml 파일 보기

@@ -0,0 +1 @@
../../../../../molecule-shared/requirements.yml

+ 318
- 0
roles/custom/matrix-element-call/molecule/default/verify.yml 파일 보기

@@ -0,0 +1,318 @@
# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
#
# SPDX-License-Identifier: AGPL-3.0-or-later

---
# Element Call is a static browser application. Its live JSON configuration and
# a browser bundle are the weight-bearing probes; no Matrix or LiveKit account is needed.
- name: Verify matrix-element-call
hosts: all
become: true
vars_files:
- "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/vars.yml"
- "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/playbook-context.yml"
vars:
matrix_element_call_root_body: "{{ matrix_element_call_root_http.stdout_lines[:-1] | join('\n') }}"
matrix_element_call_runtime: "{{ (matrix_element_call_container_inspect.stdout | from_json) | first }}"
gather_facts: false

tasks:
# A Renovate bump changes this source of truth and therefore the image expectation.
- name: Load the role's defaults under a separate name
ansible.builtin.include_vars:
file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/main.yml"
name: matrix_element_call_role_defaults

- name: Wait for the matrix-element-call service to become active
ansible.builtin.systemd_service:
name: matrix-element-call.service
register: matrix_element_call_service
until: matrix_element_call_service.status.ActiveState == 'active'
retries: 30
delay: 5
failed_when: false

# Restart=always makes ActiveState insufficient for detecting a crash loop.
- name: Assert the service is active and has not restarted
ansible.builtin.assert:
that:
- matrix_element_call_service.status.ActiveState == 'active'
- matrix_element_call_service.status.NRestarts is defined
- matrix_element_call_service.status.NRestarts | int == 0
fail_msg: >-
matrix-element-call.service is
{{ matrix_element_call_service.status.ActiveState | default('unknown') }} after
{{ matrix_element_call_service.status.NRestarts | default('?') }} restart(s)
success_msg: "matrix-element-call.service is active and has not restarted"

# Probe through the private container network, matching the deployment path from Traefik.
- name: Wait for Element Call to serve its application root
ansible.builtin.command:
argv:
- docker
- run
- --rm
- --network={{ matrix_element_call_container_network }}
- "{{ molecule_shared_image_curl }}"
- --silent
- --show-error
- --write-out
- "\nHTTP_STATUS=%{http_code}"
- http://matrix-element-call:8080/
register: matrix_element_call_root_http
changed_when: false
until: "'HTTP_STATUS=200' in matrix_element_call_root_http.stdout"
retries: 24
delay: 5
failed_when: false

- name: Assert the application root is real Element Call HTML
ansible.builtin.assert:
that:
- matrix_element_call_root_http.rc == 0
- matrix_element_call_root_http.stdout_lines[-1] == 'HTTP_STATUS=200'
- matrix_element_call_root_body | trim | length > 500
- "'<!doctype html' in matrix_element_call_root_body | lower"
- "'element call' in matrix_element_call_root_body | lower"
fail_msg: "Element Call did not return its real application HTML over the container network"
success_msg: "Element Call serves its real application root over HTTP"

- name: Fetch Element Call's live browser configuration
ansible.builtin.command:
argv:
- docker
- run
- --rm
- --network={{ matrix_element_call_container_network }}
- "{{ molecule_shared_image_curl }}"
- --silent
- --show-error
- --write-out
- "\nHTTP_STATUS=%{http_code}\nCONTENT_TYPE=%{content_type}"
- http://matrix-element-call:8080/config.json
register: matrix_element_call_config_http
changed_when: false
failed_when: false

- name: Assert the live browser configuration is served as JSON
ansible.builtin.assert:
that:
- matrix_element_call_config_http.rc == 0
- "'HTTP_STATUS=200' in matrix_element_call_config_http.stdout_lines"
- matrix_element_call_config_http.stdout | regex_search('(?m)^CONTENT_TYPE=application/json(?:;|$)') is not none
fail_msg: "Element Call did not serve its live browser configuration as JSON"
success_msg: "Element Call serves its live browser configuration as JSON"

- name: Parse the live browser configuration
ansible.builtin.set_fact:
matrix_element_call_live_config: >-
{{ matrix_element_call_config_http.stdout | regex_replace('\nHTTP_STATUS=[0-9]+\nCONTENT_TYPE=.*$', '') | from_json }}

- name: Assert the live configuration carries the configured homeserver and LiveKit service
ansible.builtin.assert:
that:
- matrix_element_call_live_config is mapping
- matrix_element_call_live_config.default_server_config['m.homeserver'].base_url == matrix_element_call_config_default_server_config_m_homeserver_base_url
- matrix_element_call_live_config.default_server_config['m.homeserver'].server_name == matrix_element_call_config_default_server_config_m_homeserver_server_name
- matrix_element_call_live_config.livekit.livekit_service_url == matrix_element_call_config_livekit_livekit_service_url
fail_msg: "The live config.json does not carry the non-default values rendered by the role"
success_msg: "The live config.json carries the configured homeserver and LiveKit service"

- name: Read the configuration file the role rendered
ansible.builtin.slurp:
src: "{{ matrix_element_call_base_path }}/config.json"
register: matrix_element_call_rendered_config_file

- name: Assert the served and rendered structured configurations are identical
ansible.builtin.assert:
that:
- matrix_element_call_rendered_config == matrix_element_call_live_config
fail_msg: "The live configuration differs from the parsed file the role rendered"
success_msg: "The running service exposes the exact structured configuration the role rendered"
vars:
matrix_element_call_rendered_config: >-
{{ matrix_element_call_rendered_config_file.content | b64decode | from_json }}

# Fetch a browser bundle named by the live HTML, proving the image contains the application.
- name: Extract a live Element Call JavaScript asset path
ansible.builtin.set_fact:
matrix_element_call_application_asset_path: >-
{{ matrix_element_call_root_body | regex_search('(?<=src=")[^"]+[.]js(?=")') }}

- name: Fetch the live Element Call application asset
ansible.builtin.command:
argv:
- docker
- run
- --rm
- --network={{ matrix_element_call_container_network }}
- "{{ molecule_shared_image_curl }}"
- --silent
- --show-error
- --output
- /dev/null
- --write-out
- "HTTP_STATUS=%{http_code}\nCONTENT_TYPE=%{content_type}\nSIZE=%{size_download}"
- "http://matrix-element-call:8080/{{ matrix_element_call_application_asset_path | regex_replace('^/', '') }}"
register: matrix_element_call_asset_http
changed_when: false
failed_when: false

- name: Assert a real Element Call application asset is served
ansible.builtin.assert:
that:
- matrix_element_call_application_asset_path | length > 0
- matrix_element_call_asset_http.rc == 0
- "'HTTP_STATUS=200' in matrix_element_call_asset_http.stdout_lines"
- matrix_element_call_asset_http.stdout | regex_search('(?m)^CONTENT_TYPE=(?:application|text)/javascript(?:;|$)') is not none
- matrix_element_call_asset_http.stdout | regex_search('(?m)^SIZE=([1-9][0-9]{4,})$') is not none
fail_msg: "Element Call did not serve the substantial JavaScript asset referenced by its live HTML"
success_msg: "Element Call serves a substantial live application asset"

- name: Read the labels file the role rendered
ansible.builtin.slurp:
src: "{{ matrix_element_call_base_path }}/labels"
register: matrix_element_call_labels_file

- name: Initialize the parsed labels
ansible.builtin.set_fact:
matrix_element_call_labels_parsed: {}

- name: Parse the rendered labels
ansible.builtin.set_fact:
matrix_element_call_labels_parsed: >-
{{ matrix_element_call_labels_parsed | combine({item.split('=', 1)[0]: item.split('=', 1)[1]}) }}
loop: "{{ (matrix_element_call_labels_file.content | b64decode).splitlines() | reject('equalto', '') }}"
when: "'=' in item"
no_log: true

- name: Assert the rendered labels carry the public routing contract
ansible.builtin.assert:
that:
- matrix_element_call_labels_parsed['traefik.enable'] == 'true'
- matrix_element_call_labels_parsed['traefik.docker.network'] == matrix_element_call_container_network
- matrix_element_call_labels_parsed['traefik.http.services.matrix-element-call.loadbalancer.server.port'] == '8080'
- matrix_element_call_labels_parsed['traefik.http.routers.matrix-element-call.rule'] == 'Host(`call.molecule.local`)'
- matrix_element_call_labels_parsed['traefik.http.routers.matrix-element-call.priority'] == '827'
- matrix_element_call_labels_parsed['traefik.http.routers.matrix-element-call.entrypoints'] == 'web'
- matrix_element_call_labels_parsed['traefik.http.routers.matrix-element-call.tls'] == 'false'
- matrix_element_call_labels_parsed['traefik.http.routers.matrix-element-call.middlewares'] == 'matrix-element-call-add-headers'
- matrix_element_call_labels_parsed['molecule.element-call.coverage'] == 'enabled'
fail_msg: "The parsed labels do not carry the scenario's routing contract"
success_msg: "The parsed labels carry the scenario's routing contract"

- name: Assert the rendered labels carry the configured response headers
ansible.builtin.assert:
that:
- matrix_element_call_labels_parsed['traefik.http.middlewares.matrix-element-call-add-headers.headers.customresponseheaders.X-XSS-Protection'] == '0'
- matrix_element_call_labels_parsed['traefik.http.middlewares.matrix-element-call-add-headers.headers.customresponseheaders.X-Content-Type-Options'] == 'molecule-nosniff'
- matrix_element_call_labels_parsed['traefik.http.middlewares.matrix-element-call-add-headers.headers.customresponseheaders.Content-Security-Policy'] == 'frame-ancestors https://embed.call.molecule.local'
- matrix_element_call_labels_parsed['traefik.http.middlewares.matrix-element-call-add-headers.headers.customresponseheaders.Permission-Policy'] == 'camera=(self), microphone=(self)'
- "'traefik.http.middlewares.matrix-element-call-add-headers.headers.customresponseheaders.Strict-Transport-Security' not in matrix_element_call_labels_parsed"
fail_msg: "The parsed labels lost response headers or incorrectly enable HSTS without TLS"
success_msg: "The parsed labels carry the configured response-header contract"

- name: Inspect the running Element Call container
ansible.builtin.command:
argv:
- docker
- container
- inspect
- matrix-element-call
register: matrix_element_call_container_inspect
changed_when: false

- name: Assert the running container uses the exact image pinned by the role
ansible.builtin.assert:
that:
- matrix_element_call_runtime.Config.Image == matrix_element_call_expected_image
fail_msg: >-
The running container uses {{ matrix_element_call_runtime.Config.Image }}, expected
{{ matrix_element_call_expected_image }}
success_msg: "The running container uses the exact image pinned by the role"
vars:
matrix_element_call_expected_image: >-
{{ matrix_element_call_role_defaults.matrix_element_call_container_image_registry_prefix_upstream_default }}element-hq/element-call:{{ matrix_element_call_role_defaults.matrix_element_call_version }}

- name: Assert the running container uses the playbook-supplied runtime
ansible.builtin.assert:
that:
- matrix_element_call_runtime.Config.User == (matrix_user_uid | string) ~ ':' ~ (matrix_user_gid | string)
- matrix_element_call_runtime.HostConfig.RestartPolicy.Name == 'no'
- matrix_element_call_runtime.HostConfig.AutoRemove is sameas true
- matrix_element_call_runtime.HostConfig.LogConfig.Type == 'none'
fail_msg: "The running container does not use the role's identity and Docker lifecycle contract"
success_msg: "The running container uses the role's identity and Docker lifecycle contract"

- name: Assert the running container has the intended privilege isolation
ansible.builtin.assert:
that:
- matrix_element_call_runtime.HostConfig.Privileged is sameas false
- matrix_element_call_runtime.HostConfig.CapAdd | default([], true) | length == 0
- matrix_element_call_runtime.HostConfig.CapDrop == ['ALL']
fail_msg: "The running container does not have the intended privilege isolation"
success_msg: "The running container drops all capabilities and is unprivileged"

- name: Assert the role's configuration is the sole read-only bind mount
ansible.builtin.assert:
that:
- matrix_element_call_runtime.Mounts | length == 1
- matrix_element_call_runtime.Mounts[0].Type == 'bind'
- matrix_element_call_runtime.Mounts[0].Source == matrix_element_call_base_path ~ '/config.json'
- matrix_element_call_runtime.Mounts[0].Destination == '/app/config.json'
- matrix_element_call_runtime.Mounts[0].RW is sameas false
fail_msg: "The role-rendered config.json is not the container's sole read-only bind mount"
success_msg: "The role-rendered config.json is mounted read-only at the image's live path"

- name: Assert the rendered and extra labels reached the running container
ansible.builtin.assert:
that:
- matrix_element_call_runtime.Config.Labels['traefik.enable'] == 'true'
- matrix_element_call_runtime.Config.Labels['traefik.docker.network'] == matrix_element_call_container_network
- matrix_element_call_runtime.Config.Labels['traefik.http.services.matrix-element-call.loadbalancer.server.port'] == '8080'
- matrix_element_call_runtime.Config.Labels['traefik.http.routers.matrix-element-call.priority'] == '827'
- matrix_element_call_runtime.Config.Labels['molecule.element-call.coverage'] == 'enabled'
- matrix_element_call_runtime.Config.Labels['molecule.element-call.extra-argument'] == 'reached'
fail_msg: "The running container does not carry the labels the role rendered and passed"
success_msg: "The configured labels reached the running container"

- name: Assert the running container is attached only to its dedicated network
ansible.builtin.assert:
that:
- matrix_element_call_runtime.HostConfig.NetworkMode == matrix_element_call_container_network
- matrix_element_call_runtime.NetworkSettings.Networks is mapping
- matrix_element_call_runtime.NetworkSettings.Networks | length == 1
- matrix_element_call_container_network in matrix_element_call_runtime.NetworkSettings.Networks
fail_msg: >-
Element Call has unexpected network attachments:
{{ matrix_element_call_runtime.NetworkSettings.Networks.keys() | list }}
success_msg: "The running container is attached only to its dedicated network"

- name: Assert the observable extra runtime argument reached Docker
ansible.builtin.assert:
that:
- matrix_element_call_runtime.Config.Hostname == 'element-call-molecule-runtime'
fail_msg: "The configured container hostname extra argument did not reach Docker"
success_msg: "The configured container extra argument reached Docker"

- name: Ask Docker for Element Call's published ports
ansible.builtin.command:
argv:
- docker
- container
- port
- matrix-element-call
register: matrix_element_call_published_ports
changed_when: false
failed_when: false

- name: Assert the role publishes no host ports
ansible.builtin.assert:
that:
- matrix_element_call_runtime.HostConfig.PortBindings | default({}, true) | length == 0
- matrix_element_call_published_ports.rc == 0
- matrix_element_call_published_ports.stdout | trim | length == 0
fail_msg: >-
Element Call unexpectedly publishes a host port:
{{ matrix_element_call_published_ports.stdout | default('unknown') }}
success_msg: "The role leaves Element Call's HTTP port unpublished"

불러오는 중...
취소
저장