Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 37 additions & 9 deletions tests/integration/backup_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pytest_operator.plugin import OpsTest
from tenacity import Retrying, stop_after_attempt, wait_exponential

from .architecture import architecture
from .helpers import (
DATABASE_APP_NAME,
build_and_deploy,
Expand All @@ -15,6 +16,7 @@
get_unit_address,
scale_application,
)
from .juju_ import juju_major_version

logger = logging.getLogger(__name__)

Expand All @@ -33,7 +35,41 @@ async def backup_deploy(
) -> str:
# Deploy S3 Integrator and TLS Certificates Operator.
use_tls = all([tls_certificates_app_name, tls_channel])
await ops_test.model.deploy(s3_integrator_app_name)
if juju_major_version >= 3:
revision = 308 if architecture == "amd64" else 309
await ops_test.model.deploy(
s3_integrator_app_name,
revision=revision,
channel="2/edge",
series="noble",
base="ubuntu@24.04",
)
# Configure and set access and secret keys.
logger.info(f"configuring S3 integrator for {cloud}")
rc, stdout, stderr = await ops_test.juju(
"add-secret",
"s3keys",
"access-key=" + credentials["access-key"],
"secret-key=" + credentials["secret-key"],
)
assert rc == 0, f"Failed to add secret: {stderr}"
secret_id = stdout.strip()
rc, stdout, stderr = await ops_test.juju("grant-secret", secret_id, s3_integrator_app_name)
assert rc == 0, "Failed to grant secret"
config["credentials"] = secret_id
await ops_test.model.applications[s3_integrator_app_name].set_config(config)
else:
await ops_test.model.deploy(s3_integrator_app_name)
await ops_test.model.applications[s3_integrator_app_name].set_config(config)
action = await ops_test.model.units.get(f"{s3_integrator_app_name}/0").run_action(
"sync-s3-credentials",
**credentials,
)
await action.wait()
async with ops_test.fast_forward(fast_interval="60s"):
await ops_test.model.wait_for_idle(
apps=[s3_integrator_app_name], status="active", timeout=1000, raise_on_error=False
)
if use_tls:
await ops_test.model.deploy(tls_certificates_app_name, channel=tls_channel)
# Deploy and relate PostgreSQL to S3 integrator (one database app for each cloud for now
Expand All @@ -57,14 +93,6 @@ async def backup_deploy(
)
await ops_test.model.relate(database_app_name, s3_integrator_app_name)

# Configure and set access and secret keys.
logger.info(f"configuring S3 integrator for {cloud}")
await ops_test.model.applications[s3_integrator_app_name].set_config(config)
action = await ops_test.model.units.get(f"{s3_integrator_app_name}/0").run_action(
"sync-s3-credentials",
**credentials,
)
await action.wait()
async with ops_test.fast_forward(fast_interval="60s"):
await ops_test.model.wait_for_idle(
apps=[database_app_name, s3_integrator_app_name], status="active", timeout=1000
Expand Down
67 changes: 39 additions & 28 deletions tests/integration/test_backups_gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,40 +167,50 @@ async def test_invalid_config_and_recovery_after_fixing_it(
database_app_name = f"new-{DATABASE_APP_NAME}"

# Provide invalid backup configurations.
logger.info("configuring S3 integrator for an invalid cloud")
await ops_test.model.applications[S3_INTEGRATOR_APP_NAME].set_config({
"endpoint": "endpoint",
"bucket": "bucket",
"path": "path",
"region": "region",
})
action = await ops_test.model.units.get(f"{S3_INTEGRATOR_APP_NAME}/0").run_action(
"sync-s3-credentials",
**{
"access-key": "access-key",
"secret-key": "secret-key",
},
)
await action.wait()
logger.info("waiting for the database charm to become blocked")
await wait_for_idle_on_blocked(
ops_test,
database_app_name,
0,
S3_INTEGRATOR_APP_NAME,
FAILED_TO_ACCESS_CREATE_BUCKET_ERROR_MESSAGE,
)
# logger.info("configuring S3 integrator for an invalid cloud")
# await ops_test.model.applications[S3_INTEGRATOR_APP_NAME].set_config({
# "endpoint": "endpoint",
# "bucket": "bucket",
# "path": "path",
# "region": "region",
# })
# action = await ops_test.model.units.get(f"{S3_INTEGRATOR_APP_NAME}/0").run_action(
# "sync-s3-credentials",
# **{
# "access-key": "access-key",
# "secret-key": "secret-key",
# },
# )
# await action.wait()
# logger.info("waiting for the database charm to become blocked")
# await wait_for_idle_on_blocked(
# ops_test,
# database_app_name,
# 0,
# S3_INTEGRATOR_APP_NAME,
# FAILED_TO_ACCESS_CREATE_BUCKET_ERROR_MESSAGE,
# )

# Provide valid backup configurations, but from another cluster repository.
logger.info(
"configuring S3 integrator for a valid cloud, but with the path of another cluster repository"
)
await ops_test.model.applications[S3_INTEGRATOR_APP_NAME].set_config(gcp_cloud_configs[0])
action = await ops_test.model.units.get(f"{S3_INTEGRATOR_APP_NAME}/0").run_action(
"sync-s3-credentials",
**gcp_cloud_configs[1],

updated_config = gcp_cloud_configs[0].copy()
updated_credentials = gcp_cloud_configs[1].copy()
rc, stdout, stderr = await ops_test.juju(
"add-secret",
"s3keysnew",
"access-key=" + updated_credentials["access-key"],
"secret-key=" + updated_credentials["secret-key"],
)
await action.wait()
assert rc == 0, f"Failed to add secret: {stderr}"
secret_id = stdout.strip()
rc, stdout, stderr = await ops_test.juju("grant-secret", secret_id, S3_INTEGRATOR_APP_NAME)
assert rc == 0, "Failed to grant secret"
updated_config["credentials"] = secret_id

await ops_test.model.applications[S3_INTEGRATOR_APP_NAME].set_config(updated_config)
await wait_for_idle_on_blocked(
ops_test,
database_app_name,
Expand All @@ -213,6 +223,7 @@ async def test_invalid_config_and_recovery_after_fixing_it(
logger.info("configuring S3 integrator for a valid cloud")
config = gcp_cloud_configs[0].copy()
config["path"] = f"/postgresql-k8s/{uuid.uuid1()}"
config["credentials"] = secret_id
await ops_test.model.applications[S3_INTEGRATOR_APP_NAME].set_config(config)
logger.info("waiting for the database charm to become active")
await ops_test.model.wait_for_idle(
Expand Down