Merge lp:~free.ekanayaka/charms/trusty/landscape-client/machine-id-charm-info into lp:~landscape/charms/trusty/landscape-client/trunk

Proposed by Free Ekanayaka
Status: Merged
Approved by: Free Ekanayaka
Approved revision: 48
Merged at revision: 45
Proposed branch: lp:~free.ekanayaka/charms/trusty/landscape-client/machine-id-charm-info
Merge into: lp:~landscape/charms/trusty/landscape-client/trunk
Diff against target: 98 lines (+25/-2)
4 files modified
hooks/common.py (+13/-0)
hooks/hooks.py (+1/-0)
hooks/install.py (+6/-2)
hooks/test_hooks.py (+5/-0)
To merge this branch: bzr merge lp:~free.ekanayaka/charms/trusty/landscape-client/machine-id-charm-info
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
Adam Collard (community) Approve
Review via email: mp+233059@code.launchpad.net

This proposal supersedes a proposal from 2014-08-28.

Description of the change

This branch adds the machine ID to the Juju info json file, so it can be grabbed by the client and sent to the server at registration. See also:

https://code.launchpad.net/~free.ekanayaka/landscape-client/juju-machine-registration/+merge/232531

and

https://code.launchpad.net/~free.ekanayaka/landscape/handle-machine-id-registration/+merge/232535

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

Looks good, +1

#1:
+ return match[(len(pattern) - 1):].replace("-", "/")

Please add a comment for this line, it took me a bit to understand the reason for the replace.

review: Approve
Revision history for this message
Adam Collard (adam-collard) wrote : Posted in a previous version of this proposal

N/F because of the glob() usage in dpkg -i

review: Needs Fixing
Revision history for this message
Adam Collard (adam-collard) wrote : Posted in a previous version of this proposal

N/F because of the glob() usage in dpkg -i

review: Needs Fixing
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote : Posted in a previous version of this proposal

#1

Fixed.

Adam: should be all fixed/replied.

Revision history for this message
Adam Collard (adam-collard) wrote : Posted in a previous version of this proposal

Free: replied inline.

Revision history for this message
Adam Collard (adam-collard) wrote : Posted in a previous version of this proposal

Typo in the comment, otherwise +1

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

Still got the typo that should be "Sniff". +1

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

+1!

review: Approve
48. By Free Ekanayaka

Fix typo

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-08-28 09:54:11 +0000
3+++ hooks/common.py 2014-09-02 13:55:51 +0000
4@@ -30,6 +30,19 @@
5 """Get relation configuration from Juju."""
6 return self._run_juju_tool("relation-get")
7
8+ def get_machine_id(self):
9+ """Return the Juju machine ID of this unit."""
10+ # XXX once #1359714 is fixed this method can be dropped and we can use
11+ # the JUJU_MACHINE_ID environment variable.
12+
13+ # Sniff the value of the machine ID by looking at the name of the
14+ # directory where hooks live. It will be something like
15+ # 'machine-0-lxc-1'.
16+ pattern = "../../machine-*"
17+ match = glob(pattern)[0]
18+ dirname = os.path.basename(match)
19+ return dirname.lstrip("machine-").replace("-", "/")
20+
21 def get_service_config(self):
22 """Get service configuration from Juju."""
23 return self._run_juju_tool("config-get")
24
25=== modified file 'hooks/hooks.py'
26--- hooks/hooks.py 2014-08-28 09:54:11 +0000
27+++ hooks/hooks.py 2014-09-02 13:55:51 +0000
28@@ -77,6 +77,7 @@
29 juju_info = {
30 "environment-uuid": juju_broker.environment.get("JUJU_ENV_UUID"),
31 "unit-name": remote_unit_name,
32+ "machine-id": juju_broker.get_machine_id(),
33 "api-addresses": juju_broker.environment.get("JUJU_API_ADDRESSES"),
34 "private-address": relation_conf.get("private-address")}
35
36
37=== modified file 'hooks/install.py'
38--- hooks/install.py 2014-08-28 10:09:11 +0000
39+++ hooks/install.py 2014-09-02 13:55:51 +0000
40@@ -8,6 +8,9 @@
41 import os
42 import subprocess
43 import sys
44+
45+from glob import glob
46+
47 from charmhelpers.core.hookenv import (
48 Hooks, UnregisteredHookError, log)
49 from charmhelpers.fetch import (
50@@ -43,6 +46,7 @@
51 data_path])
52
53
54+
55 def build_from_launchpad(url):
56 """The charm will install the code from the passed lp branch.
57 """
58@@ -55,8 +59,8 @@
59 subprocess.check_call(["make", "package"], env=env)
60 #TODO: The following call should be retried (potential race condition to
61 # acquire the dpkg lock).
62- subprocess.call(["dpkg", "-i", "../landscape-client_*.deb",
63- "../landscape-common_*.deb"])
64+ subprocess.call(["dpkg", "-i", glob("../landscape-client_*.deb")[0],
65+ glob("../landscape-common_*.deb")[0]])
66 # The _run_apt_command will ensure the command is retried in case we cannot
67 # acquire the lock for some reason.
68 _run_apt_command(["apt-get", "-f", "install"], fatal=True)
69
70=== modified file 'hooks/test_hooks.py'
71--- hooks/test_hooks.py 2014-08-28 09:54:11 +0000
72+++ hooks/test_hooks.py 2014-09-02 13:55:51 +0000
73@@ -30,6 +30,9 @@
74 def log(self, message):
75 self.logs.append(message)
76
77+ def get_machine_id(self):
78+ return "1"
79+
80 def _run_juju_tool(self, command):
81 """Override _run_juju_tool not not execute any commands."""
82 return self.commands[command]
83@@ -99,6 +102,7 @@
84 single JSON file.
85 """
86 juju_info = {"juju-env-uuid": "0afcd28d-6263-43fb-8131-afa696a984f8",
87+ "juju-machine-id": "1",
88 "juju-unit-name": "postgresql/0",
89 "juju-api-addresses": "10.0.3.1:17070",
90 "juju-private-address": "10.0.3.205"}
91@@ -184,6 +188,7 @@
92 juju_info = json.loads(read_file(juju_info_path))
93 self.assertEqual(
94 {"environment-uuid": "uuid1",
95+ "machine-id": "1",
96 "unit-name": "unit/0",
97 "api-addresses": "10.0.0.1:1234",
98 "private-address": "10.0.0.99"},

Subscribers

People subscribed via source and target branches

to all changes: