Skip to content

Commit

Permalink
update backup & HA tests (#189)
Browse files Browse the repository at this point in the history
### Problem
<!-- What issue is this PR trying to solve? -->
1. keys for AWS changed so tests no longer passed
2. HA test check for all db processes down fails

### Solution
<!-- A summary of the solution addressing the above issue -->
1. update backup configs in backup tests for the new AWS keys/configs 
2. update HA test check for all db processes down to ignore the
mongodb_exporter process
  • Loading branch information
MiaAltieri authored Mar 22, 2023
1 parent 90aa769 commit 3ab2bc9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/charms/mongodb/v0/mongodb_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _on_s3_credential_changed(self, event: CredentialsChangedEvent):
return

# pbm requires that the URI is set before adding configs
pbm_snap.set({"uri": self._backup_config.uri})
pbm_snap.set({"pbm-uri": self._backup_config.uri})

# Add and sync configuration options while handling errors related to configuring options
# and re-syncing PBM.
Expand Down
18 changes: 13 additions & 5 deletions lib/charms/operator_libs_linux/v1/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 8
LIBPATCH = 9


# Regex to locate 7-bit C1 ANSI sequences
Expand Down Expand Up @@ -976,19 +976,27 @@ def _system_set(config_item: str, value: str) -> None:
raise SnapError("Failed setting system config '{}' to '{}'".format(config_item, value))


def hold_refresh(days: int = 90) -> bool:
def hold_refresh(days: int = 90, forever: bool = False) -> bool:
"""Set the system-wide snap refresh hold.
Args:
days: number of days to hold system refreshes for. Maximum 90. Set to zero to remove hold.
forever: if True, will set a hold forever.
"""
# Currently the snap daemon can only hold for a maximum of 90 days
if not isinstance(days, int) or days > 90:
raise ValueError("days must be an int between 1 and 90")
if not isinstance(forever, bool):
raise TypeError("forever must be a bool")
if not isinstance(days, int):
raise TypeError("days must be an int")
if forever:
_system_set("refresh.hold", "forever")
logger.info("Set system-wide snap refresh hold to: forever")
elif days == 0:
_system_set("refresh.hold", "")
logger.info("Removed system-wide snap refresh hold")
else:
# Currently the snap daemon can only hold for a maximum of 90 days
if not 1 <= days <= 90:
raise ValueError("days must be between 1 and 90")
# Add the number of days to current time
target_date = datetime.now(timezone.utc).astimezone() + timedelta(days=days)
# Format for the correct datetime format
Expand Down
17 changes: 9 additions & 8 deletions tests/integration/backup_tests/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ async def test_ready_correct_conf(ops_test: OpsTest) -> None:
choices = string.ascii_letters + string.digits
unique_path = "".join([secrets.choice(choices) for _ in range(4)])
configuration_parameters = {
"bucket": "pbm-test-bucket-1",
"bucket": "data-charms-testing",
"path": f"mongodb-vm/test-{unique_path}",
"region": "us-west-2",
"endpoint": "https://s3.amazonaws.com",
"region": "us-east-1",
}

# apply new configuration options
Expand Down Expand Up @@ -218,9 +219,9 @@ async def test_multi_backup(ops_test: OpsTest, continuous_writes_to_db) -> None:
# set AWS credentials, set configs for s3 storage, and wait to resync
await helpers.set_credentials(ops_test, cloud="AWS")
configuration_parameters = {
"bucket": "pbm-test-bucket-1",
"region": "us-west-2",
"endpoint": "",
"bucket": "data-charms-testing",
"region": "us-east-1",
"endpoint": "https://s3.amazonaws.com",
}
await ops_test.model.applications[S3_APP_NAME].set_config(configuration_parameters)
await asyncio.gather(
Expand Down Expand Up @@ -299,9 +300,9 @@ async def test_restore_new_cluster(ops_test: OpsTest, add_writes_to_db, cloud_pr
await helpers.set_credentials(ops_test, cloud=cloud_provider)
if cloud_provider == "AWS":
configuration_parameters = {
"bucket": "pbm-test-bucket-1",
"region": "us-west-2",
"endpoint": "",
"bucket": "data-charms-testing",
"region": "us-east-1",
"endpoint": "https://s3.amazonaws.com",
}
else:
configuration_parameters = {
Expand Down
13 changes: 5 additions & 8 deletions tests/integration/ha_tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
MONGOD_SERVICE_DEFAULT_PATH = "/etc/systemd/system/snap.charmed-mongodb.mongod.service"
TMP_SERVICE_PATH = "tests/integration/ha_tests/tmp.service"
LOGGING_OPTIONS = f"--logpath={MONGO_COMMON_DIR}/var/log/mongod/mongodb.log --logappend"
EXPORTER_PROC = "/usr/bin/mongodb_exporter"
GREP_PROC = "grep"


class ProcessError(Exception):
Expand Down Expand Up @@ -553,20 +555,15 @@ async def all_db_processes_down(ops_test: OpsTest) -> bool:
app = await app_name(ops_test)

try:
for attempt in Retrying(stop=stop_after_attempt(50), wait=wait_fixed(3)):
for attempt in Retrying(stop=stop_after_attempt(60), wait=wait_fixed(3)):
with attempt:
for unit in ops_test.model.applications[app].units:
search_db_process = f"run --unit {unit.name} ps aux | grep {DB_PROCESS}"
search_db_process = f"run --unit {unit.name} pgrep -x mongod"
_, processes, _ = await ops_test.juju(*search_db_process.split())

# `ps aux | grep {DB_PROCESS}` is a process on it's own and will be shown in
# the output of ps aux, hence it it is important that we check if there is
# more than one process containing the name `DB_PROCESS`
# splitting processes by "\n" results in one or more empty lines, hence we
# need to process these lines accordingly.
processes = [proc for proc in processes.split("\n") if len(proc) > 0]

if len(processes) > 1:
if len(processes) > 0:
raise ProcessRunningError
except RetryError:
return False
Expand Down

0 comments on commit 3ab2bc9

Please sign in to comment.