Merge lp:~free.ekanayaka/landscape-client-charm/workload-status into lp:landscape-client-charm

Proposed by Free Ekanayaka
Status: Merged
Merged at revision: 57
Proposed branch: lp:~free.ekanayaka/landscape-client-charm/workload-status
Merge into: lp:landscape-client-charm
Diff against target: 120 lines (+58/-5)
2 files modified
hooks/common.py (+12/-4)
hooks/test_hooks.py (+46/-1)
To merge this branch: bzr merge lp:~free.ekanayaka/landscape-client-charm/workload-status
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
Alberto Donato (community) Approve
Review via email: mp+264680@code.launchpad.net

Description of the change

This branch adds support for workload status in the client charm. The possible
situations are:

1. No account-name is set. Since this is a required user input, the unit
   transitions to "blocked"

2. The juju-info file or computer-title entry are not yet there. Since
   these should eventually get written automatically by the charm, the
   unit transitions to the "maintenance" state.

3. The registration is successful, the unit transitions to the "active"
   state.

There are some situations (e.g. missing registration key) that could
have better messages, but that would require a bit more work. I think
what's in this branch is safe and good enough for a start.

See the "Unit states" section here:

https://docs.google.com/document/d/1SsHDxi58xgrim6VTKorqMn4GlzxPV9EFvu1ueBgnMlc/edit#heading=h.lir57ztwm9ax

to know more about the semantics of each state.

Note that if you are using juju < 1.24 the status_set function in
charmhelpers will gracefully downgrade to a bare logging of
the message.

To post a comment you must log in.
Revision history for this message
Alberto Donato (ack) wrote :

Looks good, +1

review: Approve
Revision history for this message
Alberto Donato (ack) :
Revision history for this message
Adam Collard (adam-collard) wrote :

+1

review: Approve
58. By Free Ekanayaka

Mention registration-key

Revision history for this message
Free Ekanayaka (free.ekanayaka) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/common.py'
2--- hooks/common.py 2014-09-24 07:35:03 +0000
3+++ hooks/common.py 2015-07-15 10:44:07 +0000
4@@ -6,7 +6,7 @@
5 from subprocess import check_output
6
7 from charmhelpers.core.hookenv import (
8- log, local_unit)
9+ log, local_unit, status_set)
10
11 from landscape.configuration import (
12 setup, register, LandscapeSetupConfiguration, ConfigurationError,
13@@ -68,6 +68,7 @@
14
15 def __init__(self):
16 self.config = Configuration()
17+ self.status_set = status_set # For testing
18
19 @property
20 def local_unit(self):
21@@ -108,10 +109,17 @@
22 return 0
23
24 if is_configured_enough:
25- return self.try_to_register()
26+ exit_code = self.try_to_register()
27+ if exit_code == 0:
28+ self.status_set("active", "System successfully registered")
29 else:
30- print ("Need account-name, computer-title and juju-info to"
31- " proceed, skipping")
32+ if not self.config.get("account_name"):
33+ self.status_set(
34+ "blocked", "Need account-name/registration-key to proceed")
35+ else:
36+ self.status_set(
37+ "maintenance",
38+ "Need computer-title and juju-info to proceed")
39 return 0
40
41 @property
42
43=== modified file 'hooks/test_hooks.py'
44--- hooks/test_hooks.py 2014-09-25 07:00:05 +0000
45+++ hooks/test_hooks.py 2015-07-15 10:44:07 +0000
46@@ -64,6 +64,14 @@
47 self.landscape_broker.config.config = os.path.join(
48 data_path, "landscape.conf")
49 self.landscape_broker.config.write()
50+ self.workload_state = None
51+ self.workload_message = None
52+
53+ def status_set(workload_state, message):
54+ self.workload_state = workload_state
55+ self.workload_message = message
56+
57+ self.landscape_broker.status_set = status_set
58 self.juju_broker = FakeJujuBroker()
59
60 def touch_juju_info_file(self):
61@@ -389,7 +397,6 @@
62 super(ConfigChangedTest, self).setUp()
63 self.landscape_broker.config.account_name = "account1"
64 self.landscape_broker.config.computer_title = "title"
65- self.touch_juju_info_file()
66 self.addCleanup(setattr, hooks, "CERT_FILE", hooks.CERT_FILE)
67 tmp_dir = self.mkdtemp()
68 hooks.CERT_FILE = "%s/cert" % tmp_dir
69@@ -398,6 +405,7 @@
70 """
71 A base64 encoded SSL cert in the configuration is decoded.
72 """
73+ self.touch_juju_info_file()
74 self.juju_broker.commands["config-get"] = {
75 "ssl-public-key": "base64:%s" % "foo".encode("base64"),
76 "account-name": "standalone",
77@@ -409,6 +417,43 @@
78 hooks.CERT_FILE, self.landscape_broker.config.ssl_public_key)
79 with open(hooks.CERT_FILE) as fh:
80 self.assertEqual("foo", fh.read())
81+ self.assertEqual("active", self.workload_state)
82+ self.assertEqual(
83+ "System successfully registered", self.workload_message)
84+
85+ def test_no_account_name(self):
86+ """
87+ If account-name is not set, the unit transitions to the blocked state.
88+ """
89+ self.touch_juju_info_file()
90+ self.juju_broker.commands["config-get"] = {
91+ "ssl-public-key": "base64:%s" % "foo".encode("base64"),
92+ "account-name": "",
93+ "ping-url": "http://127.0.0.1"}
94+
95+ hooks.config_changed(juju_broker=self.juju_broker,
96+ landscape_broker=self.landscape_broker)
97+ self.assertEqual("blocked", self.workload_state)
98+ self.assertEqual(
99+ "Need account-name/registration-key to proceed",
100+ self.workload_message)
101+
102+ def test_no_juju_info(self):
103+ """
104+ If the juju-info file hasn't been written yet, the unit transitions to
105+ the maintenance status.
106+ """
107+ self.juju_broker.commands["config-get"] = {
108+ "ssl-public-key": "base64:%s" % "foo".encode("base64"),
109+ "account-name": "standalone",
110+ "ping-url": "http://127.0.0.1"}
111+
112+ hooks.config_changed(juju_broker=self.juju_broker,
113+ landscape_broker=self.landscape_broker)
114+ self.assertEqual("maintenance", self.workload_state)
115+ self.assertEqual(
116+ "Need computer-title and juju-info to proceed",
117+ self.workload_message)
118
119
120 class RegistrationRelationJoinedTest(HookTestCase):

Subscribers

People subscribed via source and target branches

to all changes: