Skip to content

Commit 8e61e97

Browse files
committed
wip: test part
1 parent 8a2e72f commit 8e61e97

File tree

15 files changed

+69
-73
lines changed

15 files changed

+69
-73
lines changed

tests/integration/backup_tests/test_backups.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
import secrets
77
import string
88
import time
9-
from pathlib import Path
109

1110
import pytest
1211
import pytest_asyncio
13-
import yaml
1412
from pytest_operator.plugin import OpsTest
1513
from tenacity import RetryError, Retrying, stop_after_delay, wait_fixed
1614

1715
from ..ha_tests import helpers as ha_helpers
1816
from ..helpers import (
17+
METADATA,
18+
RESOURCES,
1919
check_or_scale_app,
2020
destroy_cluster,
2121
get_app_name,
@@ -29,7 +29,6 @@
2929
TIMEOUT = 15 * 60
3030
ENDPOINT = "s3-credentials"
3131
NEW_CLUSTER = "new-mongodb"
32-
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
3332
DATABASE_APP_NAME = METADATA["name"]
3433
NUM_UNITS = 3
3534

@@ -99,13 +98,10 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None:
9998
else:
10099
async with ops_test.fast_forward():
101100
my_charm = await ops_test.build_charm(".")
102-
resources = {
103-
"mongodb-image": METADATA["resources"]["mongodb-image"]["upstream-source"]
104-
}
105101
await ops_test.model.deploy(
106102
my_charm,
107103
num_units=NUM_UNITS,
108-
resources=resources,
104+
resources=RESOURCES,
109105
series="jammy",
110106
trust=True,
111107
)
@@ -406,13 +402,18 @@ async def test_restore_new_cluster(
406402

407403
# deploy a new cluster with a different name
408404
db_charm = await ops_test.build_charm(".")
409-
resources = {"mongodb-image": METADATA["resources"]["mongodb-image"]["upstream-source"]}
410405
await ops_test.model.deploy(
406+
<<<<<<< HEAD
411407
db_charm,
412408
num_units=3,
413409
resources=resources,
414410
application_name=new_cluster_app_name,
415411
trust=True,
412+
||||||| parent of 0ded9b66 (wip: test part)
413+
db_charm, num_units=3, resources=resources, application_name=new_cluster_app_name
414+
=======
415+
db_charm, num_units=3, resources=RESOURCES, application_name=new_cluster_app_name
416+
>>>>>>> 0ded9b66 (wip: test part)
416417
)
417418

418419
await asyncio.gather(

tests/integration/backup_tests/test_sharding_backups.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
from ..backup_tests import helpers as backup_helpers
1515
from ..ha_tests.helpers import deploy_and_scale_application, get_direct_mongo_client
1616
from ..helpers import (
17-
METADATA,
1817
MONGOS_PORT,
18+
RESOURCES,
1919
get_leader_id,
2020
get_password,
2121
mongodb_uri,
@@ -299,31 +299,30 @@ async def deploy_cluster_backup_test(
299299
ops_test: OpsTest, deploy_s3_integrator=True, new_names=False
300300
) -> None:
301301
"""Deploy a cluster for the backup test."""
302-
resources = {"mongodb-image": METADATA["resources"]["mongodb-image"]["upstream-source"]}
303302
my_charm = await ops_test.build_charm(".")
304303

305304
config_server_name = CONFIG_SERVER_APP_NAME if not new_names else CONFIG_SERVER_APP_NAME_NEW
306305
shard_one_name = SHARD_ONE_APP_NAME if not new_names else SHARD_ONE_APP_NAME_NEW
307306
shard_two_name = SHARD_TWO_APP_NAME if not new_names else SHARD_TWO_APP_NAME_NEW
308307
await ops_test.model.deploy(
309308
my_charm,
310-
resources=resources,
309+
resources=RESOURCES,
311310
num_units=2,
312311
config={"role": "config-server"},
313312
application_name=config_server_name,
314313
trust=True,
315314
)
316315
await ops_test.model.deploy(
317316
my_charm,
318-
resources=resources,
317+
resources=RESOURCES,
319318
num_units=2,
320319
config={"role": "shard"},
321320
application_name=shard_one_name,
322321
trust=True,
323322
)
324323
await ops_test.model.deploy(
325324
my_charm,
326-
resources=resources,
325+
resources=RESOURCES,
327326
num_units=1,
328327
config={"role": "shard"},
329328
application_name=shard_two_name,

tests/integration/ha_tests/helpers.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import kubernetes as kubernetes
1818
import ops
19-
import yaml
2019
from juju.unit import Unit
2120
from pymongo import MongoClient
2221
from pytest_operator.plugin import OpsTest
@@ -33,6 +32,7 @@
3332
APP_NAME,
3433
MONGOD_PORT,
3534
MONGOS_PORT,
35+
RESOURCES,
3636
get_app_name,
3737
get_mongo_cmd,
3838
get_password,
@@ -41,7 +41,6 @@
4141
primary_host,
4242
)
4343

44-
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
4544
MONGODB_CONTAINER_NAME = "mongod"
4645
MONGODB_SERVICE_NAME = "mongod"
4746
MONGOD_PROCESS_NAME = "mongod"
@@ -175,13 +174,11 @@ async def deploy_and_scale_mongodb(
175174
# Cache the built charm to avoid rebuilding it between tests
176175
mongodb_charm = charm
177176

178-
resources = {"mongodb-image": METADATA["resources"]["mongodb-image"]["upstream-source"]}
179-
180177
async with ops_test.fast_forward():
181178
await ops_test.model.deploy(
182179
mongodb_charm,
183180
application_name=mongodb_application_name,
184-
resources=resources,
181+
resources=RESOURCES,
185182
num_units=num_units,
186183
series="jammy",
187184
trust=True,

tests/integration/helpers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
UNIT_IDS = [0, 1, 2]
2626
MONGOS_PORT = 27018
2727
MONGOD_PORT = 27017
28+
RESOURCES = {
29+
"mongodb-image": METADATA["resources"]["mongodb-image"]["upstream-source"],
30+
"data-platform-k8s-webhook-mutator-image": METADATA["resources"][
31+
"data-platform-k8s-webhook-mutator-image"
32+
]["upstream-source"],
33+
}
2834

2935
TEST_DOCUMENTS = """[
3036
{

tests/integration/metrics_tests/test_metrics.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
# Copyright 2024 Canonical Ltd.
33
# See LICENSE file for licensing details.
44
import time
5-
from pathlib import Path
65

76
import pytest
87
import requests
9-
import yaml
108
from pytest_operator.plugin import OpsTest
119

1210
from ..ha_tests import helpers as ha_helpers
13-
from ..helpers import check_or_scale_app, get_app_name
11+
from ..helpers import RESOURCES, check_or_scale_app, get_app_name
1412

15-
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
1613
DATABASE_APP_NAME = "mongodb-k8s"
1714
MONGODB_EXPORTER_PORT = 9216
1815
MEDIAN_REELECTION_TIME = 12
@@ -63,11 +60,10 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None:
6360

6461
async with ops_test.fast_forward():
6562
my_charm = await ops_test.build_charm(".")
66-
resources = {"mongodb-image": METADATA["resources"]["mongodb-image"]["upstream-source"]}
6763
await ops_test.model.deploy(
6864
my_charm,
6965
num_units=NUM_UNITS,
70-
resources=resources,
66+
resources=RESOURCES,
7167
series="jammy",
7268
trust=True,
7369
)

tests/integration/relation_tests/test_charm_relations.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
import asyncio
55
import logging
66
import time
7-
from pathlib import Path
87

98
import pytest
10-
import yaml
119
from pymongo.uri_parser import parse_uri
1210
from pytest_operator.plugin import OpsTest
1311
from tenacity import RetryError
1412

1513
from ..ha_tests.helpers import get_replica_set_primary as replica_set_primary
16-
from ..helpers import check_or_scale_app, get_app_name, is_relation_joined, run_mongo_op
14+
from ..helpers import (
15+
RESOURCES,
16+
check_or_scale_app,
17+
get_app_name,
18+
is_relation_joined,
19+
run_mongo_op,
20+
)
1721
from .helpers import (
1822
assert_created_user_can_connect,
1923
get_application_relation_data,
@@ -25,7 +29,6 @@
2529

2630
MEDIAN_REELECTION_TIME = 12
2731
APPLICATION_APP_NAME = "application"
28-
DATABASE_METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
2932
PORT = 27017
3033
DATABASE_APP_NAME = "mongodb-k8s"
3134
FIRST_DATABASE_RELATION_NAME = "first-database"
@@ -56,18 +59,14 @@ async def test_deploy_charms(ops_test: OpsTest):
5659
False
5760
), f"provided MongoDB application, cannot be named {ANOTHER_DATABASE_APP_NAME}, this name is reserved for this test."
5861

59-
db_resources = {
60-
"mongodb-image": DATABASE_METADATA["resources"]["mongodb-image"]["upstream-source"]
61-
}
62-
6362
if app_name:
6463
await asyncio.gather(check_or_scale_app(ops_test, app_name, REQUIRED_UNITS))
6564
else:
6665
await asyncio.gather(
6766
ops_test.model.deploy(
6867
database_charm,
6968
application_name=DATABASE_APP_NAME,
70-
resources=db_resources,
69+
resources=RESOURCES,
7170
num_units=REQUIRED_UNITS,
7271
trust=True,
7372
)
@@ -82,7 +81,7 @@ async def test_deploy_charms(ops_test: OpsTest):
8281
ops_test.model.deploy(
8382
database_charm,
8483
application_name=ANOTHER_DATABASE_APP_NAME,
85-
resources=db_resources,
84+
resources=RESOURCES,
8685
num_units=REQUIRED_UNITS,
8786
trust=True,
8887
),

tests/integration/sharding_tests/helpers.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pytest_operator.plugin import OpsTest
88
from tenacity import retry, stop_after_attempt, wait_fixed
99

10-
from ..helpers import METADATA, get_application_relation_data, get_secret_content
10+
from ..helpers import RESOURCES, get_application_relation_data, get_secret_content
1111

1212
SHARD_ONE_APP_NAME = "shard-one"
1313
SHARD_TWO_APP_NAME = "shard-two"
@@ -57,10 +57,9 @@ async def deploy_cluster_components(
5757
else:
5858
my_charm = MONGODB_CHARM_NAME
5959

60-
resources = {"mongodb-image": METADATA["resources"]["mongodb-image"]["upstream-source"]}
6160
await ops_test.model.deploy(
6261
my_charm,
63-
resources=resources,
62+
resources=RESOURCES,
6463
num_units=num_units_cluster_config[CONFIG_SERVER_APP_NAME],
6564
config={"role": "config-server"},
6665
application_name=CONFIG_SERVER_APP_NAME,
@@ -70,7 +69,7 @@ async def deploy_cluster_components(
7069
)
7170
await ops_test.model.deploy(
7271
my_charm,
73-
resources=resources,
72+
resources=RESOURCES,
7473
num_units=num_units_cluster_config[SHARD_ONE_APP_NAME],
7574
config={"role": "shard"},
7675
application_name=SHARD_ONE_APP_NAME,
@@ -80,7 +79,7 @@ async def deploy_cluster_components(
8079
)
8180
await ops_test.model.deploy(
8281
my_charm,
83-
resources=resources,
82+
resources=RESOURCES,
8483
num_units=num_units_cluster_config[SHARD_TWO_APP_NAME],
8584
config={"role": "shard"},
8685
application_name=SHARD_TWO_APP_NAME,

tests/integration/sharding_tests/test_mongos.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pytest_operator.plugin import OpsTest
99

1010
from ..ha_tests.helpers import get_direct_mongo_client
11-
from ..helpers import METADATA, is_relation_joined
11+
from ..helpers import RESOURCES, is_relation_joined
1212
from .helpers import count_users, get_related_username_password
1313

1414
SHARD_ONE_APP_NAME = "shard-one"
@@ -25,18 +25,17 @@
2525
async def test_build_and_deploy(ops_test: OpsTest) -> None:
2626
"""Build and deploy a sharded cluster."""
2727
mongodb_charm = await ops_test.build_charm(".")
28-
resources = {"mongodb-image": METADATA["resources"]["mongodb-image"]["upstream-source"]}
2928
await ops_test.model.deploy(
3029
mongodb_charm,
31-
resources=resources,
30+
resources=RESOURCES,
3231
num_units=1,
3332
config={"role": "config-server"},
3433
application_name=CONFIG_SERVER_APP_NAME,
3534
trust=True,
3635
)
3736
await ops_test.model.deploy(
3837
mongodb_charm,
39-
resources=resources,
38+
resources=RESOURCES,
4039
num_units=1,
4140
config={"role": "shard"},
4241
application_name=SHARD_ONE_APP_NAME,

tests/integration/sharding_tests/test_sharding.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from ..ha_tests.helpers import get_direct_mongo_client
88
from ..helpers import (
9-
METADATA,
9+
RESOURCES,
1010
get_leader_id,
1111
get_password,
1212
set_password,
@@ -45,35 +45,34 @@
4545
async def test_build_and_deploy(ops_test: OpsTest) -> None:
4646
"""Build and deploy a sharded cluster."""
4747
my_charm = await ops_test.build_charm(".")
48-
resources = {"mongodb-image": METADATA["resources"]["mongodb-image"]["upstream-source"]}
4948

5049
await ops_test.model.deploy(
5150
my_charm,
52-
resources=resources,
51+
resources=RESOURCES,
5352
num_units=2,
5453
config={"role": "config-server"},
5554
application_name=CONFIG_SERVER_APP_NAME,
5655
trust=True,
5756
)
5857
await ops_test.model.deploy(
5958
my_charm,
60-
resources=resources,
59+
resources=RESOURCES,
6160
num_units=2,
6261
config={"role": "shard"},
6362
application_name=SHARD_ONE_APP_NAME,
6463
trust=True,
6564
)
6665
await ops_test.model.deploy(
6766
my_charm,
68-
resources=resources,
67+
resources=RESOURCES,
6968
num_units=2,
7069
config={"role": "shard"},
7170
application_name=SHARD_TWO_APP_NAME,
7271
trust=True,
7372
)
7473
await ops_test.model.deploy(
7574
my_charm,
76-
resources=resources,
75+
resources=RESOURCES,
7776
num_units=2,
7877
config={"role": "shard"},
7978
application_name=SHARD_THREE_APP_NAME,

0 commit comments

Comments
 (0)