diff --git a/lib/charms/mongodb/v0/mongodb_provider.py b/lib/charms/mongodb/v0/mongodb_provider.py index c46b34e12..54632e25d 100644 --- a/lib/charms/mongodb/v0/mongodb_provider.py +++ b/lib/charms/mongodb/v0/mongodb_provider.py @@ -86,7 +86,7 @@ def _on_relation_event(self, event): creates or drops MongoDB users and sets credentials into relation data. As a result, related charm gets credentials for accessing the MongoDB database. - """ + """ if not self.charm.unit.is_leader(): return # We shouldn't try to create or update users if the database is not @@ -248,6 +248,7 @@ def _get_or_set_password(self, relation: Relation) -> str: Returns: str: The password. """ + import pdb; pdb.set_trace() relation_data = self.database_provides.fetch_relation_data( [relation.id], ["password"], relation.name ) diff --git a/tests/integration/relation_tests/new_relations/helpers.py b/tests/integration/relation_tests/new_relations/helpers.py index 0a27f863c..cdf0588f7 100644 --- a/tests/integration/relation_tests/new_relations/helpers.py +++ b/tests/integration/relation_tests/new_relations/helpers.py @@ -97,3 +97,9 @@ async def verify_application_data( return False return True + +async def get_secret_data(ops_test, secret_uri): + secret_unique_id = secret_uri.split("/")[-1] + complete_command = f"show-secret {secret_uri} --reveal --format=json" + _, stdout, _ = await ops_test.juju(*complete_command.split()) + return json.loads(stdout)[secret_unique_id]["content"]["Data"] \ No newline at end of file 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 e3d7920bd..1fda45c1b 100644 --- a/tests/integration/relation_tests/new_relations/test_charm_relations.py +++ b/tests/integration/relation_tests/new_relations/test_charm_relations.py @@ -13,7 +13,7 @@ from tenacity import RetryError from ...ha_tests.helpers import replica_set_primary -from .helpers import get_application_relation_data, verify_application_data +from .helpers import get_application_relation_data, get_secret_data, verify_application_data MEDIAN_REELECTION_TIME = 12 APPLICATION_APP_NAME = "application" @@ -37,17 +37,17 @@ async def test_deploy_charms(ops_test: OpsTest, application_charm, database_char ops_test.model.deploy( application_charm, application_name=APPLICATION_APP_NAME, - num_units=2, + num_units=1, ), ops_test.model.deploy( database_charm, application_name=DATABASE_APP_NAME, - num_units=2, - ), - ops_test.model.deploy( - database_charm, - application_name=ANOTHER_DATABASE_APP_NAME, + num_units=1, ), + # ops_test.model.deploy( + # database_charm, + # application_name=ANOTHER_DATABASE_APP_NAME, + # ), ) await ops_test.model.wait_for_idle(apps=APP_NAMES, status="active", wait_for_at_least_units=1) @@ -56,16 +56,23 @@ 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. + import pdb; pdb.set_trace() await ops_test.model.add_relation( f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION_NAME}", DATABASE_APP_NAME ) await ops_test.model.wait_for_idle(apps=APP_NAMES, status="active") - connection_string = await get_application_relation_data( - ops_test, APPLICATION_APP_NAME, FIRST_DATABASE_RELATION_NAME, "uris" + + secret_uri = await get_application_relation_data( + ops_test, APPLICATION_APP_NAME, FIRST_DATABASE_RELATION_NAME, "secret-user" ) + + first_relation_user_data = await get_secret_data(ops_test, secret_uri) + connection_string = first_relation_user_data.get("uris") + database = await get_application_relation_data( ops_test, APPLICATION_APP_NAME, FIRST_DATABASE_RELATION_NAME, "database" ) + client = MongoClient( connection_string, directConnection=False,