-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DPE-4876][DPE-4943][DPE-4944] Add/Remove shards + fix
error
in sec…
…ret-changed hook (#273) * update libs * update tests for the new form of the monitor usr URI * legacy provider is not needed for k8s charm * sharding components succesful start with expected args * format + lint * add a basic integration test * update integration tests to work on K8s * PR feedback * add in flags from vm charm to test * pr feedback * bring libs up to date * make corresponding changes in src code * test components go into blocked state if no relation is present * k8s-afy copied over test code * use updated lib versions * WIP adding shards to cluster * add shard works * test add shard * Add remove shard tests * add in remaining basic shard tests * Apply suggestions from Mehdi's code review Co-authored-by: Mehdi Bendriss <[email protected]> * Update tests/integration/sharding_tests/helpers.py Co-authored-by: Mehdi Bendriss <[email protected]> * not necessary to open ports on K8s * fix ha tests with correct call to get password * revert change as pymongo does not serialised collection --------- Co-authored-by: Mehdi Bendriss <[email protected]>
- Loading branch information
1 parent
aed46b7
commit c636014
Showing
6 changed files
with
441 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
from typing import List, Optional | ||
|
||
|
||
def get_cluster_shards(mongos_client) -> set: | ||
"""Returns a set of the shard members.""" | ||
shard_list = mongos_client.admin.command("listShards") | ||
curr_members = [member["host"].split("/")[0] for member in shard_list["shards"]] | ||
return set(curr_members) | ||
|
||
|
||
def has_correct_shards(mongos_client, expected_shards: List[str]) -> bool: | ||
"""Returns true if the cluster config has the expected shards.""" | ||
shard_names = get_cluster_shards(mongos_client) | ||
return shard_names == set(expected_shards) | ||
|
||
|
||
def shard_has_databases( | ||
mongos_client, shard_name: str, expected_databases_on_shard: List[str] | ||
) -> bool: | ||
"""Returns true if the provided shard is a primary for the provided databases.""" | ||
databases_on_shard = get_databases_for_shard(mongos_client, shard_name=shard_name) | ||
return set(databases_on_shard) == set(expected_databases_on_shard) | ||
|
||
|
||
def get_databases_for_shard(mongos_client, shard_name) -> Optional[List[str]]: | ||
"""Returns the databases hosted on the given shard.""" | ||
config_db = mongos_client["config"] | ||
if "databases" not in config_db.list_collection_names(): | ||
return None | ||
|
||
databases_collection = config_db["databases"] | ||
|
||
if databases_collection is None: | ||
return | ||
|
||
return databases_collection.distinct("_id", {"primary": shard_name}) | ||
|
||
|
||
def write_data_to_mongodb(client, db_name, coll_name, content) -> None: | ||
"""Writes data to the provided collection and database.""" | ||
db = client[db_name] | ||
test_collection = db[coll_name] | ||
test_collection.insert_one(content) | ||
|
||
|
||
def verify_data_mongodb(client, db_name, coll_name, key, value) -> bool: | ||
"""Checks a key/value pair for a provided collection and database.""" | ||
db = client[db_name] | ||
test_collection = db[coll_name] | ||
query = test_collection.find({}, {key: 1}) | ||
return query[0][key] == value |
Oops, something went wrong.