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

Proposed by Free Ekanayaka
Status: Superseded
Proposed branch: lp:~free.ekanayaka/charms/trusty/landscape-client/machine-id-charm-info
Merge into: lp:charms/trusty/landscape-client
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
Adam Collard Approve
Alberto Donato (community) Approve
Review via email: mp+232544@code.launchpad.net

This proposal has been superseded by a proposal from 2014-09-02.

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 :

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 :

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

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

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

review: Needs Fixing
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

#1

Fixed.

Adam: should be all fixed/replied.

46. By Free Ekanayaka

Address review comments

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

Free: replied inline.

47. By Free Ekanayaka

Fix formatting

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

Typo in the comment, otherwise +1

review: Approve
48. By Free Ekanayaka

Fix typo

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hooks/common.py'
--- hooks/common.py 2014-08-28 09:54:11 +0000
+++ hooks/common.py 2014-09-02 09:16:56 +0000
@@ -30,6 +30,19 @@
30 """Get relation configuration from Juju."""30 """Get relation configuration from Juju."""
31 return self._run_juju_tool("relation-get")31 return self._run_juju_tool("relation-get")
3232
33 def get_machine_id(self):
34 """Return the Juju machine ID of this unit."""
35 # XXX once #1359714 is fixed this method can be dropped and we can use
36 # the JUJU_MACHINE_ID environment variable.
37
38 # Snif the value of the machine ID by looking at the name of the
39 # directory where hooks live. It will be something like
40 # 'machine-0-lxc-1'.
41 pattern = "../../machine-*"
42 match = glob(pattern)[0]
43 dirname = os.path.basename(match)
44 return dirname.lstrip("machine-").replace("-", "/")
45
33 def get_service_config(self):46 def get_service_config(self):
34 """Get service configuration from Juju."""47 """Get service configuration from Juju."""
35 return self._run_juju_tool("config-get")48 return self._run_juju_tool("config-get")
3649
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2014-08-28 09:54:11 +0000
+++ hooks/hooks.py 2014-09-02 09:16:56 +0000
@@ -77,6 +77,7 @@
77 juju_info = {77 juju_info = {
78 "environment-uuid": juju_broker.environment.get("JUJU_ENV_UUID"),78 "environment-uuid": juju_broker.environment.get("JUJU_ENV_UUID"),
79 "unit-name": remote_unit_name,79 "unit-name": remote_unit_name,
80 "machine-id": juju_broker.get_machine_id(),
80 "api-addresses": juju_broker.environment.get("JUJU_API_ADDRESSES"),81 "api-addresses": juju_broker.environment.get("JUJU_API_ADDRESSES"),
81 "private-address": relation_conf.get("private-address")}82 "private-address": relation_conf.get("private-address")}
8283
8384
=== modified file 'hooks/install.py'
--- hooks/install.py 2014-08-28 10:09:11 +0000
+++ hooks/install.py 2014-09-02 09:16:56 +0000
@@ -8,6 +8,9 @@
8import os8import os
9import subprocess9import subprocess
10import sys10import sys
11
12from glob import glob
13
11from charmhelpers.core.hookenv import (14from charmhelpers.core.hookenv import (
12 Hooks, UnregisteredHookError, log)15 Hooks, UnregisteredHookError, log)
13from charmhelpers.fetch import (16from charmhelpers.fetch import (
@@ -43,6 +46,7 @@
43 data_path])46 data_path])
4447
4548
49
46def build_from_launchpad(url):50def build_from_launchpad(url):
47 """The charm will install the code from the passed lp branch.51 """The charm will install the code from the passed lp branch.
48 """52 """
@@ -55,8 +59,8 @@
55 subprocess.check_call(["make", "package"], env=env)59 subprocess.check_call(["make", "package"], env=env)
56 #TODO: The following call should be retried (potential race condition to60 #TODO: The following call should be retried (potential race condition to
57 # acquire the dpkg lock).61 # acquire the dpkg lock).
58 subprocess.call(["dpkg", "-i", "../landscape-client_*.deb",62 subprocess.call(["dpkg", "-i", glob("../landscape-client_*.deb")[0],
59 "../landscape-common_*.deb"])63 glob("../landscape-common_*.deb")[0]])
60 # The _run_apt_command will ensure the command is retried in case we cannot64 # The _run_apt_command will ensure the command is retried in case we cannot
61 # acquire the lock for some reason.65 # acquire the lock for some reason.
62 _run_apt_command(["apt-get", "-f", "install"], fatal=True)66 _run_apt_command(["apt-get", "-f", "install"], fatal=True)
6367
=== modified file 'hooks/test_hooks.py'
--- hooks/test_hooks.py 2014-08-28 09:54:11 +0000
+++ hooks/test_hooks.py 2014-09-02 09:16:56 +0000
@@ -30,6 +30,9 @@
30 def log(self, message):30 def log(self, message):
31 self.logs.append(message)31 self.logs.append(message)
3232
33 def get_machine_id(self):
34 return "1"
35
33 def _run_juju_tool(self, command):36 def _run_juju_tool(self, command):
34 """Override _run_juju_tool not not execute any commands."""37 """Override _run_juju_tool not not execute any commands."""
35 return self.commands[command]38 return self.commands[command]
@@ -99,6 +102,7 @@
99 single JSON file.102 single JSON file.
100 """103 """
101 juju_info = {"juju-env-uuid": "0afcd28d-6263-43fb-8131-afa696a984f8",104 juju_info = {"juju-env-uuid": "0afcd28d-6263-43fb-8131-afa696a984f8",
105 "juju-machine-id": "1",
102 "juju-unit-name": "postgresql/0",106 "juju-unit-name": "postgresql/0",
103 "juju-api-addresses": "10.0.3.1:17070",107 "juju-api-addresses": "10.0.3.1:17070",
104 "juju-private-address": "10.0.3.205"}108 "juju-private-address": "10.0.3.205"}
@@ -184,6 +188,7 @@
184 juju_info = json.loads(read_file(juju_info_path))188 juju_info = json.loads(read_file(juju_info_path))
185 self.assertEqual(189 self.assertEqual(
186 {"environment-uuid": "uuid1",190 {"environment-uuid": "uuid1",
191 "machine-id": "1",
187 "unit-name": "unit/0",192 "unit-name": "unit/0",
188 "api-addresses": "10.0.0.1:1234",193 "api-addresses": "10.0.0.1:1234",
189 "private-address": "10.0.0.99"},194 "private-address": "10.0.0.99"},

Subscribers

People subscribed via source and target branches