Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix libs #271

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
needs:
- lint
- unit-test
- lib-check
# - lib-check
dmitry-ratushnyy marked this conversation as resolved.
Show resolved Hide resolved
- build
runs-on: ubuntu-latest
timeout-minutes: 120
Expand Down
4 changes: 2 additions & 2 deletions lib/charms/mongodb/v0/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
4 changes: 2 additions & 2 deletions lib/charms/mongodb/v0/mongodb_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
4 changes: 2 additions & 2 deletions lib/charms/mongodb/v0/mongodb_vm_legacy_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
28 changes: 14 additions & 14 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/machine_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/tls_tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/test_mongodb_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_mongodb_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/test_mongodb_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
):
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
):
Expand All @@ -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})
Expand All @@ -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
):
Expand Down
Loading