mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2026-09-04 06:53:14 +00:00
Test matrix-bridge-mautrix-googlechat with Molecule
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
---
|
||||
- name: Include roles for mautrix-googlechat Molecule tests
|
||||
hosts: all
|
||||
become: true
|
||||
vars_files:
|
||||
- "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/playbook-context.yml"
|
||||
gather_facts: true
|
||||
tasks:
|
||||
- name: Include roles for mautrix-googlechat 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
|
||||
- "custom/{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
|
||||
loop_control:
|
||||
loop_var: role_name
|
||||
|
||||
- name: Ensure mautrix-googlechat 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 mautrix-googlechat systemd service is started
|
||||
ansible.builtin.systemd_service:
|
||||
name: matrix-mautrix-googlechat.service
|
||||
state: started
|
||||
@@ -0,0 +1,90 @@
|
||||
# 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: mautrix-googlechat-${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_bridge_mautrix_googlechat_container_network: mautrix-googlechat-molecule
|
||||
|
||||
# The stub is the Matrix-side boundary. The scenario carries no Google account
|
||||
# and does not attempt to log in to Google Chat.
|
||||
matrix_bridge_mautrix_googlechat_homeserver_address: http://matrix.molecule.local:8008
|
||||
matrix_bridge_mautrix_googlechat_homeserver_domain: molecule.local
|
||||
matrix_homeserver_url: http://matrix.molecule.local:8008
|
||||
|
||||
# Postgres is the normal deployment path. Non-default identifiers make its schema
|
||||
# evidence that the role composed and supplied this exact connection string.
|
||||
matrix_bridge_mautrix_googlechat_database_engine: postgres
|
||||
matrix_bridge_mautrix_googlechat_database_hostname: matrix-postgres-molecule
|
||||
matrix_bridge_mautrix_googlechat_database_name: molecule_googlechat
|
||||
matrix_bridge_mautrix_googlechat_database_username: molecule_googlechat
|
||||
matrix_bridge_mautrix_googlechat_database_password: molecule_pg_password_7c1d43
|
||||
|
||||
matrix_bridge_mautrix_googlechat_appservice_token: molecule_googlechat_as_token_96c74e
|
||||
matrix_bridge_mautrix_googlechat_homeserver_token: molecule_googlechat_hs_token_51a2d8
|
||||
|
||||
# These differ from role/component defaults so parsed assertions prove rendering.
|
||||
matrix_bridge_mautrix_googlechat_appservice_bot_username: molecule-googlechatbot
|
||||
matrix_bridge_mautrix_googlechat_command_prefix: "!molecule-googlechat"
|
||||
matrix_bridge_mautrix_googlechat_logging_level: INFO
|
||||
matrix_bridge_mautrix_googlechat_federate_rooms: false
|
||||
matrix_bridge_mautrix_googlechat_login_shared_secret: molecule_googlechat_login_secret_6832f1
|
||||
matrix_bridge_mautrix_googlechat_metrics_enabled: true
|
||||
|
||||
# Traefik is not started; these values exercise role-rendered routing labels.
|
||||
matrix_bridge_mautrix_googlechat_public_endpoint: /molecule-googlechat
|
||||
matrix_bridge_mautrix_googlechat_container_labels_public_endpoint_hostname: googlechat.molecule.local
|
||||
matrix_bridge_mautrix_googlechat_container_labels_public_endpoint_path_prefix: /molecule-googlechat
|
||||
matrix_bridge_mautrix_googlechat_container_labels_public_endpoint_traefik_entrypoints: web
|
||||
matrix_bridge_mautrix_googlechat_container_labels_metrics_enabled: true
|
||||
matrix_bridge_mautrix_googlechat_metrics_proxying_hostname: metrics.molecule.local
|
||||
matrix_bridge_mautrix_googlechat_metrics_proxying_path_prefix: /metrics/googlechat
|
||||
matrix_bridge_mautrix_googlechat_container_labels_metrics_traefik_entrypoints: web
|
||||
matrix_bridge_mautrix_googlechat_container_labels_additional_labels: |
|
||||
molecule.googlechat.coverage=enabled
|
||||
|
||||
# verify.yml is a separate play, where role defaults are out of scope.
|
||||
matrix_bridge_mautrix_googlechat_base_path: /matrix/mautrix-googlechat
|
||||
matrix_bridge_mautrix_googlechat_config_path: /matrix/mautrix-googlechat/config
|
||||
matrix_bridge_mautrix_googlechat_data_path: /matrix/mautrix-googlechat/data
|
||||
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
|
||||
@@ -0,0 +1,86 @@
|
||||
# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
---
|
||||
- name: Prepare mautrix-googlechat Molecule tests
|
||||
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"
|
||||
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
|
||||
|
||||
- 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"
|
||||
|
||||
- name: Ensure the container network the role attaches to exists
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- docker
|
||||
- network
|
||||
- create
|
||||
- "{{ matrix_bridge_mautrix_googlechat_container_network }}"
|
||||
register: mautrix_googlechat_molecule_network
|
||||
changed_when: mautrix_googlechat_molecule_network.rc == 0
|
||||
failed_when:
|
||||
- mautrix_googlechat_molecule_network.rc != 0
|
||||
- "'already exists' not in mautrix_googlechat_molecule_network.stderr"
|
||||
|
||||
- name: Ensure Postgres is running
|
||||
ansible.builtin.include_tasks:
|
||||
file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/tasks/postgres.yml"
|
||||
vars:
|
||||
molecule_shared_postgres_network: "{{ matrix_bridge_mautrix_googlechat_container_network }}"
|
||||
molecule_shared_postgres_database: "{{ matrix_bridge_mautrix_googlechat_database_name }}"
|
||||
molecule_shared_postgres_username: "{{ matrix_bridge_mautrix_googlechat_database_username }}"
|
||||
molecule_shared_postgres_password: "{{ matrix_bridge_mautrix_googlechat_database_password }}"
|
||||
|
||||
# The bridge verifies the appservice bot before opening its listener.
|
||||
- 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_bridge_mautrix_googlechat_container_network }}"
|
||||
molecule_shared_stub_server_name: "{{ matrix_bridge_mautrix_googlechat_homeserver_domain }}"
|
||||
molecule_shared_stub_user_id: "@{{ matrix_bridge_mautrix_googlechat_appservice_bot_username }}:{{ matrix_bridge_mautrix_googlechat_homeserver_domain }}"
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../../../molecule-shared/requirements.yml
|
||||
@@ -0,0 +1,344 @@
|
||||
# SPDX-FileCopyrightText: 2026 Slavi Pantaleev
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
---
|
||||
# Proves the old Python bridge accepts the role-rendered configuration, completes its
|
||||
# Matrix-side startup, migrates real Postgres and exposes its appservice and metrics.
|
||||
- name: Verify mautrix-googlechat
|
||||
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:
|
||||
mautrix_googlechat_config: "{{ mautrix_googlechat_config_file.content | b64decode | from_yaml }}"
|
||||
mautrix_googlechat_registration: "{{ mautrix_googlechat_registration_file.content | b64decode | from_yaml }}"
|
||||
mautrix_googlechat_labels_rendered: "{{ mautrix_googlechat_labels_file.content | b64decode }}"
|
||||
gather_facts: false
|
||||
tasks:
|
||||
# Read the version from the role so a Renovate bump changes the expected image.
|
||||
- name: Load the role's defaults under a separate name
|
||||
ansible.builtin.include_vars:
|
||||
file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/main.yml"
|
||||
name: mautrix_googlechat_role_defaults
|
||||
|
||||
- name: Wait for the mautrix-googlechat service to become active
|
||||
ansible.builtin.systemd_service:
|
||||
name: matrix-mautrix-googlechat.service
|
||||
register: mautrix_googlechat_service
|
||||
until: mautrix_googlechat_service.status.ActiveState == 'active'
|
||||
retries: 30
|
||||
delay: 5
|
||||
failed_when: false
|
||||
|
||||
- name: Assert the service is active and has not been restarting
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_service.status.ActiveState == 'active'
|
||||
- mautrix_googlechat_service.status.NRestarts is defined
|
||||
- mautrix_googlechat_service.status.NRestarts | int == 0
|
||||
fail_msg: >-
|
||||
matrix-mautrix-googlechat.service is
|
||||
{{ mautrix_googlechat_service.status.ActiveState | default('unknown') }} after
|
||||
{{ mautrix_googlechat_service.status.NRestarts | default('?') }} restart(s)
|
||||
success_msg: "matrix-mautrix-googlechat.service is active and has not restarted"
|
||||
|
||||
- name: Wait for the bridge liveness endpoint
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- docker
|
||||
- run
|
||||
- --rm
|
||||
- --network={{ matrix_bridge_mautrix_googlechat_container_network }}
|
||||
- "{{ molecule_shared_image_curl }}"
|
||||
- --silent
|
||||
- --output
|
||||
- /dev/null
|
||||
- --write-out
|
||||
- "HTTP_STATUS=%{http_code}"
|
||||
- http://matrix-mautrix-googlechat:8080/_matrix/mau/live
|
||||
register: mautrix_googlechat_live
|
||||
changed_when: false
|
||||
until: mautrix_googlechat_live.rc == 0 and mautrix_googlechat_live.stdout == 'HTTP_STATUS=200'
|
||||
retries: 24
|
||||
delay: 5
|
||||
failed_when: false
|
||||
|
||||
- name: Wait for the bridge readiness endpoint
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- docker
|
||||
- run
|
||||
- --rm
|
||||
- --network={{ matrix_bridge_mautrix_googlechat_container_network }}
|
||||
- "{{ molecule_shared_image_curl }}"
|
||||
- --silent
|
||||
- --output
|
||||
- /dev/null
|
||||
- --write-out
|
||||
- "HTTP_STATUS=%{http_code}"
|
||||
- http://matrix-mautrix-googlechat:8080/_matrix/mau/ready
|
||||
register: mautrix_googlechat_ready
|
||||
changed_when: false
|
||||
until: mautrix_googlechat_ready.rc == 0 and mautrix_googlechat_ready.stdout == 'HTTP_STATUS=200'
|
||||
retries: 24
|
||||
delay: 5
|
||||
failed_when: false
|
||||
|
||||
- name: Assert the bridge is live and ready on its appservice listener
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_live.rc == 0
|
||||
- mautrix_googlechat_live.stdout == 'HTTP_STATUS=200'
|
||||
- mautrix_googlechat_ready.rc == 0
|
||||
- mautrix_googlechat_ready.stdout == 'HTTP_STATUS=200'
|
||||
fail_msg: >-
|
||||
Health probes returned live={{ mautrix_googlechat_live.stdout | default('none') }} and
|
||||
ready={{ mautrix_googlechat_ready.stdout | default('none') }}
|
||||
success_msg: "The bridge is live and ready on its appservice listener"
|
||||
|
||||
- name: Query the enabled metrics listener
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- docker
|
||||
- run
|
||||
- --rm
|
||||
- --network={{ matrix_bridge_mautrix_googlechat_container_network }}
|
||||
- "{{ molecule_shared_image_curl }}"
|
||||
- --silent
|
||||
- --show-error
|
||||
- --fail
|
||||
- http://matrix-mautrix-googlechat:8000/metrics
|
||||
register: mautrix_googlechat_metrics
|
||||
changed_when: false
|
||||
|
||||
- name: Assert the live metrics surface comes from the running Python bridge
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_metrics.rc == 0
|
||||
- "'# HELP python_gc_objects_collected_total' in mautrix_googlechat_metrics.stdout"
|
||||
- "'# HELP process_start_time_seconds' in mautrix_googlechat_metrics.stdout"
|
||||
- "'# HELP python_info' in mautrix_googlechat_metrics.stdout"
|
||||
fail_msg: "The enabled metrics listener did not expose the Python process metrics"
|
||||
success_msg: "The enabled metrics listener exposes the Python process metrics"
|
||||
|
||||
- name: Read the configuration the role rendered
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ matrix_bridge_mautrix_googlechat_config_path }}/config.yaml"
|
||||
register: mautrix_googlechat_config_file
|
||||
|
||||
- name: Assert the rendered configuration carries the appservice identity
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_config.homeserver.address == matrix_bridge_mautrix_googlechat_homeserver_address
|
||||
- mautrix_googlechat_config.homeserver.domain == matrix_bridge_mautrix_googlechat_homeserver_domain
|
||||
- mautrix_googlechat_config.appservice.id == 'googlechat'
|
||||
- mautrix_googlechat_config.appservice.address == 'http://matrix-mautrix-googlechat:8080'
|
||||
- mautrix_googlechat_config.appservice.bot_username == matrix_bridge_mautrix_googlechat_appservice_bot_username
|
||||
- mautrix_googlechat_config.appservice.as_token == matrix_bridge_mautrix_googlechat_appservice_token
|
||||
- mautrix_googlechat_config.appservice.hs_token == matrix_bridge_mautrix_googlechat_homeserver_token
|
||||
fail_msg: "The rendered configuration does not carry the scenario's appservice identity"
|
||||
success_msg: "The rendered configuration carries the scenario's appservice identity"
|
||||
|
||||
- name: Assert the rendered configuration carries non-default bridge behavior
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_config.bridge.command_prefix == matrix_bridge_mautrix_googlechat_command_prefix
|
||||
- not mautrix_googlechat_config.bridge.federate_rooms
|
||||
- mautrix_googlechat_config.bridge.login_shared_secret == matrix_bridge_mautrix_googlechat_login_shared_secret
|
||||
- mautrix_googlechat_config.bridge.web.auth.public == 'http://matrix.molecule.local:8008/molecule-googlechat/login'
|
||||
- mautrix_googlechat_config.bridge.web.auth.prefix == '/molecule-googlechat/login'
|
||||
- mautrix_googlechat_config.metrics.enabled
|
||||
- mautrix_googlechat_config.logging.root.level == matrix_bridge_mautrix_googlechat_logging_level
|
||||
fail_msg: "The rendered configuration does not carry the scenario's bridge behavior"
|
||||
success_msg: "The rendered configuration carries the scenario's bridge behavior"
|
||||
|
||||
- name: Assert the configuration points at the scenario's Postgres database
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_config.appservice.database is string
|
||||
- mautrix_googlechat_config.appservice.database is match('^postgres://')
|
||||
- matrix_bridge_mautrix_googlechat_database_username in mautrix_googlechat_config.appservice.database
|
||||
- matrix_bridge_mautrix_googlechat_database_hostname in mautrix_googlechat_config.appservice.database
|
||||
- matrix_bridge_mautrix_googlechat_database_name in mautrix_googlechat_config.appservice.database
|
||||
fail_msg: >-
|
||||
appservice.database is {{ mautrix_googlechat_config.appservice.database | default('unset') }},
|
||||
which was not composed from the scenario's Postgres settings
|
||||
success_msg: "The configuration points at the scenario's Postgres database"
|
||||
|
||||
- name: Read the appservice registration the role rendered
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ matrix_bridge_mautrix_googlechat_config_path }}/registration.yaml"
|
||||
register: mautrix_googlechat_registration_file
|
||||
|
||||
- name: Assert the registration carries the configured handshake values
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_registration.id == 'googlechat'
|
||||
- mautrix_googlechat_registration.as_token == matrix_bridge_mautrix_googlechat_appservice_token
|
||||
- mautrix_googlechat_registration.hs_token == matrix_bridge_mautrix_googlechat_homeserver_token
|
||||
- mautrix_googlechat_registration.sender_localpart == '_bot_' + matrix_bridge_mautrix_googlechat_appservice_bot_username
|
||||
- mautrix_googlechat_registration.url == 'http://matrix-mautrix-googlechat:8080'
|
||||
fail_msg: "The registration does not carry the configured handshake values"
|
||||
success_msg: "The registration carries the configured handshake values"
|
||||
|
||||
- name: Assert the registration namespaces cover only Google Chat ghosts and the bot
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_ghost_regex | length > 0
|
||||
- mautrix_googlechat_bot_regex | length > 0
|
||||
- mautrix_googlechat_ghost_mxid is match(mautrix_googlechat_ghost_regex)
|
||||
- mautrix_googlechat_wrong_ghost_mxid is not match(mautrix_googlechat_ghost_regex)
|
||||
- mautrix_googlechat_bot_mxid is match(mautrix_googlechat_bot_regex)
|
||||
fail_msg: "The registration namespaces do not cover only Google Chat ghosts and the bot"
|
||||
success_msg: "The registration namespaces cover only Google Chat ghosts and the bot"
|
||||
vars:
|
||||
mautrix_googlechat_user_regexes: "{{ mautrix_googlechat_registration.namespaces.users | map(attribute='regex') | list }}"
|
||||
mautrix_googlechat_ghost_regex: "{{ mautrix_googlechat_user_regexes | select('search', 'googlechat_') | first | default('') }}"
|
||||
mautrix_googlechat_bot_regex: "{{ mautrix_googlechat_user_regexes | reject('search', 'googlechat_') | first | default('') }}"
|
||||
mautrix_googlechat_ghost_mxid: "@googlechat_123456:{{ matrix_bridge_mautrix_googlechat_homeserver_domain }}"
|
||||
mautrix_googlechat_wrong_ghost_mxid: "@gvoice_123456:{{ matrix_bridge_mautrix_googlechat_homeserver_domain }}"
|
||||
mautrix_googlechat_bot_mxid: "@{{ matrix_bridge_mautrix_googlechat_appservice_bot_username }}:{{ matrix_bridge_mautrix_googlechat_homeserver_domain }}"
|
||||
|
||||
- name: List the tables the bridge created in Postgres
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- docker
|
||||
- exec
|
||||
- matrix-postgres-molecule
|
||||
- psql
|
||||
- --username={{ matrix_bridge_mautrix_googlechat_database_username }}
|
||||
- --dbname={{ matrix_bridge_mautrix_googlechat_database_name }}
|
||||
- --tuples-only
|
||||
- --no-align
|
||||
- "--command=SELECT tablename FROM pg_tables WHERE schemaname = 'public'"
|
||||
register: mautrix_googlechat_tables
|
||||
changed_when: false
|
||||
|
||||
- name: Assert the bridge migrated its schema into the configured database
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_tables.rc == 0
|
||||
- "'version' in mautrix_googlechat_table_names"
|
||||
- "'portal' in mautrix_googlechat_table_names"
|
||||
- "'puppet' in mautrix_googlechat_table_names"
|
||||
- "'message' in mautrix_googlechat_table_names"
|
||||
- "'mx_version' in mautrix_googlechat_table_names"
|
||||
- mautrix_googlechat_table_names | length >= 10
|
||||
fail_msg: >-
|
||||
The bridge did not migrate its schema into {{ matrix_bridge_mautrix_googlechat_database_name }}
|
||||
(found {{ mautrix_googlechat_table_names | length }} table(s))
|
||||
success_msg: "The bridge migrated its schema into the configured database"
|
||||
vars:
|
||||
mautrix_googlechat_table_names: "{{ mautrix_googlechat_tables.stdout_lines | select | list }}"
|
||||
|
||||
- name: Read the labels the role rendered
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ matrix_bridge_mautrix_googlechat_base_path }}/labels"
|
||||
register: mautrix_googlechat_labels_file
|
||||
|
||||
- name: Assert the labels route both HTTP surfaces to their configured ports
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'traefik.enable=true' in mautrix_googlechat_labels_rendered"
|
||||
- "'traefik.docker.network=' + matrix_bridge_mautrix_googlechat_container_network in mautrix_googlechat_labels_rendered"
|
||||
- "'traefik.http.services.matrix-mautrix-googlechat-public.loadbalancer.server.port=8080' in mautrix_googlechat_labels_rendered"
|
||||
- "'traefik.http.routers.matrix-mautrix-googlechat-public.rule=Host(`googlechat.molecule.local`) && PathPrefix(`/molecule-googlechat`)' in mautrix_googlechat_labels_rendered"
|
||||
- "'traefik.http.services.matrix-mautrix-googlechat-metrics.loadbalancer.server.port=8000' in mautrix_googlechat_labels_rendered"
|
||||
- "'traefik.http.routers.matrix-mautrix-googlechat-metrics.rule=Host(`metrics.molecule.local`) && PathPrefix(`/metrics/googlechat`)' in mautrix_googlechat_labels_rendered"
|
||||
- "'molecule.googlechat.coverage=enabled' in mautrix_googlechat_labels_rendered"
|
||||
fail_msg: "The rendered labels do not carry both HTTP routing contracts"
|
||||
success_msg: "The rendered labels carry both HTTP routing contracts"
|
||||
|
||||
- name: Inspect the running bridge container
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- docker
|
||||
- container
|
||||
- inspect
|
||||
- matrix-mautrix-googlechat
|
||||
register: mautrix_googlechat_container_inspect
|
||||
changed_when: false
|
||||
|
||||
- name: Parse the running bridge container inspection
|
||||
ansible.builtin.set_fact:
|
||||
mautrix_googlechat_container: "{{ (mautrix_googlechat_container_inspect.stdout | from_json) | first }}"
|
||||
|
||||
- name: Assert the running container uses the exact image pinned by the role
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_container.Config.Image == mautrix_googlechat_expected_image
|
||||
fail_msg: >-
|
||||
The running container uses {{ mautrix_googlechat_container.Config.Image }}, expected
|
||||
{{ mautrix_googlechat_expected_image }}
|
||||
success_msg: "The running container uses the exact image pinned by the role"
|
||||
vars:
|
||||
mautrix_googlechat_expected_image: >-
|
||||
{{ mautrix_googlechat_role_defaults.matrix_bridge_mautrix_googlechat_container_image_registry_prefix_upstream_default }}mautrix/googlechat:{{ mautrix_googlechat_role_defaults.matrix_bridge_mautrix_googlechat_version }}
|
||||
|
||||
- name: Assert the running container uses the playbook-supplied runtime
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_container.Config.User == (matrix_user_uid | string) + ':' + (matrix_user_gid | string)
|
||||
- mautrix_googlechat_container.Config.WorkingDir == '/opt/mautrix-googlechat'
|
||||
- mautrix_googlechat_container.Config.Cmd == ['python3', '-m', 'mautrix_googlechat', '-c', '/config/config.yaml', '--no-update']
|
||||
- mautrix_googlechat_container.HostConfig.RestartPolicy.Name == 'no'
|
||||
- mautrix_googlechat_container.HostConfig.AutoRemove
|
||||
- mautrix_googlechat_container.HostConfig.LogConfig.Type == 'none'
|
||||
fail_msg: "The running container does not use the role's exact identity, command and workdir"
|
||||
success_msg: "The running container uses the role's exact identity, command and workdir"
|
||||
|
||||
- name: Assert the running container has the intended privilege isolation
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'ALL' in mautrix_googlechat_container.HostConfig.CapDrop"
|
||||
- not mautrix_googlechat_container.HostConfig.Privileged
|
||||
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 running container carries the role's two bind mounts
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_config_mount | length > 0
|
||||
- mautrix_googlechat_config_mount.Source == matrix_bridge_mautrix_googlechat_config_path
|
||||
- not mautrix_googlechat_config_mount.RW
|
||||
- mautrix_googlechat_data_mount | length > 0
|
||||
- mautrix_googlechat_data_mount.Source == matrix_bridge_mautrix_googlechat_data_path
|
||||
- mautrix_googlechat_data_mount.RW
|
||||
- mautrix_googlechat_container.Mounts | length == 2
|
||||
fail_msg: "The running container does not carry the role's exact config and data mounts"
|
||||
success_msg: "The running container carries its read-only config and writable data mounts"
|
||||
vars:
|
||||
mautrix_googlechat_config_mount: >-
|
||||
{{ mautrix_googlechat_container.Mounts
|
||||
| selectattr('Destination', 'equalto', '/config')
|
||||
| first | default({}) }}
|
||||
mautrix_googlechat_data_mount: >-
|
||||
{{ mautrix_googlechat_container.Mounts
|
||||
| selectattr('Destination', 'equalto', '/data')
|
||||
| first | default({}) }}
|
||||
|
||||
- name: Assert the rendered labels are attached to the running container
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_container.Config.Labels['traefik.enable'] == 'true'
|
||||
- mautrix_googlechat_container.Config.Labels['traefik.docker.network'] == matrix_bridge_mautrix_googlechat_container_network
|
||||
- mautrix_googlechat_container.Config.Labels['traefik.http.services.matrix-mautrix-googlechat-public.loadbalancer.server.port'] == '8080'
|
||||
- mautrix_googlechat_container.Config.Labels['traefik.http.services.matrix-mautrix-googlechat-metrics.loadbalancer.server.port'] == '8000'
|
||||
- mautrix_googlechat_container.Config.Labels['molecule.googlechat.coverage'] == 'enabled'
|
||||
fail_msg: "The running container does not carry the labels the role rendered"
|
||||
success_msg: "The running container carries the labels the role rendered"
|
||||
|
||||
- name: Assert the running container has the exact network and port exposure
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- mautrix_googlechat_container.HostConfig.NetworkMode == matrix_bridge_mautrix_googlechat_container_network
|
||||
- matrix_bridge_mautrix_googlechat_container_network in mautrix_googlechat_container.NetworkSettings.Networks
|
||||
- mautrix_googlechat_container.NetworkSettings.Networks | length == 1
|
||||
- mautrix_googlechat_container.HostConfig.PortBindings | default({}, true) | length == 0
|
||||
fail_msg: >-
|
||||
The container has unexpected networks or host ports:
|
||||
networks={{ mautrix_googlechat_container.NetworkSettings.Networks.keys() | list }},
|
||||
ports={{ mautrix_googlechat_container.HostConfig.PortBindings | default({}) }}
|
||||
success_msg: "The container uses only its dedicated network and publishes no host ports"
|
||||
Reference in New Issue
Block a user