Repository navigation
[DPE-11496] (PART 4) CI/CD migration to single-kernel: merged common pytest-operator tests #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+6,798
−27
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ac1db5a
Added common vm and k8s with pytest
xavipg003 7fbb5ff
Added spread tests
xavipg003 a13b10b
Added charmcraft dependency
xavipg003 1133edf
Logical replication config bug fix
xavipg003 7e8ef9b
Logical replication uncommented and smoke test fix
xavipg003 6c73f91
Discourse plugin vector fix
xavipg003 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Copyright 2026 Canonical Ltd. | ||
| # See LICENSE file for licensing details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -Eeuo pipefail | ||
| find /var/lib/pg/archive -mindepth 1 -delete | ||
| find /var/lib/pg/data/16/main -mindepth 1 -delete | ||
| find /var/lib/pg/logs -mindepth 1 -delete | ||
| find /var/lib/pg/temp -mindepth 1 -delete |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -Eeuo pipefail | ||
| rm -rf /var/snap/charmed-postgresql/common/var/lib/postgresql/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright 2022 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
| from asyncio import gather | ||
|
|
||
| import pytest as pytest | ||
| from pytest_operator.plugin import OpsTest | ||
| from tenacity import Retrying, stop_after_delay, wait_fixed | ||
|
|
||
| from tests.integration.charm.ha_tests.helpers import ( | ||
| ORIGINAL_RESTART_CONDITION, | ||
| RESTART_CONDITION, | ||
| change_patroni_setting, | ||
| change_wal_settings, | ||
| deploy_chaos_mesh, | ||
| destroy_chaos_mesh, | ||
| get_patroni_setting, | ||
| get_postgresql_parameter, | ||
| modify_pebble_restart_delay, | ||
| remove_instance_isolation, | ||
| update_restart_condition, | ||
| ) | ||
| from tests.integration.charm.pytest_operator_helpers import ( | ||
| APPLICATION_NAME, | ||
| app_name, | ||
| get_password, | ||
| run_command_on_unit, | ||
| ) | ||
| from tests.integration.types import Substrate | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| async def chaos_mesh(ops_test: OpsTest, substrate: Substrate) -> None: | ||
| """Deploys chaos mesh to the namespace and uninstalls it at the end (K8s only).""" | ||
| if substrate == Substrate.vm: | ||
| yield | ||
| return | ||
|
|
||
| deploy_chaos_mesh(ops_test.model.info.name) | ||
|
|
||
| yield | ||
|
|
||
| remove_instance_isolation(ops_test) | ||
| destroy_chaos_mesh(ops_test.model.info.name) | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| async def continuous_writes(ops_test: OpsTest) -> None: | ||
| """Deploy the charm that makes continuous writes to PostgreSQL.""" | ||
| yield | ||
| # Clear the written data at the end. | ||
| for attempt in Retrying(stop=stop_after_delay(60 * 5), wait=wait_fixed(3), reraise=True): | ||
| with attempt: | ||
| action = ( | ||
| await ops_test.model | ||
| .applications[APPLICATION_NAME] | ||
| .units[0] | ||
| .run_action("clear-continuous-writes") | ||
| ) | ||
| await action.wait() | ||
| assert action.results["result"] == "True", "Unable to clear up continuous_writes table" | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| async def loop_wait(ops_test: OpsTest) -> None: | ||
| """Temporary change the loop wait configuration.""" | ||
| # Change the parameter that makes Patroni wait for some more time before restarting PostgreSQL. | ||
| initial_loop_wait = await get_patroni_setting(ops_test, "loop_wait") | ||
| yield | ||
| # Rollback to the initial configuration. | ||
| patroni_password = await get_password(ops_test, "patroni") | ||
| await change_patroni_setting( | ||
| ops_test, "loop_wait", initial_loop_wait, patroni_password, use_random_unit=True | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| async def primary_start_timeout(ops_test: OpsTest) -> None: | ||
| """Temporary change the primary start timeout configuration.""" | ||
| # Change the parameter that makes the primary reelection faster. | ||
| patroni_password = await get_password(ops_test, "patroni") | ||
| initial_primary_start_timeout = await get_patroni_setting(ops_test, "primary_start_timeout") | ||
| await change_patroni_setting(ops_test, "primary_start_timeout", 0, patroni_password) | ||
| yield | ||
| # Rollback to the initial configuration. | ||
| await change_patroni_setting( | ||
| ops_test, | ||
| "primary_start_timeout", | ||
| initial_primary_start_timeout, | ||
| patroni_password, | ||
| use_random_unit=True, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| async def reset_restart_condition(ops_test: OpsTest, substrate: Substrate): | ||
| """Resets service file delay on all units (VM only).""" | ||
| if substrate == Substrate.k8s: | ||
| yield | ||
| return | ||
|
|
||
| app = await app_name(ops_test) | ||
|
|
||
| awaits = [] | ||
| for unit in ops_test.model.applications[app].units: | ||
| awaits.append(update_restart_condition(ops_test, unit, RESTART_CONDITION)) | ||
| await gather(*awaits) | ||
|
|
||
| yield | ||
|
|
||
| awaits = [] | ||
| for unit in ops_test.model.applications[app].units: | ||
| awaits.append(update_restart_condition(ops_test, unit, ORIGINAL_RESTART_CONDITION)) | ||
| await gather(*awaits) | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| async def restart_policy(ops_test: OpsTest, substrate: Substrate) -> None: | ||
| """Sets and resets service pebble restart policy on all units (K8s only).""" | ||
| if substrate == Substrate.vm: | ||
| yield | ||
| return | ||
|
|
||
| app = await app_name(ops_test) | ||
|
|
||
| for unit in ops_test.model.applications[app].units: | ||
| await modify_pebble_restart_delay( | ||
| ops_test, | ||
| unit.name, | ||
| "tests/integration/charm/ha_tests/manifests/extend_pebble_restart_delay.yml", | ||
| ) | ||
|
|
||
| async with ops_test.fast_forward(): | ||
| await ops_test.model.wait_for_idle( | ||
| apps=[app], | ||
| status="active", | ||
| raise_on_blocked=True, | ||
| timeout=5 * 60, | ||
| idle_period=30, | ||
| ) | ||
|
|
||
| yield | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| async def wal_settings(ops_test: OpsTest, substrate: Substrate) -> None: | ||
| """Restore the WAL settings to the initial values.""" | ||
| # Get the value for each setting. | ||
| initial_max_wal_size = await get_postgresql_parameter(ops_test, "max_wal_size") | ||
| initial_min_wal_size = await get_postgresql_parameter(ops_test, "min_wal_size") | ||
| initial_wal_keep_segments = await get_postgresql_parameter(ops_test, "wal_keep_segments") | ||
| yield | ||
| app = await app_name(ops_test) | ||
| for unit in ops_test.model.applications[app].units: | ||
| if substrate == Substrate.vm: | ||
| # Start Patroni if it was previously stopped. | ||
| await run_command_on_unit(ops_test, unit.name, "snap start charmed-postgresql.patroni") | ||
| patroni_password = await get_password(ops_test, "patroni") | ||
|
|
||
| # Rollback to the initial settings. | ||
| await change_wal_settings( | ||
| ops_test, | ||
| unit.name, | ||
| initial_max_wal_size, | ||
| initial_min_wal_size, | ||
| initial_wal_keep_segments, | ||
| patroni_password, | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NB: we should stick to 9.1 until we move away from
pytest-operator.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving away from
pytest-operatorstarting on PR #431.