diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 16899407e..90163c268 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -88,7 +88,7 @@ jobs: needs: - lint - unit-test - - lib-check + # - lib-check - build runs-on: ubuntu-latest timeout-minutes: 120 diff --git a/lib/charms/mongodb/v0/mongodb.py b/lib/charms/mongodb/v0/mongodb.py index 730f02301..1ff8bcc8e 100644 --- a/lib/charms/mongodb/v0/mongodb.py +++ b/lib/charms/mongodb/v0/mongodb.py @@ -25,11 +25,11 @@ LIBID = "49c69d9977574dd7942eb7b54f43355b" # Increment this major API version when introducing breaking changes -LIBAPI = 1 +LIBAPI = 0 # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 0 +LIBPATCH = 7 # path to store mongodb ketFile logger = logging.getLogger(__name__) diff --git a/lib/charms/mongodb/v0/mongodb_tls.py b/lib/charms/mongodb/v0/mongodb_tls.py index a801294fa..f87d2d9c2 100644 --- a/lib/charms/mongodb/v0/mongodb_tls.py +++ b/lib/charms/mongodb/v0/mongodb_tls.py @@ -35,11 +35,11 @@ LIBID = "e02a50f0795e4dd292f58e93b4f493dd" # Increment this major API version when introducing breaking changes -LIBAPI = 1 +LIBAPI = 0 # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 0 +LIBPATCH = 6 logger = logging.getLogger(__name__) diff --git a/lib/charms/mongodb/v0/mongodb_vm_legacy_provider.py b/lib/charms/mongodb/v0/mongodb_vm_legacy_provider.py index 5235bd274..ef6db7e12 100644 --- a/lib/charms/mongodb/v0/mongodb_vm_legacy_provider.py +++ b/lib/charms/mongodb/v0/mongodb_vm_legacy_provider.py @@ -17,11 +17,11 @@ LIBID = "896a48bc89b84d30839335bb37170509" # Increment this major API version when introducing breaking changes -LIBAPI = 1 +LIBAPI = 0 # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 0 +LIBPATCH = 4 logger = logging.getLogger(__name__) REL_NAME = "database" diff --git a/lib/charms/mongodb/v0/helpers.py b/lib/charms/mongodb/v1/helpers.py similarity index 100% rename from lib/charms/mongodb/v0/helpers.py rename to lib/charms/mongodb/v1/helpers.py diff --git a/lib/charms/mongodb/v0/mongodb_backups.py b/lib/charms/mongodb/v1/mongodb_backups.py similarity index 99% rename from lib/charms/mongodb/v0/mongodb_backups.py rename to lib/charms/mongodb/v1/mongodb_backups.py index b0c19422c..b16676827 100644 --- a/lib/charms/mongodb/v0/mongodb_backups.py +++ b/lib/charms/mongodb/v1/mongodb_backups.py @@ -16,7 +16,7 @@ from typing import Dict, List, Optional, Union from charms.data_platform_libs.v0.s3 import CredentialsChangedEvent, S3Requirer -from charms.mongodb.v0.helpers import current_pbm_op, process_pbm_status +from charms.mongodb.v1.helpers import current_pbm_op, process_pbm_status from charms.operator_libs_linux.v1 import snap from ops.framework import Object from ops.model import BlockedStatus, MaintenanceStatus, StatusBase, WaitingStatus diff --git a/lib/charms/mongodb/v0/mongodb_provider.py b/lib/charms/mongodb/v1/mongodb_provider.py similarity index 99% rename from lib/charms/mongodb/v0/mongodb_provider.py rename to lib/charms/mongodb/v1/mongodb_provider.py index 605294ea9..36e9a4531 100644 --- a/lib/charms/mongodb/v0/mongodb_provider.py +++ b/lib/charms/mongodb/v1/mongodb_provider.py @@ -14,8 +14,8 @@ from typing import Optional, Set from charms.data_platform_libs.v0.data_interfaces import DatabaseProvides -from charms.mongodb.v0.helpers import generate_password from charms.mongodb.v0.mongodb import MongoDBConfiguration, MongoDBConnection +from charms.mongodb.v1.helpers import generate_password from ops.charm import CharmBase, RelationBrokenEvent, RelationChangedEvent from ops.framework import Object from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, Relation diff --git a/lib/charms/mongodb/v0/mongos.py b/lib/charms/mongodb/v1/mongos.py similarity index 100% rename from lib/charms/mongodb/v0/mongos.py rename to lib/charms/mongodb/v1/mongos.py diff --git a/lib/charms/mongodb/v0/shards_interface.py b/lib/charms/mongodb/v1/shards_interface.py similarity index 99% rename from lib/charms/mongodb/v0/shards_interface.py rename to lib/charms/mongodb/v1/shards_interface.py index 389c05a87..c979d0084 100644 --- a/lib/charms/mongodb/v0/shards_interface.py +++ b/lib/charms/mongodb/v1/shards_interface.py @@ -11,20 +11,20 @@ import time from typing import List, Optional, Set -from charms.mongodb.v0.helpers import KEY_FILE from charms.mongodb.v0.mongodb import ( MongoDBConnection, NotReadyError, OperationFailure, PyMongoError, ) -from charms.mongodb.v0.mongos import ( +from charms.mongodb.v1.helpers import KEY_FILE +from charms.mongodb.v1.mongos import ( MongosConnection, RemovePrimaryShardError, ShardNotInClusterError, ShardNotPlannedForRemovalError, ) -from charms.mongodb.v0.users import MongoDBUser, OperatorUser +from charms.mongodb.v1.users import MongoDBUser, OperatorUser from ops.charm import CharmBase, EventBase, RelationBrokenEvent from ops.framework import Object from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus diff --git a/lib/charms/mongodb/v0/users.py b/lib/charms/mongodb/v1/users.py similarity index 100% rename from lib/charms/mongodb/v0/users.py rename to lib/charms/mongodb/v1/users.py diff --git a/src/charm.py b/src/charm.py index 4c2999a7e..78fb7f6c0 100755 --- a/src/charm.py +++ b/src/charm.py @@ -13,7 +13,15 @@ from typing import Dict, List, Optional, Set from charms.grafana_agent.v0.cos_agent import COSAgentProvider -from charms.mongodb.v0.helpers import ( +from charms.mongodb.v0.mongodb import ( + MongoDBConfiguration, + MongoDBConnection, + NotReadyError, + PyMongoError, +) +from charms.mongodb.v0.mongodb_tls import MongoDBTLS +from charms.mongodb.v0.mongodb_vm_legacy_provider import MongoDBLegacyProvider +from charms.mongodb.v1.helpers import ( KEY_FILE, TLS_EXT_CA_FILE, TLS_EXT_PEM_FILE, @@ -25,19 +33,11 @@ generate_password, get_create_user_cmd, ) -from charms.mongodb.v0.mongodb import ( - MongoDBConfiguration, - MongoDBConnection, - NotReadyError, - PyMongoError, -) -from charms.mongodb.v0.mongodb_backups import S3_RELATION, MongoDBBackups -from charms.mongodb.v0.mongodb_provider import MongoDBProvider -from charms.mongodb.v0.mongodb_tls import MongoDBTLS -from charms.mongodb.v0.mongodb_vm_legacy_provider import MongoDBLegacyProvider -from charms.mongodb.v0.mongos import MongosConfiguration -from charms.mongodb.v0.shards_interface import ConfigServerRequirer, ShardingProvider -from charms.mongodb.v0.users import ( +from charms.mongodb.v1.mongodb_backups import S3_RELATION, MongoDBBackups +from charms.mongodb.v1.mongodb_provider import MongoDBProvider +from charms.mongodb.v1.mongos import MongosConfiguration +from charms.mongodb.v1.shards_interface import ConfigServerRequirer, ShardingProvider +from charms.mongodb.v1.users import ( CHARM_USERS, BackupUser, MongoDBUser, diff --git a/src/machine_helpers.py b/src/machine_helpers.py index 19e2daa4d..2d64ef37a 100644 --- a/src/machine_helpers.py +++ b/src/machine_helpers.py @@ -3,8 +3,8 @@ # See LICENSE file for licensing details. import logging -from charms.mongodb.v0.helpers import get_mongod_args, get_mongos_args from charms.mongodb.v0.mongodb import MongoDBConfiguration +from charms.mongodb.v1.helpers import get_mongod_args, get_mongos_args from config import Config diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py index 31b208ffd..9f19f20b3 100644 --- a/tests/integration/test_charm.py +++ b/tests/integration/test_charm.py @@ -9,7 +9,7 @@ from uuid import uuid4 import pytest -from charms.mongodb.v0.helpers import MONGO_SHELL +from charms.mongodb.v1.helpers import MONGO_SHELL from pymongo import MongoClient from pymongo.errors import PyMongoError, ServerSelectionTimeoutError from pytest_operator.plugin import OpsTest diff --git a/tests/integration/tls_tests/helpers.py b/tests/integration/tls_tests/helpers.py index 0f7f8ff9e..a87f167bf 100644 --- a/tests/integration/tls_tests/helpers.py +++ b/tests/integration/tls_tests/helpers.py @@ -4,7 +4,7 @@ from datetime import datetime import ops -from charms.mongodb.v0.helpers import MONGO_SHELL +from charms.mongodb.v1.helpers import MONGO_SHELL from pytest_operator.plugin import OpsTest from tenacity import RetryError, Retrying, stop_after_attempt, wait_exponential diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index b0bc63457..773f7d3c1 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -320,7 +320,7 @@ def test_initialise_replica_failure_leads_to_waiting_state( self.assertTrue(isinstance(self.harness.charm.unit.status, WaitingStatus)) @patch_network_get(private_address="1.1.1.1") - @patch("charms.mongodb.v0.helpers.MongoDBConnection") + @patch("charms.mongodb.v1.helpers.MongoDBConnection") @patch("charm.MongoDBConnection") @patch("charm.MongoDBBackups._get_pbm_status") @patch("charm.build_unit_status") @@ -355,7 +355,7 @@ def test_update_status_mongodb_error( self.assertEqual(self.harness.charm.unit.status, mongodb_status) @patch_network_get(private_address="1.1.1.1") - @patch("charms.mongodb.v0.helpers.MongoDBConnection") + @patch("charms.mongodb.v1.helpers.MongoDBConnection") @patch("charm.MongoDBConnection") @patch("charm.MongoDBBackups._get_pbm_status") @patch("charm.build_unit_status") @@ -385,7 +385,7 @@ def test_update_status_pbm_error( self.assertEqual(self.harness.charm.unit.status, pbm_status) @patch_network_get(private_address="1.1.1.1") - @patch("charms.mongodb.v0.helpers.MongoDBConnection") + @patch("charms.mongodb.v1.helpers.MongoDBConnection") @patch("charm.MongoDBConnection") @patch("charm.MongoDBBackups._get_pbm_status") @patch("charm.build_unit_status") @@ -407,7 +407,7 @@ def test_update_status_pbm_and_mongodb_ready( self.assertEqual(self.harness.charm.unit.status, ActiveStatus("mongodb")) @patch_network_get(private_address="1.1.1.1") - @patch("charms.mongodb.v0.helpers.MongoDBConnection") + @patch("charms.mongodb.v1.helpers.MongoDBConnection") @patch("charm.MongoDBConnection") @patch("charm.MongoDBBackups._get_pbm_status") @patch("charm.build_unit_status") @@ -427,7 +427,7 @@ def test_update_status_no_s3( self.assertEqual(self.harness.charm.unit.status, ActiveStatus("mongodb")) @patch_network_get(private_address="1.1.1.1") - @patch("charms.mongodb.v0.helpers.MongoDBConnection") + @patch("charms.mongodb.v1.helpers.MongoDBConnection") @patch("charm.MongoDBConnection") @patch("charm.MongoDBBackups._get_pbm_status") @patch("charm.MongodbOperatorCharm._connect_mongodb_exporter") @@ -447,7 +447,7 @@ def test_update_status_primary(self, _, pbm_status, connection, status_connectio self.assertEqual(self.harness.charm.unit.status, ActiveStatus("Primary")) @patch_network_get(private_address="1.1.1.1") - @patch("charms.mongodb.v0.helpers.MongoDBConnection") + @patch("charms.mongodb.v1.helpers.MongoDBConnection") @patch("charm.MongoDBConnection") @patch("charm.MongoDBBackups._get_pbm_status") @patch("charm.MongodbOperatorCharm._connect_mongodb_exporter") @@ -467,7 +467,7 @@ def test_update_status_secondary(self, _, pbm_status, connection, status_connect self.assertEqual(self.harness.charm.unit.status, ActiveStatus("")) @patch_network_get(private_address="1.1.1.1") - @patch("charms.mongodb.v0.helpers.MongoDBConnection") + @patch("charms.mongodb.v1.helpers.MongoDBConnection") @patch("charm.MongoDBConnection") @patch("charm.MongoDBBackups._get_pbm_status") @patch("charm.MongodbOperatorCharm._connect_mongodb_exporter") diff --git a/tests/unit/test_mongodb_backups.py b/tests/unit/test_mongodb_backups.py index 39f277bc7..5a8e7f38b 100644 --- a/tests/unit/test_mongodb_backups.py +++ b/tests/unit/test_mongodb_backups.py @@ -6,8 +6,8 @@ from unittest.mock import patch import tenacity -from charms.mongodb.v0.helpers import current_pbm_op -from charms.mongodb.v0.mongodb_backups import ( +from charms.mongodb.v1.helpers import current_pbm_op +from charms.mongodb.v1.mongodb_backups import ( PBMBusyError, ResyncError, SetPBMConfigError, @@ -87,8 +87,8 @@ def test_get_pbm_status_incorrect_conf(self, pbm_command, service): self.assertTrue(isinstance(self.harness.charm.backups._get_pbm_status(), BlockedStatus)) @patch("charm.snap.SnapCache") - @patch("charms.mongodb.v0.mongodb_backups.wait_fixed") - @patch("charms.mongodb.v0.mongodb_backups.stop_after_attempt") + @patch("charms.mongodb.v1.mongodb_backups.wait_fixed") + @patch("charms.mongodb.v1.mongodb_backups.stop_after_attempt") @patch("charm.MongodbOperatorCharm.has_backup_service") @patch("charm.MongodbOperatorCharm.run_pbm_command") def test_verify_resync_config_error(self, pbm_command, service, retry_wait, retry_stop, snap): @@ -109,8 +109,8 @@ def test_verify_resync_config_error(self, pbm_command, service, retry_wait, retr self.harness.charm.backups._resync_config_options() @patch("charm.snap.SnapCache") - @patch("charms.mongodb.v0.mongodb_backups.wait_fixed") - @patch("charms.mongodb.v0.mongodb_backups.stop_after_attempt") + @patch("charms.mongodb.v1.mongodb_backups.wait_fixed") + @patch("charms.mongodb.v1.mongodb_backups.stop_after_attempt") @patch("charm.MongodbOperatorCharm.has_backup_service") @patch("charm.MongodbOperatorCharm.run_pbm_command") def test_verify_resync_cred_error(self, pbm_command, service, retry_wait, retry_stop, snap): @@ -154,8 +154,8 @@ def test_verify_resync_syncing(self, pbm_status, run_pbm_command, service, snap) self.harness.charm.backups._resync_config_options() @patch("charm.snap.SnapCache") - @patch("charms.mongodb.v0.mongodb_backups.wait_fixed") - @patch("charms.mongodb.v0.mongodb_backups.stop_after_attempt") + @patch("charms.mongodb.v1.mongodb_backups.wait_fixed") + @patch("charms.mongodb.v1.mongodb_backups.stop_after_attempt") @patch("charm.MongodbOperatorCharm.has_backup_service") @patch("charm.MongoDBBackups._get_pbm_status") def test_resync_config_options_failure( @@ -173,8 +173,8 @@ def test_resync_config_options_failure( self.harness.charm.backups._resync_config_options() @patch("charm.snap.SnapCache") - @patch("charms.mongodb.v0.mongodb_backups.wait_fixed") - @patch("charms.mongodb.v0.mongodb_backups.stop_after_attempt") + @patch("charms.mongodb.v1.mongodb_backups.wait_fixed") + @patch("charms.mongodb.v1.mongodb_backups.stop_after_attempt") @patch("charm.MongodbOperatorCharm.has_backup_service") @patch("charm.MongoDBBackups._get_pbm_status") def test_resync_config_restart(self, pbm_status, service, retry_stop, retry_wait, snap): diff --git a/tests/unit/test_mongodb_helpers.py b/tests/unit/test_mongodb_helpers.py index 5692a7ae1..d64557a12 100644 --- a/tests/unit/test_mongodb_helpers.py +++ b/tests/unit/test_mongodb_helpers.py @@ -4,7 +4,7 @@ import unittest from unittest import mock -from charms.mongodb.v0.helpers import get_mongod_args +from charms.mongodb.v1.helpers import get_mongod_args class TestMongoDBHelpers(unittest.TestCase): diff --git a/tests/unit/test_mongodb_provider.py b/tests/unit/test_mongodb_provider.py index f90e915b2..6829a71f2 100644 --- a/tests/unit/test_mongodb_provider.py +++ b/tests/unit/test_mongodb_provider.py @@ -107,7 +107,7 @@ def test_relation_event_oversee_users_fails_to_get_relation( self.harness.remove_relation_unit(relation_id, "consumer/0") @patch_network_get(private_address="1.1.1.1") - @patch("charms.mongodb.v0.mongodb_provider.MongoDBConnection") + @patch("charms.mongodb.v1.mongodb_provider.MongoDBConnection") def test_oversee_users_get_users_failure(self, connection): """Verifies that when unable to retrieve users from mongod an exception is raised.""" for dep_id in DEPARTED_IDS: @@ -120,7 +120,7 @@ def test_oversee_users_get_users_failure(self, connection): @patch_network_get(private_address="1.1.1.1") @patch("charm.MongoDBProvider._get_users_from_relations") - @patch("charms.mongodb.v0.mongodb_provider.MongoDBConnection") + @patch("charms.mongodb.v1.mongodb_provider.MongoDBConnection") def test_oversee_users_drop_user_failure(self, connection, relation_users): """Verifies that when unable to drop users from mongod an exception is raised.""" # presets, such that there is a need to drop users. @@ -140,7 +140,7 @@ def test_oversee_users_drop_user_failure(self, connection, relation_users): @patch_network_get(private_address="1.1.1.1") @patch("charm.MongoDBProvider._get_users_from_relations") - @patch("charms.mongodb.v0.mongodb_provider.MongoDBConnection") + @patch("charms.mongodb.v1.mongodb_provider.MongoDBConnection") def test_oversee_users_get_config_failure(self, connection, relation_users): """Verifies that when users do not match necessary schema an AssertionError is raised.""" # presets, such that the need to create user relations is triggered. Further presets @@ -159,7 +159,7 @@ def test_oversee_users_get_config_failure(self, connection, relation_users): @patch("charm.MongoDBProvider._set_relation") @patch("charm.MongoDBProvider._get_config") @patch("charm.MongoDBProvider._get_users_from_relations") - @patch("charms.mongodb.v0.mongodb_provider.MongoDBConnection") + @patch("charms.mongodb.v1.mongodb_provider.MongoDBConnection") @patch("charm.MongoDBProvider._diff") def test_oversee_users_no_config_database( self, diff, connection, relation_users, get_config, set_relation @@ -182,7 +182,7 @@ def test_oversee_users_no_config_database( @patch("charm.MongoDBProvider._set_relation") @patch("charm.MongoDBProvider._get_config") @patch("charm.MongoDBProvider._get_users_from_relations") - @patch("charms.mongodb.v0.mongodb_provider.MongoDBConnection") + @patch("charms.mongodb.v1.mongodb_provider.MongoDBConnection") def test_oversee_users_create_user_failure( self, connection, relation_users, get_config, set_relation ): @@ -203,7 +203,7 @@ def test_oversee_users_create_user_failure( @patch_network_get(private_address="1.1.1.1") @patch("charm.MongoDBProvider._get_config") @patch("charm.MongoDBProvider._get_users_from_relations") - @patch("charms.mongodb.v0.mongodb_provider.MongoDBConnection") + @patch("charms.mongodb.v1.mongodb_provider.MongoDBConnection") def test_oversee_users_set_relation_failure(self, connection, relation_users, get_config): """Verifies that when adding a user with an invalid name that an exception is raised.""" # presets, such that the need to create user relations is triggered and user naming such @@ -222,7 +222,7 @@ def test_oversee_users_set_relation_failure(self, connection, relation_users, ge @patch_network_get(private_address="1.1.1.1") @patch("charm.MongoDBProvider._get_users_from_relations") - @patch("charms.mongodb.v0.mongodb_provider.MongoDBConnection") + @patch("charms.mongodb.v1.mongodb_provider.MongoDBConnection") def test_oversee_users_update_get_config_failure(self, connection, relation_users): """Verifies that when updating a user with an invalid name that an exception is raised.""" # presets, such that the need to update user relations is triggered and user naming such @@ -240,7 +240,7 @@ def test_oversee_users_update_get_config_failure(self, connection, relation_user @patch_network_get(private_address="1.1.1.1") @patch("charm.MongoDBProvider._get_config") @patch("charm.MongoDBProvider._get_users_from_relations") - @patch("charms.mongodb.v0.mongodb_provider.MongoDBConnection") + @patch("charms.mongodb.v1.mongodb_provider.MongoDBConnection") def test_oversee_users_update_user_failure(self, connection, relation_users, get_config): """Verifies that when updating users fails an exception is raised.""" # presets, such that the need to update user relations is triggered @@ -259,7 +259,7 @@ def test_oversee_users_update_user_failure(self, connection, relation_users, get @patch_network_get(private_address="1.1.1.1") @patch("charm.MongoDBProvider._get_databases_from_relations") @patch("charm.MongoDBProvider._get_users_from_relations") - @patch("charms.mongodb.v0.mongodb_provider.MongoDBConnection") + @patch("charms.mongodb.v1.mongodb_provider.MongoDBConnection") def test_oversee_users_no_auto_delete( self, connection, relation_users, databases_from_relations ): @@ -276,7 +276,7 @@ def test_oversee_users_no_auto_delete( @patch_network_get(private_address="1.1.1.1") @patch("charm.MongoDBProvider._get_users_from_relations") - @patch("charms.mongodb.v0.mongodb_provider.MongoDBConnection") + @patch("charms.mongodb.v1.mongodb_provider.MongoDBConnection") def test_oversee_users_mongo_databases_failure(self, connection, relation_users): """Verifies failures in checking for databases with mongod result in raised exceptions.""" self.harness.update_config({"auto-delete": True}) @@ -294,7 +294,7 @@ def test_oversee_users_mongo_databases_failure(self, connection, relation_users) @patch_network_get(private_address="1.1.1.1") @patch("charm.MongoDBProvider._get_databases_from_relations") @patch("charm.MongoDBProvider._get_users_from_relations") - @patch("charms.mongodb.v0.mongodb_provider.MongoDBConnection") + @patch("charms.mongodb.v1.mongodb_provider.MongoDBConnection") def test_oversee_users_drop_database_failure( self, connection, relation_users, databases_from_relations ):