def test_doodba_main_domain_label(cloned_template: Path, tmp_path: Path): """Make sure the doodba.domain.main label is correct.""" copy( str(cloned_template), str(tmp_path), vcs_ref="test", force=True, data={ "domains_prod": [ { "hosts": ["not0.prod.example.com", "not1.prod.example.com"], "redirect_to": "yes.prod.example.com", }, { "hosts": ["not3.prod.example.com", "not4.prod.example.com"], "path_prefixes": ["/insecure/"], "entrypoints": ["web-insecure"], }, { "hosts": ["yes.prod.example.com", "not5.prod.example.com"] }, ], "domains_test": [ { "hosts": ["not0.test.example.com", "not1.test.example.com"], "redirect_to": "yes.test.example.com", }, { "hosts": ["not3.test.example.com", "not4.test.example.com"], "path_prefixes": ["/insecure/"], "entrypoints": ["web-insecure"], }, { "hosts": ["yes.test.example.com", "not5.test.example.com"] }, ], }, ) with local.cwd(tmp_path): prod_config = yaml.load(docker_compose("-f", "prod.yaml", "config")) test_config = yaml.load(docker_compose("-f", "test.yaml", "config")) assert (prod_config["services"]["odoo"]["labels"]["doodba.domain.main"] == "yes.prod.example.com") assert (test_config["services"]["odoo"]["labels"]["doodba.domain.main"] == "yes.test.example.com") # These labels must be present to avoid that Traefik 1 builds its own # main domain assumption and tries to download its Let's Encrypt certs, # which would possibly fail and hit LE's rate limits # TODO Remove asserts when dropping Traefik 1 support assert (prod_config["services"]["odoo"]["labels"]["traefik.domain"] == "yes.prod.example.com") assert (test_config["services"]["odoo"]["labels"]["traefik.domain"] == "yes.test.example.com")
def test_cidr_whitelist_rules( tmp_path: Path, cloned_template: Path, supported_odoo_version: float ): """Make sure CIDR whitelist redirections are good for Traefik.""" copy( str(cloned_template), str(tmp_path), vcs_ref="HEAD", force=True, data={ "odoo_version": supported_odoo_version, "project_name": "test-cidr-whitelist", "cidr_whitelist": ["123.123.123.123/24", "456.456.456.456"], "domains_prod": [{"hosts": ["www.example.com"]}], "domains_test": [{"hosts": ["demo.example.com"]}], }, ) # TODO Use Traefik to test this, instead of asserting labels key = ("test-cidr-whitelist-%.1f" % supported_odoo_version).replace(".", "-") with local.cwd(tmp_path): git("add", "prod.yaml", "test.yaml") pre_commit("run", "-a", retcode=None) prod = yaml.safe_load(docker_compose("-f", "prod.yaml", "config")) test = yaml.safe_load(docker_compose("-f", "test.yaml", "config")) # Assert prod.yaml assert ( prod["services"]["odoo"]["labels"][ f"traefik.http.middlewares.{key}-prod-whitelist.IPWhiteList.sourceRange" ] == "123.123.123.123/24, 456.456.456.456" ) assert f"{key}-prod-whitelist" in prod["services"]["odoo"]["labels"][ f"traefik.http.routers.{key}-prod-main-0.middlewares" ].split(", ") assert f"{key}-prod-whitelist" in prod["services"]["odoo"]["labels"][ f"traefik.http.routers.{key}-prod-longpolling-0.middlewares" ].split(", ") assert f"{key}-prod-whitelist" in prod["services"]["odoo"]["labels"][ f"traefik.http.routers.{key}-prod-forbiddenCrawlers-0.middlewares" ].split(", ") # Assert test.yaml assert ( test["services"]["smtp"]["labels"][ f"traefik.http.middlewares.{key}-test-whitelist.IPWhiteList.sourceRange" ] == "123.123.123.123/24, 456.456.456.456" ) assert f"{key}-test-whitelist" in test["services"]["odoo"]["labels"][ f"traefik.http.routers.{key}-test-forbiddenCrawlers-0.middlewares" ].split(", ") assert f"{key}-test-whitelist" in test["services"]["odoo"]["labels"][ f"traefik.http.routers.{key}-test-longpolling-0.middlewares" ].split(", ") assert f"{key}-test-whitelist" in test["services"]["smtp"]["labels"][ f"traefik.http.routers.{key}-test-mailhog-0.middlewares" ].split(", ")
def test_doodba_main_domain_label(cloned_template: Path, tmp_path: Path): """Make sure the doodba.domain.main label is correct.""" copy( str(cloned_template), str(tmp_path), vcs_ref="test", force=True, data={ "domains_prod": [ { "hosts": ["not0.prod.example.com", "not1.prod.example.com"], "redirect_to": "yes.prod.example.com", }, { "hosts": ["not3.prod.example.com", "not4.prod.example.com"], "path_prefixes": ["/insecure/"], "entrypoints": ["web-insecure"], }, { "hosts": ["yes.prod.example.com", "not5.prod.example.com"] }, ], "domains_test": [ { "hosts": ["not0.test.example.com", "not1.test.example.com"], "redirect_to": "yes.test.example.com", }, { "hosts": ["not3.test.example.com", "not4.test.example.com"], "path_prefixes": ["/insecure/"], "entrypoints": ["web-insecure"], }, { "hosts": ["yes.test.example.com", "not5.test.example.com"] }, ], }, ) with local.cwd(tmp_path): prod_config = yaml.load(docker_compose("-f", "prod.yaml", "config")) test_config = yaml.load(docker_compose("-f", "test.yaml", "config")) assert (prod_config["services"]["odoo"]["labels"]["doodba.domain.main"] == "yes.prod.example.com") assert (test_config["services"]["odoo"]["labels"]["doodba.domain.main"] == "yes.test.example.com")
def test_backup_config( backup_deletion: bool, backup_dst: Union[None, str], cloned_template: Path, smtp_relay_host: Union[None, str], supported_odoo_version: float, tmp_path: Path, ): """Test that backup deletion setting is respected.""" data = { "backup_deletion": backup_deletion, "backup_dst": backup_dst, "odoo_version": supported_odoo_version, "smtp_relay_host": smtp_relay_host, } # Remove parameter if False, to test this is the properly default value if not backup_deletion: del data["backup_deletion"] with local.cwd(tmp_path): copy( src_path=str(cloned_template), dst_path=".", vcs_ref="test", force=True, data=data, ) prod = yaml.safe_load(docker_compose("-f", "prod.yaml", "config")) # Check backup service existence if not backup_dst: assert "backup" not in prod["services"] return # Check selected duplicity image if backup_dst == "s3://example": assert prod["services"]["backup"][ "image"] == "tecnativa/duplicity:postgres-s3" else: assert prod["services"]["backup"][ "image"] == "tecnativa/duplicity:postgres" # Check SMTP configuration if smtp_relay_host: assert "smtp" in prod["services"] assert prod["services"]["backup"]["environment"][ "SMTP_HOST"] == "smtplocal" assert "EMAIL_FROM" in prod["services"]["backup"]["environment"] assert "EMAIL_TO" in prod["services"]["backup"]["environment"] else: assert "smtp" not in prod["services"] assert "SMTP_HOST" not in prod["services"]["backup"]["environment"] assert "EMAIL_FROM" not in prod["services"]["backup"]["environment"] assert "EMAIL_TO" not in prod["services"]["backup"]["environment"] # Check backup deletion if backup_deletion: assert (prod["services"]["backup"]["environment"]["JOB_800_WHAT"] == "dup --force remove-older-than 3M $$DST") assert prod["services"]["backup"]["environment"][ "JOB_800_WHEN"] == "weekly" else: assert "JOB_800_WHAT" not in prod["services"]["backup"]["environment"] assert "JOB_800_WHEN" not in prod["services"]["backup"]["environment"]
def _install_status(module, dbname="devel"): return docker_compose( "run", "--rm", "-e", "LOG_LEVEL=WARNING", "-e", f"PGDATABASE={dbname}", "odoo", "psql", "-tc", f"select state from ir_module_module where name='{module}'", ).strip()
def _get_config_param(key, dbname="devel"): return (docker_compose( "run", "--rm", "-e", "LOG_LEVEL=WARNING", "-e", f"PGDATABASE={dbname}", "odoo", "psql", "-tc", f"select value from ir_config_parameter where key='{key}'", ).strip() or False)
def test_start( cloned_template: Path, docker: LocalCommand, supported_odoo_version: float, tmp_path: Path, ): """Test the start task. On this test flow, other downsream tasks are also tested: - img-build - git-aggregate - stop --purge """ try: with local.cwd(tmp_path): copy( src_path=str(cloned_template), vcs_ref="HEAD", force=True, data={"odoo_version": supported_odoo_version}, ) # Imagine the user is in the src subfolder for these tasks with local.cwd(tmp_path / "odoo" / "custom" / "src"): invoke("img-build") invoke("git-aggregate") # Test normal call stdout = invoke("start") print(stdout) assert "Reinitialized existing Git repository" in stdout assert "pre-commit installed" in stdout # Test "--debugpy and wait time call invoke("stop") stdout = invoke("start", "--debugpy") assert socket_is_open("127.0.0.1", int(supported_odoo_version) * 1000 + 899) # Check if auto-reload is disabled container_logs = docker_compose("logs", "odoo") assert "dev=reload" not in container_logs finally: # Imagine the user is in the odoo subrepo for this command with local.cwd(tmp_path / "odoo" / "custom" / "src" / "odoo"): invoke("stop", "--purge")
def test_dbfilter_default(cloned_template: Path, supported_odoo_version: float, tmp_path: Path): """Default DB filter inherits database name and is applied to prod only.""" with local.cwd(tmp_path): copy( src_path=str(cloned_template), dst_path=".", vcs_ref="test", force=True, data={ "odoo_version": supported_odoo_version, "backup_dst": "file:///here" }, ) devel, test, prod = map( lambda env: yaml.safe_load( docker_compose("-f", f"{env}.yaml", "config")), ("devel", "test", "prod"), ) assert "DB_FILTER" not in devel["services"]["odoo"]["environment"] 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 _containers_running(exec_path): with local.cwd(exec_path): if len(docker_compose("ps", "-aq").splitlines()) > 0: _logger.error(docker_compose("ps", "-a")) return True return False
def _docker_compose(self, *args) -> str: return cmd.docker_compose( "-f", self.test_state.artifacts / "gen" / "scion-dc.yml", "-p", "scion", *args)
def __call__(self, *args, **kwargs) -> str: """Runs docker compose with the given arguments""" with redirect_stderr(sys.stdout): return cmd.docker_compose("-f", self.compose_file, "-p", self.project, "--no-ansi", *args, **kwargs)
def _docker_compose(self, *args) -> str: with local.env(LOGNAME=os.environ['USER']): return docker_compose( '-f', self.test_state.artifacts / 'gen' / 'scion-dc.yml', '-p', 'scion', *args)
def __call__(self, *args, **kwargs) -> str: """Runs docker compose with the given arguments""" with local.env(BASE_DIR=self.base_dir, COMPOSE_FILE=self.compose_file): with redirect_stderr(sys.stdout): return docker_compose('-p', 'acceptance_scion', '--no-ansi', *args, **kwargs)