Merge lp:~alitvinov/landscape-client-charm/landscape-client-charm into lp:landscape-client-charm

Proposed by Alexander Litvinov on 2018-01-10
Status: Needs review
Proposed branch: lp:~alitvinov/landscape-client-charm/landscape-client-charm
Merge into: lp:landscape-client-charm
Diff against target: 91 lines (+31/-15)
2 files modified
hooks/common.py (+1/-0)
hooks/hooks.py (+30/-15)
To merge this branch: bzr merge lp:~alitvinov/landscape-client-charm/landscape-client-charm
Reviewer Review Type Date Requested Status
Landscape Builder test results Needs Fixing on 2018-11-07
Landscape 2018-01-10 Pending
Review via email: mp+335925@code.launchpad.net
To post a comment you must log in.
review: Abstain (executing tests)
review: Needs Fixing (test results)
review: Abstain (executing tests)
review: Needs Fixing (test results)
review: Abstain (executing tests)
review: Needs Fixing (test results)

Unmerged revisions

65. By Alexander Litvinov on 2017-11-29

These patches add support for relating landscape-server and landscape-client.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/common.py' (properties changed: -x to +x)
2--- hooks/common.py 2016-12-14 16:08:39 +0000
3+++ hooks/common.py 2018-01-10 10:03:32 +0000
4@@ -108,6 +108,7 @@
5 exit_code = self.try_to_register()
6 if exit_code == 0:
7 self.status_set("active", "System successfully registered")
8+ log("Client config updated, system successfully registered")
9 else:
10 if not self.config.get("account_name"):
11 self.status_set(
12
13=== modified file 'hooks/hooks.py'
14--- hooks/hooks.py 2017-03-03 09:59:27 +0000
15+++ hooks/hooks.py 2018-01-10 10:03:32 +0000
16@@ -19,7 +19,6 @@
17 get_ceph_client_path, write_ceph_client_keyring, write_ceph_client_config)
18 from install import install_landscape_client
19
20-
21 CERT_FILE = "/etc/ssl/certs/landscape_server_ca.crt"
22
23 JUJU_BROKER = JujuBroker()
24@@ -28,26 +27,18 @@
25 hooks = Hooks()
26
27
28-@hooks.hook("registration-relation-joined", "registration-relation-changed")
29-def registration_relation(juju_broker=JUJU_BROKER,
30- hookenv=hookenv, fetch=fetch,
31- landscape_broker=LANDSCAPE_BROKER):
32- data = juju_broker.get_relation_config()
33- if "ping-url" in data:
34- config_changed(relation_data=data, hookenv=hookenv, fetch=fetch,
35- landscape_broker=landscape_broker)
36-
37-
38-@hooks.hook("config-changed")
39-def config_changed(relation_data=None, hookenv=hookenv, fetch=fetch,
40+
41+def process_config_changed(relation_data=None, hookenv=hookenv, fetch=fetch,
42 landscape_broker=LANDSCAPE_BROKER):
43 """
44 @param relation_data: data from the context of a relation, it should
45 match the data in the config
46 """
47- hookenv.log("In config-changed for %s" % landscape_broker.local_unit)
48+ hookenv.log("In process-config-changed for %s" % landscape_broker.local_unit)
49 if relation_data is None:
50- relation_data = {}
51+ msg = "Unexpected relation_data == None"
52+ hookenv.log(msg)
53+ raise Exception(msg)
54 service_config = hookenv.config()
55 if service_config.changed("origin"):
56 install_landscape_client(service_config["origin"], fetch=fetch)
57@@ -59,10 +50,34 @@
58 if relation_data.get("ssl-public-key", "").startswith("base64:"):
59 _write_certificate(relation_data["ssl-public-key"][7:], CERT_FILE)
60 relation_data["ssl-public-key"] = CERT_FILE
61+ if relation_data.get("registration-key", "") != "" and hookenv.is_leader():
62+ if relation_data.get("account-name", "") == "":
63+ relation_data["account-name"] = "standalone"
64+ for rid in hookenv.relation_ids('registration'):
65+ hookenv.relation_set(rid, relation_data)
66 if "account-name" in relation_data:
67+ hookenv.log("Updating client config with the following data: %s" % relation_data)
68 return landscape_broker.update_client_config(relation_data)
69
70
71+@hooks.hook("registration-relation-joined", "registration-relation-changed")
72+def registration_relation(juju_broker=JUJU_BROKER,
73+ hookenv=hookenv, fetch=fetch,
74+ landscape_broker=LANDSCAPE_BROKER):
75+ data = juju_broker.get_relation_config()
76+ if "ping-url" in data:
77+ process_config_changed(relation_data=data, hookenv=hookenv, fetch=fetch,
78+ landscape_broker=LANDSCAPE_BROKER)
79+
80+
81+@hooks.hook("config-changed")
82+def config_changed(relation_data=None, hookenv=hookenv, fetch=fetch,
83+ landscape_broker=LANDSCAPE_BROKER):
84+ hookenv.log("In config-changed for %s" % landscape_broker.local_unit)
85+ process_config_changed(relation_data={}, hookenv=hookenv, fetch=fetch,
86+ landscape_broker=LANDSCAPE_BROKER)
87+
88+
89 @hooks.hook("upgrade-charm")
90 def upgrade_charm(landscape_broker=LANDSCAPE_BROKER):
91 """Idempotently upgrades state from older charms."""

Subscribers

People subscribed via source and target branches

to all changes: