Merge lp:~tribaal/charms/trusty/landscape-client/fix-unit-tests-take-two into lp:charms/trusty/landscape-client

Proposed by Chris Glass
Status: Merged
Merged at revision: 44
Proposed branch: lp:~tribaal/charms/trusty/landscape-client/fix-unit-tests-take-two
Merge into: lp:charms/trusty/landscape-client
Diff against target: 74 lines (+13/-4)
4 files modified
hooks/common.py (+4/-1)
hooks/hooks.py (+4/-3)
hooks/install.py (+1/-0)
hooks/test_hooks.py (+4/-0)
To merge this branch: bzr merge lp:~tribaal/charms/trusty/landscape-client/fix-unit-tests-take-two
Reviewer Review Type Date Requested Status
Adam Collard Approve
Free Ekanayaka (community) Approve
Review via email: mp+232534@code.launchpad.net

Description of the change

Fixes unit tests by making unit_name lazy instead of reading the env var at import time.

To post a comment you must log in.
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Tests pass fine here and the diff looks good. +1!

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

One lint issue:

=== pep8 ===

hooks/install.py:45:1: E302 expected 2 blank lines, found 1

Otherwise a big +1

review: Approve
45. By Chris Glass

Lint fix

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-06-23 11:25:40 +0000
+++ hooks/common.py 2014-08-28 10:09:37 +0000
@@ -55,7 +55,10 @@
5555
56 def __init__(self):56 def __init__(self):
57 self.config = Configuration()57 self.config = Configuration()
58 self.local_unit = local_unit()58
59 @property
60 def local_unit(self):
61 return local_unit()
5962
60 def update_client_config(self, service_config, try_to_register=True):63 def update_client_config(self, service_config, try_to_register=True):
61 """Update the client config.64 """Update the client config.
6265
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2014-08-22 09:15:59 +0000
+++ hooks/hooks.py 2014-08-28 10:09:37 +0000
@@ -6,7 +6,7 @@
6import base646import base64
77
8from charmhelpers.core.hookenv import (8from charmhelpers.core.hookenv import (
9 Hooks, UnregisteredHookError, log, local_unit)9 Hooks, UnregisteredHookError, log)
10from shutil import rmtree10from shutil import rmtree
11from subprocess import CalledProcessError11from subprocess import CalledProcessError
1212
@@ -41,7 +41,7 @@
41 @param relation_data: data from the context of a relation, it should41 @param relation_data: data from the context of a relation, it should
42 match the data in the config42 match the data in the config
43 """43 """
44 log("In config-changed for %s" % local_unit())44 juju_broker.log("In config-changed for %s" % landscape_broker.local_unit)
45 if relation_data is None:45 if relation_data is None:
46 relation_data = {}46 relation_data = {}
47 service_config = juju_broker.get_service_config()47 service_config = juju_broker.get_service_config()
@@ -67,7 +67,8 @@
67@hooks.hook("container-relation-joined", "ceph-client-relation-joined")67@hooks.hook("container-relation-joined", "ceph-client-relation-joined")
68def container_relation_joined(juju_broker=JUJU_BROKER,68def container_relation_joined(juju_broker=JUJU_BROKER,
69 landscape_broker=LANDSCAPE_BROKER):69 landscape_broker=LANDSCAPE_BROKER):
70 log("In container-relation-joined for %s" % local_unit())70 juju_broker.log("In container-relation-joined for %s"
71 "" % landscape_broker.local_unit)
71 landscape_broker.config.reload()72 landscape_broker.config.reload()
72 relation_conf = juju_broker.get_relation_config()73 relation_conf = juju_broker.get_relation_config()
73 remote_unit_name = juju_broker.environment.get("JUJU_REMOTE_UNIT")74 remote_unit_name = juju_broker.environment.get("JUJU_REMOTE_UNIT")
7475
=== modified file 'hooks/install.py'
--- hooks/install.py 2014-06-17 16:45:42 +0000
+++ hooks/install.py 2014-08-28 10:09:37 +0000
@@ -42,6 +42,7 @@
42 "install", "-o", "landscape", "-g", "root", "-m", "755", "-d",42 "install", "-o", "landscape", "-g", "root", "-m", "755", "-d",
43 data_path])43 data_path])
4444
45
45def build_from_launchpad(url):46def build_from_launchpad(url):
46 """The charm will install the code from the passed lp branch.47 """The charm will install the code from the passed lp branch.
47 """48 """
4849
=== modified file 'hooks/test_hooks.py'
--- hooks/test_hooks.py 2014-06-13 09:18:29 +0000
+++ hooks/test_hooks.py 2014-08-28 10:09:37 +0000
@@ -47,6 +47,10 @@
47 def clear_registration(self):47 def clear_registration(self):
48 self.cleared_registration = True48 self.cleared_registration = True
4949
50 @property
51 def local_unit(self):
52 return "test-unit"
53
5054
51class HookTestCase(TestCase):55class HookTestCase(TestCase):
52 """Base test class for testing hooks."""56 """Base test class for testing hooks."""

Subscribers

People subscribed via source and target branches