Skip to content

Commit

Permalink
Revert backup changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp committed Nov 10, 2023
1 parent 817c2fc commit e196f69
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
"AWS_ACCESS_KEY": "${{ secrets.AWS_ACCESS_KEY }}",
"AWS_SECRET_KEY": "${{ secrets.AWS_SECRET_KEY }}",
"GCP_ACCESS_KEY": "${{ secrets.GCP_ACCESS_KEY }}",
"GCP_SECRET_KEY": "${{ secrets.GCP_SECRET_KEY }}"
"GCP_SECRET_KEY": "${{ secrets.GCP_SECRET_KEY }}",
}
integration-test-juju2:
Expand All @@ -82,5 +82,5 @@ jobs:
"AWS_ACCESS_KEY": "${{ secrets.AWS_ACCESS_KEY }}",
"AWS_SECRET_KEY": "${{ secrets.AWS_SECRET_KEY }}",
"GCP_ACCESS_KEY": "${{ secrets.GCP_ACCESS_KEY }}",
"GCP_SECRET_KEY": "${{ secrets.GCP_SECRET_KEY }}"
"GCP_SECRET_KEY": "${{ secrets.GCP_SECRET_KEY }}",
}
18 changes: 17 additions & 1 deletion poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ optional = true

[tool.poetry.group.integration.dependencies]
pytest = "^7.4.0"
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v5.1.2", subdirectory = "python/pytest_plugins/github_secrets"}
pytest-operator = "^0.29.0"
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v5.1.2", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v5.1.2", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
Expand Down
43 changes: 16 additions & 27 deletions tests/integration/test_backups.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env python3
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
import json
import logging
import os
import uuid
from typing import Dict, Tuple

Expand All @@ -12,7 +10,7 @@
from pytest_operator.plugin import OpsTest
from tenacity import Retrying, stop_after_attempt, wait_exponential

from .helpers import (
from tests.integration.helpers import (
CHARM_SERIES,
DATABASE_APP_NAME,
construct_endpoint,
Expand All @@ -38,9 +36,8 @@


@pytest.fixture(scope="module")
async def cloud_configs(ops_test: OpsTest) -> None:
async def cloud_configs(ops_test: OpsTest, github_secrets) -> None:
# Define some configurations and credentials.
secrets = json.loads(os.environ.get("SECRETS_FROM_GITHUB", "{}"))
configs = {
AWS: {
"endpoint": "https://s3.amazonaws.com",
Expand All @@ -57,19 +54,17 @@ async def cloud_configs(ops_test: OpsTest) -> None:
}
credentials = {
AWS: {
"access-key": secrets.get("AWS_ACCESS_KEY"),
"secret-key": secrets.get("AWS_SECRET_KEY"),
"access-key": github_secrets["AWS_ACCESS_KEY"],
"secret-key": github_secrets["AWS_SECRET_KEY"],
},
GCP: {
"access-key": secrets.get("GCP_ACCESS_KEY"),
"secret-key": secrets.get("GCP_SECRET_KEY"),
"access-key": github_secrets["GCP_ACCESS_KEY"],
"secret-key": github_secrets["GCP_SECRET_KEY"],
},
}
yield configs, credentials
# Delete the previously created objects.
for cloud, config in configs.items():
if not credentials[cloud].get("secret-key"):
continue
session = boto3.session.Session(
aws_access_key_id=credentials[cloud]["access-key"],
aws_secret_access_key=credentials[cloud]["secret-key"],
Expand All @@ -84,7 +79,12 @@ async def cloud_configs(ops_test: OpsTest) -> None:
bucket_object.delete()


@pytest.mark.group(1)
async def test_none() -> None:
"""Empty test so that the suite will not fail if all tests are skippedi."""
pass


@pytest.mark.uses_secrets
@pytest.mark.abort_on_fail
async def test_backup(ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict]) -> None:
"""Build and deploy two units of PostgreSQL and then test the backup and restore actions."""
Expand All @@ -97,11 +97,6 @@ async def test_backup(ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict]) -> No
await ops_test.model.deploy(TLS_CERTIFICATES_APP_NAME, config=config, channel="legacy/stable")

for cloud, config in cloud_configs[0].items():
# Check if credentials are available
if not cloud_configs[1][cloud]["secret-key"]:
logger.warning(f"Skipping tests for {cloud}. No credentials provided")
continue

# Deploy and relate PostgreSQL to S3 integrator (one database app for each cloud for now
# as archive_mode is disabled after restoring the backup) and to TLS Certificates Operator
# (to be able to create backups from replicas).
Expand All @@ -125,7 +120,7 @@ async def test_backup(ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict]) -> No
)
await action.wait()
await ops_test.model.wait_for_idle(
apps=[database_app_name, S3_INTEGRATOR_APP_NAME], status="active", timeout=1500
apps=[database_app_name, S3_INTEGRATOR_APP_NAME], status="active", timeout=1000
)

primary = await get_primary(ops_test, f"{database_app_name}/0")
Expand Down Expand Up @@ -227,12 +222,9 @@ async def test_backup(ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict]) -> No
await ops_test.model.remove_application(TLS_CERTIFICATES_APP_NAME, block_until_done=True)


@pytest.mark.group(1)
async def test_restore_on_new_cluster(ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict]) -> None:
@pytest.mark.uses_secrets
async def test_restore_on_new_cluster(ops_test: OpsTest) -> None:
"""Test that is possible to restore a backup to another PostgreSQL cluster."""
if not cloud_configs[1][AWS]["secret-key"]:
pytest.skip("No AWS credentials")

charm = await ops_test.build_charm(".")
database_app_name = f"new-{DATABASE_APP_NAME}"
await ops_test.model.deploy(
Expand Down Expand Up @@ -308,14 +300,11 @@ async def test_restore_on_new_cluster(ops_test: OpsTest, cloud_configs: Tuple[Di
connection.close()


@pytest.mark.group(1)
@pytest.mark.uses_secrets
async def test_invalid_config_and_recovery_after_fixing_it(
ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict]
) -> None:
"""Test that the charm can handle invalid and valid backup configurations."""
if not cloud_configs[1][AWS]["secret-key"]:
pytest.skip("No AWS credentials")

database_app_name = f"new-{DATABASE_APP_NAME}"

# Provide invalid backup configurations.
Expand Down

0 comments on commit e196f69

Please sign in to comment.