forked from canonical/postgresql-k8s-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DPE-5301] Add check for low storage space on pgdata volume (canonica…
- Loading branch information
1 parent
d193317
commit 8bd0f2e
Showing
2 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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,55 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
import logging | ||
|
||
import pytest | ||
from pytest_operator.plugin import OpsTest | ||
|
||
from .helpers import ( | ||
DATABASE_APP_NAME, | ||
STORAGE_PATH, | ||
build_and_deploy, | ||
get_primary, | ||
run_command_on_unit, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
MAX_RETRIES = 20 | ||
INSUFFICIENT_SIZE_WARNING = "<10% free space on pgdata volume." | ||
|
||
|
||
@pytest.mark.group(1) | ||
@pytest.mark.abort_on_fail | ||
async def test_filling_and_emptying_pgdata_storage(ops_test: OpsTest): | ||
"""Build and deploy the charm and saturate its pgdata volume.""" | ||
# Build and deploy the PostgreSQL charm. | ||
async with ops_test.fast_forward(): | ||
await build_and_deploy(ops_test, 1) | ||
|
||
# Saturate pgdata storage with random data | ||
primary = await get_primary(ops_test, DATABASE_APP_NAME) | ||
await run_command_on_unit( | ||
ops_test, | ||
primary, | ||
f"FREE_SPACE=$(df --output=avail {STORAGE_PATH}/pgdata | tail -1) && dd if=/dev/urandom of={STORAGE_PATH}/pgdata/tmp bs=1M count=$(( (FREE_SPACE * 91 / 100) / 1024 ))", | ||
) | ||
|
||
# wait for charm to get blocked | ||
async with ops_test.fast_forward(): | ||
await ops_test.model.block_until( | ||
lambda: any( | ||
unit.workload_status == "blocked" | ||
and unit.workload_status_message == INSUFFICIENT_SIZE_WARNING | ||
for unit in ops_test.model.applications[DATABASE_APP_NAME].units | ||
), | ||
timeout=500, | ||
) | ||
|
||
# Delete big file to release storage space | ||
await run_command_on_unit(ops_test, primary, f"rm {STORAGE_PATH}/pgdata/tmp") | ||
|
||
# wait for charm to resolve | ||
await ops_test.model.wait_for_idle(apps=[DATABASE_APP_NAME], status="active", timeout=1000) |