Merge ~mthaddon/apache2-charm/+git/apache2-charm:active-status into apache2-charm:master

Proposed by Tom Haddon
Status: Merged
Approved by: Tom Haddon
Approved revision: e4a5e4662cafec6433e170cacbe6834b4fc10281
Merged at revision: 15d7f8b375bb2fcf7e3bed154b609969fdd82a04
Proposed branch: ~mthaddon/apache2-charm/+git/apache2-charm:active-status
Merge into: apache2-charm:master
Diff against target: 81 lines (+18/-10)
1 file modified
hooks/hooks.py (+18/-10)
Reviewer Review Type Date Requested Status
Haw Loeung +1 Approve
Canonical IS Reviewers Pending
Review via email: mp+407489@code.launchpad.net

Commit message

Set status for the charm, and if service check fails, set the charm to a blocked state

Description of the change

Due to lack of tests for this charm, the following tests have been done manually:
 * Deploy to an LXC locally, confirm juju status is set to active
 * Set config to something that would break the service check, and confirm it's set to blocked status. Set config to something that is okay again, confirm the charm recovers to active status.

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
Haw Loeung (hloeung) wrote :

LGTM

review: Approve (+1)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 15d7f8b375bb2fcf7e3bed154b609969fdd82a04

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/hooks.py b/hooks/hooks.py
2index 1c2d0a8..6128b34 100755
3--- a/hooks/hooks.py
4+++ b/hooks/hooks.py
5@@ -1,30 +1,31 @@
6 #!/usr/bin/env python2
7
8+import ast
9+import base64
10 import errno
11+import grp
12 import os
13+import os.path
14+import pwd
15 import re
16+import shutil
17 import socket
18 import subprocess
19 import sys
20 import yaml
21-import base64
22-import grp
23-import pwd
24-import shutil
25-import os.path
26-import ast
27
28+from charmhelpers.contrib.charmsupport import nrpe
29 from charmhelpers.core.hookenv import (
30- open_port,
31 close_port,
32- log,
33 config as orig_config_get,
34- relations_of_type,
35+ log,
36+ open_port,
37 relation_set,
38 relation_ids,
39+ relations_of_type,
40+ status_set,
41 unit_get
42 )
43-from charmhelpers.contrib.charmsupport import nrpe
44 from charmhelpers.fetch import apt_update, add_source
45
46 ###############################################################################
47@@ -291,6 +292,7 @@ def config_get(scope=None):
48
49
50 def install_hook():
51+ status_set("maintenance", "installing unit")
52 apt_source = config_get('apt-source') or ''
53 apt_key_id = config_get('apt-key-id') or False
54 if apt_source and apt_key_id:
55@@ -602,6 +604,7 @@ def enable_mpm(config):
56
57
58 def config_changed():
59+ status_set("maintenance", "configuring unit")
60 relationship_data = {}
61 config_data = config_get()
62
63@@ -756,6 +759,9 @@ def config_changed():
64 if service_apache2("check"):
65 if config_data["config_change_command"] in ["reload", "restart"]:
66 service_apache2(config_data["config_change_command"])
67+ else:
68+ status_set("blocked", "service check failed, possible invalid configuration")
69+ return
70
71 if config_data['openid_provider']:
72 if not os.path.exists('/etc/apache2/security'):
73@@ -772,6 +778,8 @@ def config_changed():
74 if config_get().changed('servername'):
75 logs_relation_joined()
76
77+ status_set("active", "Unit is ready")
78+
79
80 def ensure_disabled(sites):
81 to_disable = [s for s in sites if os.path.exists(site_filename(s, True))]

Subscribers

People subscribed via source and target branches

to all changes: