From 6772697ddcbeabdeeea8378f04e9fde9a80604f1 Mon Sep 17 00:00:00 2001 From: mibe Date: Tue, 30 Jul 2024 16:26:18 +0100 Subject: [PATCH 1/4] #33 Added configurable idle time for a SaaS database --- pytest-saas/doc/changes/unreleased.md | 4 ++++ pytest-saas/exasol/pytest_saas/__init__.py | 16 ++++++++++++++-- pytest-saas/test/integration/pytest_saas_test.py | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pytest-saas/doc/changes/unreleased.md b/pytest-saas/doc/changes/unreleased.md index 79e701b..41e7ecf 100644 --- a/pytest-saas/doc/changes/unreleased.md +++ b/pytest-saas/doc/changes/unreleased.md @@ -1 +1,5 @@ # Unreleased + +## Feature + +* #33: Added configurable idle time for saas-database diff --git a/pytest-saas/exasol/pytest_saas/__init__.py b/pytest-saas/exasol/pytest_saas/__init__.py index 4b788ab..bd3a5be 100644 --- a/pytest-saas/exasol/pytest_saas/__init__.py +++ b/pytest-saas/exasol/pytest_saas/__init__.py @@ -1,5 +1,5 @@ import os -from pathlib import Path +from datetime import timedelta import pytest from exasol.saas.client import openapi @@ -28,11 +28,20 @@ def pytest_addoption(parser): ) parser.addoption( "--project-short-tag", + default='2', help="""Short tag aka. "abbreviation" for your current project. See docstring in project_short_tag.py for more details. pytest plugin for exasol-saas-api will include this short tag into the names of created database instances.""", ) + parser.addoption( + "--idle-time", + help=""" + The SaaS cluster would normally stop after a certain period of inactivity. + The default period is 2 hours. For some tests, this period is too short. + Use this parameter to set a sufficient idle period in the number of hours. + """ + ) def _env(var: str) -> str: @@ -87,10 +96,13 @@ def saas_database( """ db_id = request.config.getoption("--saas-database-id") keep = request.config.getoption("--keep-saas-database") + idle_time = float(request.config.getoption("--idle-time")) + if db_id: yield api_access.get_database(db_id) return - with api_access.database(database_name, keep) as db: + with api_access.database(database_name, keep, + idle_time=timedelta(hours=idle_time)) as db: yield db diff --git a/pytest-saas/test/integration/pytest_saas_test.py b/pytest-saas/test/integration/pytest_saas_test.py index 1a69dbe..ef234fb 100644 --- a/pytest-saas/test/integration/pytest_saas_test.py +++ b/pytest-saas/test/integration/pytest_saas_test.py @@ -36,6 +36,7 @@ def _env(**kwargs): def test_no_cli_args(request): assert not request.config.getoption("--keep-saas-database") assert request.config.getoption("--saas-database-id") is None + assert reqeust.config.getoption("--idle-time") == "2" """), _cli_args(), ), @@ -45,11 +46,13 @@ def test_cli_args(request): assert request.config.getoption("--keep-saas-database") assert "123" == request.config.getoption("--saas-database-id") assert "PST" == request.config.getoption("--project-short-tag") + assert "3.5" == request.config.getoption("--idle-time") """), _cli_args( "--keep-saas-database", "--project-short-tag", "PST", "--saas-database-id", "123", + "--idle-time", "3.5" ), ), ]) From 26dc587f86b7bb0d658f91fbde85a1b545d761eb Mon Sep 17 00:00:00 2001 From: mibe Date: Tue, 30 Jul 2024 16:37:28 +0100 Subject: [PATCH 2/4] #33 Added configurable idle time for a SaaS database --- pytest-saas/exasol/pytest_saas/__init__.py | 3 ++- pytest-saas/test/integration/pytest_saas_test.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pytest-saas/exasol/pytest_saas/__init__.py b/pytest-saas/exasol/pytest_saas/__init__.py index bd3a5be..5d1ae34 100644 --- a/pytest-saas/exasol/pytest_saas/__init__.py +++ b/pytest-saas/exasol/pytest_saas/__init__.py @@ -28,7 +28,6 @@ def pytest_addoption(parser): ) parser.addoption( "--project-short-tag", - default='2', help="""Short tag aka. "abbreviation" for your current project. See docstring in project_short_tag.py for more details. pytest plugin for exasol-saas-api will include this short tag into @@ -36,6 +35,8 @@ def pytest_addoption(parser): ) parser.addoption( "--idle-time", + action="store_true", + default="2", help=""" The SaaS cluster would normally stop after a certain period of inactivity. The default period is 2 hours. For some tests, this period is too short. diff --git a/pytest-saas/test/integration/pytest_saas_test.py b/pytest-saas/test/integration/pytest_saas_test.py index ef234fb..33072d4 100644 --- a/pytest-saas/test/integration/pytest_saas_test.py +++ b/pytest-saas/test/integration/pytest_saas_test.py @@ -36,7 +36,7 @@ def _env(**kwargs): def test_no_cli_args(request): assert not request.config.getoption("--keep-saas-database") assert request.config.getoption("--saas-database-id") is None - assert reqeust.config.getoption("--idle-time") == "2" + assert request.config.getoption("--idle-time") == "2" """), _cli_args(), ), From 864c497acd814259d4de8fe6c9ef8abc470de3d5 Mon Sep 17 00:00:00 2001 From: mibe Date: Tue, 30 Jul 2024 17:12:26 +0100 Subject: [PATCH 3/4] #33 Added configurable idle time for a SaaS database --- pytest-saas/exasol/pytest_saas/__init__.py | 2 +- pytest-saas/test/integration/pytest_saas_test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest-saas/exasol/pytest_saas/__init__.py b/pytest-saas/exasol/pytest_saas/__init__.py index 5d1ae34..e638cbd 100644 --- a/pytest-saas/exasol/pytest_saas/__init__.py +++ b/pytest-saas/exasol/pytest_saas/__init__.py @@ -35,7 +35,7 @@ def pytest_addoption(parser): ) parser.addoption( "--idle-time", - action="store_true", + action="store", default="2", help=""" The SaaS cluster would normally stop after a certain period of inactivity. diff --git a/pytest-saas/test/integration/pytest_saas_test.py b/pytest-saas/test/integration/pytest_saas_test.py index 33072d4..d3033bd 100644 --- a/pytest-saas/test/integration/pytest_saas_test.py +++ b/pytest-saas/test/integration/pytest_saas_test.py @@ -52,7 +52,7 @@ def test_cli_args(request): "--keep-saas-database", "--project-short-tag", "PST", "--saas-database-id", "123", - "--idle-time", "3.5" + "--idle-time", "3.5", ), ), ]) From 36c07293bf8a204d5e7104e808579db7857de7dd Mon Sep 17 00:00:00 2001 From: mibe Date: Wed, 31 Jul 2024 12:53:10 +0100 Subject: [PATCH 4/4] #33 Changed the cli argument name --- pytest-saas/exasol/pytest_saas/__init__.py | 12 ++++++------ pytest-saas/test/integration/pytest_saas_test.py | 11 +++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pytest-saas/exasol/pytest_saas/__init__.py b/pytest-saas/exasol/pytest_saas/__init__.py index e638cbd..4f0a506 100644 --- a/pytest-saas/exasol/pytest_saas/__init__.py +++ b/pytest-saas/exasol/pytest_saas/__init__.py @@ -2,7 +2,7 @@ from datetime import timedelta import pytest -from exasol.saas.client import openapi +from exasol.saas import client as saas_client from exasol.saas.client.api_access import ( OpenApiAccess, create_saas_client, @@ -34,9 +34,9 @@ def pytest_addoption(parser): the names of created database instances.""", ) parser.addoption( - "--idle-time", + "--saas-max-idle-hours", action="store", - default="2", + default=saas_client.Limits.AUTOSTOP_DEFAULT_IDLE_TIME.total_seconds() / 3600, help=""" The SaaS cluster would normally stop after a certain period of inactivity. The default period is 2 hours. For some tests, this period is too short. @@ -90,20 +90,20 @@ def api_access(saas_host, saas_pat, saas_account_id) -> OpenApiAccess: @pytest.fixture(scope="session") def saas_database( request, api_access, database_name -) -> openapi.models.database.Database: +) -> saas_client.openapi.models.database.Database: """ Note: The SaaS instance database returned by this fixture initially will not be operational. The startup takes about 20 minutes. """ db_id = request.config.getoption("--saas-database-id") keep = request.config.getoption("--keep-saas-database") - idle_time = float(request.config.getoption("--idle-time")) + idle_hours = float(request.config.getoption("--saas-max-idle-hours")) if db_id: yield api_access.get_database(db_id) return with api_access.database(database_name, keep, - idle_time=timedelta(hours=idle_time)) as db: + idle_time=timedelta(hours=idle_hours)) as db: yield db diff --git a/pytest-saas/test/integration/pytest_saas_test.py b/pytest-saas/test/integration/pytest_saas_test.py index d3033bd..8da857e 100644 --- a/pytest-saas/test/integration/pytest_saas_test.py +++ b/pytest-saas/test/integration/pytest_saas_test.py @@ -4,6 +4,7 @@ from unittest import mock import pytest +from exasol.saas import client as saas_client pytest_plugins = "pytester" @@ -32,11 +33,13 @@ def _env(**kwargs): @pytest.mark.parametrize( "files,cli_args", [ - ( _testfile(""" + ( _testfile(f""" def test_no_cli_args(request): + import pytest assert not request.config.getoption("--keep-saas-database") assert request.config.getoption("--saas-database-id") is None - assert request.config.getoption("--idle-time") == "2" + assert float(request.config.getoption("--saas-max-idle-hours")) * 3600 == \ + pytest.approx({saas_client.Limits.AUTOSTOP_DEFAULT_IDLE_TIME.total_seconds()}) """), _cli_args(), ), @@ -46,13 +49,13 @@ def test_cli_args(request): assert request.config.getoption("--keep-saas-database") assert "123" == request.config.getoption("--saas-database-id") assert "PST" == request.config.getoption("--project-short-tag") - assert "3.5" == request.config.getoption("--idle-time") + assert "3.5" == request.config.getoption("--saas-max-idle-hours") """), _cli_args( "--keep-saas-database", "--project-short-tag", "PST", "--saas-database-id", "123", - "--idle-time", "3.5", + "--saas-max-idle-hours", "3.5", ), ), ])