from ops.charm import CharmBase
from ops.framework import StoredState
from ops.main import main
-from ops.model import ActiveStatus, Container
+from ops.model import ActiveStatus, BlockedStatus, Container
SERVICE_PORT = 80
logger.debug(e.message)
self.unit.status = e.status
- def _on_required_relation_broken(self, _) -> None:
- """Handler for the kafka-broken event."""
+ def _on_nbi_relation_broken(self, _) -> None:
+ """Handler for the nbi relation broken event."""
# Check Pebble has started in the container
try:
check_container_ready(self.container)
except CharmError:
pass
finally:
- self._on_update_status()
+ self.unit.status = BlockedStatus("need nbi relation")
# ---------------------------------------------------------------------------
# Validation and configuration and more
self.on.update_status: self._on_update_status,
# Relation events
self.on["nbi"].relation_changed: self._on_config_changed,
- self.on["nbi"].relation_broken: self._on_required_relation_broken,
+ self.on["nbi"].relation_broken: self._on_nbi_relation_broken,
}
for event, handler in event_handler_mapping.items():
self.framework.observe(event, handler)
mocker.patch("charm.KubernetesServicePatch", lambda x, y: None)
harness = Harness(OsmNgUiCharm)
harness.begin()
- harness.charm.unit.get_container("ng-ui").push(
- "/etc/nginx/sites-available/default", sites_default, make_dirs=True
- )
+ container = harness.charm.unit.get_container("ng-ui")
+ harness.set_can_connect(container, True)
+ container.push("/etc/nginx/sites-available/default", sites_default, make_dirs=True)
yield harness
harness.cleanup()
def test_ready(harness: Harness):
- _add_relation(harness)
+ _add_nbi_relation(harness)
assert harness.charm.unit.status == ActiveStatus()
def test_container_stops_after_relation_broken(harness: Harness):
harness.charm.on[container_name].pebble_ready.emit(container_name)
container = harness.charm.unit.get_container(container_name)
- relation_id = _add_relation(harness)
+ relation_id = _add_nbi_relation(harness)
check_service_active(container, service_name)
harness.remove_relation(relation_id)
with pytest.raises(CharmError):
check_service_active(container, service_name)
+ assert type(harness.charm.unit.status) == BlockedStatus
+ assert harness.charm.unit.status.message == "need nbi relation"
-def _add_relation(harness: Harness):
- # Add nbi relation
+def _add_nbi_relation(harness: Harness):
relation_id = harness.add_relation("nbi", "nbi")
harness.add_relation_unit(relation_id, "nbi/0")
- harness.update_relation_data(relation_id, "nbi", {"host": "nbi", "port": 9999})
+ harness.update_relation_data(relation_id, "nbi", {"host": "nbi", "port": "9999"})
return relation_id
[vars]
src_path = {toxinidir}/src
tst_path = {toxinidir}/tests
-lib_path = {toxinidir}/lib/charms/osm_ng_ui
all_path = {[vars]src_path} {[vars]tst_path}
[testenv]
codespell
commands =
# uncomment the following line if this charm owns a lib
- codespell {[vars]lib_path}
codespell {toxinidir} --skip {toxinidir}/.git --skip {toxinidir}/.tox \
--skip {toxinidir}/build --skip {toxinidir}/lib --skip {toxinidir}/venv \
--skip {toxinidir}/.mypy_cache --skip {toxinidir}/icon.svg
coverage[toml]
-r{toxinidir}/requirements.txt
commands =
- coverage run --source={[vars]src_path},{[vars]lib_path} \
+ coverage run --source={[vars]src_path} \
-m pytest {[vars]tst_path}/unit -v --tb native -s {posargs}
coverage report
coverage xml