diff --git a/.gitignore b/.gitignore index 584f95e0e..d13ec08f6 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ share/ /requirements.txt /requirements-last-build.txt +/charm_internal_version diff --git a/charmcraft.yaml b/charmcraft.yaml index d28b18d57..c4f803ece 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -20,6 +20,11 @@ parts: override-build: | rustup default stable craftctl default + files: + plugin: dump + source: . + prime: + - charm_internal_version bases: - build-on: - name: "ubuntu" diff --git a/lib/charms/mongodb/v0/set_status.py b/lib/charms/mongodb/v0/set_status.py index 98d1dabac..912493870 100644 --- a/lib/charms/mongodb/v0/set_status.py +++ b/lib/charms/mongodb/v0/set_status.py @@ -7,6 +7,7 @@ from typing import Optional, Tuple from charms.mongodb.v1.mongodb import MongoConfiguration, MongoDBConnection +from data_platform_helpers.version_check import NoVersionError, get_charm_revision from ops.charm import CharmBase from ops.framework import Object from ops.model import ActiveStatus, BlockedStatus, StatusBase, WaitingStatus @@ -22,7 +23,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 3 +LIBPATCH = 4 AUTH_FAILED_CODE = 18 UNAUTHORISED_CODE = 13 @@ -88,7 +89,7 @@ def is_status_related_to_mismatched_revision(self, status_type: str) -> bool: "goal state" which processes data differently and the other via the ".status" property. Hence we have to be flexible to handle each. """ - if not self.charm.get_cluster_mismatched_revision_status(): + if not self.get_cluster_mismatched_revision_status(): return False if "waiting" in status_type and self.charm.is_role(Config.Role.CONFIG_SERVER): @@ -153,7 +154,7 @@ def is_unit_status_ready_for_upgrade(self) -> bool: if isinstance(current_status, ActiveStatus): return True - if not isinstance(current_status, WaitingStatus): + if not isinstance(current_status, BlockedStatus): return False if status_message and "is not up-to date with config-server" in status_message: @@ -235,7 +236,49 @@ def get_invalid_integration_status(self) -> Optional[StatusBase]: "Relation to s3-integrator is not supported, config role must be config-server" ) - return self.charm.get_cluster_mismatched_revision_status() + return self.get_cluster_mismatched_revision_status() + + def get_cluster_mismatched_revision_status(self) -> Optional[StatusBase]: + """Returns a Status if the cluster has mismatched revisions.""" + # check for invalid versions in sharding integrations, i.e. a shard running on + # revision 88 and a config-server running on revision 110 + current_charms_version = get_charm_revision( + self.charm.unit, local_version=self.charm.get_charm_internal_revision + ) + local_identifier = ( + "-locally built" + if self.charm.version_checker.is_local_charm(self.charm.app.name) + else "" + ) + try: + if self.charm.version_checker.are_related_apps_valid(): + return + except NoVersionError as e: + # relations to shards/config-server are expected to provide a version number. If they + # do not, it is because they are from an earlier charm revision, i.e. pre-revison X. + logger.debug(e) + if self.charm.is_role(Config.Role.SHARD): + return BlockedStatus( + f"Charm revision ({current_charms_version}{local_identifier}) is not up-to date with config-server." + ) + + if self.charm.is_role(Config.Role.SHARD): + config_server_revision = self.charm.version_checker.get_version_of_related_app( + self.get_config_server_name() + ) + remote_local_identifier = ( + "-locally built" + if self.charm.version_checker.is_local_charm(self.get_config_server_name()) + else "" + ) + return BlockedStatus( + f"Charm revision ({current_charms_version}{local_identifier}) is not up-to date with config-server ({config_server_revision}{remote_local_identifier})." + ) + + if self.charm.is_role(Config.Role.CONFIG_SERVER): + return WaitingStatus( + f"Waiting for shards to upgrade/downgrade to revision {current_charms_version}{local_identifier}." + ) def build_unit_status(mongodb_config: MongoConfiguration, unit_host: str) -> StatusBase: diff --git a/poetry.lock b/poetry.lock index 29cce4e2c..a281084e2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -208,89 +208,89 @@ files = [ [[package]] name = "certifi" -version = "2024.7.4" +version = "2024.8.30" description = "Python package for providing Mozilla's CA Bundle." optional = false python-versions = ">=3.6" files = [ - {file = "certifi-2024.7.4-py3-none-any.whl", hash = "sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90"}, - {file = "certifi-2024.7.4.tar.gz", hash = "sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b"}, + {file = "certifi-2024.8.30-py3-none-any.whl", hash = "sha256:922820b53db7a7257ffbda3f597266d435245903d80737e34f8a45ff3e3230d8"}, + {file = "certifi-2024.8.30.tar.gz", hash = "sha256:bec941d2aa8195e248a60b31ff9f0558284cf01a52591ceda73ea9afffd69fd9"}, ] [[package]] name = "cffi" -version = "1.17.0" +version = "1.17.1" description = "Foreign Function Interface for Python calling C code." optional = false python-versions = ">=3.8" files = [ - {file = "cffi-1.17.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:f9338cc05451f1942d0d8203ec2c346c830f8e86469903d5126c1f0a13a2bcbb"}, - {file = "cffi-1.17.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:a0ce71725cacc9ebf839630772b07eeec220cbb5f03be1399e0457a1464f8e1a"}, - {file = "cffi-1.17.0-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c815270206f983309915a6844fe994b2fa47e5d05c4c4cef267c3b30e34dbe42"}, - {file = "cffi-1.17.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d6bdcd415ba87846fd317bee0774e412e8792832e7805938987e4ede1d13046d"}, - {file = "cffi-1.17.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8a98748ed1a1df4ee1d6f927e151ed6c1a09d5ec21684de879c7ea6aa96f58f2"}, - {file = "cffi-1.17.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:0a048d4f6630113e54bb4b77e315e1ba32a5a31512c31a273807d0027a7e69ab"}, - {file = "cffi-1.17.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:24aa705a5f5bd3a8bcfa4d123f03413de5d86e497435693b638cbffb7d5d8a1b"}, - {file = "cffi-1.17.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:856bf0924d24e7f93b8aee12a3a1095c34085600aa805693fb7f5d1962393206"}, - {file = "cffi-1.17.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:4304d4416ff032ed50ad6bb87416d802e67139e31c0bde4628f36a47a3164bfa"}, - {file = "cffi-1.17.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:331ad15c39c9fe9186ceaf87203a9ecf5ae0ba2538c9e898e3a6967e8ad3db6f"}, - {file = "cffi-1.17.0-cp310-cp310-win32.whl", hash = "sha256:669b29a9eca6146465cc574659058ed949748f0809a2582d1f1a324eb91054dc"}, - {file = "cffi-1.17.0-cp310-cp310-win_amd64.whl", hash = "sha256:48b389b1fd5144603d61d752afd7167dfd205973a43151ae5045b35793232aa2"}, - {file = "cffi-1.17.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c5d97162c196ce54af6700949ddf9409e9833ef1003b4741c2b39ef46f1d9720"}, - {file = "cffi-1.17.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:5ba5c243f4004c750836f81606a9fcb7841f8874ad8f3bf204ff5e56332b72b9"}, - {file = "cffi-1.17.0-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:bb9333f58fc3a2296fb1d54576138d4cf5d496a2cc118422bd77835e6ae0b9cb"}, - {file = "cffi-1.17.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:435a22d00ec7d7ea533db494da8581b05977f9c37338c80bc86314bec2619424"}, - {file = "cffi-1.17.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d1df34588123fcc88c872f5acb6f74ae59e9d182a2707097f9e28275ec26a12d"}, - {file = "cffi-1.17.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:df8bb0010fdd0a743b7542589223a2816bdde4d94bb5ad67884348fa2c1c67e8"}, - {file = "cffi-1.17.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a8b5b9712783415695663bd463990e2f00c6750562e6ad1d28e072a611c5f2a6"}, - {file = "cffi-1.17.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:ffef8fd58a36fb5f1196919638f73dd3ae0db1a878982b27a9a5a176ede4ba91"}, - {file = "cffi-1.17.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:4e67d26532bfd8b7f7c05d5a766d6f437b362c1bf203a3a5ce3593a645e870b8"}, - {file = "cffi-1.17.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:45f7cd36186db767d803b1473b3c659d57a23b5fa491ad83c6d40f2af58e4dbb"}, - {file = "cffi-1.17.0-cp311-cp311-win32.whl", hash = "sha256:a9015f5b8af1bb6837a3fcb0cdf3b874fe3385ff6274e8b7925d81ccaec3c5c9"}, - {file = "cffi-1.17.0-cp311-cp311-win_amd64.whl", hash = "sha256:b50aaac7d05c2c26dfd50c3321199f019ba76bb650e346a6ef3616306eed67b0"}, - {file = "cffi-1.17.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aec510255ce690d240f7cb23d7114f6b351c733a74c279a84def763660a2c3bc"}, - {file = "cffi-1.17.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:2770bb0d5e3cc0e31e7318db06efcbcdb7b31bcb1a70086d3177692a02256f59"}, - {file = "cffi-1.17.0-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:db9a30ec064129d605d0f1aedc93e00894b9334ec74ba9c6bdd08147434b33eb"}, - {file = "cffi-1.17.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a47eef975d2b8b721775a0fa286f50eab535b9d56c70a6e62842134cf7841195"}, - {file = "cffi-1.17.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:f3e0992f23bbb0be00a921eae5363329253c3b86287db27092461c887b791e5e"}, - {file = "cffi-1.17.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6107e445faf057c118d5050560695e46d272e5301feffda3c41849641222a828"}, - {file = "cffi-1.17.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eb862356ee9391dc5a0b3cbc00f416b48c1b9a52d252d898e5b7696a5f9fe150"}, - {file = "cffi-1.17.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:c1c13185b90bbd3f8b5963cd8ce7ad4ff441924c31e23c975cb150e27c2bf67a"}, - {file = "cffi-1.17.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:17c6d6d3260c7f2d94f657e6872591fe8733872a86ed1345bda872cfc8c74885"}, - {file = "cffi-1.17.0-cp312-cp312-win32.whl", hash = "sha256:c3b8bd3133cd50f6b637bb4322822c94c5ce4bf0d724ed5ae70afce62187c492"}, - {file = "cffi-1.17.0-cp312-cp312-win_amd64.whl", hash = "sha256:dca802c8db0720ce1c49cce1149ff7b06e91ba15fa84b1d59144fef1a1bc7ac2"}, - {file = "cffi-1.17.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:6ce01337d23884b21c03869d2f68c5523d43174d4fc405490eb0091057943118"}, - {file = "cffi-1.17.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:cab2eba3830bf4f6d91e2d6718e0e1c14a2f5ad1af68a89d24ace0c6b17cced7"}, - {file = "cffi-1.17.0-cp313-cp313-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:14b9cbc8f7ac98a739558eb86fabc283d4d564dafed50216e7f7ee62d0d25377"}, - {file = "cffi-1.17.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b00e7bcd71caa0282cbe3c90966f738e2db91e64092a877c3ff7f19a1628fdcb"}, - {file = "cffi-1.17.0-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:41f4915e09218744d8bae14759f983e466ab69b178de38066f7579892ff2a555"}, - {file = "cffi-1.17.0-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e4760a68cab57bfaa628938e9c2971137e05ce48e762a9cb53b76c9b569f1204"}, - {file = "cffi-1.17.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:011aff3524d578a9412c8b3cfaa50f2c0bd78e03eb7af7aa5e0df59b158efb2f"}, - {file = "cffi-1.17.0-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:a003ac9edc22d99ae1286b0875c460351f4e101f8c9d9d2576e78d7e048f64e0"}, - {file = "cffi-1.17.0-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:ef9528915df81b8f4c7612b19b8628214c65c9b7f74db2e34a646a0a2a0da2d4"}, - {file = "cffi-1.17.0-cp313-cp313-win32.whl", hash = "sha256:70d2aa9fb00cf52034feac4b913181a6e10356019b18ef89bc7c12a283bf5f5a"}, - {file = "cffi-1.17.0-cp313-cp313-win_amd64.whl", hash = "sha256:b7b6ea9e36d32582cda3465f54c4b454f62f23cb083ebc7a94e2ca6ef011c3a7"}, - {file = "cffi-1.17.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:964823b2fc77b55355999ade496c54dde161c621cb1f6eac61dc30ed1b63cd4c"}, - {file = "cffi-1.17.0-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:516a405f174fd3b88829eabfe4bb296ac602d6a0f68e0d64d5ac9456194a5b7e"}, - {file = "cffi-1.17.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:dec6b307ce928e8e112a6bb9921a1cb00a0e14979bf28b98e084a4b8a742bd9b"}, - {file = "cffi-1.17.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e4094c7b464cf0a858e75cd14b03509e84789abf7b79f8537e6a72152109c76e"}, - {file = "cffi-1.17.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2404f3de742f47cb62d023f0ba7c5a916c9c653d5b368cc966382ae4e57da401"}, - {file = "cffi-1.17.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3aa9d43b02a0c681f0bfbc12d476d47b2b2b6a3f9287f11ee42989a268a1833c"}, - {file = "cffi-1.17.0-cp38-cp38-win32.whl", hash = "sha256:0bb15e7acf8ab35ca8b24b90af52c8b391690ef5c4aec3d31f38f0d37d2cc499"}, - {file = "cffi-1.17.0-cp38-cp38-win_amd64.whl", hash = "sha256:93a7350f6706b31f457c1457d3a3259ff9071a66f312ae64dc024f049055f72c"}, - {file = "cffi-1.17.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:1a2ddbac59dc3716bc79f27906c010406155031a1c801410f1bafff17ea304d2"}, - {file = "cffi-1.17.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:6327b572f5770293fc062a7ec04160e89741e8552bf1c358d1a23eba68166759"}, - {file = "cffi-1.17.0-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:dbc183e7bef690c9abe5ea67b7b60fdbca81aa8da43468287dae7b5c046107d4"}, - {file = "cffi-1.17.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5bdc0f1f610d067c70aa3737ed06e2726fd9d6f7bfee4a351f4c40b6831f4e82"}, - {file = "cffi-1.17.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6d872186c1617d143969defeadac5a904e6e374183e07977eedef9c07c8953bf"}, - {file = "cffi-1.17.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:0d46ee4764b88b91f16661a8befc6bfb24806d885e27436fdc292ed7e6f6d058"}, - {file = "cffi-1.17.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6f76a90c345796c01d85e6332e81cab6d70de83b829cf1d9762d0a3da59c7932"}, - {file = "cffi-1.17.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:0e60821d312f99d3e1569202518dddf10ae547e799d75aef3bca3a2d9e8ee693"}, - {file = "cffi-1.17.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:eb09b82377233b902d4c3fbeeb7ad731cdab579c6c6fda1f763cd779139e47c3"}, - {file = "cffi-1.17.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:24658baf6224d8f280e827f0a50c46ad819ec8ba380a42448e24459daf809cf4"}, - {file = "cffi-1.17.0-cp39-cp39-win32.whl", hash = "sha256:0fdacad9e0d9fc23e519efd5ea24a70348305e8d7d85ecbb1a5fa66dc834e7fb"}, - {file = "cffi-1.17.0-cp39-cp39-win_amd64.whl", hash = "sha256:7cbc78dc018596315d4e7841c8c3a7ae31cc4d638c9b627f87d52e8abaaf2d29"}, - {file = "cffi-1.17.0.tar.gz", hash = "sha256:f3157624b7558b914cb039fd1af735e5e8049a87c817cc215109ad1c8779df76"}, + {file = "cffi-1.17.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:df8b1c11f177bc2313ec4b2d46baec87a5f3e71fc8b45dab2ee7cae86d9aba14"}, + {file = "cffi-1.17.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:8f2cdc858323644ab277e9bb925ad72ae0e67f69e804f4898c070998d50b1a67"}, + {file = "cffi-1.17.1-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:edae79245293e15384b51f88b00613ba9f7198016a5948b5dddf4917d4d26382"}, + {file = "cffi-1.17.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:45398b671ac6d70e67da8e4224a065cec6a93541bb7aebe1b198a61b58c7b702"}, + {file = "cffi-1.17.1-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ad9413ccdeda48c5afdae7e4fa2192157e991ff761e7ab8fdd8926f40b160cc3"}, + {file = "cffi-1.17.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:5da5719280082ac6bd9aa7becb3938dc9f9cbd57fac7d2871717b1feb0902ab6"}, + {file = "cffi-1.17.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2bb1a08b8008b281856e5971307cc386a8e9c5b625ac297e853d36da6efe9c17"}, + {file = "cffi-1.17.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:045d61c734659cc045141be4bae381a41d89b741f795af1dd018bfb532fd0df8"}, + {file = "cffi-1.17.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:6883e737d7d9e4899a8a695e00ec36bd4e5e4f18fabe0aca0efe0a4b44cdb13e"}, + {file = "cffi-1.17.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:6b8b4a92e1c65048ff98cfe1f735ef8f1ceb72e3d5f0c25fdb12087a23da22be"}, + {file = "cffi-1.17.1-cp310-cp310-win32.whl", hash = "sha256:c9c3d058ebabb74db66e431095118094d06abf53284d9c81f27300d0e0d8bc7c"}, + {file = "cffi-1.17.1-cp310-cp310-win_amd64.whl", hash = "sha256:0f048dcf80db46f0098ccac01132761580d28e28bc0f78ae0d58048063317e15"}, + {file = "cffi-1.17.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:a45e3c6913c5b87b3ff120dcdc03f6131fa0065027d0ed7ee6190736a74cd401"}, + {file = "cffi-1.17.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:30c5e0cb5ae493c04c8b42916e52ca38079f1b235c2f8ae5f4527b963c401caf"}, + {file = "cffi-1.17.1-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f75c7ab1f9e4aca5414ed4d8e5c0e303a34f4421f8a0d47a4d019ceff0ab6af4"}, + {file = "cffi-1.17.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a1ed2dd2972641495a3ec98445e09766f077aee98a1c896dcb4ad0d303628e41"}, + {file = "cffi-1.17.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:46bf43160c1a35f7ec506d254e5c890f3c03648a4dbac12d624e4490a7046cd1"}, + {file = "cffi-1.17.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:a24ed04c8ffd54b0729c07cee15a81d964e6fee0e3d4d342a27b020d22959dc6"}, + {file = "cffi-1.17.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:610faea79c43e44c71e1ec53a554553fa22321b65fae24889706c0a84d4ad86d"}, + {file = "cffi-1.17.1-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:a9b15d491f3ad5d692e11f6b71f7857e7835eb677955c00cc0aefcd0669adaf6"}, + {file = "cffi-1.17.1-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:de2ea4b5833625383e464549fec1bc395c1bdeeb5f25c4a3a82b5a8c756ec22f"}, + {file = "cffi-1.17.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:fc48c783f9c87e60831201f2cce7f3b2e4846bf4d8728eabe54d60700b318a0b"}, + {file = "cffi-1.17.1-cp311-cp311-win32.whl", hash = "sha256:85a950a4ac9c359340d5963966e3e0a94a676bd6245a4b55bc43949eee26a655"}, + {file = "cffi-1.17.1-cp311-cp311-win_amd64.whl", hash = "sha256:caaf0640ef5f5517f49bc275eca1406b0ffa6aa184892812030f04c2abf589a0"}, + {file = "cffi-1.17.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:805b4371bf7197c329fcb3ead37e710d1bca9da5d583f5073b799d5c5bd1eee4"}, + {file = "cffi-1.17.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:733e99bc2df47476e3848417c5a4540522f234dfd4ef3ab7fafdf555b082ec0c"}, + {file = "cffi-1.17.1-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1257bdabf294dceb59f5e70c64a3e2f462c30c7ad68092d01bbbfb1c16b1ba36"}, + {file = "cffi-1.17.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:da95af8214998d77a98cc14e3a3bd00aa191526343078b530ceb0bd710fb48a5"}, + {file = "cffi-1.17.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d63afe322132c194cf832bfec0dc69a99fb9bb6bbd550f161a49e9e855cc78ff"}, + {file = "cffi-1.17.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f79fc4fc25f1c8698ff97788206bb3c2598949bfe0fef03d299eb1b5356ada99"}, + {file = "cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b62ce867176a75d03a665bad002af8e6d54644fad99a3c70905c543130e39d93"}, + {file = "cffi-1.17.1-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:386c8bf53c502fff58903061338ce4f4950cbdcb23e2902d86c0f722b786bbe3"}, + {file = "cffi-1.17.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:4ceb10419a9adf4460ea14cfd6bc43d08701f0835e979bf821052f1805850fe8"}, + {file = "cffi-1.17.1-cp312-cp312-win32.whl", hash = "sha256:a08d7e755f8ed21095a310a693525137cfe756ce62d066e53f502a83dc550f65"}, + {file = "cffi-1.17.1-cp312-cp312-win_amd64.whl", hash = "sha256:51392eae71afec0d0c8fb1a53b204dbb3bcabcb3c9b807eedf3e1e6ccf2de903"}, + {file = "cffi-1.17.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f3a2b4222ce6b60e2e8b337bb9596923045681d71e5a082783484d845390938e"}, + {file = "cffi-1.17.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:0984a4925a435b1da406122d4d7968dd861c1385afe3b45ba82b750f229811e2"}, + {file = "cffi-1.17.1-cp313-cp313-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d01b12eeeb4427d3110de311e1774046ad344f5b1a7403101878976ecd7a10f3"}, + {file = "cffi-1.17.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:706510fe141c86a69c8ddc029c7910003a17353970cff3b904ff0686a5927683"}, + {file = "cffi-1.17.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:de55b766c7aa2e2a3092c51e0483d700341182f08e67c63630d5b6f200bb28e5"}, + {file = "cffi-1.17.1-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:c59d6e989d07460165cc5ad3c61f9fd8f1b4796eacbd81cee78957842b834af4"}, + {file = "cffi-1.17.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dd398dbc6773384a17fe0d3e7eeb8d1a21c2200473ee6806bb5e6a8e62bb73dd"}, + {file = "cffi-1.17.1-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:3edc8d958eb099c634dace3c7e16560ae474aa3803a5df240542b305d14e14ed"}, + {file = "cffi-1.17.1-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:72e72408cad3d5419375fc87d289076ee319835bdfa2caad331e377589aebba9"}, + {file = "cffi-1.17.1-cp313-cp313-win32.whl", hash = "sha256:e03eab0a8677fa80d646b5ddece1cbeaf556c313dcfac435ba11f107ba117b5d"}, + {file = "cffi-1.17.1-cp313-cp313-win_amd64.whl", hash = "sha256:f6a16c31041f09ead72d69f583767292f750d24913dadacf5756b966aacb3f1a"}, + {file = "cffi-1.17.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:636062ea65bd0195bc012fea9321aca499c0504409f413dc88af450b57ffd03b"}, + {file = "cffi-1.17.1-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c7eac2ef9b63c79431bc4b25f1cd649d7f061a28808cbc6c47b534bd789ef964"}, + {file = "cffi-1.17.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e221cf152cff04059d011ee126477f0d9588303eb57e88923578ace7baad17f9"}, + {file = "cffi-1.17.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:31000ec67d4221a71bd3f67df918b1f88f676f1c3b535a7eb473255fdc0b83fc"}, + {file = "cffi-1.17.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6f17be4345073b0a7b8ea599688f692ac3ef23ce28e5df79c04de519dbc4912c"}, + {file = "cffi-1.17.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0e2b1fac190ae3ebfe37b979cc1ce69c81f4e4fe5746bb401dca63a9062cdaf1"}, + {file = "cffi-1.17.1-cp38-cp38-win32.whl", hash = "sha256:7596d6620d3fa590f677e9ee430df2958d2d6d6de2feeae5b20e82c00b76fbf8"}, + {file = "cffi-1.17.1-cp38-cp38-win_amd64.whl", hash = "sha256:78122be759c3f8a014ce010908ae03364d00a1f81ab5c7f4a7a5120607ea56e1"}, + {file = "cffi-1.17.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:b2ab587605f4ba0bf81dc0cb08a41bd1c0a5906bd59243d56bad7668a6fc6c16"}, + {file = "cffi-1.17.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:28b16024becceed8c6dfbc75629e27788d8a3f9030691a1dbf9821a128b22c36"}, + {file = "cffi-1.17.1-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1d599671f396c4723d016dbddb72fe8e0397082b0a77a4fab8028923bec050e8"}, + {file = "cffi-1.17.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ca74b8dbe6e8e8263c0ffd60277de77dcee6c837a3d0881d8c1ead7268c9e576"}, + {file = "cffi-1.17.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:f7f5baafcc48261359e14bcd6d9bff6d4b28d9103847c9e136694cb0501aef87"}, + {file = "cffi-1.17.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:98e3969bcff97cae1b2def8ba499ea3d6f31ddfdb7635374834cf89a1a08ecf0"}, + {file = "cffi-1.17.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:cdf5ce3acdfd1661132f2a9c19cac174758dc2352bfe37d98aa7512c6b7178b3"}, + {file = "cffi-1.17.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:9755e4345d1ec879e3849e62222a18c7174d65a6a92d5b346b1863912168b595"}, + {file = "cffi-1.17.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:f1e22e8c4419538cb197e4dd60acc919d7696e5ef98ee4da4e01d3f8cfa4cc5a"}, + {file = "cffi-1.17.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:c03e868a0b3bc35839ba98e74211ed2b05d2119be4e8a0f224fba9384f1fe02e"}, + {file = "cffi-1.17.1-cp39-cp39-win32.whl", hash = "sha256:e31ae45bc2e29f6b2abd0de1cc3b9d5205aa847cafaecb8af1476a609a2f6eb7"}, + {file = "cffi-1.17.1-cp39-cp39-win_amd64.whl", hash = "sha256:d016c76bdd850f3c626af19b0542c9677ba156e4ee4fccfdd7848803533ef662"}, + {file = "cffi-1.17.1.tar.gz", hash = "sha256:1c39c6016c32bc48dd54561950ebd6836e1670f2ae46128f67cf49e789c52824"}, ] [package.dependencies] @@ -597,17 +597,18 @@ test-randomorder = ["pytest-randomly"] [[package]] name = "data-platform-helpers" -version = "0.1.2" +version = "0.1.3" description = "" optional = false python-versions = "<4.0,>=3.10" files = [ - {file = "data_platform_helpers-0.1.2-py3-none-any.whl", hash = "sha256:079cda5a3a65cd2e2c3e349467a1bfa6bf53eff4e24b4197312c15cbd818225c"}, - {file = "data_platform_helpers-0.1.2.tar.gz", hash = "sha256:f62ca1710f798f5870a3ef5d515f6221b63976441d62861e0817a2cfcd3e8150"}, + {file = "data_platform_helpers-0.1.3-py3-none-any.whl", hash = "sha256:1fbaff7972430e4452ed7d6b4183f88599ee4a67e7828682b8fb0bb908b17786"}, + {file = "data_platform_helpers-0.1.3.tar.gz", hash = "sha256:5b63e4ec26f611369349058d05a7aac1c5f11001d44884d40cec0552782f8346"}, ] [package.dependencies] -ops = ">=2.12.0,<3.0.0" +ops = ">=2.15.0,<3.0.0" +pytest_operator = ">=0.36.0,<0.37.0" [[package]] name = "decorator" @@ -656,13 +657,13 @@ test = ["pytest (>=6)"] [[package]] name = "executing" -version = "2.0.1" +version = "2.1.0" description = "Get the currently executing AST node of a frame, and other information" optional = false -python-versions = ">=3.5" +python-versions = ">=3.8" files = [ - {file = "executing-2.0.1-py2.py3-none-any.whl", hash = "sha256:eac49ca94516ccc753f9fb5ce82603156e590b27525a8bc32cce8ae302eb61bc"}, - {file = "executing-2.0.1.tar.gz", hash = "sha256:35afe2ce3affba8ee97f2d69927fa823b08b472b7b994e36a52a964b93d16147"}, + {file = "executing-2.1.0-py2.py3-none-any.whl", hash = "sha256:8d63781349375b5ebccc3142f4b30350c0cd9c79f921cde38be2be4637e98eaf"}, + {file = "executing-2.1.0.tar.gz", hash = "sha256:8ea27ddd260da8150fa5a708269c4a10e76161e2496ec3e587da9e3c0fe4b9ab"}, ] [package.extras] @@ -867,13 +868,13 @@ tomli = {version = "*", markers = "python_version > \"3.6\" and python_version < [[package]] name = "ipython" -version = "8.26.0" +version = "8.27.0" description = "IPython: Productive Interactive Computing" optional = false python-versions = ">=3.10" files = [ - {file = "ipython-8.26.0-py3-none-any.whl", hash = "sha256:e6b347c27bdf9c32ee9d31ae85defc525755a1869f14057e900675b9e8d6e6ff"}, - {file = "ipython-8.26.0.tar.gz", hash = "sha256:1cec0fbba8404af13facebe83d04436a7434c7400e59f47acf467c64abd0956c"}, + {file = "ipython-8.27.0-py3-none-any.whl", hash = "sha256:f68b3cb8bde357a5d7adc9598d57e22a45dfbea19eb6b98286fa3b288c9cd55c"}, + {file = "ipython-8.27.0.tar.gz", hash = "sha256:0b99a2dc9f15fd68692e898e5568725c6d49c527d36a9fb5960ffbdeaa82ff7e"}, ] [package.dependencies] @@ -1209,13 +1210,13 @@ signedtoken = ["cryptography (>=3.0.0)", "pyjwt (>=2.0.0,<3)"] [[package]] name = "ops" -version = "2.16.0" +version = "2.16.1" description = "The Python library behind great charms" optional = false python-versions = ">=3.8" files = [ - {file = "ops-2.16.0-py3-none-any.whl", hash = "sha256:82d982d08035f059a28129139547b62c9326d4a25e5421bb3fd8d9145585b09d"}, - {file = "ops-2.16.0.tar.gz", hash = "sha256:c4405185744c82589fca4752a76cd7eabd667cf2d3f07d2700b82777186b8de9"}, + {file = "ops-2.16.1-py3-none-any.whl", hash = "sha256:11b0466ebb8c80f2a3a11752b63f5ab3b145d7520bc743281d7e7b19c12ac79d"}, + {file = "ops-2.16.1.tar.gz", hash = "sha256:64315cd114cd5f445ce0f382ecebe431dd05620a7917f76eb2d77632fdea8cbb"}, ] [package.dependencies] @@ -1327,19 +1328,19 @@ ptyprocess = ">=0.5" [[package]] name = "platformdirs" -version = "4.2.2" +version = "4.3.2" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a `user data dir`." optional = false python-versions = ">=3.8" files = [ - {file = "platformdirs-4.2.2-py3-none-any.whl", hash = "sha256:2d7a1657e36a80ea911db832a8a6ece5ee53d8de21edd5cc5879af6530b1bfee"}, - {file = "platformdirs-4.2.2.tar.gz", hash = "sha256:38b7b51f512eed9e84a22788b4bce1de17c0adb134d6becb09836e37d8654cd3"}, + {file = "platformdirs-4.3.2-py3-none-any.whl", hash = "sha256:eb1c8582560b34ed4ba105009a4badf7f6f85768b30126f351328507b2beb617"}, + {file = "platformdirs-4.3.2.tar.gz", hash = "sha256:9e5e27a08aa095dd127b9f2e764d74254f482fef22b0970773bfba79d091ab8c"}, ] [package.extras] -docs = ["furo (>=2023.9.10)", "proselint (>=0.13)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.25.2)"] -test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)"] -type = ["mypy (>=1.8)"] +docs = ["furo (>=2024.8.6)", "proselint (>=0.14)", "sphinx (>=8.0.2)", "sphinx-autodoc-typehints (>=2.4)"] +test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=8.3.2)", "pytest-cov (>=5)", "pytest-mock (>=3.14)"] +type = ["mypy (>=1.11.2)"] [[package]] name = "pluggy" @@ -1809,13 +1810,13 @@ dev = ["pre-commit", "pytest-asyncio", "tox"] [[package]] name = "pytest-operator" -version = "0.34.0" +version = "0.36.0" description = "Fixtures for Operators" optional = false python-versions = "*" files = [ - {file = "pytest-operator-0.34.0.tar.gz", hash = "sha256:b2d85c666436fae41e8e8f914e12c07362c473caa0f325c58e1270b00fd4fca4"}, - {file = "pytest_operator-0.34.0-py3-none-any.whl", hash = "sha256:a3534ef376c5931beb04859359f18a4477001e14ed664459fb148cfafaffb943"}, + {file = "pytest_operator-0.36.0-py3-none-any.whl", hash = "sha256:edab65d9d80b19fc85acddeda4a1fd3bb55a781f43ffbb6e9c4002aeeada6ad2"}, + {file = "pytest_operator-0.36.0.tar.gz", hash = "sha256:041eeabd4c9590614f78b7568c74b0d42f768815a6b5c183da8ccfc23345bea9"}, ] [package.dependencies] @@ -2433,4 +2434,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.10.12" -content-hash = "cdc104b93da7cd27ccc3049cd02ebd19901c358dd35babd040d251b4ed95dcfd" +content-hash = "6cfbe750105ba54c490b5b2378086e9be12f1531825b7c13ef58b85e1a36665b" diff --git a/pyproject.toml b/pyproject.toml index 4be308e4c..fe8362772 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ tenacity = "^8.2.3" pyyaml = "^6.0.1" jinja2 = "^3.1.3" poetry-core = "^1.9.0" -data-platform-helpers = "^0.1.2" +data-platform-helpers = "^0.1.3" pyOpenSSL = "^24.2.1" setuptools = "^72.0.0" @@ -72,7 +72,7 @@ juju = "^3.5.0" pytest = "^8.1.1" pytest-asyncio = "^0.21.1" pytest-mock = "^3.14.0" -pytest-operator = "^0.34.0" +pytest-operator = "^0.36.0" pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v21.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"} pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v21.0.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"} pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v21.0.0", subdirectory = "python/pytest_plugins/github_secrets"} diff --git a/src/charm.py b/src/charm.py index 69f784023..ef0551d87 100755 --- a/src/charm.py +++ b/src/charm.py @@ -38,6 +38,10 @@ OperatorUser, ) from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider +from data_platform_helpers.version_check import ( + CrossAppVersionChecker, + get_charm_revision, +) from ops.charm import ( ActionEvent, CharmBase, @@ -56,7 +60,6 @@ ModelError, Relation, RelationDataContent, - StatusBase, Unit, WaitingStatus, ) @@ -140,6 +143,15 @@ def __init__(self, *args): self.config_server = ShardingProvider(self) self.cluster = ClusterProvider(self) + self.version_checker = CrossAppVersionChecker( + self, + version=get_charm_revision(self.unit, local_version=self.get_charm_internal_revision), + relations_to_check=[ + Config.Relations.SHARDING_RELATIONS_NAME, + Config.Relations.CONFIG_SERVER_RELATIONS_NAME, + ], + ) + # BEGIN: properties @property @@ -470,16 +482,15 @@ def primary(self) -> str | None: return None + @property + def get_charm_internal_revision(self) -> str: + """Returns the contents of the get_charm_internal_revision file.""" + with open(Config.CHARM_INTERNAL_VERSION_FILE, "r") as f: + return f.read().strip() + # END: properties # BEGIN: generic helper methods - def get_cluster_mismatched_revision_status(self) -> Optional[StatusBase]: - """Returns a Status if the cluster has mismatched revisions. - - TODO implement this method as a part of sharding upgrades. - """ - return None - def remote_mongos_config(self, hosts) -> MongoConfiguration: """Generates a MongoConfiguration object for mongos in the deployment of MongoDB.""" # mongos that are part of the cluster have the same username and password, but different @@ -1568,7 +1579,7 @@ def is_relation_feasible(self, rel_interface: str) -> bool: ) return False - if revision_mismatch_status := self.get_cluster_mismatched_revision_status(): + if revision_mismatch_status := self.status.get_cluster_mismatched_revision_status(): self.status.set_and_share_status(revision_mismatch_status) return False diff --git a/src/config.py b/src/config.py index 4ad08755f..4da258456 100644 --- a/src/config.py +++ b/src/config.py @@ -22,6 +22,7 @@ class Config: MONGOD_CONF_DIR = "/etc/mongod" MONGODB_LOG_FILENAME = "mongodb.log" + CHARM_INTERNAL_VERSION_FILE = "charm_internal_version" LICENSE_PATH = "/licenses/LICENSE" CONTAINER_NAME = "mongod" SERVICE_NAME = "mongod" diff --git a/src/exceptions.py b/src/exceptions.py index 4e1e2a67e..946d7d73b 100644 --- a/src/exceptions.py +++ b/src/exceptions.py @@ -7,40 +7,26 @@ class MongoError(Exception): """Common parent for Mongo errors, allowing to catch them all at once.""" - pass - class AdminUserCreationError(MongoError): """Raised when a commands to create an admin user on MongoDB fail.""" - pass - class ApplicationHostNotFoundError(MongoError): """Raised when a queried host is not in the application peers or the current host.""" - pass - class MongoSecretError(MongoError): """Common parent for all Mongo Secret Exceptions.""" - pass - class SecretNotAddedError(MongoSecretError): """Raised when a Juju 3 secret couldn't be set or re-set.""" - pass - class MissingSecretError(MongoSecretError): """Could be raised when a Juju 3 mandatory secret couldn't be found.""" - pass - class SecretAlreadyExistsError(MongoSecretError): """A secret that we want to create already exists.""" - - pass diff --git a/tests/integration/upgrades/test_revision_check.py b/tests/integration/upgrades/test_revision_check.py new file mode 100644 index 000000000..31d3631af --- /dev/null +++ b/tests/integration/upgrades/test_revision_check.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. +import pytest +from pytest_operator.plugin import OpsTest + +from ..helpers import METADATA, wait_for_mongodb_units_blocked + +MONGODB_K8S_CHARM = "mongodb-k8s" +SHARD_REL_NAME = "sharding" +CONFIG_SERVER_REL_NAME = "config-server" + +LOCAL_SHARD_APP_NAME = "local-shard" +REMOTE_SHARD_APP_NAME = "remote-shard" +LOCAL_CONFIG_SERVER_APP_NAME = "local-config-server" +REMOTE_CONFIG_SERVER_APP_NAME = "remote-config-server" + +CLUSTER_COMPONENTS = [ + LOCAL_SHARD_APP_NAME, + REMOTE_SHARD_APP_NAME, + LOCAL_CONFIG_SERVER_APP_NAME, + REMOTE_CONFIG_SERVER_APP_NAME, +] + + +@pytest.mark.group(1) +@pytest.mark.abort_on_fail +async def test_build_and_deploy(ops_test: OpsTest) -> None: + my_charm = await ops_test.build_charm(".") + resources = {"mongodb-image": METADATA["resources"]["mongodb-image"]["upstream-source"]} + + await ops_test.model.deploy( + MONGODB_K8S_CHARM, + application_name=REMOTE_SHARD_APP_NAME, + config={"role": "shard"}, + channel="edge", + ) + + await ops_test.model.deploy( + MONGODB_K8S_CHARM, + application_name=REMOTE_CONFIG_SERVER_APP_NAME, + config={"role": "config-server"}, + channel="edge", + ) + await ops_test.model.deploy( + my_charm, + resources=resources, + config={"role": "config-server"}, + application_name=LOCAL_CONFIG_SERVER_APP_NAME, + ) + await ops_test.model.deploy( + my_charm, + resources=resources, + config={"role": "shard"}, + application_name=LOCAL_SHARD_APP_NAME, + ) + + await ops_test.model.wait_for_idle(apps=CLUSTER_COMPONENTS, idle_period=20) + + +@pytest.mark.group(1) +@pytest.mark.abort_on_fail +async def test_local_config_server_reports_remote_shard(ops_test: OpsTest) -> None: + """Tests that the local config server reports remote shard.""" + await ops_test.model.integrate( + f"{REMOTE_SHARD_APP_NAME}:{SHARD_REL_NAME}", + f"{LOCAL_CONFIG_SERVER_APP_NAME}:{CONFIG_SERVER_REL_NAME}", + ) + + await ops_test.model.wait_for_idle( + apps=[LOCAL_CONFIG_SERVER_APP_NAME], + status="waiting", + raise_on_blocked=False, + idle_period=20, + ) + + config_server_unit = ops_test.model.applications[LOCAL_CONFIG_SERVER_APP_NAME].units[0] + + assert ( + "Waiting for shards to upgrade/downgrade to revision" + in config_server_unit.workload_status_message + ), "Config server does not correctly report mismatch in revision" + + +@pytest.mark.group(1) +@pytest.mark.abort_on_fail +async def test_local_shard_reports_remote_config_server(ops_test: OpsTest) -> None: + """Tests that the local shard reports remote config-server.""" + await ops_test.model.integrate( + f"{LOCAL_SHARD_APP_NAME}:{SHARD_REL_NAME}", + f"{REMOTE_CONFIG_SERVER_APP_NAME}:{CONFIG_SERVER_REL_NAME}", + ) + + await wait_for_mongodb_units_blocked( + ops_test, + LOCAL_SHARD_APP_NAME, + timeout=300, + ) + + shard_unit = ops_test.model.applications[LOCAL_SHARD_APP_NAME].units[0] + assert ( + "is not up-to date with config-server." in shard_unit.workload_status_message + ), "Shard does not correctly report mismatch in revision" diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index cd9b2e7be..fbdaeeff0 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -36,8 +36,9 @@ class TestCharm(unittest.TestCase): + @patch("charm.get_charm_revision") @patch_network_get(private_address="1.1.1.1") - def setUp(self): + def setUp(self, *unused): self.maxDiff = None self.harness = Harness(MongoDBCharm) mongo_resource = { @@ -583,9 +584,11 @@ def test_reconfigure_remove_member_failure(self, connection, defer): connection.return_value.__enter__.return_value.remove_replset_member.assert_called() defer.assert_called() + @patch("charms.mongodb.v0.set_status.get_charm_revision") + @patch("charm.CrossAppVersionChecker.is_local_charm") @patch("ops.framework.EventBase.defer") @patch("charm.MongoDBConnection") - def test_reconfigure_peer_not_ready(self, connection, defer): + def test_reconfigure_peer_not_ready(self, connection, defer, *unused): """Tests reconfigure does not proceed when the adding member is not ready. Verifies in relation joined events, that when the adding member is not ready that the event diff --git a/tests/unit/test_mongodb_backups.py b/tests/unit/test_mongodb_backups.py index 8a25593f0..7f0a5eb17 100644 --- a/tests/unit/test_mongodb_backups.py +++ b/tests/unit/test_mongodb_backups.py @@ -31,8 +31,9 @@ class TestMongoBackups(unittest.TestCase): + @patch("charm.get_charm_revision") @patch_network_get(private_address="1.1.1.1") - def setUp(self): + def setUp(self, *unused): self.harness = Harness(MongoDBCharm) self.harness.begin() self.harness.add_relation("database-peers", "database-peers") diff --git a/tests/unit/test_mongodb_provider.py b/tests/unit/test_mongodb_provider.py index 53fbf7e59..2c421b86b 100644 --- a/tests/unit/test_mongodb_provider.py +++ b/tests/unit/test_mongodb_provider.py @@ -25,8 +25,9 @@ class TestMongoProvider(unittest.TestCase): + @patch("charm.get_charm_revision") @patch_network_get(private_address="1.1.1.1") - def setUp(self): + def setUp(self, *unused): self.harness = Harness(MongoDBCharm) mongo_resource = { "registrypath": "mongo:4.4", @@ -62,9 +63,11 @@ def test_relation_event_db_not_initialised(self, oversee_users, defer): defer.assert_not_called() @patch_network_get(private_address="1.1.1.1") + @patch("charm.CrossAppVersionChecker.is_local_charm") + @patch("charms.mongodb.v0.set_status.get_charm_revision") @patch("ops.framework.EventBase.defer") @patch("charm.MongoDBProvider.oversee_users") - def test_relation_event_oversee_users_mongo_failure(self, oversee_users, defer): + def test_relation_event_oversee_users_mongo_failure(self, oversee_users, defer, *unused): """Tests the errors related to pymongo when overseeing users result in a defer.""" # presets self.harness.set_leader(True) @@ -86,9 +89,11 @@ def test_relation_event_oversee_users_mongo_failure(self, oversee_users, defer): # oversee_users raises AssertionError when unable to attain users from relation @patch_network_get(private_address="1.1.1.1") + @patch("charm.CrossAppVersionChecker.is_local_charm") + @patch("charms.mongodb.v0.set_status.get_charm_revision") @patch("ops.framework.EventBase.defer") @patch("charm.MongoDBProvider.oversee_users") - def test_relation_event_oversee_users_fails_to_get_relation(self, oversee_users, defer): + def test_relation_event_oversee_users_fails_to_get_relation(self, oversee_users, *unused): """Verifies that when users are formatted incorrectly an assertion error is raised.""" # presets self.harness.set_leader(True) diff --git a/tox.ini b/tox.ini index d02b9c293..383199139 100644 --- a/tox.ini +++ b/tox.ini @@ -28,13 +28,16 @@ allowlist_externals = charmcraft charmcraftcache mv + rm commands_pre = + python -c 'import pathlib; import shutil; import subprocess; git_hash=subprocess.run(["git", "describe", "--always", "--dirty"], capture_output=True, check=True, encoding="utf-8").stdout; file = pathlib.Path("charm_internal_version"); file.write_text(f"{git_hash}")' poetry export --only main,charm-libs --output requirements.txt commands = build-production: charmcraft pack {posargs} build-dev: charmcraftcache pack {posargs} commands_post = mv requirements.txt requirements-last-build.txt + rm charm_internal_version [testenv:format] description = Apply coding style standards to code @@ -62,15 +65,21 @@ commands = [testenv:unit] description = Run unit tests +allowlist_externals = + poetry + rm set_env = {[testenv]set_env} commands_pre = + python -c 'import pathlib; import shutil; import subprocess; git_hash=subprocess.run(["git", "describe", "--always", "--dirty"], capture_output=True, check=True, encoding="utf-8").stdout; file = pathlib.Path("charm_internal_version"); file.write_text(f"{git_hash}")' poetry install --only main,charm-libs,unit commands = poetry run coverage run --source={[vars]src_path},{[vars]lib_path} \ -m pytest -v --tb native -s {posargs} {[vars]tests_path}/unit poetry run coverage report poetry run coverage xml +commands_post = + rm charm_internal_version [testenv:integration] description = Run integration tests