Merge ~gabrielcocenza/charm-nrpe:bug/1998120 into charm-nrpe:master
- Git
- lp:~gabrielcocenza/charm-nrpe
- bug/1998120
- Merge into master
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Eric Chen | ||||
Approved revision: | f9bf892c3d756875330d6fedfda607f596bae22f | ||||
Merged at revision: | 239fb7941b37f12ad2550205700a684500d19983 | ||||
Proposed branch: | ~gabrielcocenza/charm-nrpe:bug/1998120 | ||||
Merge into: | charm-nrpe:master | ||||
Diff against target: |
183 lines (+75/-67) 3 files modified
hooks/services.py (+74/-62) mod/charmhelpers (+1/-1) tox.ini (+0/-4) |
||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Eric Chen | Approve | ||
Martin Kalcok (community) | Approve | ||
🤖 prod-jenkaas-bootstack (community) | continuous-integration | Approve | |
Robert Gildein | Pending | ||
BootStack Reviewers | Pending | ||
Review via email: mp+434197@code.launchpad.net |
Commit message
make service manager resilient in case the IP is not ready.
Closes-Bug: #1998120
Description of the change
See Bug 1924780 for more details. Units might run the install hook without having public IP ready. Charms should be resilient of such scenario.
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:ce5472d25b4
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:702e7b7cd00
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:3418316e54b
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:4aaa90cebc9
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:4aaa90cebc9
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:940fa803a4d
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:d56b12bffbe
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:ebb874dd124
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:ebb874dd124
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:ebb874dd124
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:ebb874dd124
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:ebb874dd124
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:ebb874dd124
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:d0a251f73b3
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:f9bf892c3d7
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:f9bf892c3d7
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
PASSED: Continuous integration, rev:f9bf892c3d7
https:/
Executed test runs:
SUCCESS: https:/
None: https:/
Click here to trigger a rebuild:
https:/
Martin Kalcok (martin-kalcok) wrote : | # |
Thanks Gabriel, LGTM.
Eric Chen (eric-chen) : | # |
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
Change successfully merged at revision 239fb7941b37f12
Preview Diff
1 | diff --git a/hooks/services.py b/hooks/services.py |
2 | index 34b9887..2c6dbce 100644 |
3 | --- a/hooks/services.py |
4 | +++ b/hooks/services.py |
5 | @@ -1,9 +1,10 @@ |
6 | """Nrpe service definifition.""" |
7 | |
8 | import os |
9 | +from subprocess import CalledProcessError |
10 | |
11 | from charmhelpers.core import hookenv |
12 | -from charmhelpers.core.hookenv import status_set |
13 | +from charmhelpers.core.hookenv import WARNING, log, status_set |
14 | from charmhelpers.core.services import helpers |
15 | from charmhelpers.core.services.base import ServiceManager |
16 | |
17 | @@ -13,61 +14,64 @@ import nrpe_utils |
18 | |
19 | config = hookenv.config() |
20 | |
21 | -manager = ServiceManager( |
22 | - [ |
23 | - { |
24 | - "service": "nrpe-install", |
25 | - "data_ready": [ |
26 | - nrpe_utils.install_packages, |
27 | - nrpe_utils.install_charm_files, |
28 | - ], |
29 | - "start": [], |
30 | - "stop": [], |
31 | - }, |
32 | - { |
33 | - "service": "nrpe-config", |
34 | - "required_data": [ |
35 | - config, |
36 | - nrpe_helpers.MonitorsRelation(), |
37 | - nrpe_helpers.PrincipalRelation(), |
38 | - nrpe_helpers.NagiosInfo(), |
39 | - ], |
40 | - "data_ready": [ |
41 | - nrpe_utils.update_nrpe_external_master_relation, |
42 | - nrpe_utils.update_monitor_relation, |
43 | - nrpe_utils.create_host_export_fragment, |
44 | - nrpe_utils.render_nrped_files, |
45 | - nrpe_utils.update_cis_audit_cronjob, |
46 | - helpers.render_template( |
47 | - source="nrpe.tmpl", target="/etc/nagios/nrpe.cfg" |
48 | - ), |
49 | - ], |
50 | - "provided_data": [nrpe_helpers.PrincipalRelation()], |
51 | - "ports": [hookenv.config("server_port"), "ICMP"], |
52 | - "start": [nrpe_utils.maybe_open_ports, nrpe_utils.restart_nrpe], |
53 | - "stop": [], |
54 | - }, |
55 | - { |
56 | - "service": "nrpe-rsync", |
57 | - "required_data": [ |
58 | - config, |
59 | - nrpe_helpers.PrincipalRelation(), |
60 | - nrpe_helpers.RsyncEnabled(), |
61 | - nrpe_helpers.NagiosInfo(), |
62 | - ], |
63 | - "data_ready": [ |
64 | - nrpe_utils.remove_host_export_fragments, |
65 | - helpers.render_template( |
66 | - source="rsync-juju.d.tmpl", |
67 | - target="/etc/rsync-juju.d/010-nrpe-external-master.conf", |
68 | - ), |
69 | - nrpe_utils.create_host_export_fragment, |
70 | - ], |
71 | - "start": [nrpe_utils.restart_rsync], |
72 | - "stop": [], |
73 | - }, |
74 | - ] |
75 | -) |
76 | + |
77 | +def get_manager(): |
78 | + """Instantiate a ServiceManager object.""" |
79 | + return ServiceManager( |
80 | + [ |
81 | + { |
82 | + "service": "nrpe-install", |
83 | + "data_ready": [ |
84 | + nrpe_utils.install_packages, |
85 | + nrpe_utils.install_charm_files, |
86 | + ], |
87 | + "start": [], |
88 | + "stop": [], |
89 | + }, |
90 | + { |
91 | + "service": "nrpe-config", |
92 | + "required_data": [ |
93 | + config, |
94 | + nrpe_helpers.MonitorsRelation(), |
95 | + nrpe_helpers.PrincipalRelation(), |
96 | + nrpe_helpers.NagiosInfo(), |
97 | + ], |
98 | + "data_ready": [ |
99 | + nrpe_utils.update_nrpe_external_master_relation, |
100 | + nrpe_utils.update_monitor_relation, |
101 | + nrpe_utils.create_host_export_fragment, |
102 | + nrpe_utils.render_nrped_files, |
103 | + nrpe_utils.update_cis_audit_cronjob, |
104 | + helpers.render_template( |
105 | + source="nrpe.tmpl", target="/etc/nagios/nrpe.cfg" |
106 | + ), |
107 | + ], |
108 | + "provided_data": [nrpe_helpers.PrincipalRelation()], |
109 | + "ports": [hookenv.config("server_port"), "ICMP"], |
110 | + "start": [nrpe_utils.maybe_open_ports, nrpe_utils.restart_nrpe], |
111 | + "stop": [], |
112 | + }, |
113 | + { |
114 | + "service": "nrpe-rsync", |
115 | + "required_data": [ |
116 | + config, |
117 | + nrpe_helpers.PrincipalRelation(), |
118 | + nrpe_helpers.RsyncEnabled(), |
119 | + nrpe_helpers.NagiosInfo(), |
120 | + ], |
121 | + "data_ready": [ |
122 | + nrpe_utils.remove_host_export_fragments, |
123 | + helpers.render_template( |
124 | + source="rsync-juju.d.tmpl", |
125 | + target="/etc/rsync-juju.d/010-nrpe-external-master.conf", |
126 | + ), |
127 | + nrpe_utils.create_host_export_fragment, |
128 | + ], |
129 | + "start": [nrpe_utils.restart_rsync], |
130 | + "stop": [], |
131 | + }, |
132 | + ] |
133 | + ) |
134 | |
135 | |
136 | def get_revision(): |
137 | @@ -88,10 +92,18 @@ def get_revision(): |
138 | def manage(): |
139 | """Manage nrpe service.""" |
140 | status_set("maintenance", "starting") |
141 | - manager.manage() |
142 | - if not nrpe_utils.has_consumer(): |
143 | - status_set("blocked", "Nagios server not configured or related") |
144 | - elif nrpe_helpers.has_netlinks_error(): |
145 | - status_set("blocked", "Netlinks parsing encountered failure; see logs") |
146 | + try: |
147 | + manager = get_manager() |
148 | + except (CalledProcessError, KeyError, IndexError) as err: |
149 | + msg = "Public address not available yet" |
150 | + log(msg, level=WARNING) |
151 | + log(err, level=WARNING) |
152 | + status_set("waiting", msg) |
153 | else: |
154 | - status_set("active", "Ready{}".format(get_revision())) |
155 | + manager.manage() |
156 | + if not nrpe_utils.has_consumer(): |
157 | + status_set("blocked", "Nagios server not configured or related") |
158 | + elif nrpe_helpers.has_netlinks_error(): |
159 | + status_set("blocked", "Netlinks parsing encountered failure; see logs") |
160 | + else: |
161 | + status_set("active", "Ready{}".format(get_revision())) |
162 | diff --git a/mod/charmhelpers b/mod/charmhelpers |
163 | index 9b40e00..460e9e6 160000 |
164 | --- a/mod/charmhelpers |
165 | +++ b/mod/charmhelpers |
166 | @@ -1 +1 @@ |
167 | -Subproject commit 9b40e0070deab2fc4aef4725e8bdf95cd96cb471 |
168 | +Subproject commit 460e9e6dd33abdd58f1b82890243e2ee06014429 |
169 | diff --git a/tox.ini b/tox.ini |
170 | index 6b76204..df9003f 100644 |
171 | --- a/tox.ini |
172 | +++ b/tox.ini |
173 | @@ -2,10 +2,6 @@ |
174 | skipsdist=True |
175 | skip_missing_interpreters = True |
176 | envlist = lint, unit, func |
177 | -requires = |
178 | - pip < 20.3 |
179 | - virtualenv < 20.0 |
180 | - setuptools < 50.0.0 |
181 | |
182 | [testenv] |
183 | basepython = python3 |
This merge proposal is being monitored by mergebot. Change the status to Approved to merge.