Merge lp:~chad.smith/charms/trusty/landscape-client/landscape-client-scrub-whitespace into lp:charms/trusty/landscape-client

Proposed by Chad Smith
Status: Merged
Approved by: Chad Smith
Approved revision: 55
Merged at revision: 55
Proposed branch: lp:~chad.smith/charms/trusty/landscape-client/landscape-client-scrub-whitespace
Merge into: lp:charms/trusty/landscape-client
Diff against target: 44 lines (+22/-1)
2 files modified
hooks/hooks.py (+1/-1)
hooks/test_hooks.py (+21/-0)
To merge this branch: bzr merge lp:~chad.smith/charms/trusty/landscape-client/landscape-client-scrub-whitespace
Reviewer Review Type Date Requested Status
Bogdana Vereha (community) Approve
Adam Collard Approve
Review via email: mp+290525@code.launchpad.net

Commit message

landscape-client charm now strips leading and trailing whitespace from any provided service config settings provided by juju set X=""" Y """. Helps with include-file:// juju-deployer directives that may contain newlines.

Description of the change

landscape-client charm now strips leading and trailing whitespace from any provided service config settings provided by juju.

For dev testing:
juju switch local
juju bootstrap

# setup a landscape account with freshdata
# set account registration key to asdfasdf (example IP of local 'OPL': 192.168.2.11)
echo -e "asdfasdf\n" > /tmp/my-regkey

Use a bundle something like the following:

local-client:
    series: trusty
    services:
        ubuntu:
            charm: cs:trusty/ubuntu-1
            num_units: 1
        landscape-client:
            branch: lp:~chad.smith/charms/trusty/landscape-client/landscape-client-scrub-whitespace
            num_units: 0
            options:
                account-name: onward
                url: http://192.168.2.11:8080/message-system
                ping-url: http://192.168.2.11:8081/ping
                registration-key: include-file:///tmp/my-regkey
    relations:
        - [ubuntu, landscape-client]

# client should register despite the newline in the /tmp/my-regkey
# juju ssh ubuntu/0 'sudo cat /etc/landscape/client.conf'
# ensure registration-key does not contain a newline, like the following:
registration_key = """asdfasdf
"""

To post a comment you must log in.
Revision history for this message
Adam Collard (adam-collard) wrote :

Looks good! +1

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

+1

review: Approve

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 2014-09-25 07:00:05 +0000
3+++ hooks/hooks.py 2016-03-30 20:48:35 +0000
4@@ -46,7 +46,7 @@
5 service_config = juju_broker.get_service_config()
6 # Only update client config with service configs that have been set
7 service_config = dict(
8- (key, value) for key, value in service_config.iteritems()
9+ (key, value.strip()) for key, value in service_config.iteritems()
10 if value is not None)
11 relation_data.update(service_config)
12 if relation_data.get("ssl-public-key", "").startswith("base64:"):
13
14=== modified file 'hooks/test_hooks.py'
15--- hooks/test_hooks.py 2014-09-25 07:00:05 +0000
16+++ hooks/test_hooks.py 2016-03-30 20:48:35 +0000
17@@ -410,6 +410,27 @@
18 with open(hooks.CERT_FILE) as fh:
19 self.assertEqual("foo", fh.read())
20
21+ def test_whitespace_removed_from_config_settings(self):
22+ """Leading and trailing whitespace is removed from config settings"""
23+ self.juju_broker.commands["config-get"] = {
24+ "ssl-public-key": " base64:%s" % "foo".encode("base64"),
25+ "account-name": " standalone\t",
26+ "registration-key": " mykey\n",
27+ "ping-url": " \thttp://127.0.0.1\n "}
28+ hooks.config_changed(juju_broker=self.juju_broker,
29+ landscape_broker=self.landscape_broker)
30+ self.assertEqual(
31+ hooks.CERT_FILE, self.landscape_broker.config.ssl_public_key)
32+ with open(hooks.CERT_FILE) as fh:
33+ self.assertEqual("foo", fh.read())
34+ self.assertEqual(
35+ "standalone", self.landscape_broker.config.account_name)
36+ self.assertEqual(
37+ "mykey", self.landscape_broker.config.registration_key)
38+ self.assertEqual(
39+ "http://127.0.0.1", self.landscape_broker.config.ping_url)
40+
41+
42
43 class RegistrationRelationJoinedTest(HookTestCase):
44 """Test for the registration-relation-joined hook."""

Subscribers

People subscribed via source and target branches

to all changes: