Merge lp:~adam-collard/landscape-client-charm/juju-2-support into lp:landscape-client-charm

Proposed by Adam Collard
Status: Merged
Approved by: Adam Collard
Approved revision: 62
Merged at revision: 60
Proposed branch: lp:~adam-collard/landscape-client-charm/juju-2-support
Merge into: lp:landscape-client-charm
Diff against target: 101 lines (+34/-12)
3 files modified
hooks/hooks.py (+3/-1)
hooks/install.py (+1/-1)
hooks/test_hooks.py (+30/-10)
To merge this branch: bzr merge lp:~adam-collard/landscape-client-charm/juju-2-support
Reviewer Review Type Date Requested Status
Bogdana Vereha (community) Approve
Alberto Donato (community) Approve
Review via email: mp+295697@code.launchpad.net

Commit message

Add support for Juju 2.0's changed environment variable name.

Description of the change

Add support for Juju 2.0's changed environment variable name.

Note that I have uploaded this to cs:~adam-collard/trusty/landscape-client-3 and cs:~adam-collard/xenial/landscape-client-1 in the development channel

Testing instructions:
 * Deploy charm with Juju 2.0 and check that landscape-client registers

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

+1 looks good

review: Approve
Revision history for this message
Bogdana Vereha (bogdana) wrote :

+1

review: Approve
62. By Adam Collard

Fix lint

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2016-03-30 20:04:13 +0000
3+++ hooks/hooks.py 2016-05-26 08:23:18 +0000
4@@ -71,8 +71,10 @@
5 landscape_broker.config.reload()
6 # We use the remote unit for the unit name, since we want to associate this
7 # client with the unit it's managing, not its own unit.
8+ model_uuid = juju_broker.environment.get(
9+ "JUJU_MODEL_UUID", juju_broker.environment.get("JUJU_ENV_UUID"))
10 juju_info = {
11- "environment-uuid": juju_broker.environment.get("JUJU_ENV_UUID"),
12+ "environment-uuid": model_uuid,
13 "machine-id": juju_broker.get_machine_id(),
14 "api-addresses": juju_broker.environment.get("JUJU_API_ADDRESSES")}
15
16
17=== modified file 'hooks/install.py'
18--- hooks/install.py 2016-05-02 08:59:58 +0000
19+++ hooks/install.py 2016-05-26 08:23:18 +0000
20@@ -56,7 +56,7 @@
21 subprocess.check_call("/usr/lib/pbuilder/pbuilder-satisfydepends")
22 env = {"DEBUILD_OPTS": "-uc -us"}
23 subprocess.check_call(["make", "package"], env=env)
24- #TODO: The following call should be retried (potential race condition to
25+ # TODO: The following call should be retried (potential race condition to
26 # acquire the dpkg lock).
27 subprocess.call(["dpkg", "-i", glob("../landscape-client_*.deb")[0],
28 glob("../landscape-common_*.deb")[0]])
29
30=== modified file 'hooks/test_hooks.py'
31--- hooks/test_hooks.py 2016-04-15 08:51:31 +0000
32+++ hooks/test_hooks.py 2016-05-26 08:23:18 +0000
33@@ -23,7 +23,7 @@
34 self.commands = {"relation-get": {}, "config-get": {}}
35 self.environment = {
36 "JUJU_ENV_UUID": str(uuid4()),
37- "JUJU_API_ADRESSES": "juju.example.com:12345"}
38+ "JUJU_API_ADDRESSES": "juju.example.com:12345"}
39 self.logs = []
40
41 def log(self, message):
42@@ -168,12 +168,12 @@
43 self.landscape_broker.config.account_name = "account1"
44 self.landscape_broker.config.write()
45
46- def test_writes_juju_json(self):
47+ def test_writes_juju_1_json(self):
48 """
49- When the hook runs, the environment UUID, which unit the client
50- is managed, the Juju API addresses, and the unit's private
51- address are written to the juju-info.json file inside the
52- client's data path.
53+ When the hook runs in Juju 1, the environment UUID, which unit the
54+ client is managed, the Juju API addresses, and the unit's
55+ private address are written to the juju-info.json file inside
56+ the client's data path.
57 """
58 self.juju_broker.environment.update({
59 "JUJU_ENV_UUID": "uuid1",
60@@ -184,9 +184,30 @@
61 juju_info_path = self.landscape_broker.juju_filename
62 juju_info = json.loads(read_file(juju_info_path))
63 self.assertEqual(
64- {"environment-uuid": "uuid1",
65- "machine-id": "1",
66- "api-addresses": "10.0.0.1:1234"},
67+ {u"environment-uuid": u"uuid1",
68+ u"machine-id": u"1",
69+ u"api-addresses": u"10.0.0.1:1234"},
70+ juju_info)
71+
72+ def test_writes_juju_2_json(self):
73+ """
74+ When the hook runs in Juju 2, the model UUID, which unit the
75+ client is managed, the Juju API addresses, and the unit's
76+ private address are written to the juju-info.json file inside
77+ the client's data path.
78+ """
79+ self.juju_broker.environment.update({
80+ "JUJU_MODEL_UUID": "uuid2",
81+ "JUJU_API_ADDRESSES": "10.0.0.1:1234"})
82+ hooks.container_relation_joined(juju_broker=self.juju_broker,
83+ landscape_broker=self.landscape_broker)
84+
85+ juju_info_path = self.landscape_broker.juju_filename
86+ juju_info = json.loads(read_file(juju_info_path))
87+ self.assertEqual(
88+ {u"environment-uuid": u"uuid2",
89+ u"machine-id": u"1",
90+ u"api-addresses": u"10.0.0.1:1234"},
91 juju_info)
92
93 def test_registers_after_juju_info_is_written(self):
94@@ -474,7 +495,6 @@
95 "mykey", self.landscape_broker.config.registration_key)
96 self.assertEqual(
97 "http://127.0.0.1", self.landscape_broker.config.ping_url)
98-
99
100
101 class RegistrationRelationJoinedTest(HookTestCase):

Subscribers

People subscribed via source and target branches

to all changes: