Merge ~raychan96/charm-openstack-service-checks:fix-http-https-checks into charm-openstack-service-checks:master

Proposed by Chi Wai CHAN
Status: Merged
Approved by: Ramesh Sattaru
Approved revision: ba40b7d31d5a018d09b2ca2d19e8d3206bea7ee4
Merged at revision: e1476c7653afe6d8a46674845080c9e9925f085e
Proposed branch: ~raychan96/charm-openstack-service-checks:fix-http-https-checks
Merge into: charm-openstack-service-checks:master
Diff against target: 112 lines (+34/-25)
2 files modified
src/lib/lib_openstack_service_checks.py (+28/-21)
src/tests/unit/test_lib.py (+6/-4)
Reviewer Review Type Date Requested Status
🤖 prod-jenkaas-bootstack (community) continuous-integration Approve
Erhan Sunar (community) Approve
Eric Chen Approve
BootStack Reviewers Pending
Review via email: mp+432796@code.launchpad.net

Commit message

Fix rendering of `check_http` when scheme is https

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Eric Chen (eric-chen) :
review: Approve
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Erhan Sunar (esunar) wrote :

LGTM

review: Approve
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision e1476c7653afe6d8a46674845080c9e9925f085e

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/lib/lib_openstack_service_checks.py b/src/lib/lib_openstack_service_checks.py
2index 1caf8b5..8295ea8 100644
3--- a/src/lib/lib_openstack_service_checks.py
4+++ b/src/lib/lib_openstack_service_checks.py
5@@ -669,8 +669,12 @@ class OSCHelper:
6 def _render_http_endpoint_checks(self, url, host, port, nrpe, interface, **kwargs):
7 """Render NRPE checks for http endpoint."""
8 if self.charm_config.get("check_{}_urls".format(interface)):
9- command = "{} -H {} -p {} -u {}".format(
10- "/usr/lib/nagios/plugins/check_http", host, port, url
11+ command = "{} -H {} -p {} -u {} {}".format(
12+ "/usr/lib/nagios/plugins/check_http",
13+ host,
14+ port,
15+ url,
16+ kwargs.get("check_http_options", ""),
17 )
18 nrpe.add_check(
19 shortname=kwargs.get("shortname", "check_http"),
20@@ -779,25 +783,7 @@ class OSCHelper:
21 check_url = urlparse(endpoint.url)
22 host, port = self._split_url(check_url.netloc, check_url.scheme)
23
24- nrpe_shortname = "{}_{}".format(service_name, endpoint.interface)
25- self._render_http_endpoint_checks(
26- url=endpoint.healthcheck_url,
27- host=host,
28- port=port,
29- nrpe=nrpe,
30- interface=endpoint.interface,
31- shortname=nrpe_shortname,
32- description="Endpoint url check for {} {}".format(
33- service_name, endpoint.interface
34- ),
35- create_log="Added nrpe http endpoint check for {}, {}".format(
36- service_name, endpoint.interface
37- ),
38- remove_log="Removed nrpe http endpoint check for {}, {}".format(
39- service_name, endpoint.interface
40- ),
41- )
42-
43+ check_http_options = []
44 if check_url.scheme == "https":
45 url = endpoint.healthcheck_url.strip().split(" ")[0]
46 nrpe_shortname = "{}_{}_cert".format(service_name, endpoint.interface)
47@@ -818,6 +804,27 @@ class OSCHelper:
48 service_name, endpoint.interface
49 ),
50 )
51+ check_http_options.append("-S")
52+
53+ nrpe_shortname = "{}_{}".format(service_name, endpoint.interface)
54+ self._render_http_endpoint_checks(
55+ url=endpoint.healthcheck_url,
56+ host=host,
57+ port=port,
58+ nrpe=nrpe,
59+ interface=endpoint.interface,
60+ shortname=nrpe_shortname,
61+ description="Endpoint url check for {} {}".format(
62+ service_name, endpoint.interface
63+ ),
64+ create_log="Added nrpe http endpoint check for {}, {}".format(
65+ service_name, endpoint.interface
66+ ),
67+ remove_log="Removed nrpe http endpoint check for {}, {}".format(
68+ service_name, endpoint.interface
69+ ),
70+ check_http_options="".join(check_http_options),
71+ )
72
73 nrpe.write()
74
75diff --git a/src/tests/unit/test_lib.py b/src/tests/unit/test_lib.py
76index 9d767c3..82ff578 100644
77--- a/src/tests/unit/test_lib.py
78+++ b/src/tests/unit/test_lib.py
79@@ -256,19 +256,21 @@ def test__render_http_endpoint_checks(mock_config, interface):
80 test_url = "/"
81 test_host = "http://localhost"
82 test_port = "80"
83- test_kwargs = {"interface": interface}
84+ test_interface = interface
85+ test_kwargs = {"check_http_options": ""}
86
87- test_cmd = "{} -H {} -p {} -u {}".format(
88+ test_cmd = "{} -H {} -p {} -u {} {}".format(
89 "/usr/lib/nagios/plugins/check_http",
90 test_host,
91 test_port,
92 test_url,
93+ test_kwargs["check_http_options"],
94 )
95
96 # enable check_{}_urls
97 mock_config.return_value = {"check_{}_urls".format(interface): True}
98 OSCHelper()._render_http_endpoint_checks(
99- test_url, test_host, test_port, nrpe, **test_kwargs
100+ test_url, test_host, test_port, nrpe, test_interface, **test_kwargs
101 )
102 nrpe.add_check.assert_called_with(
103 check_cmd=test_cmd,
104@@ -280,7 +282,7 @@ def test__render_http_endpoint_checks(mock_config, interface):
105 # disable check_{}_urls
106 mock_config.return_value = {}
107 OSCHelper()._render_http_endpoint_checks(
108- test_url, test_host, test_port, nrpe, **test_kwargs
109+ test_url, test_host, test_port, nrpe, test_interface, **test_kwargs
110 )
111 nrpe.remove_check.assert_called_with(
112 shortname="check_http",

Subscribers

People subscribed via source and target branches

to all changes: