From 4a21f812a4c0b3ddb40393bb430bfed22b92c79c Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Wed, 8 Nov 2023 13:38:01 +0000 Subject: [PATCH] fix(backup): convert odoo regex extensions The backup image [accepts a regexp on `DBS_TO_INCLUDE`][1]. But [Odoo uses a regexp with custom extensions][2] (`%h` and `%d`). If you use any of those extensions, the backup jobrunner will fail with `CalledProcessError`. Additionally, regexps usually contain a `$` symbol, which [needs to be escaped for docker-compose][3]. [1]: https://github.com/Tecnativa/docker-duplicity#dbs_to_includeexclude [2]: https://www.odoo.com/documentation/16.0/developer/reference/cli.html#cmdoption-odoo-bin-db-filter [3]: https://docs.docker.com/compose/compose-file/compose-file-v2/#variable-substitution BREAKING CHANGE: if your dbfilter contained `$$` previously, to do that escaping yourself, you will have to convert it to a single `$` @moduon MT-4191 --- common.yaml.jinja | 2 +- prod.yaml.jinja | 2 +- tests/test_settings_effect.py | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/common.yaml.jinja b/common.yaml.jinja index 1004e625..76bdc577 100644 --- a/common.yaml.jinja +++ b/common.yaml.jinja @@ -92,7 +92,7 @@ services: init: true environment: DB_VERSION: "{{ postgres_version or 'latest' }}" - DBS_TO_INCLUDE: "{{ odoo_dbfilter }}" + DBS_TO_INCLUDE: "{{ odoo_dbfilter | replace('$', '$$') | replace('%d', '.*') | replace('%h', '.*') }}" DST: "{{ backup_dst }}" {%- if smtp_relay_host %} EMAIL_FROM: "{{ backup_email_from }}" diff --git a/prod.yaml.jinja b/prod.yaml.jinja index 9e61a84c..d06ad181 100644 --- a/prod.yaml.jinja +++ b/prod.yaml.jinja @@ -19,7 +19,7 @@ services: - .docker/odoo.env - .docker/db-access.env environment: - DB_FILTER: "{{ odoo_dbfilter }}" + DB_FILTER: "{{ odoo_dbfilter | replace('$', '$$') }}" DOODBA_ENVIRONMENT: "${DOODBA_ENVIRONMENT-prod}" INITIAL_LANG: "{{ odoo_initial_lang }}" {%- if smtp_relay_host %} diff --git a/tests/test_settings_effect.py b/tests/test_settings_effect.py index c7f3ddd8..93baecf1 100644 --- a/tests/test_settings_effect.py +++ b/tests/test_settings_effect.py @@ -113,3 +113,27 @@ def test_dbfilter_default( assert "DB_FILTER" not in test.services["odoo"].environment assert prod.services["odoo"].environment["DB_FILTER"] == "^prod" assert prod.services["backup"].environment["DBS_TO_INCLUDE"] == "^prod" + + +def test_dbfilter_custom_odoo_extensions( + cloned_template: Path, supported_odoo_version: float, tmp_path: Path +): + """Fixes custom Odoo regexp extensions in dbfilter for the backup service.""" + with local.cwd(tmp_path): + run_copy( + src_path=str(cloned_template), + dst_path=".", + data={ + "odoo_version": supported_odoo_version, + "postgres_version": DBVER_PER_ODOO[supported_odoo_version]["latest"], + "backup_dst": "file:///here", + "odoo_dbfilter": "^%d_%h$", + }, + vcs_ref="test", + defaults=True, + overwrite=True, + unsafe=True, + ) + prod = DockerClient(compose_files=["prod.yaml"]).compose.config() + assert prod.services["odoo"].environment["DB_FILTER"] == "^%d_%h$$" + assert prod.services["backup"].environment["DBS_TO_INCLUDE"] == "^.*_.*$$"