Skip to content
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
17 changes: 14 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,9 @@ def _provide_all_haproxy_route_requirements(self) -> None:
paths=appserver_paths,
protocol="http",
check_path="/",
check_interval=2,
check_rise=2,
check_fall=3,
header_rewrite_expressions=forwarded_proto_https,
allow_http=allow_http_default,
unit_address=unit_ip,
Expand All @@ -1382,6 +1385,9 @@ def _provide_all_haproxy_route_requirements(self) -> None:
paths=["/ping"],
protocol="http",
check_path="/ping",
check_interval=2,
check_rise=2,
check_fall=3,
header_rewrite_expressions=forwarded_proto_https,
allow_http=allow_http_always,
unit_address=unit_ip,
Expand All @@ -1393,6 +1399,9 @@ def _provide_all_haproxy_route_requirements(self) -> None:
paths=["/message-system", "/attachment"],
protocol="http",
check_path="/message-system",
check_interval=2,
check_rise=2,
check_fall=3,
header_rewrite_expressions=forwarded_proto_https,
allow_http=allow_http_default,
unit_address=unit_ip,
Expand All @@ -1403,7 +1412,10 @@ def _provide_all_haproxy_route_requirements(self) -> None:
ports=api_ports,
paths=["/api"],
protocol="http",
check_path="/api",
check_path="/api/about",
check_interval=2,
check_rise=2,
check_fall=3,
header_rewrite_expressions=forwarded_proto_https,
allow_http=allow_http_default,
unit_address=unit_ip,
Expand All @@ -1415,7 +1427,7 @@ def _provide_all_haproxy_route_requirements(self) -> None:
paths=["/upload"],
protocol="http",
check_path="/upload",
check_interval=2000,
check_interval=2,
check_rise=2,
check_fall=3,
header_rewrite_expressions=forwarded_proto_https,
Expand All @@ -1432,7 +1444,6 @@ def _provide_all_haproxy_route_requirements(self) -> None:
ports=appserver_ports,
paths=["/repository"],
protocol="http",
check_path="/",
header_rewrite_expressions=forwarded_proto_https,
allow_http=allow_http_always,
unit_address=unit_ip,
Expand Down
94 changes: 93 additions & 1 deletion tests/unit/test_haproxy_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_package_upload_has_health_checks(self, replicas_network_state):
mock = _run_provide(context, state)
calls = _calls_for(mock, "package-upload")
assert calls
assert calls[0].kwargs.get("check_interval") == 2000
assert calls[0].kwargs.get("check_interval") == 2
assert calls[0].kwargs.get("check_rise") == 2
assert calls[0].kwargs.get("check_fall") == 3

Expand Down Expand Up @@ -252,6 +252,98 @@ def test_pingserver_service_name_prefix(self, replicas_network_state):
assert calls[0].kwargs["service"].startswith("landscape-pingserver-")


class TestHealthChecks:
"""Each route uses check_path with the path the backend actually serves."""

def test_no_check_port_on_any_route(self, replicas_network_state):
context = Context(LandscapeServerCharm)
state = State(**replicas_network_state)
mock = _run_provide(context, state)
for c in mock.call_args_list:
assert "check_port" not in c.kwargs, (
f"check_port should not be set for {c.kwargs.get('service')}"
)

def test_appserver_check_path(self, replicas_network_state):
context = Context(LandscapeServerCharm)
state = State(**replicas_network_state)
mock = _run_provide(context, state)
calls = _calls_for(mock, "appserver")
assert calls[0].kwargs.get("check_path") == "/"

def test_pingserver_check_path(self, replicas_network_state):
context = Context(LandscapeServerCharm)
state = State(**replicas_network_state)
mock = _run_provide(context, state)
calls = _calls_for(mock, "pingserver")
assert calls[0].kwargs.get("check_path") == "/ping"

def test_message_server_check_path(self, replicas_network_state):
context = Context(LandscapeServerCharm)
state = State(**replicas_network_state)
mock = _run_provide(context, state)
calls = _calls_for(mock, "message-server")
assert calls[0].kwargs.get("check_path") == "/message-system"

def test_api_check_path(self, replicas_network_state):
context = Context(LandscapeServerCharm)
state = State(**replicas_network_state)
mock = _run_provide(context, state)
calls = _calls_for(mock, "api")
assert calls[0].kwargs.get("check_path") == "/api/about"

def test_package_upload_check_path(self, replicas_network_state):
context = Context(LandscapeServerCharm)
state = State(**replicas_network_state)
mock = _run_provide(context, state)
calls = _calls_for(mock, "package-upload")
assert calls[0].kwargs.get("check_path") == "/upload"

def test_repository_has_no_health_check(self, replicas_network_state):
context = Context(LandscapeServerCharm)
state = State(**replicas_network_state)
mock = _run_provide(context, state)
calls = _calls_for(mock, "repository")
assert "check_path" not in calls[0].kwargs
assert "check_interval" not in calls[0].kwargs

def test_appserver_has_health_check_timing(self, replicas_network_state):
context = Context(LandscapeServerCharm)
state = State(**replicas_network_state)
mock = _run_provide(context, state)
calls = _calls_for(mock, "appserver")
assert calls[0].kwargs.get("check_interval") == 2
assert calls[0].kwargs.get("check_rise") == 2
assert calls[0].kwargs.get("check_fall") == 3

def test_pingserver_has_health_check_timing(self, replicas_network_state):
context = Context(LandscapeServerCharm)
state = State(**replicas_network_state)
mock = _run_provide(context, state)
calls = _calls_for(mock, "pingserver")
assert calls[0].kwargs.get("check_interval") == 2
assert calls[0].kwargs.get("check_rise") == 2
assert calls[0].kwargs.get("check_fall") == 3

def test_message_server_has_health_check_timing(self, replicas_network_state):
context = Context(LandscapeServerCharm)
state = State(**replicas_network_state)
mock = _run_provide(context, state)
calls = _calls_for(mock, "message-server")
assert calls[0].kwargs.get("check_interval") == 2
assert calls[0].kwargs.get("check_rise") == 2
assert calls[0].kwargs.get("check_fall") == 3

def test_api_has_health_check_timing(self, replicas_network_state):
context = Context(LandscapeServerCharm)
state = State(**replicas_network_state)
mock = _run_provide(context, state)
calls = _calls_for(mock, "api")
assert calls[0].kwargs.get("check_interval") == 2
assert calls[0].kwargs.get("check_rise") == 2
assert calls[0].kwargs.get("check_fall") == 3


class TestConditionalRoutes:
"""hostagent-messenger and ubuntu-installer-attach routes are conditional."""

Expand Down
Loading