-
Notifications
You must be signed in to change notification settings - Fork 0
[MISC] Tests #26
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
Draft
dragomirp
wants to merge
6
commits into
16/edge
Choose a base branch
from
tests
base: 16/edge
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[MISC] Tests #26
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9289e61
Tests
dragomirp e3147cf
Bump snaps and test helpers
dragomirp 3eee089
Stop machine before removing
dragomirp f9e9d01
Upgrade test
dragomirp cd7f9ca
Unused envvars
dragomirp 8231132
No multiple units during upgrade
dragomirp 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| charm_major = 1 | ||
| workload = "16.13" | ||
| workload = "16.14" | ||
|
|
||
| [snap] | ||
| name = "charmed-postgresql" | ||
|
|
||
| [snap.revisions] | ||
| # amd64 | ||
| x86_64 = "332" | ||
| x86_64 = "360" | ||
| # arm64 | ||
| aarch64 = "331" | ||
| aarch64 = "359" |
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
Empty file.
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,37 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright 2022 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| import logging | ||
|
|
||
| import pytest | ||
| from tenacity import Retrying, stop_after_attempt | ||
|
|
||
| from .high_availability_helpers_new import get_app_leader | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| DB_TEST_APP_NAME = "postgresql-test-app" | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def continuous_writes(juju): | ||
| """Starts continuous writes to the MySQL cluster for a test and clear the writes at the end.""" | ||
| application_unit = get_app_leader(juju, DB_TEST_APP_NAME) | ||
|
|
||
| logger.info("Clearing continuous writes") | ||
| juju.run(unit=application_unit, action="clear-continuous-writes", wait=120).raise_on_failure() | ||
|
|
||
| logger.info("Starting continuous writes") | ||
|
|
||
| for attempt in Retrying(stop=stop_after_attempt(10), reraise=True): | ||
| with attempt: | ||
| result = juju.run(unit=application_unit, action="start-continuous-writes") | ||
| result.raise_on_failure() | ||
|
|
||
| assert result.results["result"] == "True" | ||
|
|
||
| yield | ||
|
|
||
| logger.info("Clearing continuous writes") | ||
| juju.run(unit=application_unit, action="clear-continuous-writes", wait=120).raise_on_failure() |
140 changes: 140 additions & 0 deletions
140
tests/integration/high_availability/high_availability_helpers_new.py
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,140 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright 2025 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
| from collections.abc import Callable | ||
|
|
||
| import jubilant | ||
| from jubilant import Juju | ||
| from jubilant.statustypes import Status, UnitStatus | ||
| from tenacity import Retrying, stop_after_delay, wait_fixed | ||
|
|
||
| from constants import PEER | ||
|
|
||
| from ..helpers import execute_queries_on_unit | ||
|
|
||
| MINUTE_SECS = 60 | ||
| SERVER_CONFIG_USERNAME = "operator" | ||
|
|
||
| JujuModelStatusFn = Callable[[Status], bool] | ||
| JujuAppsStatusFn = Callable[[Status, str], bool] | ||
|
|
||
|
|
||
| def check_db_units_writes_increment( | ||
| juju: Juju, | ||
| app_name: str, | ||
| app_units: list[str] | None = None, | ||
| db_name: str = "postgresql_test_app_database", | ||
| ) -> None: | ||
| """Ensure that continuous writes is incrementing on all units. | ||
|
|
||
| Also, ensure that all continuous writes up to the max written value is available | ||
| on all units (ensure that no committed data is lost). | ||
| """ | ||
| if not app_units: | ||
| app_units = get_app_units(juju, app_name) | ||
|
|
||
| app_primary = get_db_primary_unit(juju, app_name) | ||
| app_max_value = get_db_max_written_value(juju, app_name, app_primary, db_name) | ||
|
|
||
| for unit_name in app_units: | ||
| for attempt in Retrying( | ||
| reraise=True, | ||
| stop=stop_after_delay(5 * MINUTE_SECS), | ||
| wait=wait_fixed(10), | ||
| ): | ||
| with attempt: | ||
| unit_max_value = get_db_max_written_value(juju, app_name, unit_name, db_name) | ||
| assert unit_max_value > app_max_value, "Writes not incrementing" | ||
| app_max_value = unit_max_value | ||
|
|
||
|
|
||
| def get_app_leader(juju: Juju, app_name: str) -> str: | ||
| """Get the leader unit for the given application.""" | ||
| model_status = juju.status() | ||
| app_status = model_status.apps[app_name] | ||
| for name, status in app_status.units.items(): | ||
| if status.leader: | ||
| return name | ||
|
|
||
| raise Exception("No leader unit found") | ||
|
|
||
|
|
||
| def get_app_units(juju: Juju, app_name: str) -> dict[str, UnitStatus]: | ||
| """Get the units for the given application.""" | ||
| model_status = juju.status() | ||
| app_status = model_status.apps[app_name] | ||
| return app_status.units | ||
|
|
||
|
|
||
| def get_unit_ip(juju: Juju, app_name: str, unit_name: str) -> str: | ||
| """Get the application unit IP.""" | ||
| model_status = juju.status() | ||
| app_status = model_status.apps[app_name] | ||
| for name, status in app_status.units.items(): | ||
| if name == unit_name: | ||
| return status.public_address | ||
|
|
||
| raise Exception("No application unit found") | ||
|
|
||
|
|
||
| def get_db_primary_unit(juju: Juju, app_name: str) -> str: | ||
| """Get the current primary node of the cluster.""" | ||
| postgresql_primary = get_app_leader(juju, app_name) | ||
| task = juju.run(unit=postgresql_primary, action="get-primary", wait=5 * MINUTE_SECS) | ||
| task.raise_on_failure() | ||
|
|
||
| primary = task.results.get("primary") | ||
| if primary != "None": | ||
| return primary | ||
|
|
||
| raise Exception("No primary node found") | ||
|
|
||
|
|
||
| def get_db_max_written_value( | ||
| juju: Juju, app_name: str, unit_name: str, db_name: str = "postgresql_test_app_database" | ||
| ) -> int: | ||
| """Retrieve the max written value in the PostgreSQL database. | ||
|
|
||
| Args: | ||
| juju: The Juju model. | ||
| app_name: The application name. | ||
| unit_name: The unit name. | ||
| db_name: The database to connect to. | ||
| """ | ||
| password = get_user_password(juju, app_name, SERVER_CONFIG_USERNAME) | ||
|
|
||
| output = execute_queries_on_unit( | ||
| get_unit_ip(juju, app_name, unit_name), | ||
| SERVER_CONFIG_USERNAME, | ||
| password, | ||
| ["SELECT MAX(number) FROM continuous_writes;"], | ||
| db_name, | ||
| ) | ||
| return output[0] | ||
|
|
||
|
|
||
| def wait_for_apps_status(jubilant_status_func: JujuAppsStatusFn, *apps: str) -> JujuModelStatusFn: | ||
| """Waits for Juju agents to be idle, and for applications to reach a certain status. | ||
|
|
||
| Args: | ||
| jubilant_status_func: The Juju apps status function to wait for. | ||
| apps: The applications to wait for. | ||
|
|
||
| Returns: | ||
| Juju model status function. | ||
| """ | ||
| return lambda status: all(( | ||
| jubilant.all_agents_idle(status, *apps), | ||
| jubilant_status_func(status, *apps), | ||
| )) | ||
|
|
||
|
|
||
| # PG helpers | ||
|
|
||
|
|
||
| def get_user_password(juju: Juju, app_name: str, user: str) -> str | None: | ||
|
|
||
| """Get a system user's password.""" | ||
| for secret in juju.secrets(): | ||
| if secret.label == f"{PEER}.{app_name}.app": | ||
| revealed_secret = juju.show_secret(secret.uri, reveal=True) | ||
| return revealed_secret.content.get(f"{user}-password") | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.