2 # Copyright 2022 Canonical Ltd.
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 # For those usages not covered by the Apache License, Version 2.0 please
17 # contact: legal@canonical.com
19 # To get in touch with the maintainers, please contact:
20 # osm-charmers@lists.launchpad.net
22 # Learn more about testing at: https://juju.is/docs/sdk/testing
26 from pathlib
import Path
30 from pytest_operator
.plugin
import OpsTest
32 logger
= logging
.getLogger(__name__
)
34 METADATA
= yaml
.safe_load(Path("./metadata.yaml").read_text())
35 RO_APP
= METADATA
["name"]
36 KAFKA_CHARM
= "kafka-k8s"
38 MONGO_DB_CHARM
= "mongodb-k8s"
39 MONGO_DB_APP
= "mongodb"
40 ZOOKEEPER_CHARM
= "zookeeper-k8s"
41 ZOOKEEPER_APP
= "zookeeper"
42 APPS
= [KAFKA_APP
, MONGO_DB_APP
, ZOOKEEPER_APP
, RO_APP
]
45 @pytest.mark
.abort_on_fail
46 async def test_ro_is_deployed(ops_test
: OpsTest
):
47 charm
= await ops_test
.build_charm(".")
48 resources
= {"ro-image": METADATA
["resources"]["ro-image"]["upstream-source"]}
51 ops_test
.model
.deploy(charm
, resources
=resources
, application_name
=RO_APP
),
52 ops_test
.model
.deploy(ZOOKEEPER_CHARM
, application_name
=ZOOKEEPER_APP
, channel
="stable"),
53 ops_test
.model
.deploy(KAFKA_CHARM
, application_name
=KAFKA_APP
, channel
="stable"),
54 ops_test
.model
.deploy(MONGO_DB_CHARM
, application_name
=MONGO_DB_APP
, channel
="edge"),
57 async with ops_test
.fast_forward():
58 await ops_test
.model
.wait_for_idle(
62 assert ops_test
.model
.applications
[RO_APP
].status
== "blocked"
63 unit
= ops_test
.model
.applications
[RO_APP
].units
[0]
64 assert unit
.workload_status_message
== "need kafka, mongodb relations"
66 logger
.info("Adding relations")
67 await ops_test
.model
.add_relation(KAFKA_APP
, ZOOKEEPER_APP
)
68 await ops_test
.model
.add_relation(RO_APP
, MONGO_DB_APP
)
69 await ops_test
.model
.add_relation(RO_APP
, KAFKA_APP
)
71 async with ops_test
.fast_forward():
72 await ops_test
.model
.wait_for_idle(
79 @pytest.mark
.abort_on_fail
80 async def test_ro_scales(ops_test
: OpsTest
):
81 logger
.info("Scaling osm-ro")
83 assert len(ops_test
.model
.applications
[RO_APP
].units
) == 1
84 await ops_test
.model
.applications
[RO_APP
].scale(expected_units
)
85 async with ops_test
.fast_forward():
86 await ops_test
.model
.wait_for_idle(
87 apps
=[RO_APP
], status
="active", timeout
=1000, wait_for_exact_units
=expected_units
91 @pytest.mark
.abort_on_fail
92 async def test_ro_blocks_without_kafka(ops_test
: OpsTest
):
93 await asyncio
.gather(ops_test
.model
.applications
[KAFKA_APP
].remove())
94 async with ops_test
.fast_forward():
95 await ops_test
.model
.wait_for_idle(apps
=[RO_APP
])
96 assert ops_test
.model
.applications
[RO_APP
].status
== "blocked"
97 for unit
in ops_test
.model
.applications
[RO_APP
].units
:
98 assert unit
.workload_status_message
== "need kafka relation"