Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-ratushnyy committed Oct 6, 2023
1 parent 9322887 commit caed80e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/charms/mongodb/v0/mongodb_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/relation_tests/new_relations/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)

Expand All @@ -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,
Expand Down

0 comments on commit caed80e

Please sign in to comment.