diff --git a/tests/integration/backup_tests/test_backups.py b/tests/integration/backup_tests/test_backups.py index d74144829..9d380195e 100644 --- a/tests/integration/backup_tests/test_backups.py +++ b/tests/integration/backup_tests/test_backups.py @@ -21,7 +21,6 @@ ENDPOINT = "s3-credentials" NEW_CLUSTER = "new-mongodb" - logger = logging.getLogger(__name__) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index b6b592ed0..db64ec13d 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -5,7 +5,7 @@ import logging import subprocess from pathlib import Path -from typing import Dict, Optional +from typing import Dict, List, Optional import ops import yaml @@ -223,7 +223,7 @@ async def check_or_scale_app(ops_test: OpsTest, user_app_name: str, required_uni await ops_test.model.wait_for_idle() -async def get_app_name(ops_test: OpsTest) -> str: +async def get_app_name(ops_test: OpsTest, test_deployments: List[str] = []) -> str: """Returns the name of the cluster running MongoDB. This is important since not all deployments of the MongoDB charm have the application name @@ -237,6 +237,11 @@ async def get_app_name(ops_test: OpsTest) -> str: # of `local:focal/mongodb-6` if "mongodb" in status["applications"][app]["charm"]: logger.debug("Found mongodb app named '%s'", app) + + if app in test_deployments: + logger.debug("mongodb app named '%s', was deployed by the test, not by user", app) + continue + return app return None diff --git a/tests/integration/relation_tests/new_relations/test_charm_relations.py b/tests/integration/relation_tests/new_relations/test_charm_relations.py index 443270de7..e7d38417f 100644 --- a/tests/integration/relation_tests/new_relations/test_charm_relations.py +++ b/tests/integration/relation_tests/new_relations/test_charm_relations.py @@ -40,6 +40,11 @@ async def test_deploy_charms(ops_test: OpsTest, application_charm, database_char # set data in the relation application databag using only the leader unit). required_units = 2 app_name = await get_app_name(ops_test) + if app_name == ANOTHER_DATABASE_APP_NAME: + assert ( + False + ), f"provided MongoDB application, cannot be named {ANOTHER_DATABASE_APP_NAME}, this name is reserved for this test." + if app_name: await asyncio.gather( ops_test.model.deploy( @@ -83,7 +88,10 @@ async def test_deploy_charms(ops_test: OpsTest, application_charm, database_char async def test_database_relation_with_charm_libraries(ops_test: OpsTest): """Test basic functionality of database relation interface.""" # Relate the charms and wait for them exchanging some connection data. - db_app_name = await get_app_name(ops_test) or DATABASE_APP_NAME + db_app_name = ( + await get_app_name(ops_test, test_deployments=[ANOTHER_DATABASE_APP_NAME]) + or DATABASE_APP_NAME + ) await ops_test.model.integrate( f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION_NAME}", db_app_name ) @@ -130,7 +138,10 @@ async def test_database_relation_with_charm_libraries(ops_test: OpsTest): async def test_app_relation_metadata_change(ops_test: OpsTest) -> None: """Verifies that the app metadata changes with db relation joined and departed events.""" # verify application metadata is correct before adding/removing units. - db_app_name = await get_app_name(ops_test) or DATABASE_APP_NAME + db_app_name = ( + await get_app_name(ops_test, test_deployments=[ANOTHER_DATABASE_APP_NAME]) + or DATABASE_APP_NAME + ) try: await verify_application_data( ops_test, APPLICATION_APP_NAME, db_app_name, FIRST_DATABASE_RELATION_NAME @@ -270,7 +281,10 @@ async def test_two_applications_doesnt_share_the_same_relation_data( ) await ops_test.model.wait_for_idle(apps=all_app_names, status="active") - db_app_name = await get_app_name(ops_test) or DATABASE_APP_NAME + db_app_name = ( + await get_app_name(ops_test, test_deployments=[ANOTHER_DATABASE_APP_NAME]) + or DATABASE_APP_NAME + ) # Relate the new application with the database # and wait for them exchanging some connection data. await ops_test.model.integrate( @@ -293,7 +307,10 @@ async def test_an_application_can_connect_to_multiple_database_clusters(ops_test """Test that an application can connect to different clusters of the same database.""" # Relate the application with both database clusters # and wait for them exchanging some connection data. - db_app_name = await get_app_name(ops_test) or DATABASE_APP_NAME + db_app_name = ( + await get_app_name(ops_test, test_deployments=[ANOTHER_DATABASE_APP_NAME]) + or DATABASE_APP_NAME + ) first_cluster_relation = await ops_test.model.integrate( f"{APPLICATION_APP_NAME}:{MULTIPLE_DATABASE_CLUSTERS_RELATION_NAME}", db_app_name ) @@ -328,7 +345,10 @@ async def test_an_application_can_connect_to_multiple_aliased_database_clusters( # """Test that an application can connect to different clusters of the same database.""" # Relate the application with both database clusters # and wait for them exchanging some connection data. - db_app_name = await get_app_name(ops_test) or DATABASE_APP_NAME + db_app_name = ( + await get_app_name(ops_test, test_deployments=[ANOTHER_DATABASE_APP_NAME]) + or DATABASE_APP_NAME + ) await asyncio.gather( ops_test.model.integrate( f"{APPLICATION_APP_NAME}:{ALIASED_MULTIPLE_DATABASE_CLUSTERS_RELATION_NAME}", @@ -364,7 +384,10 @@ async def test_an_application_can_connect_to_multiple_aliased_database_clusters( async def test_an_application_can_request_multiple_databases(ops_test: OpsTest, application_charm): """Test that an application can request additional databases using the same interface.""" # Relate the charms using another relation and wait for them exchanging some connection data. - db_app_name = await get_app_name(ops_test) or DATABASE_APP_NAME + db_app_name = ( + await get_app_name(ops_test, test_deployments=[ANOTHER_DATABASE_APP_NAME]) + or DATABASE_APP_NAME + ) await ops_test.model.integrate( f"{APPLICATION_APP_NAME}:{SECOND_DATABASE_RELATION_NAME}", db_app_name ) @@ -388,7 +411,10 @@ async def test_removed_relation_no_longer_has_access(ops_test: OpsTest): connection_string = await get_connection_string( ops_test, APPLICATION_APP_NAME, FIRST_DATABASE_RELATION_NAME ) - db_app_name = await get_app_name(ops_test) or DATABASE_APP_NAME + db_app_name = ( + await get_app_name(ops_test, test_deployments=[ANOTHER_DATABASE_APP_NAME]) + or DATABASE_APP_NAME + ) await ops_test.model.applications[db_app_name].remove_relation( f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION_NAME}", f"{db_app_name}:database" )